KTextEditor

modificationinterface.h
1 /*
2  SPDX-FileCopyrightText: 2005 Christoph Cullmann <[email protected]>
3 
4  Documentation:
5  SPDX-FileCopyrightText: 2005 Dominik Haumann <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #ifndef KTEXTEDITOR_MODIFICATIONINTERFACE_H
11 #define KTEXTEDITOR_MODIFICATIONINTERFACE_H
12 
13 #include <ktexteditor_export.h>
14 
15 #include <QObject>
16 
17 namespace KTextEditor
18 {
19 class Document;
20 class View;
21 
22 /**
23  * \class ModificationInterface modificationinterface.h <KTextEditor/ModificationInterface>
24  *
25  * \brief External modification extension interface for the Document.
26  *
27  * \ingroup kte_group_doc_extensions
28  *
29  * \section modiface_intro Introduction
30  *
31  * The class ModificationInterface provides methods to handle modifications
32  * of all opened files caused by external programs. Whenever the
33  * modified-on-disk state changes the signal modifiedOnDisk() is emitted
34  * along with a ModifiedOnDiskReason. Set the state by calling
35  * setModifiedOnDisk(). Whether the Editor should show warning dialogs to
36  * inform the user about external modified files can be controlled with
37  * setModifiedOnDiskWarning(). The slot modifiedOnDisk() is called to ask
38  * the user what to do whenever a file was modified.
39  *
40  * \section modiface_access Accessing the ModificationInterface
41  *
42  * The ModificationInterface is supposed to be an extension interface for a
43  * Document, i.e. the Document inherits the interface \e provided that the
44  * used KTextEditor library implements the interface. Use qobject_cast to
45  * access the interface:
46  * \code
47  * // doc is of type KTextEditor::Document*
48  * auto iface = qobject_cast<KTextEditor::ModificationInterface*>(doc);
49  *
50  * if (iface) {
51  * // the implementation supports the interface
52  * // do stuff
53  * } else {
54  * // the implementation does not support the interface
55  * }
56  * \endcode
57  *
58  * \see KTextEditor::Document
59  * \author Christoph Cullmann <[email protected]>
60  */
61 class KTEXTEDITOR_EXPORT ModificationInterface
62 {
63 public:
65 
66  /**
67  * Virtual destructor.
68  */
69  virtual ~ModificationInterface();
70 
71 public:
72  /**
73  * Reasons why a document is modified on disk.
74  */
76  OnDiskUnmodified = 0, ///< Not modified
77  OnDiskModified = 1, ///< The file was modified on disk
78  OnDiskCreated = 2, ///< The file was created on disk
79  OnDiskDeleted = 3 ///< The file was deleted on disk
80  };
81 
82 public:
83  /**
84  * Set the document's modified-on-disk state to \p reason.
85  * KTextEditor implementations should emit the signal modifiedOnDisk()
86  * along with the reason. When the document is in a clean state again the
87  * reason should be ModifiedOnDiskReason::OnDiskUnmodified.
88  *
89  * \param reason the modified-on-disk reason.
90  * \see ModifiedOnDiskReason, modifiedOnDisk()
91  */
92  virtual void setModifiedOnDisk(ModifiedOnDiskReason reason) = 0;
93 
94  /**
95  * Control, whether the editor should show a warning dialog whenever a file
96  * was modified on disk. If \p on is \e true the editor will show warning
97  * dialogs.
98  * \param on controls, whether the editor should show a warning dialog for
99  * files modified on disk
100  */
101  virtual void setModifiedOnDiskWarning(bool on) = 0;
102 
103  /*
104  * These stuff is implemented as SIGNALS in the real document
105  */
106 public:
107  /**
108  * This signal is emitted whenever the \p document changed its
109  * modified-on-disk state.
110  * \param document the Document object that represents the file on disk
111  * \param isModified if \e true, the file was modified rather than created
112  * or deleted
113  * \param reason the reason why the signal was emitted
114  * \see setModifiedOnDisk()
115  */
116  virtual void modifiedOnDisk(KTextEditor::Document *document, bool isModified, KTextEditor::ModificationInterface::ModifiedOnDiskReason reason) = 0;
117 
118 private:
119  class ModificationInterfacePrivate *const d = nullptr;
120 };
121 
122 }
123 
124 Q_DECLARE_INTERFACE(KTextEditor::ModificationInterface, "org.kde.KTextEditor.ModificationInterface")
125 
126 #endif
void setModifiedOnDiskWarning(bool on) override
Control, whether the editor should show a warning dialog whenever a file was modified on disk.
void setModifiedOnDisk(ModifiedOnDiskReason reason) override
Set the document's modified-on-disk state to reason.
@ OnDiskModified
The file was modified on disk.
@ OnDiskCreated
The file was created on disk.
ModifiedOnDiskReason
Reasons why a document is modified on disk.
@ OnDiskDeleted
The file was deleted on disk.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
Definition: katetextblock.h:22
External modification extension interface for the Document.
void modifiedOnDisk(KTextEditor::Document *doc, bool isModified, KTextEditor::ModificationInterface::ModifiedOnDiskReason reason) override
Indicate this file is modified on disk.
virtual ~ModificationInterface()
Virtual destructor.
A KParts derived class representing a text document.
Definition: document.h:185
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:50:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.