A class for storing and manipulating a source code file. More...
Classes | |
| class | Iterator |
| Iterates the text in a CodeDocument. More... | |
| class | Listener |
| An object that receives callbacks from the CodeDocument when its text changes. More... | |
| class | Position |
| A position in a code document. More... | |
Public Member Functions | |
| CodeDocument () | |
| Creates a new, empty document. | |
| ~CodeDocument () | |
| Destructor. | |
| const String | getAllContent () const throw () |
| Returns the full text of the document. | |
| const String | getTextBetween (const Position &start, const Position &end) const throw () |
| Returns a section of the document's text. | |
| const String | getLine (int lineIndex) const throw () |
| Returns a line from the document. | |
| int | getNumCharacters () const throw () |
| Returns the number of characters in the document. | |
| int | getNumLines () const throw () |
| Returns the number of lines in the document. | |
| int | getMaximumLineLength () throw () |
| Returns the number of characters in the longest line of the document. | |
| void | deleteSection (const Position &startPosition, const Position &endPosition) |
| Deletes a section of the text. | |
| void | insertText (const Position &position, const String &text) |
| Inserts some text into the document at a given position. | |
| void | replaceAllContent (const String &newContent) |
| Clears the document and replaces it with some new text. | |
| bool | loadFromStream (InputStream &stream) |
| Replaces the editor's contents with the contents of a stream. | |
| bool | writeToStream (OutputStream &stream) |
| Writes the editor's current contents to a stream. | |
| const String | getNewLineCharacters () const throw () |
| Returns the preferred new-line characters for the document. | |
| void | setNewLineCharacters (const String &newLine) throw () |
| Sets the new-line characters that the document should use. | |
| void | newTransaction () |
| Begins a new undo transaction. | |
| void | undo () |
| Undo the last operation. | |
| void | redo () |
| Redo the last operation. | |
| void | clearUndoHistory () |
| Clears the undo history. | |
| UndoManager & | getUndoManager () throw () |
| Returns the document's UndoManager. | |
| void | setSavePoint () throw () |
| Makes a note that the document's current state matches the one that is saved. | |
| bool | hasChangedSinceSavePoint () const throw () |
| Returns true if the state of the document differs from the state it was in when setSavePoint() was last called. | |
| const Position | findWordBreakAfter (const Position &position) const throw () |
| Searches for a word-break. | |
| const Position | findWordBreakBefore (const Position &position) const throw () |
| Searches for a word-break. | |
| void | addListener (Listener *listener) throw () |
| Registers a listener object to receive callbacks when the document changes. | |
| void | removeListener (Listener *listener) throw () |
| Deregisters a listener. | |
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.
| CodeDocument::CodeDocument | ( | ) |
Creates a new, empty document.
| CodeDocument::~CodeDocument | ( | ) |
Destructor.
| const String CodeDocument::getAllContent | ( | ) | const throw () |
Returns the full text of the document.
| const String CodeDocument::getTextBetween | ( | const Position & | start, | |
| const Position & | end | |||
| ) | const throw () |
Returns a section of the document's text.
| const String CodeDocument::getLine | ( | int | lineIndex | ) | const throw () |
Returns a line from the document.
| int CodeDocument::getNumCharacters | ( | ) | const throw () |
Returns the number of characters in the document.
| int CodeDocument::getNumLines | ( | ) | const throw () |
Returns the number of lines in the document.
| int CodeDocument::getMaximumLineLength | ( | ) | throw () |
Returns the number of characters in the longest line of the document.
Deletes a section of the text.
This operation is undoable.
Inserts some text into the document at a given position.
This operation is undoable.
| void 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.
| bool 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.
| bool CodeDocument::writeToStream | ( | OutputStream & | stream | ) |
Writes the editor's current contents to a stream.
| const String CodeDocument::getNewLineCharacters | ( | ) | const throw () |
Returns the preferred new-line characters for the document.
This will be either "\n", "\r\n", or (rarely) "\r".
| void CodeDocument::setNewLineCharacters | ( | const String & | newLine | ) | throw () |
Sets the new-line characters that the document should use.
The string must be either "\n", "\r\n", or (rarely) "\r".
| void 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.
| void CodeDocument::undo | ( | ) |
Undo the last operation.
| void CodeDocument::redo | ( | ) |
Redo the last operation.
| void CodeDocument::clearUndoHistory | ( | ) |
Clears the undo history.
| UndoManager& CodeDocument::getUndoManager | ( | ) | throw () |
Returns the document's UndoManager.
| void CodeDocument::setSavePoint | ( | ) | throw () |
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.
| bool CodeDocument::hasChangedSinceSavePoint | ( | ) | const throw () |
Returns true if the state of the document differs from the state it was in when setSavePoint() was last called.
Searches for a word-break.
Searches for a word-break.
| void CodeDocument::addListener | ( | Listener * | listener | ) | throw () |
Registers a listener object to receive callbacks when the document changes.
If the listener is already registered, this method has no effect.
| void CodeDocument::removeListener | ( | Listener * | listener | ) | throw () |
Deregisters a listener.
1.6.3