forked from vnotex/vnote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvedittab.h
More file actions
217 lines (147 loc) · 6.2 KB
/
vedittab.h
File metadata and controls
217 lines (147 loc) · 6.2 KB
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
#ifndef VEDITTAB_H
#define VEDITTAB_H
#include <QWidget>
#include <QString>
#include <QPointer>
#include "vtableofcontent.h"
#include "vfile.h"
#include "utils/vvim.h"
#include "vedittabinfo.h"
#include "vwordcountinfo.h"
#include "vsearchconfig.h"
class VEditArea;
class VSnippet;
// VEditTab is the base class of an edit tab inside VEditWindow.
class VEditTab : public QWidget
{
Q_OBJECT
public:
VEditTab(VFile *p_file, VEditArea *p_editArea, QWidget *p_parent = 0);
virtual ~VEditTab();
// Close current tab.
// @p_forced: if true, discard the changes.
virtual bool closeFile(bool p_forced) = 0;
// Enter read mode.
// @p_discard: whether set the discard action as the default one.
virtual void readFile(bool p_discard = false) = 0;
// Save file.
virtual bool saveFile() = 0;
bool isEditMode() const;
virtual bool isModified() const;
void focusTab();
// Whether this tab has focus.
bool tabHasFocus() const;
// Scroll to @p_header.
// Will emit currentHeaderChanged() if @p_header is valid.
virtual void scrollToHeader(const VHeaderPointer &p_header) { Q_UNUSED(p_header) }
VFile *getFile() const;
// User requests to insert image.
virtual void insertImage() = 0;
// User requests to insert link.
virtual void insertLink();
// User requests to table.
virtual void insertTable();
// Search @p_text in current note.
virtual void findText(const QString &p_text, uint p_options, bool p_peek,
bool p_forward = true) = 0;
virtual void findText(const VSearchToken &p_token,
bool p_forward = true,
bool p_fromStart = false) = 0;
// Replace @p_text with @p_replaceText in current note.
virtual void replaceText(const QString &p_text, uint p_options,
const QString &p_replaceText, bool p_findNext) = 0;
virtual void replaceTextAll(const QString &p_text, uint p_options,
const QString &p_replaceText) = 0;
virtual void nextMatch(const QString &p_text, uint p_options, bool p_forward) = 0;
// Return selected text.
virtual QString getSelectedText() const = 0;
virtual void clearSearchedWordHighlight() = 0;
// Request current tab to propogate its status about Vim.
virtual void requestUpdateVimStatus() = 0;
// Insert decoration markers or decorate selected text.
virtual void decorateText(TextDecoration p_decoration, int p_level = -1)
{
Q_UNUSED(p_decoration);
Q_UNUSED(p_level);
}
// Create a filled VEditTabInfo.
virtual VEditTabInfo fetchTabInfo(VEditTabInfo::InfoType p_type = VEditTabInfo::InfoType::All) const;
const VTableOfContent &getOutline() const;
const VHeaderPointer &getCurrentHeader() const;
// Restore status from @p_info.
// If this tab is not ready yet, it will restore once it is ready.
void tryRestoreFromTabInfo(const VEditTabInfo &p_info);
// Emit signal to update current status.
virtual void updateStatus();
// Called by evaluateMagicWordsByCaptain() to evaluate the magic words.
virtual void evaluateMagicWords();
// Insert snippet @p_snippet.
virtual void applySnippet(const VSnippet *p_snippet);
// Prompt for user to apply a snippet.
virtual void applySnippet();
// Check whether this file has been changed outside.
void checkFileChangeOutside();
// Reload the editor from file.
virtual void reload() = 0;
// Reload file from disk and reload the editor.
void reloadFromDisk();
// Handle the change of file or directory, such as the file has been moved.
virtual void handleFileOrDirectoryChange(bool p_isFile, UpdateAction p_act);
// Fetch tab stat info.
virtual VWordCountInfo fetchWordCountInfo(bool p_editMode) const;
public slots:
// Enter edit mode
virtual void editFile() = 0;
virtual void handleVimCmdCommandCancelled();
virtual void handleVimCmdCommandFinished(VVim::CommandLineType p_type, const QString &p_cmd);
virtual void handleVimCmdCommandChanged(VVim::CommandLineType p_type, const QString &p_cmd);
virtual QString handleVimCmdRequestNextCommand(VVim::CommandLineType p_type, const QString &p_cmd);
virtual QString handleVimCmdRequestPreviousCommand(VVim::CommandLineType p_type, const QString &p_cmd);
virtual QString handleVimCmdRequestRegister(int p_key, int p_modifiers);
protected:
void wheelEvent(QWheelEvent *p_event) Q_DECL_OVERRIDE;
// Called when VEditTab get focus. Should focus the proper child widget.
virtual void focusChild() = 0;
// Called to zoom in/out content.
virtual void zoom(bool p_zoomIn, qreal p_step = 0.25) = 0;
// Restore from @p_fino.
// Return true if succeed.
virtual bool restoreFromTabInfo(const VEditTabInfo &p_info) = 0;
// Write modified buffer content to backup file.
virtual void writeBackupFile();
// File related to this tab.
QPointer<VFile> m_file;
bool m_isEditMode;
// Table of content of this tab.
VTableOfContent m_outline;
// Current header in m_outline of this tab.
VHeaderPointer m_currentHeader;
VEditArea *m_editArea;
// Tab info to restore from once ready.
VEditTabInfo m_infoToRestore;
// Whether check the file change outside.
bool m_checkFileChange;
// File has diverged from disk.
bool m_fileDiverged;
// Tab has been ready or not.
int m_ready;
// Whether backup file is enabled.
bool m_enableBackupFile;
signals:
void getFocused();
void outlineChanged(const VTableOfContent &p_outline);
void currentHeaderChanged(const VHeaderPointer &p_header);
// The status of current tab has updates.
void statusUpdated(const VEditTabInfo &p_info);
// Emit when want to show message in status bar.
void statusMessage(const QString &p_msg);
void vimStatusUpdated(const VVim *p_vim);
// Request to close itself.
void closeRequested(VEditTab *p_tab);
// Request main window to show Vim cmd line.
void triggerVimCmd(VVim::CommandLineType p_type);
private slots:
// Called when app focus changed.
void handleFocusChanged(QWidget *p_old, QWidget *p_now);
};
#endif // VEDITTAB_H