openshot-audio  0.1.4
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) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_CODEDOCUMENT_H_INCLUDED
26 #define JUCE_CODEDOCUMENT_H_INCLUDED
27 
28 class CodeDocumentLine;
29 
30 
31 //==============================================================================
43 {
44 public:
46  CodeDocument();
47 
49  ~CodeDocument();
50 
51  //==============================================================================
60  {
61  public:
67 
78  Position (const CodeDocument& ownerDocument,
79  int line, int indexInLine) noexcept;
80 
88  Position (const CodeDocument& ownerDocument,
89  int charactersFromStartOfDocument) noexcept;
90 
96  Position (const Position&) noexcept;
97 
99  ~Position();
100 
101  Position& operator= (const Position&);
102 
103  bool operator== (const Position&) const noexcept;
104  bool operator!= (const Position&) const noexcept;
105 
112  void setPosition (int charactersFromStartOfDocument);
113 
117  int getPosition() const noexcept { return characterPos; }
118 
128  void setLineAndIndex (int newLine, int newIndexInLine);
129 
133  int getLineNumber() const noexcept { return line; }
134 
141  int getIndexInLine() const noexcept { return indexInLine; }
142 
149  void setPositionMaintained (bool isMaintained);
150 
151  //==============================================================================
155  void moveBy (int characterDelta);
156 
161  Position movedBy (int characterDelta) const;
162 
167  Position movedByLines (int deltaLines) const;
168 
172  juce_wchar getCharacter() const;
173 
177  String getLineText() const;
178 
179  private:
180  CodeDocument* owner;
181  int characterPos, line, indexInLine;
182  bool positionMaintained;
183  };
184 
185  //==============================================================================
187  String getAllContent() const;
188 
190  String getTextBetween (const Position& start, const Position& end) const;
191 
193  String getLine (int lineIndex) const noexcept;
194 
196  int getNumCharacters() const noexcept;
197 
199  int getNumLines() const noexcept { return lines.size(); }
200 
202  int getMaximumLineLength() noexcept;
203 
207  void deleteSection (const Position& startPosition, const Position& endPosition);
208 
212  void deleteSection (int startIndex, int endIndex);
213 
217  void insertText (const Position& position, const String& text);
218 
222  void insertText (int insertIndex, const String& text);
223 
227  void replaceSection (int startIndex, int endIndex, const String& newText);
228 
234  void replaceAllContent (const String& newContent);
235 
239  void applyChanges (const String& newContent);
240 
244  bool loadFromStream (InputStream& stream);
245 
247  bool writeToStream (OutputStream& stream);
248 
249  //==============================================================================
254  String getNewLineCharacters() const noexcept { return newLineChars; }
255 
260  void setNewLineCharacters (const String& newLine) noexcept;
261 
262  //==============================================================================
269  void newTransaction();
270 
274  void undo();
275 
279  void redo();
280 
284  void clearUndoHistory();
285 
287  UndoManager& getUndoManager() noexcept { return undoManager; }
288 
289  //==============================================================================
299  void setSavePoint() noexcept;
300 
306  bool hasChangedSinceSavePoint() const noexcept;
307 
308  //==============================================================================
310  Position findWordBreakAfter (const Position& position) const noexcept;
312  Position findWordBreakBefore (const Position& position) const noexcept;
314  void findTokenContaining (const Position& pos, Position& start, Position& end) const noexcept;
316  void findLineContaining (const Position& pos, Position& start, Position& end) const noexcept;
317 
318  //==============================================================================
323  {
324  public:
325  Listener() {}
326  virtual ~Listener() {}
327 
329  virtual void codeDocumentTextInserted (const String& newText, int insertIndex) = 0;
330 
332  virtual void codeDocumentTextDeleted (int startIndex, int endIndex) = 0;
333  };
334 
339  void addListener (Listener* listener) noexcept;
340 
344  void removeListener (Listener* listener) noexcept;
345 
346  //==============================================================================
355  {
356  public:
357  Iterator (const CodeDocument& document) noexcept;
358  Iterator (const Iterator&) noexcept;
359  Iterator& operator= (const Iterator&) noexcept;
360  ~Iterator() noexcept;
361 
365  juce_wchar nextChar() noexcept;
366 
368  juce_wchar peekNextChar() const noexcept;
369 
371  void skip() noexcept;
372 
374  int getPosition() const noexcept { return position; }
375 
377  void skipWhitespace() noexcept;
378 
380  void skipToEndOfLine() noexcept;
381 
383  int getLine() const noexcept { return line; }
384 
386  bool isEOF() const noexcept;
387 
388  private:
389  const CodeDocument* document;
390  mutable String::CharPointerType charPointer;
391  int line, position;
392  };
393 
394 private:
395  //==============================================================================
398  friend class Iterator;
399  friend class Position;
400 
402  Array <Position*> positionsToMaintain;
403  UndoManager undoManager;
404  int currentActionIndex, indexOfSavedState;
405  int maximumLineLength;
406  ListenerList <Listener> listeners;
407  String newLineChars;
408 
409  void insert (const String& text, int insertPos, bool undoable);
410  void remove (int startPos, int endPos, bool undoable);
411  void checkLastLineStatus();
412 
414 };
415 
416 
417 #endif // JUCE_CODEDOCUMENT_H_INCLUDED
Definition: juce_CodeDocument.cpp:802
int getIndexInLine() const noexcept
Definition: juce_CodeDocument.h:141
Listener()
Definition: juce_CodeDocument.h:325
Definition: juce_CodeDocument.cpp:25
#define noexcept
Definition: juce_CompilerSupport.h:141
Definition: juce_CodeDocument.h:59
NewLine newLine
Definition: juce_core.cpp:35
Definition: juce_CodeDocument.h:354
Definition: juce_InputStream.h:41
Definition: juce_String.h:43
#define JUCE_API
Definition: juce_StandardHeader.h:139
UndoManager & getUndoManager() noexcept
Definition: juce_CodeDocument.h:287
Definition: juce_CodeDocument.h:42
int getNumLines() const noexcept
Definition: juce_CodeDocument.h:199
Definition: juce_ListenerList.h:69
String getNewLineCharacters() const noexcept
Definition: juce_CodeDocument.h:254
Definition: juce_CodeDocument.cpp:895
Definition: juce_OutputStream.h:42
int getLineNumber() const noexcept
Definition: juce_CodeDocument.h:133
int getPosition() const noexcept
Definition: juce_CodeDocument.h:117
int getLine() const noexcept
Definition: juce_CodeDocument.h:383
bool operator==(const var &v1, const var &v2) noexcept
Definition: juce_Variant.cpp:565
Definition: juce_ApplicationCommandID.h:83
Definition: juce_Array.h:60
Definition: juce_ApplicationCommandID.h:86
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
virtual ~Listener()
Definition: juce_CodeDocument.h:326
Definition: juce_UndoManager.h:49
bool operator!=(const var &v1, const var &v2) noexcept
Definition: juce_Variant.cpp:566
Definition: juce_CodeDocument.h:322
wchar_t juce_wchar
Definition: juce_CharacterFunctions.h:49
int getPosition() const noexcept
Definition: juce_CodeDocument.h:374