forked from vnotex/vnote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvedittab.cpp
More file actions
268 lines (219 loc) · 5.74 KB
/
vedittab.cpp
File metadata and controls
268 lines (219 loc) · 5.74 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
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
#include "vedittab.h"
#include <QApplication>
#include <QWheelEvent>
#include "utils/vutils.h"
#include "vconfigmanager.h"
extern VConfigManager *g_config;
VEditTab::VEditTab(VFile *p_file, VEditArea *p_editArea, QWidget *p_parent)
: QWidget(p_parent),
m_file(p_file),
m_isEditMode(false),
m_outline(p_file),
m_currentHeader(p_file, -1),
m_editArea(p_editArea),
m_checkFileChange(true),
m_fileDiverged(false),
m_ready(0),
m_enableBackupFile(g_config->getEnableBackupFile())
{
connect(qApp, &QApplication::focusChanged,
this, &VEditTab::handleFocusChanged);
}
VEditTab::~VEditTab()
{
if (m_file) {
m_file->close();
}
}
void VEditTab::focusTab()
{
focusChild();
emit getFocused();
updateStatus();
}
bool VEditTab::isEditMode() const
{
return m_isEditMode;
}
bool VEditTab::isModified() const
{
return false;
}
VFile *VEditTab::getFile() const
{
return m_file;
}
void VEditTab::handleFocusChanged(QWidget * /* p_old */, QWidget *p_now)
{
if (p_now == this) {
// When VEditTab get focus, it should focus to current widget.
focusChild();
emit getFocused();
updateStatus();
} else if (isAncestorOf(p_now)) {
emit getFocused();
updateStatus();
}
}
void VEditTab::wheelEvent(QWheelEvent *p_event)
{
if (p_event->modifiers() & Qt::ControlModifier) {
QPoint angle = p_event->angleDelta();
if (!angle.isNull() && (angle.y() != 0)) {
// Zoom in/out current tab.
zoom(angle.y() > 0);
}
p_event->accept();
return;
}
QWidget::wheelEvent(p_event);
}
VEditTabInfo VEditTab::fetchTabInfo(VEditTabInfo::InfoType p_type) const
{
VEditTabInfo info;
info.m_type = p_type;
info.m_editTab = const_cast<VEditTab *>(this);
return info;
}
const VHeaderPointer &VEditTab::getCurrentHeader() const
{
return m_currentHeader;
}
const VTableOfContent &VEditTab::getOutline() const
{
return m_outline;
}
void VEditTab::tryRestoreFromTabInfo(const VEditTabInfo &p_info)
{
if (p_info.m_editTab != this) {
m_infoToRestore.clear();
return;
}
if (restoreFromTabInfo(p_info)) {
m_infoToRestore.clear();
return;
}
// Save it and restore later.
m_infoToRestore = p_info;
}
void VEditTab::updateStatus()
{
emit statusUpdated(fetchTabInfo());
}
void VEditTab::evaluateMagicWords()
{
}
bool VEditTab::tabHasFocus() const
{
QWidget *wid = QApplication::focusWidget();
return wid == this || isAncestorOf(wid);
}
void VEditTab::insertLink()
{
}
void VEditTab::insertTable()
{
}
void VEditTab::applySnippet(const VSnippet *p_snippet)
{
Q_UNUSED(p_snippet);
}
void VEditTab::applySnippet()
{
}
void VEditTab::checkFileChangeOutside()
{
if (!m_checkFileChange) {
return;
}
bool missing = false;
if (m_file->isChangedOutside(missing)) {
// It may be caused by cutting files.
if (missing) {
qWarning() << "file is missing when check file's outside change" << m_file->fetchPath();
return;
}
int ret = VUtils::showMessage(QMessageBox::Information,
tr("Information"),
tr("Note <span style=\"%1\">%2</span> has been modified by another program.")
.arg(g_config->c_dataTextStyle).arg(m_file->fetchPath()),
tr("Do you want to reload it?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes,
this);
switch (ret) {
case QMessageBox::Yes:
reloadFromDisk();
break;
case QMessageBox::No:
m_checkFileChange = false;
m_fileDiverged = true;
updateStatus();
break;
default:
Q_ASSERT(false);
break;
}
}
}
void VEditTab::reloadFromDisk()
{
bool ret = m_file->reload();
if (!ret) {
VUtils::showMessage(QMessageBox::Warning,
tr("Warning"),
tr("Fail to reload note <span style=\"%1\">%2</span>.")
.arg(g_config->c_dataTextStyle).arg(m_file->getName()),
tr("Please check if file %1 exists.").arg(m_file->fetchPath()),
QMessageBox::Ok,
QMessageBox::Ok,
this);
}
m_fileDiverged = !ret;
m_checkFileChange = ret;
reload();
}
void VEditTab::writeBackupFile()
{
}
void VEditTab::handleFileOrDirectoryChange(bool p_isFile, UpdateAction p_act)
{
Q_UNUSED(p_isFile);
Q_UNUSED(p_act);
}
void VEditTab::handleVimCmdCommandCancelled()
{
}
void VEditTab::handleVimCmdCommandFinished(VVim::CommandLineType p_type, const QString &p_cmd)
{
Q_UNUSED(p_type);
Q_UNUSED(p_cmd);
}
void VEditTab::handleVimCmdCommandChanged(VVim::CommandLineType p_type, const QString &p_cmd)
{
Q_UNUSED(p_type);
Q_UNUSED(p_cmd);
}
QString VEditTab::handleVimCmdRequestNextCommand(VVim::CommandLineType p_type, const QString &p_cmd)
{
Q_UNUSED(p_type);
Q_UNUSED(p_cmd);
return QString();
}
QString VEditTab::handleVimCmdRequestPreviousCommand(VVim::CommandLineType p_type, const QString &p_cmd)
{
Q_UNUSED(p_type);
Q_UNUSED(p_cmd);
return QString();
}
QString VEditTab::handleVimCmdRequestRegister(int p_key, int p_modifiers)
{
Q_UNUSED(p_key);
Q_UNUSED(p_modifiers);
return QString();
}
VWordCountInfo VEditTab::fetchWordCountInfo(bool p_editMode) const
{
Q_UNUSED(p_editMode);
return VWordCountInfo();
}