File indexing completed on 2024-05-19 04:00:02
0001 /* 0002 SPDX-FileCopyrightText: 2001-2014 Christoph Cullmann <cullmann@kde.org> 0003 SPDX-FileCopyrightText: 2005-2014 Dominik Haumann <dhaumann@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KTEXTEDITOR_DOCUMENT_H 0009 #define KTEXTEDITOR_DOCUMENT_H 0010 0011 #include <ktexteditor_export.h> 0012 0013 #include <ktexteditor/cursor.h> 0014 #include <ktexteditor/movingcursor.h> 0015 #include <ktexteditor/movingrange.h> 0016 #include <ktexteditor/range.h> 0017 0018 // our main baseclass of the KTextEditor::Document 0019 #include <KParts/ReadWritePart> 0020 #include <KSyntaxHighlighting/Theme> 0021 0022 // the list of views 0023 #include <QList> 0024 0025 class KConfigGroup; 0026 0027 namespace KTextEditor 0028 { 0029 class DocumentPrivate; 0030 class EditingTransactionPrivate; 0031 class MainWindow; 0032 class Message; 0033 class View; 0034 class AnnotationModel; 0035 0036 /** 0037 * \brief Search flags for use with searchText. 0038 * 0039 * Modifies the behavior of searchText. 0040 * By default it is searched for a case-sensitive plaintext pattern, 0041 * without processing of escape sequences, with "whole words" off, 0042 * in forward direction, within a non-block-mode text range. 0043 * 0044 * \see SearchOptions 0045 * \author Sebastian Pipping \<webmaster@hartwork.org\> 0046 */ 0047 enum SearchOption { 0048 Default = 0, ///< Default settings 0049 0050 // modes 0051 Regex = 1 << 1, ///< Treats the pattern as a regular expression 0052 0053 // options for all modes 0054 CaseInsensitive = 1 << 4, ///< Ignores cases, e.g. "a" matches "A" 0055 Backwards = 1 << 5, ///< Searches in backward direction 0056 0057 // options for plaintext 0058 EscapeSequences = 1 << 10, ///< Plaintext mode: Processes escape sequences 0059 WholeWords = 1 << 11, ///< Plaintext mode: Whole words only, e.g. @em not "amp" in "example" 0060 0061 MaxSearchOption = 1 << 31 ///< Placeholder for binary compatibility 0062 }; 0063 0064 /// Stores a combination of #SearchOption values. 0065 Q_DECLARE_FLAGS(SearchOptions, SearchOption) 0066 Q_DECLARE_OPERATORS_FOR_FLAGS(SearchOptions) 0067 0068 /** 0069 * \class Mark 0070 * \see doc_marktext 0071 */ 0072 class Mark 0073 { 0074 public: 0075 /** The line that contains the mark. */ 0076 int line; 0077 0078 /** The mark types in the line, combined with logical OR. */ 0079 uint type; 0080 }; 0081 0082 /** 0083 * \class Document document.h <KTextEditor/Document> 0084 * 0085 * \brief A KParts derived class representing a text document. 0086 * 0087 * Topics: 0088 * - \ref doc_intro 0089 * - \ref doc_manipulation 0090 * - \ref doc_views 0091 * - \ref doc_readwrite 0092 * - \ref doc_notifications 0093 * - \ref doc_recovery 0094 * - \ref doc_movinginterface 0095 * - \ref doc_config 0096 * - \ref doc_modiface 0097 * - \ref doc_marktext 0098 * - \ref doc_annoiface 0099 * 0100 * \section doc_intro Introduction 0101 * 0102 * The Document class represents a pure text document providing methods to 0103 * modify the content and create views. A document can have any number 0104 * of views, each view representing the same content, i.e. all views are 0105 * synchronized. Support for text selection is handled by a View and text 0106 * format attributes by the Attribute class. 0107 * 0108 * To load a document call KParts::ReadOnlyPart::openUrl(). 0109 * To reload a document from a file call documentReload(), to save the 0110 * document call documentSave() or documentSaveAs(). Whenever the modified 0111 * state of the document changes the signal modifiedChanged() is emitted. 0112 * Check the modified state with KParts::ReadWritePart::isModified(). 0113 * Further signals are documentUrlChanged(). The encoding can be specified 0114 * with setEncoding(), however this will only take effect on file reload and 0115 * file save. 0116 * 0117 * \section doc_manipulation Text Manipulation 0118 * 0119 * Get the whole content with text() and set new content with setText(). 0120 * Call insertText() or insertLine() to insert new text or removeText() 0121 * and removeLine() to remove content. Whenever the document's content 0122 * changed the signal textChanged() is emitted. Additional signals are 0123 * textInserted() and textRemoved(). Note, that the first line in the 0124 * document is line 0. 0125 * 0126 * A Document provides full undo/redo history. 0127 * Text manipulation actions can be grouped together to one undo/redo action by 0128 * using an the class EditingTransaction. You can stack multiple EditingTransaction%s. 0129 * Internally, the Document has a reference counter. If this reference counter 0130 * is increased the first time (by creating an instance of EditingTransaction), 0131 * the signal editingStarted() is emitted. Only when the internal reference counter 0132 * reaches zero again, the signal editingFinished() and optionally the signal 0133 * textChanged() are emitted. Whether an editing transaction is currently active 0134 * can be checked by calling isEditingTransactionRunning(). 0135 * 0136 * @note The signal editingFinished() is always emitted when the last instance 0137 * of EditingTransaction is destroyed. Contrary, the signal textChanged() 0138 * is emitted only if text changed. Hence, textChanged() is more accurate 0139 * with respect to changes in the Document. 0140 * 0141 * Every text editing transaction is also available through the signals 0142 * lineWrapped(), lineUnwrapped(), textInserted() and textRemoved(). 0143 * However, these signals should be used with care. Please be aware of the 0144 * following warning: 0145 * 0146 * @warning Never change the Document's contents when edit actions are active, 0147 * i.e. in between of (foreign) editing transactions. In case you 0148 * violate this, the currently active edit action may perform edits 0149 * that lead to undefined behavior. 0150 * 0151 * \section doc_views Document Views 0152 * 0153 * A View displays the document's content. As already mentioned, a document 0154 * can have any number of views, all synchronized. Get a list of all views 0155 * with views(). Create a new view with createView(). Every time a new view 0156 * is created the signal viewCreated() is emitted. 0157 * 0158 * \section doc_readwrite Read-Only Mode 0159 * 0160 * A Document may be in read-only mode, for instance due to missing file 0161 * permissions. The read-only mode can be checked with isReadWrite(). Further, 0162 * the signal readWriteChanged() is emitted whenever the state changes either 0163 * to read-only mode or to read/write mode. The read-only mode can be controlled 0164 * with setReadWrite(). 0165 * 0166 * \section doc_notifications Notifications in Documents and Views 0167 * 0168 * A Document has the ability to show a Message to the user in a View. 0169 * The Message then is shown either the specified View if Message::setView() 0170 * was called, or in all View%s of the Document. 0171 * 0172 * To post a message just create a new Message and send it with postMessage(). 0173 * Further information is available in the API documentation of Message. 0174 * 0175 * @see Message 0176 * 0177 * \section doc_recovery Crash Recovery for Documents 0178 * 0179 * When the system or the application using the editor component crashed 0180 * with unsaved changes in the Document, the View notifies the user about 0181 * the lost data and asks, whether the data should be recovered. 0182 * 0183 * This Document gives you control over the data recovery process. Use 0184 * isDataRecoveryAvailable() to check for lost data. If you do not want the 0185 * editor component to handle the data recovery process automatically, you can 0186 * either trigger the data recovery by calling recoverData() or discard it 0187 * through discardDataRecovery(). 0188 * 0189 * \section doc_movinginterface Document Moving Interface 0190 * 0191 * Document Moving Interface allows you to create MovingRange and MovingCursor. A 0192 * Moving Range or Cursor is a special type of range/cursor because it automatically 0193 * moves on text insertion or removal. Additionally, one can use the moving ranges to 0194 * change the color of a particular word or give it a different attribute such as bold. 0195 * Use newMovingCursor() to create a new moving cursor and newMovingRange() to create 0196 * a new moving range. 0197 * 0198 * Upon destruction or reload, a document will remove all its moving ranges. You can 0199 * connect to aboutToDeleteMovingInterfaceContent() and aboutToInvalidateMovingInterfaceContent() 0200 * signals to know when that is going to happen and update the cached ranges accordingly. 0201 * 0202 * \section doc_config Document Config 0203 * Config provides methods to access and modify the low level config information for a given 0204 * Document. 0205 * KTextEditor::Document has support for the following config keys: 0206 * - backup-on-save-local [bool], enable/disable backup when saving local files 0207 * - backup-on-save-remote [bool], enable/disable backup when saving remote files 0208 * - backup-on-save-suffix [string], set the suffix for file backups, e.g. "~" 0209 * - backup-on-save-prefix [string], set the prefix for file backups, e.g. "." 0210 * - replace-tabs [bool], whether to replace tabs 0211 * - indent-pasted-text [bool], whether to indent pasted text 0212 * - tab-width [int], read/set the width for tabs 0213 * - indent-width [int], read/set the indentation width 0214 * - on-the-fly-spellcheck [bool], enable/disable on the fly spellcheck 0215 * 0216 * \section doc_modiface External modification extension interface for the Document. 0217 * 0218 * The class ModificationInterface provides methods to handle modifications 0219 * of all opened files caused by external programs. Whenever the 0220 * modified-on-disk state changes the signal modifiedOnDisk() is emitted 0221 * along with a ModifiedOnDiskReason. Set the state by calling 0222 * setModifiedOnDisk(). Whether the Editor should show warning dialogs to 0223 * inform the user about external modified files can be controlled with 0224 * setModifiedOnDiskWarning(). The slot modifiedOnDisk() is called to ask 0225 * the user what to do whenever a file was modified. 0226 * 0227 * \section doc_marktext 0228 * 0229 * The Mark Interface provides methods to enable and disable marks in a 0230 * Document, a marked line can be visualized for example with a shaded 0231 * background color and/or a pixmap in the iconborder of the Document's View. 0232 * There are a number of predefined mark types, specified in 0233 * reservedMarkersCount(). Additionally it is possible to add custom marks 0234 * and set custom pixmaps. 0235 * 0236 * Get all marks in the document by calling marks(). Use clearMarks() to 0237 * remove all marks in the entire document. A single mark can be retrieved 0238 * with mark(). To remove all marks from a line call clearMark(). To add 0239 * and remove marks from a given line use addMark() and removeMark(). It is 0240 * also possible to replace all marks with setMark(), i.e. setMark() is the 0241 * same as a call of clearMark() followed by addMark(). The signals 0242 * marksChanged() and markChanged() are emitted whenever a line's marks 0243 * changed. 0244 * 0245 * \attention A mark type is represented as an \e uint. An \e uint can have 0246 * several mark types combined (see above: logical OR). That means for 0247 * all functions/signals with an \e uint parameter, e.g. setMark(), 0248 * removeMark(), etc, the \e uint may contain \e multiple marks, i.e. 0249 * you can add and remove multiple marks \e simultaneously. 0250 * 0251 * All marks that should be editable by the user can be specified with a mark 0252 * mask via setEditableMarks(). To set a description and pixmap of a mark type 0253 * call setMarkDescription() and setMarkPixmap(). 0254 * 0255 * \section doc_annoiface Annotation Interface 0256 * 0257 * The Annotation Interface is designed to provide line annotation information 0258 * for a document. This interface provides means to associate a document with a 0259 * annotation model, which provides some annotation information for each line 0260 * in the document. 0261 * 0262 * Setting a model for a Document makes the model data available for all views. 0263 * If you only want to provide annotations in exactly one view, you can use 0264 * the AnnotationViewInterface directly. See the AnnotationViewInterface for 0265 * further details. To summarize, the two use cases are 0266 * - (1) show annotations in all views. This means you set an AnnotationModel 0267 * with this interface, and then call setAnnotationBorderVisible() for 0268 * each view. 0269 * - (2) show annotations only in one view. This means to \e not use this 0270 * interface. Instead, use the AnnotationViewInterface, which inherits 0271 * this interface. This means you set a model for the specific View. 0272 * 0273 * If you set a model to the Document \e and the View, the View's model has 0274 * higher priority. 0275 * 0276 * More information about interfaces for the document can be found in 0277 * \ref kte_group_doc_extensions. 0278 * 0279 * \see KParts::ReadWritePart, KTextEditor::Editor, KTextEditor::View, 0280 * KTextEditor::MarkInterface 0281 * \author Christoph Cullmann \<cullmann@kde.org\> 0282 */ 0283 class KTEXTEDITOR_EXPORT Document : public KParts::ReadWritePart 0284 { 0285 Q_OBJECT 0286 0287 protected: 0288 /** 0289 * Constructor. 0290 * 0291 * Create a new document with \p parent. 0292 * 0293 * Pass it the internal implementation to store a d-pointer. 0294 * 0295 * \param impl d-pointer to use 0296 * \param parent parent object 0297 * \see Editor::createDocument() 0298 */ 0299 Document(DocumentPrivate *impl, const KPluginMetaData &data, QObject *parent); 0300 0301 public: 0302 /** 0303 * Virtual destructor. 0304 */ 0305 ~Document() override; 0306 0307 /** 0308 * \name Manage View%s of this Document 0309 * 0310 * \{ 0311 */ 0312 public: 0313 /** 0314 * Create a new view attached to @p parent. 0315 * @param parent parent widget 0316 * @param mainWindow the main window responsible for this view, if any 0317 * @return the new view 0318 */ 0319 virtual View *createView(QWidget *parent, KTextEditor::MainWindow *mainWindow = nullptr) = 0; 0320 0321 /** 0322 * Returns the views pre-casted to KTextEditor::View%s 0323 */ 0324 virtual QList<View *> views() const = 0; 0325 0326 Q_SIGNALS: 0327 /** 0328 * This signal is emitted whenever the \p document creates a new \p view. 0329 * It should be called for every view to help applications / plugins to 0330 * attach to the \p view. 0331 * \attention This signal should be emitted after the view constructor is 0332 * completed, e.g. in the createView() method. 0333 * \param document the document for which a new view is created 0334 * \param view the new view 0335 * \see createView() 0336 */ 0337 void viewCreated(KTextEditor::Document *document, KTextEditor::View *view); 0338 0339 //!\} 0340 0341 /** 0342 * \name General Information about this Document 0343 * 0344 * \{ 0345 */ 0346 public: 0347 /** 0348 * Get this document's name. 0349 * The editor part should provide some meaningful name, like some unique 0350 * "Untitled XYZ" for the document - \e without URL or basename for 0351 * documents with url. 0352 * \return readable document name 0353 */ 0354 virtual QString documentName() const = 0; 0355 0356 /** 0357 * Get this document's mimetype. 0358 * \return mimetype 0359 */ 0360 virtual QString mimeType() = 0; 0361 0362 /** 0363 * Get the git hash of the Document's contents on disk. 0364 * The returned hash equals the git hash of the file written to disk. 0365 * If the document is a remote document, the checksum may not be 0366 * available. In this case, QByteArray::isNull() returns \e true. 0367 * 0368 * git hash is defined as: 0369 * 0370 * sha1("blob " + filesize + "\0" + filecontent) 0371 * 0372 * \return the git hash of the document 0373 */ 0374 virtual QByteArray checksum() const = 0; 0375 0376 /* 0377 * SIGNALS 0378 * following signals should be emitted by the editor document. 0379 */ 0380 Q_SIGNALS: 0381 /** 0382 * This signal is emitted whenever the \p document name changes. 0383 * \param document document which changed its name 0384 * \see documentName() 0385 */ 0386 void documentNameChanged(KTextEditor::Document *document); 0387 0388 /** 0389 * This signal is emitted whenever the \p document URL changes. 0390 * \param document document which changed its URL 0391 * \see KParts::ReadOnlyPart::url() 0392 */ 0393 void documentUrlChanged(KTextEditor::Document *document); 0394 0395 /** 0396 * This signal is emitted whenever the \p document's buffer changed from 0397 * either state \e unmodified to \e modified or vice versa. 0398 * 0399 * \param document document which changed its modified state 0400 * \see KParts::ReadWritePart::isModified(). 0401 * \see KParts::ReadWritePart::setModified() 0402 */ 0403 void modifiedChanged(KTextEditor::Document *document); 0404 0405 /** 0406 * This signal is emitted whenever the readWrite state of a document 0407 * changes. 0408 * \param document the document whose read/write property changed 0409 * \see KParts::ReadWritePart::setReadWrite() 0410 */ 0411 void readWriteChanged(KTextEditor::Document *document); 0412 0413 /* 0414 * VERY IMPORTANT: Methods to set and query the current encoding of the 0415 * document 0416 */ 0417 public: 0418 /** 0419 * Set the encoding for this document. This encoding will be used 0420 * while loading and saving files, it will \e not affect the already 0421 * existing content of the document, e.g. if the file has already been 0422 * opened without the correct encoding, this will \e not fix it, you 0423 * would for example need to trigger a reload for this. 0424 * \param encoding new encoding for the document, the name must be 0425 * accepted by QStringDecoder/QStringEncoder, if an empty encoding name is given, the 0426 * part should fallback to its own default encoding, e.g. the 0427 * system encoding or the global user settings 0428 * \return \e true on success, or \e false, if the encoding could not be set. 0429 * \see encoding() 0430 */ 0431 virtual bool setEncoding(const QString &encoding) = 0; 0432 0433 /** 0434 * Get the current chosen encoding. The return value is an empty string, 0435 * if the document uses the default encoding of the editor and no own 0436 * special encoding. 0437 * \return current encoding of the document 0438 * \see setEncoding() 0439 */ 0440 virtual QString encoding() const = 0; 0441 0442 //!\} 0443 0444 /** 0445 * \name File Loading and Saving 0446 * 0447 * All this actions cause user interaction in some cases. 0448 * \{ 0449 */ 0450 public: 0451 /** 0452 * Reload the current file. 0453 * The user will be prompted by the part on changes and more and can 0454 * cancel this action if it can harm. 0455 * \return \e true if the reload has been done, otherwise \e false. If 0456 * the document has no url set, it will just return \e false. 0457 */ 0458 virtual bool documentReload() = 0; 0459 0460 /** 0461 * Save the current file. 0462 * The user will be asked for a filename if needed and more. 0463 * \return \e true on success, i.e. the save has been done, otherwise 0464 * \e false 0465 */ 0466 virtual bool documentSave() = 0; 0467 0468 /** 0469 * Save the current file to another location. 0470 * The user will be asked for a filename and more. 0471 * \return \e true on success, i.e. the save has been done, otherwise 0472 * \e false 0473 */ 0474 virtual bool documentSaveAs() = 0; 0475 0476 /** 0477 * True, eg if the file for opening could not be read 0478 * This doesn't have to handle the KPart job canceled cases. 0479 * @return was there some problem loading the file? 0480 */ 0481 bool openingError() const; 0482 0483 /* 0484 * SIGNALS 0485 * Following signals should be emitted by the document if the text content 0486 * is changed. 0487 */ 0488 Q_SIGNALS: 0489 /** 0490 * This signal should be emitted after a document has been saved to disk or for remote files uploaded. 0491 * saveAs should be set to true, if the operation is a save as operation 0492 */ 0493 void documentSavedOrUploaded(KTextEditor::Document *document, bool saveAs); 0494 0495 /** 0496 * Warn anyone listening that the current document is about to close. 0497 * At this point all of the information is still accessible, such as the text, 0498 * cursors and ranges. 0499 * 0500 * Any modifications made to the document at this point will be lost. 0501 * 0502 * \param document the document being closed 0503 */ 0504 void aboutToClose(KTextEditor::Document *document); 0505 0506 /** 0507 * Warn anyone listening that the current document is about to reload. 0508 * At this point all of the information is still accessible, such as the text, 0509 * cursors and ranges. 0510 * 0511 * Any modifications made to the document at this point will be lost. 0512 * 0513 * \param document the document being reloaded 0514 */ 0515 void aboutToReload(KTextEditor::Document *document); 0516 0517 /** 0518 * Emitted after the current document was reloaded. 0519 * At this point, some information might have been invalidated, like 0520 * for example the editing history. 0521 * 0522 * \param document the document that was reloaded. 0523 * 0524 * @since 4.6 0525 */ 0526 void reloaded(KTextEditor::Document *document); 0527 0528 /** 0529 * Emitted just before the document will be saved 0530 * Any modifications made to the document at this point 0531 * will get stored on disk. 0532 * 0533 * \param document the document that was reloaded. 0534 * 0535 * @since 5.91 0536 */ 0537 void aboutToSave(KTextEditor::Document *document); 0538 0539 //!\} 0540 0541 /** 0542 * \name Text Manipulation 0543 * 0544 * \{ 0545 */ 0546 public: 0547 /** 0548 * Editing transaction support. 0549 * 0550 * Edit commands during this sequence will be bunched together so that 0551 * they represent a single undo command in the editor, and so that 0552 * repaint events do not occur in between. 0553 * 0554 * Your application should \e not return control to the event loop while 0555 * it has an unterminated (i.e. this object is not destructed) editing 0556 * sequence (result undefined) - so do all of your work in one go! 0557 * 0558 * Using this class typically looks as follows: 0559 * @code 0560 * void foo() { 0561 * KTextEditor::Document::EditingTransaction transaction(document); 0562 * // now call editing functions 0563 * document->removeText(...) 0564 * document->insertText(...) 0565 * } 0566 * @endcode 0567 * 0568 * Although usually not required, the EditingTransaction additionally 0569 * allows to manually call finish() and start() in between. 0570 * 0571 * @see editingStarted(), editingFinished() 0572 */ 0573 class KTEXTEDITOR_EXPORT EditingTransaction 0574 { 0575 public: 0576 /** 0577 * Constructs the object and starts an editing transaction by 0578 * calling start(). 0579 * 0580 * @param document document for the transaction 0581 * @see start() 0582 */ 0583 explicit EditingTransaction(Document *document); 0584 0585 /** 0586 * No copy constructor, don't allow this to be copied. 0587 */ 0588 EditingTransaction(const EditingTransaction &) = delete; 0589 0590 /** 0591 * No assignment operator, no copying around editing transations. 0592 */ 0593 EditingTransaction &operator=(const EditingTransaction &) = delete; 0594 0595 /** 0596 * Destructs the object and, if needed, finishes a running editing 0597 * transaction by calling finish(). 0598 * 0599 * @see finish() 0600 */ 0601 ~EditingTransaction(); 0602 0603 /** 0604 * By calling start(), the editing transaction can be started again. 0605 * This function only is of use in combination with finish(). 0606 * 0607 * @see finish() 0608 */ 0609 void start(); 0610 0611 /** 0612 * By calling finish(), the editing transaction can be finished 0613 * already before destruction of this instance. 0614 * 0615 * @see start() 0616 */ 0617 void finish(); 0618 0619 private: 0620 /** 0621 * private d-pointer 0622 */ 0623 EditingTransactionPrivate *const d; 0624 }; 0625 0626 /** 0627 * Check whether an editing transaction is currently running. 0628 * 0629 * @see EditingTransaction 0630 */ 0631 virtual bool isEditingTransactionRunning() const = 0; 0632 0633 /* 0634 * General access to the document's text content. 0635 */ 0636 public: 0637 /** 0638 * Get the document content. 0639 * \return the complete document content 0640 * \see setText() 0641 */ 0642 virtual QString text() const = 0; 0643 0644 /** 0645 * Get the document content within the given \p range. 0646 * \param range the range of text to retrieve 0647 * \param block Set this to \e true to receive text in a visual block, 0648 * rather than everything inside \p range. 0649 * \return the requested text part, or QString() for invalid ranges. 0650 * \see setText() 0651 */ 0652 virtual QString text(Range range, bool block = false) const = 0; 0653 0654 /** 0655 * Get the character at text position \p cursor. 0656 * \param position the location of the character to retrieve 0657 * \return the requested character, or QChar() for invalid cursors. 0658 * \see setText() 0659 */ 0660 virtual QChar characterAt(KTextEditor::Cursor position) const = 0; 0661 0662 /** 0663 * Get the word at the text position \p cursor. 0664 * The returned word is defined by the word boundaries to the left and 0665 * right starting at \p cursor. The algorithm takes highlighting information 0666 * into account, e.g. a dash ('-') in C++ is interpreted as word boundary, 0667 * whereas e.g. CSS allows identifiers with dash ('-'). 0668 * 0669 * If \p cursor is not a valid text position or if there is no word 0670 * under the requested position \p cursor, an empty string is returned. 0671 * 0672 * \param cursor requested cursor position for the word 0673 * \return the word under the cursor or an empty string if there is no word. 0674 * 0675 * \see wordRangeAt(), characterAt() 0676 */ 0677 virtual QString wordAt(KTextEditor::Cursor cursor) const = 0; 0678 0679 /** 0680 * Get the text range for the word located under the text position \p cursor. 0681 * The returned word is defined by the word boundaries to the left and 0682 * right starting at \p cursor. The algorithm takes highlighting information 0683 * into account, e.g. a dash ('-') in C++ is interpreted as word boundary, 0684 * whereas e.g. CSS allows identifiers with dash ('-'). 0685 * 0686 * If \p cursor is not a valid text position or if there is no word 0687 * under the requested position \p cursor, an invalid text range is returned. 0688 * If the text range is valid, it is \e always on a single line. 0689 * 0690 * \param cursor requested cursor position for the word 0691 * \return the Range spanning the word under the cursor or an invalid range if there is no word. 0692 * 0693 * \see wordAt(), characterAt(), KTextEditor::Range::isValid() 0694 */ 0695 virtual KTextEditor::Range wordRangeAt(KTextEditor::Cursor cursor) const = 0; 0696 0697 /** 0698 * Get whether \p cursor is a valid text position. 0699 * A cursor position at (line, column) is valid, if 0700 * - line >= 0 and line < lines() holds, and 0701 * - column >= 0 and column <= lineLength(column). 0702 * 0703 * The text position \p cursor is also invalid if it is inside a Unicode surrogate. 0704 * Therefore, use this function when iterating over the characters of a line. 0705 * 0706 * \param cursor cursor position to check for validity 0707 * \return true, if \p cursor is a valid text position, otherwise \p false 0708 * 0709 * \since 5.0 0710 */ 0711 virtual bool isValidTextPosition(KTextEditor::Cursor cursor) const = 0; 0712 0713 /** 0714 * Get the document content within the given \p range. 0715 * \param range the range of text to retrieve 0716 * \param block Set this to \e true to receive text in a visual block, 0717 * rather than everything inside \p range. 0718 * \return the requested text lines, or QStringList() for invalid ranges. 0719 * no end of line termination is included. 0720 * \see setText() 0721 */ 0722 virtual QStringList textLines(Range range, bool block = false) const = 0; 0723 0724 /** 0725 * Get a single text line. 0726 * \param line the wanted line 0727 * \return the requested line, or "" for invalid line numbers 0728 * \see text(), lineLength() 0729 */ 0730 virtual QString line(int line) const = 0; 0731 0732 /** 0733 * Get the count of lines of the document. 0734 * \return the current number of lines in the document 0735 * \see length() 0736 */ 0737 virtual int lines() const = 0; 0738 0739 /** 0740 * Check whether \p line currently contains unsaved data. 0741 * If \p line contains unsaved data, \e true is returned, otherwise \e false. 0742 * When the user saves the file, a modified line turns into a \e saved line. 0743 * In this case isLineModified() returns \e false and in its stead isLineSaved() 0744 * returns \e true. 0745 * \param line line to query 0746 * \see isLineSaved(), isLineTouched() 0747 * \since 5.0 0748 */ 0749 virtual bool isLineModified(int line) const = 0; 0750 0751 /** 0752 * Check whether \p line currently contains only saved text. 0753 * Saved text in this case implies that a line was touched at some point 0754 * by the user and then then changes were either undone or the user saved 0755 * the file. 0756 * 0757 * In case \p line was touched and currently contains only saved data, 0758 * \e true is returned, otherwise \e false. 0759 * \param line line to query 0760 * \see isLineModified(), isLineTouched() 0761 * \since 5.0 0762 */ 0763 virtual bool isLineSaved(int line) const = 0; 0764 0765 /** 0766 * Check whether \p line was touched since the file was opened. 0767 * This equals the statement isLineModified() || isLineSaved(). 0768 * \param line line to query 0769 * \see isLineModified(), isLineSaved() 0770 * \since 5.0 0771 */ 0772 virtual bool isLineTouched(int line) const = 0; 0773 0774 /** 0775 * End position of the document. 0776 * \return The last column on the last line of the document 0777 * \see all() 0778 */ 0779 virtual Cursor documentEnd() const = 0; 0780 0781 /** 0782 * A Range which encompasses the whole document. 0783 * \return A range from the start to the end of the document 0784 */ 0785 inline Range documentRange() const 0786 { 0787 return Range(Cursor::start(), documentEnd()); 0788 } 0789 0790 /** 0791 * Get the count of characters in the document. A TAB character counts as 0792 * only one character. 0793 * \return the number of characters in the document 0794 * \see lines() 0795 */ 0796 virtual qsizetype totalCharacters() const = 0; 0797 0798 /** 0799 * Returns if the document is empty. 0800 */ 0801 virtual bool isEmpty() const; 0802 0803 /** 0804 * Get the length of a given line in characters. 0805 * \param line line to get length from 0806 * \return the number of characters in the line or -1 if the line was 0807 * invalid 0808 * \see line() 0809 */ 0810 virtual int lineLength(int line) const = 0; 0811 0812 /** 0813 * Get the end cursor position of line \p line. 0814 * \param line line 0815 * \see lineLength(), line() 0816 */ 0817 inline Cursor endOfLine(int line) const 0818 { 0819 return Cursor(line, lineLength(line)); 0820 } 0821 0822 /** 0823 * Set the given text as new document content. 0824 * \param text new content for the document 0825 * \return \e true on success, otherwise \e false 0826 * \see text() 0827 */ 0828 virtual bool setText(const QString &text) = 0; 0829 0830 /** 0831 * Set the given text as new document content. 0832 * \param text new content for the document 0833 * \return \e true on success, otherwise \e false 0834 * \see text() 0835 */ 0836 virtual bool setText(const QStringList &text) = 0; 0837 0838 /** 0839 * Remove the whole content of the document. 0840 * \return \e true on success, otherwise \e false 0841 * \see removeText(), removeLine() 0842 */ 0843 virtual bool clear() = 0; 0844 0845 /** 0846 * Insert \p text at \p position. 0847 * \param position position to insert the text 0848 * \param text text to insert 0849 * \param block insert this text as a visual block of text rather than a linear sequence 0850 * \return \e true on success, otherwise \e false 0851 * \see setText(), removeText() 0852 */ 0853 virtual bool insertText(KTextEditor::Cursor position, const QString &text, bool block = false) = 0; 0854 0855 /** 0856 * Insert \p text at \p position. 0857 * \param position position to insert the text 0858 * \param text text to insert 0859 * \param block insert this text as a visual block of text rather than a linear sequence 0860 * \return \e true on success, otherwise \e false 0861 * \see setText(), removeText() 0862 */ 0863 virtual bool insertText(KTextEditor::Cursor position, const QStringList &text, bool block = false) = 0; 0864 0865 /** 0866 * Replace text from \p range with specified \p text. 0867 * \param range range of text to replace 0868 * \param text text to replace with 0869 * \param block replace text as a visual block of text rather than a linear sequence 0870 * \return \e true on success, otherwise \e false 0871 * \see setText(), removeText(), insertText() 0872 */ 0873 virtual bool replaceText(Range range, const QString &text, bool block = false); 0874 0875 /** 0876 * Replace text from \p range with specified \p text. 0877 * \param range range of text to replace 0878 * \param text text to replace with 0879 * \param block replace text as a visual block of text rather than a linear sequence 0880 * \return \e true on success, otherwise \e false 0881 * \see setText(), removeText(), insertText() 0882 */ 0883 virtual bool replaceText(Range range, const QStringList &text, bool block = false); 0884 0885 /** 0886 * Remove the text specified in \p range. 0887 * \param range range of text to remove 0888 * \param block set this to true to remove a text block on the basis of columns, rather than everything inside \p range 0889 * \return \e true on success, otherwise \e false 0890 * \see setText(), insertText() 0891 */ 0892 virtual bool removeText(Range range, bool block = false) = 0; 0893 0894 /** 0895 * Insert line(s) at the given line number. The newline character '\\n' 0896 * is treated as line delimiter, so it is possible to insert multiple 0897 * lines. To append lines at the end of the document, use 0898 * \code 0899 * insertLine( lines(), text ) 0900 * \endcode 0901 * \param line line where to insert the text 0902 * \param text text which should be inserted 0903 * \return \e true on success, otherwise \e false 0904 * \see insertText() 0905 */ 0906 virtual bool insertLine(int line, const QString &text) = 0; 0907 0908 /** 0909 * Insert line(s) at the given line number. The newline character '\\n' 0910 * is treated as line delimiter, so it is possible to insert multiple 0911 * lines. To append lines at the end of the document, use 0912 * \code 0913 * insertLine( lines(), text ) 0914 * \endcode 0915 * \param line line where to insert the text 0916 * \param text text which should be inserted 0917 * \return \e true on success, otherwise \e false 0918 * \see insertText() 0919 */ 0920 virtual bool insertLines(int line, const QStringList &text) = 0; 0921 0922 /** 0923 * Remove \p line from the document. 0924 * \param line line to remove 0925 * \return \e true on success, otherwise \e false 0926 * \see removeText(), clear() 0927 */ 0928 virtual bool removeLine(int line) = 0; 0929 0930 /** 0931 * \brief Searches the given input range for a text pattern. 0932 * 0933 * Searches for a text pattern within the given input range. 0934 * The kind of search performed depends on the \p options 0935 * used. Use this function for plaintext searches as well as 0936 * regular expression searches. If no match is found the first 0937 * (and only) element in the vector return is the invalid range. 0938 * When searching for regular expressions, the first element holds 0939 * the range of the full match, the subsequent elements hold 0940 * the ranges of the capturing parentheses. 0941 * 0942 * \param range Input range to search in 0943 * \param pattern Text pattern to search for 0944 * \param options Combination of search flags 0945 * \return List of ranges (length >=1) 0946 * 0947 * \author Sebastian Pipping \<webmaster@hartwork.org\> 0948 * 0949 * \since 5.11 0950 */ 0951 QList<KTextEditor::Range> searchText(KTextEditor::Range range, const QString &pattern, const SearchOptions options = Default) const; 0952 0953 /** 0954 * \brief Retrives the offset for the given cursor position 0955 * NOTE: It will return -1 if the cursor was invalid or out of bounds. 0956 * \since 6.0 0957 */ 0958 virtual qsizetype cursorToOffset(KTextEditor::Cursor c) const = 0; 0959 0960 /** 0961 * \brief Retrives the cursor position for given offset 0962 * NOTE: It will return an invalid cursor(-1, -1) if offset is invalid. 0963 * \since 6.0 0964 */ 0965 virtual KTextEditor::Cursor offsetToCursor(qsizetype offset) const = 0; 0966 /* 0967 * SIGNALS 0968 * Following signals should be emitted by the document if the text content 0969 * is changed. 0970 */ 0971 Q_SIGNALS: 0972 /** 0973 * Editing transaction has started. 0974 * \param document document which emitted this signal 0975 */ 0976 void editingStarted(KTextEditor::Document *document); 0977 0978 /** 0979 * Editing transaction has finished. 0980 * 0981 * @note This signal is emitted also for editing actions that maybe do not 0982 * modify the @p document contents (think of having an empty 0983 * EditingTransaction). If you want to get notified only 0984 * after text really changed, connect to the signal textChanged(). 0985 * 0986 * \param document document which emitted this signal 0987 * @see textChanged() 0988 */ 0989 void editingFinished(KTextEditor::Document *document); 0990 0991 /** 0992 * A line got wrapped. 0993 * \param document document which emitted this signal 0994 * @param position position where the wrap occurred 0995 */ 0996 void lineWrapped(KTextEditor::Document *document, KTextEditor::Cursor position); 0997 0998 /** 0999 * A line got unwrapped. 1000 * \param document document which emitted this signal 1001 * @param line line where the unwrap occurred 1002 */ 1003 void lineUnwrapped(KTextEditor::Document *document, int line); 1004 1005 /** 1006 * Text got inserted. 1007 * \param document document which emitted this signal 1008 * @param position position where the insertion occurred 1009 * @param text inserted text 1010 */ 1011 void textInserted(KTextEditor::Document *document, KTextEditor::Cursor position, const QString &text); 1012 1013 /** 1014 * Text got removed. 1015 * \param document document which emitted this signal 1016 * @param range range where the removal occurred 1017 * @param text removed text 1018 */ 1019 void textRemoved(KTextEditor::Document *document, KTextEditor::Range range, const QString &text); 1020 1021 /** 1022 * The \p document emits this signal whenever its text changes. 1023 * \param document document which emitted this signal 1024 * \see text(), textLine() 1025 */ 1026 void textChanged(KTextEditor::Document *document); 1027 1028 //!\} 1029 1030 /** 1031 * \name Highlighting and Related Information 1032 * 1033 * \{ 1034 */ 1035 public: 1036 /** 1037 * Get the default style of the character located at @p position. 1038 * If @p position is not a valid text position, the default style 1039 * KSyntaxHighlighting::Theme::TextStyle::Normal is returned. 1040 * 1041 * @note Further information about the colors of default styles depend on 1042 * the currently chosen schema. Since each View may have a different 1043 * color schema, the color information can be obtained through 1044 * View::defaultStyleAttribute() and View::lineAttributes(). 1045 * 1046 * @param position text position 1047 * @return default style, see enum KSyntaxHighlighting::Theme::TextStyle 1048 * @see View::defaultStyleAttribute(), View::lineAttributes() 1049 */ 1050 virtual KSyntaxHighlighting::Theme::TextStyle defaultStyleAt(KTextEditor::Cursor position) const = 0; 1051 1052 /** 1053 * Return the name of the currently used mode 1054 * \return name of the used mode 1055 * \see modes(), setMode() 1056 */ 1057 virtual QString mode() const = 0; 1058 1059 /** 1060 * Return the name of the currently used mode 1061 * \return name of the used mode 1062 * \see highlightingModes(), setHighlightingMode() 1063 */ 1064 virtual QString highlightingMode() const = 0; 1065 1066 /** 1067 * \brief Get all available highlighting modes for the current document. 1068 * 1069 * Each document can be highlighted using an arbitrary number of highlighting 1070 * contexts. This method will return the names for each of the used modes. 1071 * 1072 * Example: The "PHP (HTML)" mode includes the highlighting for PHP, HTML, CSS and JavaScript. 1073 * 1074 * \return Returns a list of embedded highlighting modes for the current Document. 1075 * 1076 * \see KTextEditor::Document::highlightingMode() 1077 */ 1078 virtual QStringList embeddedHighlightingModes() const = 0; 1079 1080 /** 1081 * \brief Get the highlight mode used at a given position in the document. 1082 * 1083 * Retrieve the name of the applied highlight mode at a given \p position 1084 * in the current document. 1085 * 1086 * Calling this might trigger re-highlighting up to the given line. 1087 * Therefore this is not const. 1088 * 1089 * \see highlightingModes() 1090 */ 1091 virtual QString highlightingModeAt(KTextEditor::Cursor position) = 0; 1092 1093 /** 1094 * Return a list of the names of all possible modes 1095 * \return list of mode names 1096 * \see mode(), setMode() 1097 */ 1098 virtual QStringList modes() const = 0; 1099 1100 /** 1101 * Return a list of the names of all possible modes 1102 * \return list of mode names 1103 * \see highlightingMode(), setHighlightingMode() 1104 */ 1105 virtual QStringList highlightingModes() const = 0; 1106 1107 /** 1108 * Set the current mode of the document by giving its name 1109 * \param name name of the mode to use for this document 1110 * \return \e true on success, otherwise \e false 1111 * \see mode(), modes(), modeChanged() 1112 */ 1113 virtual bool setMode(const QString &name) = 0; 1114 1115 /** 1116 * Set the current mode of the document by giving its name 1117 * \param name name of the mode to use for this document 1118 * \return \e true on success, otherwise \e false 1119 * \see highlightingMode(), highlightingModes(), highlightingModeChanged() 1120 */ 1121 virtual bool setHighlightingMode(const QString &name) = 0; 1122 1123 /** 1124 * Returns the name of the section for a highlight given its index in the highlight 1125 * list (as returned by highlightModes()). 1126 * 1127 * You can use this function to build a tree of the highlight names, organized in sections. 1128 * 1129 * \param index the index of the highlight in the list returned by modes() 1130 */ 1131 virtual QString highlightingModeSection(int index) const = 0; 1132 1133 /** 1134 * Returns the name of the section for a mode given its index in the highlight 1135 * list (as returned by modes()). 1136 * 1137 * You can use this function to build a tree of the mode names, organized in sections. 1138 * 1139 * \param index the index of the highlight in the list returned by modes() 1140 */ 1141 virtual QString modeSection(int index) const = 0; 1142 1143 /* 1144 * SIGNALS 1145 * Following signals should be emitted by the document if the mode 1146 * of the document changes 1147 */ 1148 Q_SIGNALS: 1149 /** 1150 * Warn anyone listening that the current document's mode has 1151 * changed. 1152 * 1153 * \param document the document whose mode has changed 1154 * \see setMode() 1155 */ 1156 void modeChanged(KTextEditor::Document *document); 1157 1158 /** 1159 * Warn anyone listening that the current document's highlighting mode has 1160 * changed. 1161 * 1162 * \param document the document which's mode has changed 1163 * \see setHighlightingMode() 1164 */ 1165 void highlightingModeChanged(KTextEditor::Document *document); 1166 1167 //!\} 1168 1169 /** 1170 * \name Printing 1171 * 1172 * \{ 1173 */ 1174 public: 1175 /** 1176 * Print the document. This should result in showing the print dialog. 1177 * 1178 * @returns true if document was printed 1179 */ 1180 virtual bool print() = 0; 1181 1182 /** 1183 * Shows the print preview dialog/ 1184 */ 1185 virtual void printPreview() = 0; 1186 1187 //!\} 1188 1189 /** 1190 * \name Showing Interactive Notifications 1191 * 1192 * \{ 1193 */ 1194 public: 1195 /** 1196 * Post @p message to the Document and its View%s. 1197 * If multiple Message%s are posted, the one with the highest priority 1198 * is shown first. 1199 * 1200 * Usually, you can simply forget the pointer, as the Message is deleted 1201 * automatically, once it is processed or the document gets closed. 1202 * 1203 * If the Document does not have a View yet, the Message is queued and 1204 * shown, once a View for the Document is created. 1205 * 1206 * @param message the message to show 1207 * @return @e true, if @p message was posted. @e false, if message == 0. 1208 */ 1209 virtual bool postMessage(Message *message) = 0; 1210 1211 //!\} 1212 1213 /** 1214 * \name Session Configuration 1215 * 1216 * \{ 1217 */ 1218 public: 1219 /** 1220 * Read session settings from the given \p config. 1221 * 1222 * Known flags: 1223 * - \p SkipUrl => do not save/restore the file 1224 * - \p SkipMode => do not save/restore the mode 1225 * - \p SkipHighlighting => do not save/restore the highlighting 1226 * - \p SkipEncoding => do not save/restore the encoding 1227 * 1228 * \param config read the session settings from this KConfigGroup 1229 * \param flags additional flags 1230 * \see writeSessionConfig() 1231 */ 1232 virtual void readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) = 0; 1233 1234 /** 1235 * Write session settings to the \p config. 1236 * See readSessionConfig() for more details about available \p flags. 1237 * 1238 * \param config write the session settings to this KConfigGroup 1239 * \param flags additional flags 1240 * \see readSessionConfig() 1241 */ 1242 virtual void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) = 0; 1243 1244 //!\} 1245 1246 /** 1247 * \name Crash Recovery 1248 * 1249 * \{ 1250 */ 1251 public: 1252 /** 1253 * Returns whether a recovery is available for the current document. 1254 * 1255 * \see recoverData(), discardDataRecovery() 1256 */ 1257 virtual bool isDataRecoveryAvailable() const = 0; 1258 1259 /** 1260 * If recover data is available, calling recoverData() will trigger the 1261 * recovery of the data. If isDataRecoveryAvailable() returns \e false, 1262 * calling this function does nothing. 1263 * 1264 * \see isDataRecoveryAvailable(), discardDataRecovery() 1265 */ 1266 virtual void recoverData() = 0; 1267 1268 /** 1269 * If recover data is available, calling discardDataRecovery() will discard 1270 * the recover data and the recover data is lost. 1271 * If isDataRecoveryAvailable() returns \e false, calling this function 1272 * does nothing. 1273 * 1274 * \see isDataRecoveryAvailable(), recoverData() 1275 */ 1276 virtual void discardDataRecovery() = 0; 1277 1278 //!\} 1279 1280 Q_SIGNALS: 1281 /** 1282 * This signal is emitted whenever the current document configuration is changed. 1283 * 1284 * \param document the document which's config has changed 1285 * 1286 * \since 5.79 1287 */ 1288 void configChanged(KTextEditor::Document *document); 1289 1290 /** 1291 * \name Moving Interface 1292 * 1293 * \{ 1294 */ 1295 public: 1296 /** 1297 * Create a new moving cursor for this document. 1298 * @param position position of the moving cursor to create 1299 * @param insertBehavior insertion behavior 1300 * @return new moving cursor for the document 1301 */ 1302 virtual MovingCursor *newMovingCursor(KTextEditor::Cursor position, MovingCursor::InsertBehavior insertBehavior = MovingCursor::MoveOnInsert) = 0; 1303 1304 /** 1305 * Create a new moving range for this document. 1306 * @param range range of the moving range to create 1307 * @param insertBehaviors insertion behaviors 1308 * @param emptyBehavior behavior on becoming empty 1309 * @return new moving range for the document 1310 */ 1311 virtual MovingRange *newMovingRange(Range range, 1312 MovingRange::InsertBehaviors insertBehaviors = MovingRange::DoNotExpand, 1313 MovingRange::EmptyBehavior emptyBehavior = MovingRange::AllowEmpty) = 0; 1314 1315 /** 1316 * Current revision 1317 * @return current revision 1318 */ 1319 virtual qint64 revision() const = 0; 1320 1321 /** 1322 * Last revision the buffer got successful saved 1323 * @return last revision buffer got saved, -1 if none 1324 */ 1325 virtual qint64 lastSavedRevision() const = 0; 1326 1327 /** 1328 * Lock a revision, this will keep it around until released again. 1329 * But all revisions will always be cleared on buffer clear() (and therefor load()) 1330 * @param revision revision to lock 1331 */ 1332 virtual void lockRevision(qint64 revision) = 0; 1333 1334 /** 1335 * Release a revision. 1336 * @param revision revision to release 1337 */ 1338 virtual void unlockRevision(qint64 revision) = 0; 1339 1340 /** 1341 * Transform a cursor from one revision to an other. 1342 * @param cursor cursor to transform 1343 * @param insertBehavior behavior of this cursor on insert of text at its position 1344 * @param fromRevision from this revision we want to transform 1345 * @param toRevision to this revision we want to transform, default of -1 is current revision 1346 */ 1347 virtual void 1348 transformCursor(KTextEditor::Cursor &cursor, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1) = 0; 1349 1350 /** 1351 * Transform a cursor from one revision to an other. 1352 * @param line line number of the cursor to transform 1353 * @param column column number of the cursor to transform 1354 * @param insertBehavior behavior of this cursor on insert of text at its position 1355 * @param fromRevision from this revision we want to transform 1356 * @param toRevision to this revision we want to transform, default of -1 is current revision 1357 */ 1358 virtual void 1359 transformCursor(int &line, int &column, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1) = 0; 1360 1361 /** 1362 * Transform a range from one revision to an other. 1363 * @param range range to transform 1364 * @param insertBehaviors behavior of this range on insert of text at its position 1365 * @param emptyBehavior behavior on becoming empty 1366 * @param fromRevision from this revision we want to transform 1367 * @param toRevision to this revision we want to transform, default of -1 is current revision 1368 */ 1369 virtual void transformRange(KTextEditor::Range &range, 1370 KTextEditor::MovingRange::InsertBehaviors insertBehaviors, 1371 MovingRange::EmptyBehavior emptyBehavior, 1372 qint64 fromRevision, 1373 qint64 toRevision = -1) = 0; 1374 1375 Q_SIGNALS: 1376 /** 1377 * This signal is emitted before the cursors/ranges/revisions of a document 1378 * are destroyed as the document is deleted. 1379 * @param document the document which the interface belongs to which is in the process of being deleted 1380 */ 1381 void aboutToDeleteMovingInterfaceContent(KTextEditor::Document *document); 1382 1383 /** 1384 * This signal is emitted before the ranges of a document are invalidated 1385 * and the revisions are deleted as the document is cleared (for example on 1386 * load/reload). While this signal is emitted, the old document content is 1387 * still valid and accessible before the clear. 1388 * @param document the document which the interface belongs to which will invalidate its data 1389 */ 1390 void aboutToInvalidateMovingInterfaceContent(KTextEditor::Document *document); 1391 1392 //!\} 1393 1394 /** 1395 * \name Config 1396 * 1397 * \{ 1398 */ 1399 public: 1400 /** 1401 * \brief Get a list of all available keys. 1402 */ 1403 virtual QStringList configKeys() const = 0; 1404 /** 1405 * \brief Get a value for the \p key. 1406 */ 1407 virtual QVariant configValue(const QString &key) = 0; 1408 /** 1409 * \brief Set a the \p key's value to \p value. 1410 */ 1411 virtual void setConfigValue(const QString &key, const QVariant &value) = 0; 1412 //!\} 1413 1414 /** 1415 * \name Modification Interface 1416 * 1417 * \{ 1418 */ 1419 public: 1420 /** 1421 * Reasons why a document is modified on disk. 1422 */ 1423 enum ModifiedOnDiskReason { 1424 OnDiskUnmodified = 0, ///< Not modified 1425 OnDiskModified = 1, ///< The file was modified on disk 1426 OnDiskCreated = 2, ///< The file was created on disk 1427 OnDiskDeleted = 3 ///< The file was deleted on disk 1428 }; 1429 1430 /** 1431 * Set the document's modified-on-disk state to \p reason. 1432 * KTextEditor implementations should emit the signal modifiedOnDisk() 1433 * along with the reason. When the document is in a clean state again the 1434 * reason should be ModifiedOnDiskReason::OnDiskUnmodified. 1435 * 1436 * \param reason the modified-on-disk reason. 1437 * \see ModifiedOnDiskReason, modifiedOnDisk() 1438 */ 1439 virtual void setModifiedOnDisk(ModifiedOnDiskReason reason) = 0; 1440 1441 /** 1442 * Control, whether the editor should show a warning dialog whenever a file 1443 * was modified on disk. If \p on is \e true the editor will show warning 1444 * dialogs. 1445 * \param on controls, whether the editor should show a warning dialog for 1446 * files modified on disk 1447 */ 1448 virtual void setModifiedOnDiskWarning(bool on) = 0; 1449 1450 Q_SIGNALS: 1451 /** 1452 * This signal is emitted whenever the \p document changed its 1453 * modified-on-disk state. 1454 * \param document the Document object that represents the file on disk 1455 * \param isModified if \e true, the file was modified rather than created 1456 * or deleted 1457 * \param reason the reason why the signal was emitted 1458 * \see setModifiedOnDisk() 1459 */ 1460 void modifiedOnDisk(KTextEditor::Document *document, bool isModified, KTextEditor::Document::ModifiedOnDiskReason reason); 1461 //!\} 1462 1463 /** 1464 * \name Mark Interface 1465 * 1466 * \{ 1467 */ 1468 public: 1469 /** 1470 * Get all marks set on the \p line. 1471 * \param line requested line 1472 * \return a \e uint representing of the marks set in \p line concatenated 1473 * by logical OR 1474 * \see addMark(), removeMark() 1475 */ 1476 virtual uint mark(int line) = 0; 1477 1478 /** 1479 * Set the \p line's mark types to \p markType. 1480 * If \p line already contains a mark of the given type it has no effect. 1481 * All other marks are deleted before the mark is set. You can achieve 1482 * the same by calling 1483 * \code 1484 * clearMark(line); 1485 * addMark(line, markType); 1486 * \endcode 1487 * \param line line to set the mark 1488 * \param markType mark type 1489 * \see clearMark(), addMark(), mark() 1490 */ 1491 virtual void setMark(int line, uint markType) = 0; 1492 1493 /** 1494 * Clear all marks set in the \p line. 1495 * \param line line to clear marks 1496 * \see clearMarks(), removeMark(), addMark() 1497 */ 1498 virtual void clearMark(int line) = 0; 1499 1500 /** 1501 * Add marks of type \p markType to \p line. Existing marks on this line 1502 * are preserved. If the mark \p markType already is set, nothing 1503 * happens. 1504 * \param line line to set the mark 1505 * \param markType mark type 1506 * \see removeMark(), setMark() 1507 */ 1508 virtual void addMark(int line, uint markType) = 0; 1509 1510 /** 1511 * Remove the mark mask of type \p markType from \p line. 1512 * \param line line to remove the mark 1513 * \param markType mark type to be removed 1514 * \see clearMark() 1515 */ 1516 virtual void removeMark(int line, uint markType) = 0; 1517 1518 /** 1519 * Get a hash holding all marks in the document. 1520 * The hash key for a mark is its line. 1521 * \return a hash holding all marks in the document 1522 * 1523 * KF6 TODO: Change Mark* to Mark. No need for pointer here. 1524 */ 1525 virtual const QHash<int, KTextEditor::Mark *> &marks() = 0; 1526 1527 /** 1528 * Clear all marks in the entire document. 1529 * \see clearMark(), removeMark() 1530 */ 1531 /// TODO: dominik: add argument unit mask = 0 1532 virtual void clearMarks() = 0; 1533 1534 /** 1535 * Get the number of predefined mark types we have so far. 1536 * \note FIXME: If you change this you have to make sure katepart 1537 * supports the new size! 1538 * \return number of reserved marker types 1539 */ 1540 static int reservedMarkersCount() 1541 { 1542 return 7; 1543 } 1544 1545 /** 1546 * Predefined mark types. 1547 * 1548 * To add a new standard mark type, edit this interface and document 1549 * the type. 1550 */ 1551 enum MarkTypes { 1552 /** Bookmark */ 1553 markType01 = 0x1, 1554 /** Breakpoint active */ 1555 markType02 = 0x2, 1556 /** Breakpoint reached */ 1557 markType03 = 0x4, 1558 /** Breakpoint disabled */ 1559 markType04 = 0x8, 1560 /** Execution mark */ 1561 markType05 = 0x10, 1562 /** Warning */ 1563 markType06 = 0x20, 1564 /** Error */ 1565 markType07 = 0x40, 1566 1567 markType08 = 0x80, 1568 markType09 = 0x100, 1569 markType10 = 0x200, 1570 markType11 = 0x400, 1571 markType12 = 0x800, 1572 markType13 = 0x1000, 1573 markType14 = 0x2000, 1574 markType15 = 0x4000, 1575 markType16 = 0x8000, 1576 markType17 = 0x10000, 1577 markType18 = 0x20000, 1578 markType19 = 0x40000, 1579 markType20 = 0x80000, 1580 markType21 = 0x100000, 1581 markType22 = 0x200000, 1582 markType23 = 0x400000, 1583 markType24 = 0x800000, 1584 markType25 = 0x1000000, 1585 markType26 = 0x2000000, 1586 markType27 = 0x4000000, 1587 markType28 = 0x8000000, 1588 markType29 = 0x10000000, 1589 markType30 = 0x20000000, 1590 markType31 = 0x40000000, 1591 markType32 = 0x80000000, 1592 /* reserved marks */ 1593 Bookmark = markType01, 1594 BreakpointActive = markType02, 1595 BreakpointReached = markType03, 1596 BreakpointDisabled = markType04, 1597 Execution = markType05, 1598 Warning = markType06, 1599 Error = markType07, 1600 SearchMatch = markType32, 1601 }; 1602 1603 /* 1604 * Methods to modify mark properties. 1605 */ 1606 public: 1607 /** 1608 * Set the \p mark's description to \p text. 1609 * \param mark mark to set the description 1610 * \param text new descriptive text 1611 * \see markDescription(), setMarkPixmap() 1612 */ 1613 virtual void setMarkDescription(MarkTypes mark, const QString &text) = 0; 1614 1615 /** 1616 * Get the \p mark's description to text. 1617 * \param mark mark to set the description 1618 * \return text of the given \p mark or QString(), if the entry does not 1619 * exist 1620 * \see setMarkDescription(), setMarkPixmap() 1621 */ 1622 virtual QString markDescription(MarkTypes mark) const = 0; 1623 1624 /** 1625 * Set the mark mask the user is allowed to toggle to \p markMask. 1626 * I.e. concatenate all editable marks with a logical OR. If the user should 1627 * be able to add a bookmark and set a breakpoint with the context menu in 1628 * the icon pane, you have to call 1629 * \code 1630 * // iface is of Type KTextEditor::MarkInterface* 1631 * // only make bookmark and breakpoint editable 1632 * iface->setEditableMarks( MarkInterface::Bookmark | 1633 * MarkInterface::BreakpointActive ); 1634 * 1635 * // or preserve last settings, and add bookmark and breakpoint 1636 * iface->setEditableMarks( iface->editableMarks() | 1637 * MarkInterface::Bookmark | 1638 * MarkInterface::BreakpointActive ); 1639 * \endcode 1640 * \param markMask bitmap pattern 1641 * \see editableMarks(), setMarkPixmap(), setMarkDescription() 1642 */ 1643 virtual void setEditableMarks(uint markMask) = 0; 1644 1645 /** 1646 * Get, which marks can be toggled by the user. 1647 * The returned value is a mark mask containing all editable marks combined 1648 * with a logical OR. 1649 * \return mark mask containing all editable marks 1650 * \see setEditableMarks() 1651 */ 1652 virtual uint editableMarks() const = 0; 1653 1654 /** 1655 * Possible actions on a mark. 1656 * \see markChanged() 1657 */ 1658 enum MarkChangeAction { 1659 MarkAdded = 0, /**< action: a mark was added. */ 1660 MarkRemoved = 1 /**< action: a mark was removed. */ 1661 }; 1662 1663 /** 1664 * Set the \p mark's icon to \p icon. 1665 * \param markType mark type to which the icon will be attached 1666 * \param icon new icon 1667 * \see setMarkDescription() 1668 */ 1669 virtual void setMarkIcon(MarkTypes markType, const QIcon &icon) = 0; 1670 1671 /** 1672 * Get the \p mark's icon. 1673 * \param markType mark type. If the icon does not exist the resulting is null 1674 * (check with QIcon::isNull()). 1675 * \see setMarkDescription() 1676 */ 1677 virtual QIcon markIcon(MarkTypes markType) const = 0; 1678 1679 Q_SIGNALS: 1680 /** 1681 * The \p document emits this signal whenever a mark mask changed. 1682 * \param document document which emitted this signal 1683 * \see markChanged() 1684 */ 1685 void marksChanged(KTextEditor::Document *document); 1686 1687 /** 1688 * The \p document emits this signal whenever the \p mark changes. 1689 * \param document the document which emitted the signal 1690 * \param mark changed mark 1691 * \param action action, either removed or added 1692 * \see marksChanged() 1693 */ 1694 void markChanged(KTextEditor::Document *document, KTextEditor::Mark mark, KTextEditor::Document::MarkChangeAction action); 1695 1696 /** 1697 * The \p document emits this signal whenever the \p mark is hovered using the mouse, 1698 * and the receiver may show a tooltip. 1699 * \param document the document which emitted the signal 1700 * \param mark mark that was hovered 1701 * \param position mouse position during the hovering 1702 * \param handled set this to 'true' if this event was handled externally 1703 */ 1704 void markToolTipRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint position, bool &handled); 1705 1706 /** 1707 * The \p document emits this signal whenever the \p mark is right-clicked to show a context menu. 1708 * The receiver may show an own context menu instead of the kate internal one. 1709 * \param document the document which emitted the signal 1710 * \param mark mark that was right-clicked 1711 * \param pos position where the menu should be started 1712 * \param handled set this to 'true' if this event was handled externally, and kate should not create an own context menu. 1713 */ 1714 void markContextMenuRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint pos, bool &handled); 1715 1716 /** 1717 * The \p document emits this signal whenever the \p mark is left-clicked. 1718 * \param document the document which emitted the signal 1719 * \param mark mark that was right-clicked 1720 * \param handled set this to 'true' if this event was handled externally, and kate should not do own handling of the left click. 1721 */ 1722 void markClicked(KTextEditor::Document *document, KTextEditor::Mark mark, bool &handled); 1723 //!\} 1724 1725 /** 1726 * \name Annotation Interface 1727 * 1728 * \{ 1729 */ 1730 public: 1731 /** 1732 * Sets a new \ref AnnotationModel for this document to provide 1733 * annotation information for each line. 1734 * 1735 * \param model the new AnnotationModel 1736 */ 1737 virtual void setAnnotationModel(AnnotationModel *model) = 0; 1738 1739 /** 1740 * returns the currently set \ref AnnotationModel or 0 if there's none 1741 * set 1742 * @returns the current \ref AnnotationModel 1743 */ 1744 virtual AnnotationModel *annotationModel() const = 0; 1745 //!\} 1746 1747 private: 1748 /** 1749 * private d-pointer, pointing to the internal implementation 1750 */ 1751 DocumentPrivate *const d; 1752 }; 1753 1754 } 1755 1756 #endif