-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathnppMenu.cpp
203 lines (154 loc) · 7.72 KB
/
nppMenu.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
#include "StdAfx.h"
#include "XMLTools.h"
#include "nppMenu.h"
#include "Report.h"
#include <assert.h>
std::vector<FuncItem> nppMenu;
struct struct_menuitems menuitems = {};
void ToggleMenuItem(int idx, bool& value) {
value = !value;
::CheckMenuItem(::GetMenu(nppData._nppHandle), nppMenu[idx]._cmdID, MF_BYCOMMAND | (value ? MF_CHECKED : MF_UNCHECKED));
nppMenu[idx]._init2Check = value;
savePluginParams();
}
void insertXMLCheckTag() {
dbgln("insertXMLCheckTag()");
ToggleMenuItem(menuitems.menuitemToggleCheckXML, config.doCheckXML);
}
void insertValidationTag() {
dbgln("insertValidationTag()");
ToggleMenuItem(menuitems.menuitemToggleValidation, config.doValidation);
}
/*
void insertPrettyPrintTag() {
dbgln("insertPrettyPrintTag()");
doPrettyPrint = !doPrettyPrint;
::CheckMenuItem(::GetMenu(nppData._nppHandle), funcItem[menuitemPrettyPrint]._cmdID, MF_BYCOMMAND | (doPrettyPrint?MF_CHECKED:MF_UNCHECKED));
savePluginParams();
}
*/
void insertXMLCloseTag() {
dbgln("insertXMLCloseTag()");
ToggleMenuItem(menuitems.menuitemToggleCloseTag, config.doCloseTag);
}
void insertTagAutoIndent() {
dbgln("insertTagAutoIndent()");
static bool tagAutoIndentWarningDisplayed = false;
if (!tagAutoIndentWarningDisplayed) {
Report::_printf_inf(L"This function is in alpha state and might disappear in future release.");
tagAutoIndentWarningDisplayed = true;
}
ToggleMenuItem(menuitems.menuitemToggleAutoIndent, config.doAutoIndent);
}
void insertAttributeAutoComplete() {
dbgln("insertAttributeAutoComplete()");
static bool insertAttributeAutoCompleteWarningDisplayed = false;
if (!insertAttributeAutoCompleteWarningDisplayed) {
Report::_printf_inf(L"This function is in alpha state and might disappear in future release.");
insertAttributeAutoCompleteWarningDisplayed = true;
}
ToggleMenuItem(menuitems.menuitemToggleAttrAutoComplete, config.doAttrAutoComplete);
}
void insertAutoXMLType() {
dbgln("insertAutoXMLType()");
ToggleMenuItem(menuitems.menuitemToggleAutoXMLType, config.doAutoXMLType);
}
void togglePreventXXE() {
dbgln("togglePreventXXE()");
ToggleMenuItem(menuitems.menuitemTogglePreventXXE, config.doPreventXXE);
}
void toggleAllowHuge() {
dbgln("toggleAllowHuge()");
ToggleMenuItem(menuitems.menuitemToggleAllowHuge, config.doAllowHuge);
}
void togglePrettyPrintAllFiles() {
dbgln("togglePrettyPrintAllFiles()");
ToggleMenuItem(menuitems.menuitemTogglePrettyPrintAllFiles, config.doPrettyPrintAllOpenFiles);
}
int addMenuItem(const wchar_t* title, PFUNCPLUGINCMD action, bool checked, ShortcutKey *shortcut) {
FuncItem item;
wcscpy(item._itemName, title);
item._pFunc = action;
item._init2Check = checked;
item._pShKey = shortcut;
nppMenu.push_back(item);
return static_cast<int>(nppMenu.size() - 1);
}
void addMenuSeparator() {
FuncItem item;
item._itemName[0] = 0;
item._pFunc = NULL;
item._pShKey = NULL;
nppMenu.push_back(item);
}
ShortcutKey *createShortcut(unsigned char key, bool enableALT, bool enableCTRL, bool enableSHIFT) {
auto shortcut = new ShortcutKey(); // no parentheses needed as it's Plain Old Data (POD) otherwise C4345
shortcut->_isAlt = enableALT;
shortcut->_isCtrl = enableCTRL;
shortcut->_isShift = enableSHIFT;
shortcut->_key = key;
return shortcut;
}
void initMenu() {
dbgln("Building plugin menu entries... ", DBG_LEVEL::DBG_INFO);
menuitems.menuitemToggleCheckXML = addMenuItem(L"Enable XML syntax auto-check", insertXMLCheckTag, config.doCheckXML);
menuitems.menuitemCheckXML = addMenuItem(L"Check XML syntax now", manualXMLCheck);
addMenuSeparator();
menuitems.menuitemToggleValidation = addMenuItem(L"Enable auto-validation", insertValidationTag, config.doValidation);
menuitems.menuitemValidateXML = addMenuItem(L"Validate now", manualValidation, false, createShortcut('M'));
menuitems.menuitemFirstError = addMenuItem(L"First error", highlightFirstError);
menuitems.menuitemPreviousError = addMenuItem(L"Previous error", highlightPreviousError);
menuitems.menuitemNextError = addMenuItem(L"Next error", highlightNextError);
menuitems.menuitemLastError = addMenuItem(L"Last error", highlightLastError);
addMenuSeparator();
menuitems.menuitemToggleCloseTag = addMenuItem(L"Tag auto-close", insertXMLCloseTag, config.doCloseTag);
/*
Report::strcpy(funcItem[menuentry]._itemName, L"Tag auto-indent");
funcItem[menuentry]._pFunc = insertTagAutoIndent;
funcItem[menuentry]._init2Check = doAutoIndent = (::GetPrivateProfileInt(sectionName, L"doAutoIndent", 0, iniFilePath) != 0);
doAutoIndent = funcItem[menuentry]._init2Check;
menuitemAutoIndent = menuentry;
++menuentry;
Report::strcpy(funcItem[menuentry]._itemName, L"Auto-complete attributes");
funcItem[menuentry]._pFunc = insertAttributeAutoComplete;
funcItem[menuentry]._init2Check = doAttrAutoComplete = (::GetPrivateProfileInt(sectionName, L"doAttrAutoComplete", 0, iniFilePath) != 0);
doAttrAutoComplete = funcItem[menuentry]._init2Check;
menuitemAttrAutoComplete = menuentry;
++menuentry;
*/
addMenuSeparator();
menuitems.menuitemToggleAutoXMLType = addMenuItem(L"Set XML type automatically", insertAutoXMLType, config.doAutoXMLType);
menuitems.menuitemTogglePreventXXE = addMenuItem(L"Prevent XXE", togglePreventXXE, config.doPreventXXE);
menuitems.menuitemToggleAllowHuge = addMenuItem(L"Allow huge files", toggleAllowHuge, config.doAllowHuge);
addMenuSeparator();
menuitems.menuitemPrettyPrint = addMenuItem(L"Pretty print", nppPrettyPrintXmlFast, false, createShortcut('B'));
menuitems.menuitemPrettyPrintIndentAttr = addMenuItem(L"Pretty print - indent attributes", nppPrettyPrintXmlAttrFast, false, createShortcut('A'));
menuitems.menuitemPrettyPrintIndentOnly = addMenuItem(L"Pretty print - indent only", nppPrettyPrintXmlIndentOnlyFast);
menuitems.menuitemLinearize = addMenuItem(L"Linearize", nppLinearizeXmlFast, false, createShortcut('L'));
menuitems.menuitemTogglePrettyPrintAllFiles = addMenuItem(L"Apply to all open files", togglePrettyPrintAllFiles, config.doPrettyPrintAllOpenFiles);
#ifdef _DEBUG
menuitems.menuitemTokenize = addMenuItem(L"Tokenize (debug)", nppTokenizeXmlFast, false);
#endif
addMenuSeparator();
menuitems.menuitemCurrentXMLPath = addMenuItem(L"Current XML Path", getCurrentXPathStd);
menuitems.menuitemCurrentXMLPathNS = addMenuItem(L"Current XML Path with predicates", getCurrentXPathPredicate, false, createShortcut('P'));
menuitems.menuitemEvalXPath = addMenuItem(L"Evaluate XPath expression...", evaluateXPath);
addMenuSeparator();
menuitems.menuitemXSLTransform = addMenuItem(L"XSL Transformation...", performXSLTransform);
addMenuSeparator();
menuitems.menuitemEscape = addMenuItem(L"Escape characters in selection (<> → &<&>)", nppConvertXML2Text);
menuitems.menuitemUnescape = addMenuItem(L"Unescape characters in selection (&<&> → <>)", nppConvertText2XML);
addMenuSeparator();
menuitems.menuitemComment = addMenuItem(L"Comment selection", commentSelection, false, createShortcut('C'));
menuitems.menuitemUncomment = addMenuItem(L"Uncomment selection", uncommentSelection, false, createShortcut('R'));
addMenuSeparator();
menuitems.menuitemOptions = addMenuItem(L"Options...", optionsDlg);
menuitems.menuitemDebugWindow = addMenuItem(L"Debug window...", showDebugDlg);
menuitems.menuitemAbout = addMenuItem(L"About XML Tools / Donate...", aboutBox);
dbgln("done.", DBG_LEVEL::DBG_INFO);
}
void destroyMenu() {
for (size_t i = 0; i < nppMenu.size(); ++i) {
if (nppMenu[i]._pShKey) delete nppMenu[i]._pShKey;
}
}