FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ghostwriter/src/DocumentManager.h at master · jackcoolpython/ghostwriter · GitHub
jackcoolpython
ghostwriter
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ghostwriter
/
src
/
DocumentManager.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
304 lines (260 loc) · 10.3 KB
Breadcrumbs
ghostwriter
/
src
/
DocumentManager.h
Copy path
File metadata and controls
304 lines (260 loc) · 10.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
**********************************************************************
*
* Copyright (C) 2014-2020 wereturtle
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
**********************************************************************
*/
#
ifndef
DOCUMENTMANAGER_H
#
define
DOCUMENTMANAGER_H
#
include
<
QFutureWatcher
>
#
include
<
QObject
>
#
include
<
QWidget
>
#
include
"
DocumentStatistics.h
"
#
include
"
MarkdownDocument.h
"
#
include
"
MarkdownEditor.h
"
#
include
"
Outline.h
"
#
include
"
SessionStatistics.h
"
class
QFileSystemWatcher
;
/*
*
* Manages the life-cycle of a document, facilitating user interaction for
* opening, closing, saving, etc.
*/
class
DocumentManager
:
public
QObject
{
Q_OBJECT
public:
/*
*
* Constructor. Takes MarkdownEditor as a parameter, which is used
* to display the current document to the user. Also takes the
* document statistics as a parameter in order to reset the statistics
* when a new file is loaded.
*/
DocumentManager
(
MarkdownEditor* editor,
Outline* outline,
DocumentStatistics* documentStats,
SessionStatistics* sessionStats,
QWidget* parent =
0
);
/*
*
* Destructor.
*/
virtual
~DocumentManager
();
/*
*
* Gets the current document that is opened.
*/
MarkdownDocument*
getDocument
()
const
;
/*
*
* Gets whether auto-save is enabled.
*/
bool
getAutoSaveEnabled
()
const
;
/*
*
* Gets whether automatic file backup (i.e., creation of a .backup
* file at regular intervals), is enabled.
*/
bool
getFileBackupEnabled
()
const
;
/*
*
* Gets whether tracking the recent file history is enabled.
*/
void
setFileHistoryEnabled
(
bool
enabled);
signals:
/*
*
* Emitted when the document's display name changes, which is useful
* for updating the editor's containing window or tab to have the new
* document display name.
*/
void
documentDisplayNameChanged
(
const
QString& displayName);
/*
*
* Emitted when the document's modification state changes. The
* modified parameter will be true if the document has been modified.
*/
void
documentModifiedChanged
(
bool
modified);
/*
*
* Emitted when an operation on the document has started, such as
* when a document is being loaded into the editor either from being
* opened or reloaded from disk. Connect to this signal to notify
* the user of a possibly long operation for the document, such as
* with a progress bar. The description parameter will contain
* descriptive text to display to the user regarding the operation.
*/
void
operationStarted
(
const
QString& description);
/*
*
* Emitted to update the status of a document operation begun with
* operationStarted(). The description is optional. If no
* description is provided, then the previous description used in
* operationStarted() should be used to display status to the user.
* Upon receipt of this signal, it is recommended that the GUI
* be updated to refresh the status as well as the editor and
* any other widgets that might have changed due to a document
* operation, so that those changes can be displayed to the user.
*
* A call to QWidget's update() and qApp->processEvents() will
* perform this refresh.
*/
void
operationUpdate
(
const
QString& description = QString());
/*
*
* Emitted when an operation on the document has finished, such as
* when a document has finished loading into the editor either from
* being opened or reloaded from disk. Connect to this signal to notify
* the user that a long operation for the document has completed,
* such as by removing a progress bar that was previously displayed
* when the operation first started.
*/
void
operationFinished
();
/*
*
* Emitted when the document is closed.
*/
void
documentClosed
();
public slots:
/*
*
* Sets whether auto-saving of the file is enabled.
*/
void
setAutoSaveEnabled
(
bool
enabled);
/*
*
* Sets whether a backup file is created (with a .backup extension)
* on disk before the document is saved.
*/
void
setFileBackupEnabled
(
bool
enabled);
/*
*
* Prompts the user for a file path, and loads the document with the
* file contents at the selected path.
*/
void
open
(
const
QString& filePath = QString());
/*
*
* Reopens the last closed file, if any is available in the document
* history.
*/
void
reopenLastClosedFile
();
/*
*
* Reloads document from disk contents. This method does nothing if
* the document is new and is not associated with a file on disk.
* Note that if the document is modified, this method will discard
* changes before reloading. It is left to the caller to check for
* modification and save any changes before calling this method.
*/
void
reload
();
/*
*
* Renames file represented by this document to the given file path.
* This method does nothing if the document is new and is not
* associated with a file on disk.
*/
void
rename
();
/*
*
* Savse document contents to disk. This method does nothing if the
* document is new and is not associated with a file on disk.
*/
bool
save
();
/*
*
* Prompts the user for a file path location, and saves the document
* contents to the selected file path. This method is
* also called if the document is new and is now going to be saved to
* a file path for the first time. Future save operations to the same
* file path can be achieved by calling save() instead.
*/
bool
saveAs
();
/*
*
* Closes the current file, clearing the editor of text and leaving
* only an untitled "new" document in its place. Note that isNew()
* will return true after this method is called.
*/
bool
close
();
/*
*
* Exports the current file, prompting the user for the desired
* export format.
*/
void
exportFile
();
private slots:
void
onDocumentModifiedChanged
(
bool
modified);
void
onSaveCompleted
();
void
onFileChangedExternally
(
const
QString& path);
void
autoSaveFile
();
private:
static
const
QString
FILE_CHOOSER_FILTER
;
QWidget* parentWidget;
MarkdownDocument* document;
MarkdownEditor* editor;
Outline* outline;
DocumentStatistics* documentStats;
SessionStatistics* sessionStats;
QFutureWatcher<QString>* saveFutureWatcher;
QFileSystemWatcher* fileWatcher;
bool
fileHistoryEnabled;
bool
createBackupOnSave;
/*
* This flag is used to prevent notifying the user that the document
* was modified when the user is the one who modified it by saving.
* See code for onFileChangedExternally() for details.
*/
bool
saveInProgress;
/*
* This timer's timeout signal is connected to the autoSaveFile() slot,
* which saves the document if it can be saved and has been modified.
*/
QTimer* autoSaveTimer;
bool
autoSaveEnabled;
/*
* Boolean flag used to track if the prompt for the file having been
* externally modified is already displayed and should not be displayed
* again.
*/
bool
documentModifiedNotifVisible;
/*
* Begins asynchronous save operation. Called by save() and saveAs().
*/
void
saveFile
();
/*
* Loads the document with the file contents at the given path.
*/
bool
loadFile
(
const
QString& filePath);
/*
* Sets the file path for the document, such that the file will be
* monitored for external changes made to it, and the display name
* for the document updated.
*/
void
setFilePath
(
const
QString& filePath);
/*
* Checks if changes need to be saved before an operation
* can continue. The user will be prompted to save if
* necessary, and this method will return true if the
* operation can proceed.
*/
bool
checkSaveChanges
();
/*
* Checks if file on the disk is read only. This method will return
* true if save operation can proceed.
*/
bool
checkPermissionsBeforeSave
();
/*
* Saves the given text to the given file path, returning a null
* string if successful, otherwise an error message. Note that this
* method is intended to be run in a separate thread from the main
* Qt event loop, and should thus never interact with any widgets.
*/
QString saveToDisk
(
const
QString& filePath,
const
QString& text,
bool
createBackup
)
const
;
/*
* Creates a backup file with a ".backup" extension of the file having
* the specified path. Note that this method is intended to be run in
* a separate thread from the main Qt event loop, and should thus never
* interact with any widgets.
*/
void
backupFile
(
const
QString& filePath)
const
;
};
#
endif
//
DOCUMENTMANAGER_H
Back
|
FazBrowse Home
|
New Git URL