JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
Classes | Public Member Functions | Friends | List of all members
juce::CodeDocument Class Reference

A class for storing and manipulating a source code file. More...

#include "juce_CodeDocument.h"

Classes

struct  DeleteAction
 
struct  InsertAction
 
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.
 
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.
 
UndoManagergetUndoManager () 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.
 

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}

Definition at line 45 of file juce_CodeDocument.h.

Constructor & Destructor Documentation

◆ CodeDocument()

juce::CodeDocument::CodeDocument ( )

Creates a new, empty document.

Definition at line 556 of file juce_CodeDocument.cpp.

◆ ~CodeDocument()

juce::CodeDocument::~CodeDocument ( )

Destructor.

Definition at line 560 of file juce_CodeDocument.cpp.

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

Definition at line 878 of file juce_CodeDocument.cpp.

◆ applyChanges()

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

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

Definition at line 670 of file juce_CodeDocument.cpp.

◆ clearUndoHistory()

void juce::CodeDocument::clearUndoHistory ( )

Clears the undo history.

See also
UndoManager::clearUndoHistory

Definition at line 737 of file juce_CodeDocument.cpp.

◆ deleteSection() [1/2]

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

Deletes a section of the text.

This operation is undoable.

Definition at line 644 of file juce_CodeDocument.cpp.

◆ deleteSection() [2/2]

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

Deletes a section of the text.

This operation is undoable.

Definition at line 649 of file juce_CodeDocument.cpp.

◆ findLineContaining()

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

Finds the line that contains the given position.

Definition at line 851 of file juce_CodeDocument.cpp.

◆ findTokenContaining()

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

Finds the token that contains the given position.

Definition at line 837 of file juce_CodeDocument.cpp.

◆ findWordBreakAfter()

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

Searches for a word-break.

Definition at line 759 of file juce_CodeDocument.cpp.

◆ findWordBreakBefore()

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

Searches for a word-break.

Definition at line 797 of file juce_CodeDocument.cpp.

◆ getAllContent()

String juce::CodeDocument::getAllContent ( ) const

Returns the full text of the document.

Definition at line 564 of file juce_CodeDocument.cpp.

◆ getLine()

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

Returns a line from the document.

Definition at line 623 of file juce_CodeDocument.cpp.

◆ getMaximumLineLength()

int juce::CodeDocument::getMaximumLineLength ( )
noexcept

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

Definition at line 631 of file juce_CodeDocument.cpp.

◆ getNewLineCharacters()

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

Returns the preferred new-line characters for the document.

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

See also
setNewLineCharacters

Definition at line 259 of file juce_CodeDocument.h.

◆ getNumCharacters()

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

Returns the number of characters in the document.

Definition at line 615 of file juce_CodeDocument.cpp.

◆ getNumLines()

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

Returns the number of lines in the document.

Definition at line 204 of file juce_CodeDocument.h.

◆ getTextBetween()

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

Returns a section of the document's text.

Definition at line 570 of file juce_CodeDocument.cpp.

◆ getUndoManager()

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

Returns the document's UndoManager.

Definition at line 292 of file juce_CodeDocument.h.

◆ 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

Definition at line 747 of file juce_CodeDocument.cpp.

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

Definition at line 654 of file juce_CodeDocument.cpp.

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

Definition at line 659 of file juce_CodeDocument.cpp.

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

Definition at line 692 of file juce_CodeDocument.cpp.

◆ 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

Definition at line 721 of file juce_CodeDocument.cpp.

◆ redo()

void juce::CodeDocument::redo ( )

Redo the last operation.

See also
UndoManager::redo

Definition at line 732 of file juce_CodeDocument.cpp.

◆ removeListener()

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

Deregisters a listener.

See also
addListener

Definition at line 879 of file juce_CodeDocument.cpp.

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

Definition at line 686 of file juce_CodeDocument.cpp.

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

Definition at line 664 of file juce_CodeDocument.cpp.

◆ 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

Definition at line 715 of file juce_CodeDocument.cpp.

◆ 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

Definition at line 742 of file juce_CodeDocument.cpp.

◆ undo()

void juce::CodeDocument::undo ( )

Undo the last operation.

See also
UndoManager::undo

Definition at line 726 of file juce_CodeDocument.cpp.

◆ writeToStream()

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

Writes the editor's current contents to a stream.

Definition at line 701 of file juce_CodeDocument.cpp.

Friends And Related Symbol Documentation

◆ Iterator

friend class Iterator
friend

Definition at line 432 of file juce_CodeDocument.h.

◆ Position

friend class Position
friend

Definition at line 433 of file juce_CodeDocument.h.


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