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

## 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

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

- juce_gui_extra/code_editor/juce_CodeDocument.h

## Classes

class | Position
| A position in a code document. More...
class | Listener
| An object that receives callbacks from the CodeDocument when its text changes. More...
class | Iterator
| Iterates the text in a CodeDocument. More...

## Public Member Functions

| CodeDocument ()
| Creates a new, empty document.
| ~CodeDocument ()
| Destructor.
String | getAllContent () const
| Returns the full text of the document.
String | getTextBetween (const Position &start, const Position &end) const
| Returns a section of the document's text.
String | getLine (int lineIndex) const noexcept
| Returns a line from the document.
int | getNumCharacters () const noexcept
| Returns the number of characters in the document.
int | getNumLines () const noexcept
| Returns the number of lines in the document.
int | getMaximumLineLength () noexcept
| 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 | deleteSection (int startIndex, int endIndex)
| 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 | insertText (int insertIndex, const String &text)
| Inserts some text into the document at a given position.
void | replaceSection (int startIndex, int endIndex, const String &newText)
| Replaces a section of the text with a new string.
void | replaceAllContent (const String &newContent)
| Clears the document and replaces it with some new text.
void | applyChanges (const String &newContent)
| Analyses the changes between the current content and some new text, and applies those changes.
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.
String | getNewLineCharacters () const noexcept
| Returns the preferred new-line characters for the document.
void | setNewLineCharacters (const String &newLineCharacters) noexcept
| 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 () noexcept
| Returns the document's UndoManager.
void | setSavePoint () noexcept
| Makes a note that the document's current state matches the one that is saved.
bool | hasChangedSinceSavePoint () const noexcept
| Returns true if the state of the document differs from the state it was in when setSavePoint() was last called.
Position | findWordBreakAfter (const Position &position) const noexcept
| Searches for a word-break.
Position | findWordBreakBefore (const Position &position) const noexcept
| Searches for a word-break.
void | findTokenContaining (const Position &pos, Position &start, Position &end) const noexcept
| Finds the token that contains the given position.
void | findLineContaining (const Position &pos, Position &start, Position &end) const noexcept
| Finds the line that contains the given position.
void | addListener (Listener *listener)
| Registers a listener object to receive callbacks when the document changes.
void | removeListener (Listener *listener)
| Deregisters a listener.

## Constructors and Destructors

## CodeDocument()

juce::CodeDocument::CodeDocument | ( |  | ) |

Creates a new, empty document.

Referenced by juce::CodeDocument::Iterator::Iterator(), juce::CodeDocument::Iterator::Iterator(), and juce::CodeDocument::Iterator::toPosition().

## ~CodeDocument()

juce::CodeDocument::~CodeDocument | ( |  | ) |

Destructor.

## Member Functions

## getAllContent()

String juce::CodeDocument::getAllContent | ( |  | ) | const

Returns the full text of the document.

## getTextBetween()

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

Returns a section of the document's text.

References juce::end().

## getLine()

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

noexcept

Returns a line from the document.

## getNumCharacters()

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

noexcept

Returns the number of characters in the document.

## getNumLines()

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

inline noexcept

Returns the number of lines in the document.

References getNumLines().

Referenced by getNumLines().

## getMaximumLineLength()

int juce::CodeDocument::getMaximumLineLength | ( |  | ) |

noexcept

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

## deleteSection() [1/2]

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

Deletes a section of the text.

This operation is undoable.

References deleteSection().

Referenced by deleteSection(), and deleteSection().

## deleteSection() [2/2]

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

Deletes a section of the text.

This operation is undoable.

References deleteSection().

## 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.

References insertText().

Referenced by insertText(), and insertText().

## 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.

References insertText().

## 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.

References replaceSection().

Referenced by replaceSection().

## 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.

References replaceAllContent().

Referenced by replaceAllContent().

## applyChanges()

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

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

References applyChanges().

Referenced by applyChanges().

## 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.

References loadFromStream().

Referenced by loadFromStream().

## writeToStream()

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

Writes the editor's current contents to a stream.

References writeToStream().

Referenced by writeToStream().

## getNewLineCharacters()

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

inline noexcept

Returns the preferred new-line characters for the document.

This will be either "\\n", "\\r\\n", or (rarely) "\\r".

See also
  setNewLineCharacters

References getNewLineCharacters().

Referenced by getNewLineCharacters().

## 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

## 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

## undo()

void juce::CodeDocument::undo | ( |  | ) |

Undo the last operation.

See also
  UndoManager::undo

## redo()

void juce::CodeDocument::redo | ( |  | ) |

Redo the last operation.

See also
  UndoManager::redo

## clearUndoHistory()

void juce::CodeDocument::clearUndoHistory | ( |  | ) |

Clears the undo history.

See also
  UndoManager::clearUndoHistory

## getUndoManager()

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

inline noexcept

Returns the document's UndoManager.

## 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

## 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

References hasChangedSinceSavePoint().

Referenced by hasChangedSinceSavePoint().

## findWordBreakAfter()

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

noexcept

Searches for a word-break.

References findWordBreakAfter().

Referenced by findWordBreakAfter().

## findWordBreakBefore()

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

noexcept

Searches for a word-break.

References findWordBreakBefore().

Referenced by findWordBreakBefore().

## findTokenContaining()

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

noexcept

Finds the token that contains the given position.

References juce::end(), and findTokenContaining().

Referenced by findTokenContaining().

## findLineContaining()

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

noexcept

Finds the line that contains the given position.

References juce::end(), and findLineContaining().

Referenced by findLineContaining().

## addListener()

void juce::CodeDocument::addListener | ( | Listener * | listener | ) |

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

## removeListener()

void juce::CodeDocument::removeListener | ( | Listener * | listener | ) |

Deregisters a listener.

See also
  addListener

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited