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
juce_CodeDocument.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29class CodeDocumentLine;
30
31
32//==============================================================================
45class JUCE_API CodeDocument
46{
47public:
50
53
54 //==============================================================================
62 class JUCE_API Position
63 {
64 public:
69 Position() noexcept;
70
81 Position (const CodeDocument& ownerDocument,
82 int line, int indexInLine) noexcept;
83
91 Position (const CodeDocument& ownerDocument,
92 int charactersFromStartOfDocument) noexcept;
93
99 Position (const Position&) noexcept;
100
102 ~Position();
103
104 Position& operator= (const Position&);
105
106 bool operator== (const Position&) const noexcept;
107 bool operator!= (const Position&) const noexcept;
108
115 void setPosition (int charactersFromStartOfDocument);
116
120 int getPosition() const noexcept { return characterPos; }
121
131 void setLineAndIndex (int newLineNumber, int newIndexInLine);
132
136 int getLineNumber() const noexcept { return line; }
137
144 int getIndexInLine() const noexcept { return indexInLine; }
145
152 void setPositionMaintained (bool isMaintained);
153
154 //==============================================================================
158 void moveBy (int characterDelta);
159
164 Position movedBy (int characterDelta) const;
165
170 Position movedByLines (int deltaLines) const;
171
175 juce_wchar getCharacter() const;
176
180 String getLineText() const;
181
182 private:
183 CodeDocument* owner = nullptr;
184 int characterPos = 0, line = 0, indexInLine = 0;
185 bool positionMaintained = false;
186
187 friend class CodeDocument;
188 };
189
190 //==============================================================================
192 String getAllContent() const;
193
195 String getTextBetween (const Position& start, const Position& end) const;
196
198 String getLine (int lineIndex) const noexcept;
199
201 int getNumCharacters() const noexcept;
202
204 int getNumLines() const noexcept { return lines.size(); }
205
207 int getMaximumLineLength() noexcept;
208
212 void deleteSection (const Position& startPosition, const Position& endPosition);
213
217 void deleteSection (int startIndex, int endIndex);
218
222 void insertText (const Position& position, const String& text);
223
227 void insertText (int insertIndex, const String& text);
228
232 void replaceSection (int startIndex, int endIndex, const String& newText);
233
239 void replaceAllContent (const String& newContent);
240
244 void applyChanges (const String& newContent);
245
249 bool loadFromStream (InputStream& stream);
250
252 bool writeToStream (OutputStream& stream);
253
254 //==============================================================================
259 String getNewLineCharacters() const noexcept { return newLineChars; }
260
265 void setNewLineCharacters (const String& newLineCharacters) noexcept;
266
267 //==============================================================================
274 void newTransaction();
275
279 void undo();
280
284 void redo();
285
289 void clearUndoHistory();
290
292 UndoManager& getUndoManager() noexcept { return undoManager; }
293
294 //==============================================================================
304 void setSavePoint() noexcept;
305
311 bool hasChangedSinceSavePoint() const noexcept;
312
313 //==============================================================================
315 Position findWordBreakAfter (const Position& position) const noexcept;
317 Position findWordBreakBefore (const Position& position) const noexcept;
319 void findTokenContaining (const Position& pos, Position& start, Position& end) const noexcept;
321 void findLineContaining (const Position& pos, Position& start, Position& end) const noexcept;
322
323 //==============================================================================
327 class JUCE_API Listener
328 {
329 public:
330 Listener() = default;
331 virtual ~Listener() = default;
332
334 virtual void codeDocumentTextInserted (const String& newText, int insertIndex) = 0;
335
337 virtual void codeDocumentTextDeleted (int startIndex, int endIndex) = 0;
338 };
339
344 void addListener (Listener* listener);
345
349 void removeListener (Listener* listener);
350
351 //==============================================================================
359 class JUCE_API Iterator
360 {
361 public:
366 Iterator() noexcept;
367
368 Iterator (const CodeDocument& document) noexcept;
370 ~Iterator() noexcept;
371
372 Iterator (const Iterator&) = default;
373 Iterator& operator= (const Iterator&) = default;
374
379 juce_wchar nextChar() noexcept;
380
382 juce_wchar peekNextChar() const noexcept;
383
388 juce_wchar previousChar() noexcept;
389
391 juce_wchar peekPreviousChar() const noexcept;
392
394 void skip() noexcept;
395
397 int getPosition() const noexcept { return position; }
398
400 void skipWhitespace() noexcept;
401
403 void skipToEndOfLine() noexcept;
404
406 void skipToStartOfLine() noexcept;
407
409 int getLine() const noexcept { return line; }
410
412 bool isEOF() const noexcept;
413
415 bool isSOF() const noexcept;
416
418 CodeDocument::Position toPosition() const;
419
420 private:
421 bool reinitialiseCharPtr() const;
422
423 const CodeDocument* document;
424 mutable String::CharPointerType charPointer { nullptr };
425 int line = 0, position = 0;
426 };
427
428private:
429 //==============================================================================
430 struct InsertAction;
431 struct DeleteAction;
432 friend class Iterator;
433 friend class Position;
434
435 OwnedArray<CodeDocumentLine> lines;
436 Array<Position*> positionsToMaintain;
437 UndoManager undoManager;
438 int currentActionIndex = 0, indexOfSavedState = -1;
439 int maximumLineLength = -1;
440 ListenerList<Listener> listeners;
441 String newLineChars { "\r\n" };
442
443 void insert (const String& text, int insertPos, bool undoable);
444 void remove (int startPos, int endPos, bool undoable);
445 void checkLastLineStatus();
446
448};
449
450} // namespace juce
Iterates the text in a CodeDocument.
int getPosition() const noexcept
Returns the position as the number of characters from the start of the document.
An object that receives callbacks from the CodeDocument when its text changes.
virtual void codeDocumentTextInserted(const String &newText, int insertIndex)=0
Called by a CodeDocument when text is added.
virtual void codeDocumentTextDeleted(int startIndex, int endIndex)=0
Called by a CodeDocument when text is deleted.
A position in a code document.
int getIndexInLine() const noexcept
Returns the number of characters from the start of the line.
int getPosition() const noexcept
Returns the position as the number of characters from the start of the document.
int getLineNumber() const noexcept
Returns the line number of this position.
A class for storing and manipulating a source code file.
UndoManager & getUndoManager() noexcept
Returns the document's UndoManager.
The base class for streams that read data.
The base class for streams that write data to some kind of destination.
The JUCE String class!
Definition juce_String.h:53
Manages a list of undo/redo commands.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
remove