25
25
#include " rapidjson/document.h"
26
26
27
27
HANDLE g_hMod;
28
- CHAR * curJSON= NULL ;
28
+ CHAR * curJSON = NULL ;
29
29
JSONDialog jsonDialog;
30
30
//
31
31
// The plugin data that Notepad++ needs
@@ -42,8 +42,8 @@ NppData nppData;
42
42
// It will be called while plugin loading
43
43
void pluginInit (HANDLE hModule)
44
44
{
45
- g_hMod= hModule;
46
- jsonDialog.init ((HINSTANCE)g_hMod,nppData._nppHandle );
45
+ g_hMod = hModule;
46
+ jsonDialog.init ((HINSTANCE)g_hMod, nppData._nppHandle );
47
47
}
48
48
49
49
//
@@ -65,38 +65,38 @@ void commandMenuInit()
65
65
// bool check0nInit // optional. Make this menu item be checked visually
66
66
// );
67
67
68
- ShortcutKey *openJSONsk= new ShortcutKey ();
69
- openJSONsk->_isAlt = TRUE ;
70
- openJSONsk->_isCtrl = TRUE ;
71
- openJSONsk->_isShift = TRUE ;
72
- openJSONsk->_key = ' J' ;
73
-
74
- ShortcutKey *formatJSONsk= new ShortcutKey ();
75
- formatJSONsk->_isAlt = TRUE ;
76
- formatJSONsk->_isCtrl = TRUE ;
77
- formatJSONsk->_isShift = TRUE ;
78
- formatJSONsk->_key = ' M' ;
79
- setCommand (0 , TEXT (" Show &JSON Viewer" ), openJSONDialog,openJSONsk , false );
80
- setCommand (1 , TEXT (" &Format JSON" ), formatSelectedJSON,formatJSONsk , false );
81
- setCommand (2 , TEXT (" &About" ), openAboutDlg,NULL , false );
68
+ ShortcutKey *openJSONsk = new ShortcutKey ();
69
+ openJSONsk->_isAlt = TRUE ;
70
+ openJSONsk->_isCtrl = TRUE ;
71
+ openJSONsk->_isShift = TRUE ;
72
+ openJSONsk->_key = ' J' ;
73
+
74
+ ShortcutKey *formatJSONsk = new ShortcutKey ();
75
+ formatJSONsk->_isAlt = TRUE ;
76
+ formatJSONsk->_isCtrl = TRUE ;
77
+ formatJSONsk->_isShift = TRUE ;
78
+ formatJSONsk->_key = ' M' ;
79
+ setCommand (0 , TEXT (" Show &JSON Viewer" ), openJSONDialog, openJSONsk , false );
80
+ setCommand (1 , TEXT (" &Format JSON" ), formatSelectedJSON, formatJSONsk , false );
81
+ setCommand (2 , TEXT (" &About" ), openAboutDlg, NULL , false );
82
82
}
83
83
84
- INT_PTR CALLBACK abtDlgProc (HWND hwndDlg,UINT uMsg,WPARAM wParam, LPARAM /* lParam*/ )
84
+ INT_PTR CALLBACK abtDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM /* lParam*/ )
85
85
{
86
- switch (uMsg)
86
+ switch (uMsg)
87
87
{
88
88
case WM_INITDIALOG:
89
- ConvertStaticToHyperlink (hwndDlg,IDC_WEB);
89
+ ConvertStaticToHyperlink (hwndDlg, IDC_WEB);
90
90
return TRUE ;
91
91
case WM_COMMAND:
92
- switch (LOWORD (wParam))
92
+ switch (LOWORD (wParam))
93
93
{
94
94
case IDCANCEL: // Close this dialog when clicking to close button
95
95
case IDOK:
96
- EndDialog (hwndDlg,wParam);
96
+ EndDialog (hwndDlg, wParam);
97
97
return TRUE ;
98
98
case IDC_WEB:
99
- ShellExecute (hwndDlg, TEXT (" open" ),TEXT (" https://sourceforge.net/projects/nppjsonviewer/" ),NULL , NULL , SW_SHOWNORMAL);
99
+ ShellExecute (hwndDlg, TEXT (" open" ), TEXT (" https://sourceforge.net/projects/nppjsonviewer/" ), NULL , NULL , SW_SHOWNORMAL);
100
100
return TRUE ;
101
101
}
102
102
}
@@ -105,7 +105,7 @@ INT_PTR CALLBACK abtDlgProc(HWND hwndDlg,UINT uMsg,WPARAM wParam, LPARAM /*lPara
105
105
106
106
void openAboutDlg ()
107
107
{
108
- ::CreateDialog ((HINSTANCE)g_hMod,MAKEINTRESOURCE(IDD_ABOUTDLG),nppData._nppHandle,abtDlgProc);
108
+ ::CreateDialog ((HINSTANCE)g_hMod, MAKEINTRESOURCE(IDD_ABOUTDLG), nppData._nppHandle, abtDlgProc);
109
109
}
110
110
111
111
@@ -123,7 +123,7 @@ void commandMenuCleanUp()
123
123
//
124
124
// This function help you to initialize your plugin commands
125
125
//
126
- bool setCommand (size_t index, TCHAR *cmdName, PFUNCPLUGINCMD pFunc, ShortcutKey *sk, bool check0nInit)
126
+ bool setCommand (size_t index, TCHAR *cmdName, PFUNCPLUGINCMD pFunc, ShortcutKey *sk, bool check0nInit)
127
127
{
128
128
if (index >= nbFunc)
129
129
return false ;
@@ -147,7 +147,7 @@ void showJSONDialog(char *json)
147
147
{
148
148
jsonDialog.setParent (nppData._nppHandle );
149
149
jsonDialog.setJSON (json);
150
- tTbData data = {0 };
150
+ tTbData data = { 0 };
151
151
152
152
if (!jsonDialog.isCreated ())
153
153
{
@@ -157,7 +157,7 @@ void showJSONDialog(char *json)
157
157
data.uMask = DWS_DF_CONT_LEFT;
158
158
159
159
data.pszModuleName = jsonDialog.getPluginFileName ();
160
- data.pszName = L" JSON Viewer" ;
160
+ data.pszName = L" JSON Viewer" ;
161
161
162
162
// the dlgDlg should be the index of funcItem where the current function pointer is
163
163
data.dlgID = 0 ;
@@ -171,9 +171,10 @@ void selectAllIfUnselectedAndSetCurJSON(size_t selectedTextLength, HWND curScint
171
171
size_t allTextlength = ::SendMessage (curScintilla, SCI_GETLENGTH, 0 , (LPARAM)curJSON);
172
172
::SendMessage (curScintilla, SCI_SETSELECTIONSTART, 0 , (LPARAM)curJSON);
173
173
::SendMessage (curScintilla, SCI_SETSELECTIONEND, allTextlength, (LPARAM)curJSON);
174
- curJSON = new CHAR[allTextlength+1 ];
175
- } else {
176
- curJSON = new CHAR[selectedTextLength+1 ];
174
+ curJSON = new CHAR[allTextlength + 1 ];
175
+ }
176
+ else {
177
+ curJSON = new CHAR[selectedTextLength + 1 ];
177
178
}
178
179
179
180
::SendMessage (curScintilla, SCI_GETSELTEXT, 0 , (LPARAM)curJSON);
@@ -187,7 +188,7 @@ void openJSONDialog()
187
188
if (which == -1 )
188
189
return ;
189
190
190
- HWND curScintilla = (which == 0 )? nppData._scintillaMainHandle : nppData._scintillaSecondHandle ;
191
+ HWND curScintilla = (which == 0 ) ? nppData._scintillaMainHandle : nppData._scintillaSecondHandle ;
191
192
size_t start = ::SendMessage (curScintilla, SCI_GETSELECTIONSTART, 0 , 0 );
192
193
size_t end = ::SendMessage (curScintilla, SCI_GETSELECTIONEND, 0 , 0 );
193
194
if (end < start)
@@ -198,20 +199,20 @@ void openJSONDialog()
198
199
}
199
200
200
201
size_t asciiTextLen = end - start;
201
- selectAllIfUnselectedAndSetCurJSON (asciiTextLen, curScintilla);
202
-
202
+ selectAllIfUnselectedAndSetCurJSON (asciiTextLen, curScintilla);
203
+
203
204
showJSONDialog (curJSON);
204
- delete [] curJSON;
205
+ delete[] curJSON;
205
206
}
206
207
207
- void formatSelectedJSON (){
208
+ void formatSelectedJSON () {
208
209
// Get the current scintilla
209
210
int which = -1 ;
210
211
::SendMessage (nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0 , (LPARAM)&which);
211
212
if (which == -1 )
212
213
return ;
213
214
214
- HWND curScintilla = (which == 0 )? nppData._scintillaMainHandle : nppData._scintillaSecondHandle ;
215
+ HWND curScintilla = (which == 0 ) ? nppData._scintillaMainHandle : nppData._scintillaSecondHandle ;
215
216
size_t start = ::SendMessage (curScintilla, SCI_GETSELECTIONSTART, 0 , 0 );
216
217
size_t end = ::SendMessage (curScintilla, SCI_GETSELECTIONEND, 0 , 0 );
217
218
if (end < start)
@@ -222,16 +223,20 @@ void formatSelectedJSON(){
222
223
}
223
224
224
225
size_t asciiTextLen = end - start;
225
- selectAllIfUnselectedAndSetCurJSON (asciiTextLen, curScintilla);
226
+ selectAllIfUnselectedAndSetCurJSON (asciiTextLen, curScintilla);
226
227
227
228
rapidjson::StringBuffer sb;
228
229
rapidjson::PrettyWriter<rapidjson::StringBuffer> pw (sb);
230
+ bool useTabs = ::SendMessage (curScintilla, SCI_GETUSETABS, 0 , 0 );
231
+ int indentLen = useTabs ? 1 : ::SendMessage (curScintilla, SCI_GETTABWIDTH, 0 , 0 );
232
+ char indentChar = useTabs ? ' \t ' : ' ' ;
233
+ pw.SetIndent (indentChar, indentLen);
229
234
rapidjson::StringStream ss (curJSON);
230
235
rapidjson::Reader reader;
231
236
232
237
reader.Parse (ss, pw);
233
238
const char * fJson = sb.GetString ();
234
- ::SendMessage (curScintilla,SCI_REPLACESEL,0 , (LPARAM)fJson);
235
-
236
- delete [] curJSON;
239
+ ::SendMessage (curScintilla, SCI_REPLACESEL, 0 , (LPARAM)fJson);
240
+
241
+ delete[] curJSON;
237
242
}
0 commit comments