LMMS
Loading...
Searching...
No Matches
juce::CodeDocument Class Reference

#include <juce_CodeDocument.h>

Classes

class  Position
class  Listener
class  Iterator
struct  InsertAction
struct  DeleteAction

Public Member Functions

 CodeDocument ()
 ~CodeDocument ()
String getAllContent () const
String getTextBetween (const Position &start, const Position &end) const
String getLine (int lineIndex) const noexcept
int getNumCharacters () const noexcept
int getNumLines () const noexcept
int getMaximumLineLength () noexcept
void deleteSection (const Position &startPosition, const Position &endPosition)
void deleteSection (int startIndex, int endIndex)
void insertText (const Position &position, const String &text)
void insertText (int insertIndex, const String &text)
void replaceSection (int startIndex, int endIndex, const String &newText)
void replaceAllContent (const String &newContent)
void applyChanges (const String &newContent)
bool loadFromStream (InputStream &stream)
bool writeToStream (OutputStream &stream)
String getNewLineCharacters () const noexcept
void setNewLineCharacters (const String &newLineCharacters) noexcept
void newTransaction ()
void undo ()
void redo ()
void clearUndoHistory ()
UndoManagergetUndoManager () noexcept
void setSavePoint () noexcept
bool hasChangedSinceSavePoint () const noexcept
Position findWordBreakAfter (const Position &position) const noexcept
Position findWordBreakBefore (const Position &position) const noexcept
void findTokenContaining (const Position &pos, Position &start, Position &end) const noexcept
void findLineContaining (const Position &pos, Position &start, Position &end) const noexcept
void addListener (Listener *listener)
void removeListener (Listener *listener)

Private Member Functions

void insert (const String &text, int insertPos, bool undoable)
void remove (int startPos, int endPos, bool undoable)
void checkLastLineStatus ()

Private Attributes

OwnedArray< CodeDocumentLinelines
Array< Position * > positionsToMaintain
UndoManager undoManager
int currentActionIndex = 0
int indexOfSavedState = -1
int maximumLineLength = -1
ListenerList< Listenerlisteners
String newLineChars { "\r\n" }

Friends

class Iterator
class Position

Detailed Description

A class for storing and manipulating a source code file.

When using a CodeEditorComponent, it takes one of these as its source object.

The CodeDocument stores its content as an array of lines, which makes it quick to insert and delete.

See also
CodeEditorComponent

@tags{GUI}

Constructor & Destructor Documentation

◆ CodeDocument()

juce::CodeDocument::CodeDocument ( )

Creates a new, empty document.

◆ ~CodeDocument()

juce::CodeDocument::~CodeDocument ( )

Destructor.

Member Function Documentation

◆ addListener()

void juce::CodeDocument::addListener ( CodeDocument::Listener * l)

Registers a listener object to receive callbacks when the document changes. If the listener is already registered, this method has no effect.

See also
removeListener

◆ applyChanges()

void juce::CodeDocument::applyChanges ( const String & newContent)

Analyses the changes between the current content and some new text, and applies those changes.

◆ checkLastLineStatus()

void juce::CodeDocument::checkLastLineStatus ( )
private

◆ clearUndoHistory()

void juce::CodeDocument::clearUndoHistory ( )

Clears the undo history.

See also
UndoManager::clearUndoHistory

◆ deleteSection() [1/2]

void juce::CodeDocument::deleteSection ( const Position & startPosition,
const Position & endPosition )

Deletes a section of the text. This operation is undoable.

◆ deleteSection() [2/2]

void juce::CodeDocument::deleteSection ( int startIndex,
int endIndex )

Deletes a section of the text. This operation is undoable.

◆ findLineContaining()

void juce::CodeDocument::findLineContaining ( const Position & pos,
Position & start,
Position & end ) const
noexcept

Finds the line that contains the given position.

◆ findTokenContaining()

void juce::CodeDocument::findTokenContaining ( const Position & pos,
Position & start,
Position & end ) const
noexcept

Finds the token that contains the given position.

◆ findWordBreakAfter()

CodeDocument::Position juce::CodeDocument::findWordBreakAfter ( const Position & position) const
noexcept

Searches for a word-break.

◆ findWordBreakBefore()

CodeDocument::Position juce::CodeDocument::findWordBreakBefore ( const Position & position) const
noexcept

Searches for a word-break.

◆ getAllContent()

String juce::CodeDocument::getAllContent ( ) const

Returns the full text of the document.

◆ getLine()

String juce::CodeDocument::getLine ( int lineIndex) const
noexcept

Returns a line from the document.

◆ getMaximumLineLength()

int juce::CodeDocument::getMaximumLineLength ( )
noexcept

Returns the number of characters in the longest line of the document.

◆ getNewLineCharacters()

String juce::CodeDocument::getNewLineCharacters ( ) const
inlinenoexcept

Returns the preferred new-line characters for the document. This will be either "\\n", "\\r\\n", or (rarely) "\\r".

See also
setNewLineCharacters

◆ getNumCharacters()

int juce::CodeDocument::getNumCharacters ( ) const
noexcept

Returns the number of characters in the document.

◆ getNumLines()

int juce::CodeDocument::getNumLines ( ) const
inlinenoexcept

Returns the number of lines in the document.

◆ getTextBetween()

String juce::CodeDocument::getTextBetween ( const Position & start,
const Position & end ) const

Returns a section of the document's text.

◆ getUndoManager()

UndoManager & juce::CodeDocument::getUndoManager ( )
inlinenoexcept

Returns the document's UndoManager

◆ hasChangedSinceSavePoint()

bool juce::CodeDocument::hasChangedSinceSavePoint ( ) const
noexcept

Returns true if the state of the document differs from the state it was in when setSavePoint() was last called.

See also
setSavePoint

◆ insert()

void juce::CodeDocument::insert ( const String & text,
int insertPos,
bool undoable )
private

◆ insertText() [1/2]

void juce::CodeDocument::insertText ( const Position & position,
const String & text )

Inserts some text into the document at a given position. This operation is undoable.

◆ insertText() [2/2]

void juce::CodeDocument::insertText ( int insertIndex,
const String & text )

Inserts some text into the document at a given position. This operation is undoable.

◆ loadFromStream()

bool juce::CodeDocument::loadFromStream ( InputStream & stream)

Replaces the editor's contents with the contents of a stream. This will also reset the undo history and save point marker.

◆ newTransaction()

void juce::CodeDocument::newTransaction ( )

Begins a new undo transaction.

The document itself will not call this internally, so relies on whatever is using the document to periodically call this to break up the undo sequence into sensible chunks.

See also
UndoManager::beginNewTransaction

◆ redo()

void juce::CodeDocument::redo ( )

Redo the last operation.

See also
UndoManager::redo

◆ remove()

void juce::CodeDocument::remove ( int startPos,
int endPos,
bool undoable )
private

◆ removeListener()

void juce::CodeDocument::removeListener ( CodeDocument::Listener * l)

Deregisters a listener.

See also
addListener

◆ replaceAllContent()

void juce::CodeDocument::replaceAllContent ( const String & newContent)

Clears the document and replaces it with some new text.

This operation is undoable - if you're trying to completely reset the document, you might want to also call clearUndoHistory() and setSavePoint() after using this method.

◆ replaceSection()

void juce::CodeDocument::replaceSection ( int startIndex,
int endIndex,
const String & newText )

Replaces a section of the text with a new string. This operation is undoable.

◆ setNewLineCharacters()

void juce::CodeDocument::setNewLineCharacters ( const String & newLineCharacters)
noexcept

Sets the new-line characters that the document should use. The string must be either "\\n", "\\r\\n", or (rarely) "\\r".

See also
getNewLineCharacters

◆ setSavePoint()

void juce::CodeDocument::setSavePoint ( )
noexcept

Makes a note that the document's current state matches the one that is saved.

After this has been called, hasChangedSinceSavePoint() will return false until the document has been altered, and then it'll start returning true. If the document is altered, but then undone until it gets back to this state, hasChangedSinceSavePoint() will again return false.

See also
hasChangedSinceSavePoint

◆ undo()

void juce::CodeDocument::undo ( )

Undo the last operation.

See also
UndoManager::undo

◆ writeToStream()

bool juce::CodeDocument::writeToStream ( OutputStream & stream)

Writes the editor's current contents to a stream.

◆ Iterator

friend class Iterator
friend

◆ Position

friend class Position
friend

Member Data Documentation

◆ currentActionIndex

int juce::CodeDocument::currentActionIndex = 0
private

◆ indexOfSavedState

int juce::CodeDocument::indexOfSavedState = -1
private

◆ lines

OwnedArray<CodeDocumentLine> juce::CodeDocument::lines
private

◆ listeners

ListenerList<Listener> juce::CodeDocument::listeners
private

◆ maximumLineLength

int juce::CodeDocument::maximumLineLength = -1
private

◆ newLineChars

String juce::CodeDocument::newLineChars { "\r\n" }
private

◆ positionsToMaintain

Array<Position*> juce::CodeDocument::positionsToMaintain
private

◆ undoManager

UndoManager juce::CodeDocument::undoManager
private

The documentation for this class was generated from the following files: