forked from altairwei/WizNotePlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wizactions.cpp
295 lines (247 loc) · 9.9 KB
/
wizactions.cpp
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
#include "wizactions.h"
#include <QAction>
#include <QMenuBar>
#include "share/wizmisc.h"
#include "share/wizsettings.h"
#include "share/wizanimateaction.h"
struct WIZACTION
{
QString strName;
QString strText;
QString strText2;
QString strShortcut;
};
CWizActions::CWizActions(CWizExplorerApp& app, QObject* parent)
: m_parent(parent)
, m_app(app)
{
}
WIZACTION* CWizActions::actionsData()
{
// useless, just for translation
static WIZACTION arrayRoot[] =
{
// root
{"actionFile", QObject::tr("&File")},
{"actionEdit", QObject::tr("&Edit")},
{"actionView", QObject::tr("&View")},
{"actionFormat", QObject::tr("For&mat")},
{"actionTools", QObject::tr("&Tools")},
{"actionHelp", QObject::tr("&Help")},
// sub
{"actionText", QObject::tr("Text")},
{"actionList", QObject::tr("List")},
{"actionTable", QObject::tr("Table")},
{"actionLink", QObject::tr("Link")},
{"actionStyle", QObject::tr("Style")}
};
Q_UNUSED(arrayRoot);
static WIZACTION arrayActions[] =
{
{"actionPreference", QObject::tr("Preference"), "", ""},
{"actionAbout", QObject::tr("About WizNote"), "", ""},
#ifdef QT_DEBUG
{"actionAboutPlugins", QObject::tr("About plugins"), "", ""},
#endif
{"actionExit", QObject::tr("Exit"), "", ""},
{"actionLogout", QObject::tr("Logout"), "", ""},
{WIZACTION_GLOBAL_SYNC, QObject::tr("Sync"), "", ""},
{WIZACTION_GLOBAL_NEW_DOCUMENT, QObject::tr("New Note"), "", "Ctrl+N"},
//{WIZACTION_GLOBAL_VIEW_MESSAGES, QObject::tr("View messages"), "", ""},
{"actionGoBack", QObject::tr("Back"), "", ""},
{"actionGoForward", QObject::tr("Forward"), "", ""},
{"actionConsole", QObject::tr("Console"), "", ""},
{"actionRebuildFTS", QObject::tr("Rebuild full text search index"), "", ""},
{"actionSearch", QObject::tr("Search document"), "", "Alt+Ctrl+F"},
{"actionResetSearch", QObject::tr("Reset search"), "", "Ctrl+R"},
{"actionFeedback", QObject::tr("User support"), "", ""},
// editing
{WIZACTION_EDITOR_UNDO, QObject::tr("Undo"), "", "Ctrl+Z"},
{WIZACTION_EDITOR_REDO, QObject::tr("Redo"), "", "Shift+Ctrl+Z"},
{WIZACTION_EDITOR_CUT, QObject::tr("Cut"), "", "Ctrl+X"},
{WIZACTION_EDITOR_COPY, QObject::tr("Copy"), "", "Ctrl+C"},
{WIZACTION_EDITOR_PASTE, QObject::tr("Paste"), "", "Ctrl+V"},
{WIZACTION_EDITOR_PASTE_PLAIN, QObject::tr("Paste as plain text"), "", "Shift+Ctrl+V"},
{WIZACTION_EDITOR_DELETE, QObject::tr("Delete"), "", ""},
{WIZACTION_EDITOR_SELECT_ALL, QObject::tr("Select all"), "", "Ctrl+A"},
// view
{WIZACTION_GLOBAL_TOGGLE_CATEGORY, QObject::tr("Hide category view"), QObject::tr("Show category view"), "Ctrl+Alt+s"},
{WIZACTION_GLOBAL_TOGGLE_FULLSCREEN, QObject::tr("Enter Fullscreen"), QObject::tr("Leave Fullscreen"), "Ctrl+Meta+f"},
// format
{WIZACTION_FORMAT_JUSTIFYLEFT, QObject::tr("Justify left"), "", "Ctrl+["},
{WIZACTION_FORMAT_JUSTIFYRIGHT, QObject::tr("Justify right"), "", "Ctrl+]"},
{WIZACTION_FORMAT_JUSTIFYCENTER, QObject::tr("Justify center"), "", "Ctrl+="},
{WIZACTION_FORMAT_JUSTIFYJUSTIFY, QObject::tr("Justify both side"), "", ""},
{WIZACTION_FORMAT_INDENT, QObject::tr("Indent"), "", ""},
{WIZACTION_FORMAT_OUTDENT, QObject::tr("Outdent"), "", ""},
{WIZACTION_FORMAT_UNORDEREDLIST, QObject::tr("Convert to unoredered list"), "", "Ctrl+Alt+U"},
{WIZACTION_FORMAT_ORDEREDLIST, QObject::tr("Convert to ordered list"), "", "Ctrl+Alt+O"},
{WIZACTION_FORMAT_INSERT_TABLE, QObject::tr("Insert table"), "", ""},
{WIZACTION_FORMAT_INSERT_LINK, QObject::tr("Insert link"), "", "Ctrl+K"},
{WIZACTION_FORMAT_BOLD, QObject::tr("Bold"), "", "Ctrl+B"},
{WIZACTION_FORMAT_ITALIC, QObject::tr("Italic"), "", "Ctrl+I"},
{WIZACTION_FORMAT_UNDERLINE, QObject::tr("Underline"), "", "Ctrl+U"},
{WIZACTION_FORMAT_STRIKETHROUGH, QObject::tr("Strike through"), "", "Ctrl+Alt+K"},
{WIZACTION_FORMAT_INSERT_HORIZONTAL, QObject::tr("Insert horizontal"), "", "Shift+Ctrl+H"},
{WIZACTION_FORMAT_INSERT_DATE, QObject::tr("Insert date"), "", "Shift+Ctrl+D"},
{WIZACTION_FORMAT_INSERT_TIME, QObject::tr("Insert time"), "", "Shift+Ctrl+Alt+D"},
{WIZACTION_FORMAT_REMOVE_FORMAT, QObject::tr("Remove format"), "", ""},
{WIZACTION_FORMAT_VIEW_SOURCE, QObject::tr("View html source"), "", ""},
{"", "", "", ""}
};
return arrayActions;
}
QAction* CWizActions::addAction(WIZACTION& action)
{
QString strText = action.strText;
QString strIconName = action.strName;
QString strShortcut = action.strShortcut;
QString strSlot = "1on_" + action.strName + "_triggered()";
QAction* pAction = new QAction(strText, m_parent);
if (!strIconName.isEmpty()) {
pAction->setIcon(::WizLoadSkinIcon(m_app.userSettings().skin(), strIconName));
}
if (!strShortcut.isEmpty()) {
pAction->setShortcut(QKeySequence::fromString(strShortcut));
}
if (action.strName == "actionAbout")
pAction->setMenuRole(QAction::AboutRole);
else if (action.strName == "actionAboutPlugins")
pAction->setMenuRole(QAction::ApplicationSpecificRole);
else if (action.strName == "actionPreference")
pAction->setMenuRole(QAction::PreferencesRole);
else if (action.strName == "actionExit")
pAction->setMenuRole(QAction::QuitRole);
// Used for building menu from ini file
pAction->setObjectName(action.strName);
pAction->setShortcutContext(Qt::ApplicationShortcut);
m_actions[action.strName] = pAction;
QObject::connect(pAction, "2triggered()", m_parent, strSlot.toUtf8());
return pAction;
}
void CWizActions::init()
{
int index = 0;
WIZACTION* arrayData = actionsData();
while (1)
{
WIZACTION& action = arrayData[index];
if (action.strName.isEmpty())
break;
addAction(action);
index++;
}
}
QAction* CWizActions::actionFromName(const QString& strActionName)
{
QAction* pAction = m_actions[strActionName];
if (pAction) {
return pAction;
}
WIZACTION data = {strActionName, strActionName};
return addAction(data);
}
void CWizActions::toggleActionText(const QString& strActionName)
{
int i = 0;
WIZACTION* action;
WIZACTION* arrayData = actionsData();
while (1) {
action = &arrayData[i];
if (action->strName.isEmpty())
return;
if (action->strName == strActionName) {
break;
}
i++;
}
if (action->strText2.isEmpty()) {
return;
}
QAction* pAction = m_actions[strActionName];
if (!pAction)
return;
if (pAction->text() == action->strText) {
pAction->setText(action->strText2);
} else {
pAction->setText(action->strText);
}
}
CWizAnimateAction* CWizActions::animateActionFromName(const QString& strActionName)
{
return dynamic_cast<CWizAnimateAction*>(actionFromName(strActionName));
}
QMenu* CWizActions::toMenu(QWidget* parent, CWizSettings& settings, const QString& strSection)
{
QMenu* pMenu = new QMenu(parent);
QString strLocalText = QObject::tr(strSection.toUtf8());
pMenu->setTitle(strLocalText);
buildMenu(pMenu, settings, strSection);
return pMenu;
}
void CWizActions::buildMenu(QMenu* pMenu, CWizSettings& settings, const QString& strSection)
{
int index = 0;
while (true)
{
QString strKey = WizIntToStr(index);
QString strAction = settings.GetString(strSection, strKey);
if (strAction.isEmpty())
break;
// no fullscreen mode menu
#ifndef Q_OS_MAC
if (strAction == WIZACTION_GLOBAL_TOGGLE_FULLSCREEN) {
index++;
continue;
}
#endif
#ifndef QT_DEBUG
if (strAction == "actionAboutPlugins") {
index++;
continue;
}
#endif
if (strAction.startsWith("-"))
{
pMenu->addSeparator();
}
else if (strAction.startsWith("+"))
{
strAction.remove(0, 1);
pMenu->addMenu(toMenu(pMenu, settings, strAction));
}
else
{
pMenu->addAction(actionFromName(strAction));
}
index++;
}
}
void CWizActions::buildMenuBar(QMenuBar* menuBar, const QString& strFileName)
{
CWizSettings settings(strFileName);
int index = 0;
while (true)
{
QString strKey = WizIntToStr(index);
QString strAction = settings.GetString("MainMenu", strKey);
if (strAction.isEmpty())
break;
if (strAction.startsWith("-"))
{
continue;
}
else if (strAction.startsWith("+"))
{
strAction.remove(0, 1);
QString strLocalText = QObject::tr(strAction.toUtf8());
QMenu* pMenu = menuBar->addMenu(strLocalText);
buildMenu(pMenu, settings, strAction);
}
else
{
menuBar->addAction(actionFromName(strAction));
}
index++;
}
}