Skip to content

Commit 2d18457

Browse files
authored
Merge pull request #44 from SinghRajenM/master
Some code enhancement
2 parents fae3b57 + fd41ad6 commit 2d18457

File tree

10 files changed

+139
-125
lines changed

10 files changed

+139
-125
lines changed

NppJSONViewer/DockingDlgInterface.h

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ along with this program; if not, write to the Free Software
1717
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1818
*/
1919

20-
#ifndef DOCKINGDLGINTERFACE_H
21-
#define DOCKINGDLGINTERFACE_H
20+
#pragma once
2221

2322
#include "StaticDialog.h"
2423
#include "dockingResource.h"
@@ -29,95 +28,93 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2928
class DockingDlgInterface : public StaticDialog
3029
{
3130
public:
32-
DockingDlgInterface(): StaticDialog() {};
33-
DockingDlgInterface(int dlgID): StaticDialog(), _dlgID(dlgID) {};
34-
31+
DockingDlgInterface() : StaticDialog() {};
32+
DockingDlgInterface(int dlgID) : StaticDialog(), _dlgID(dlgID) {};
33+
3534
virtual void init(HINSTANCE hInst, HWND parent)
3635
{
3736
StaticDialog::init(hInst, parent);
3837
::GetModuleFileName((HMODULE)hInst, _moduleName, MAX_PATH);
3938
lstrcpy(_moduleName, PathFindFileName(_moduleName));
4039
}
4140

42-
void create(tTbData * data, bool isRTL = false){
41+
void create(tTbData * data, bool isRTL = false)
42+
{
4343
StaticDialog::create(_dlgID, isRTL);
4444
::GetWindowText(_hSelf, _pluginName, sizeof(_pluginName));
4545

46-
// user information
47-
data->hClient = _hSelf;
48-
data->pszName = _pluginName;
46+
// user information
47+
data->hClient = _hSelf;
48+
data->pszName = _pluginName;
4949

5050
// supported features by plugin
51-
data->uMask = 0;
51+
data->uMask = 0;
5252

5353
// additional info
54-
data->pszAddInfo = NULL;
54+
data->pszAddInfo = NULL;
5555
_data = data;
5656

57-
};
57+
}
5858

59-
virtual void updateDockingDlg(void) {
59+
virtual void updateDockingDlg(void)
60+
{
6061
::SendMessage(_hParent, NPPM_DMMUPDATEDISPINFO, 0, (LPARAM)_hSelf);
6162
}
6263

63-
virtual void destroy() {
64-
};
64+
virtual void destroy() {}
6565

66-
virtual void display(bool toShow = true) const {
67-
::SendMessage(_hParent, toShow?NPPM_DMMSHOW:NPPM_DMMHIDE, 0, (LPARAM)_hSelf);
68-
};
66+
virtual void display(bool toShow = true) const
67+
{
68+
::SendMessage(_hParent, toShow ? NPPM_DMMSHOW : NPPM_DMMHIDE, 0, (LPARAM)_hSelf);
69+
}
6970

70-
const TCHAR * getPluginFileName() const {
71-
return _moduleName;
72-
};
71+
const TCHAR * getPluginFileName() const { return _moduleName; }
7372

74-
protected :
73+
protected:
7574
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM /*wParam*/, LPARAM lParam)
7675
{
77-
switch (message)
76+
switch (message)
7877
{
7978

80-
case WM_NOTIFY:
81-
{
82-
LPNMHDR pnmh = (LPNMHDR)lParam;
79+
case WM_NOTIFY:
80+
{
81+
LPNMHDR pnmh = (LPNMHDR)lParam;
8382

84-
if (pnmh->hwndFrom == _hParent)
83+
if (pnmh->hwndFrom == _hParent)
84+
{
85+
switch (LOWORD(pnmh->code))
86+
{
87+
case DMN_CLOSE:
88+
{
89+
break;
90+
}
91+
case DMN_FLOAT:
92+
{
93+
_isFloating = true;
94+
break;
95+
}
96+
case DMN_DOCK:
8597
{
86-
switch (LOWORD(pnmh->code))
87-
{
88-
case DMN_CLOSE:
89-
{
90-
break;
91-
}
92-
case DMN_FLOAT:
93-
{
94-
_isFloating = true;
95-
break;
96-
}
97-
case DMN_DOCK:
98-
{
99-
_isFloating = false;
100-
break;
101-
}
102-
default:
103-
break;
104-
}
98+
_isFloating = false;
99+
break;
100+
}
101+
default:
102+
break;
105103
}
106-
break;
107104
}
108-
default:
109-
break;
105+
break;
106+
}
107+
default:
108+
break;
110109
}
111110
return FALSE;
112111
};
113-
112+
114113
// Handles
115-
HWND _HSource;
116-
tTbData* _data;
117-
int _dlgID;
118-
bool _isFloating;
119-
TCHAR _moduleName[MAX_PATH];
120-
TCHAR _pluginName[MAX_PATH];
114+
HWND _HSource = nullptr;
115+
tTbData* _data = nullptr;
116+
int _dlgID = 0;
117+
bool _isFloating = false;
118+
TCHAR _moduleName[MAX_PATH] = {};
119+
TCHAR _pluginName[MAX_PATH] = {};
121120
};
122-
123-
#endif // DOCKINGDLGINTERFACE_H

NppJSONViewer/JSONDialog.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ HTREEITEM JSONDialog::insertToTree(HWND hWndDlg,HTREEITEM parent, const char *te
6161
tvinsert.hInsertAfter=TVI_LAST;
6262
tvinsert.item.mask=TVIF_TEXT;
6363

64-
int len = strlen(text) + 1;
64+
auto len = strlen(text) + 1;
6565
wchar_t *w_msg = new wchar_t[len];
6666
if (w_msg)
6767
{
6868
memset(w_msg, 0, len);
69-
MultiByteToWideChar(CP_UTF8, NULL, text, -1, w_msg, len);
69+
MultiByteToWideChar(CP_UTF8, NULL, text, -1, w_msg, static_cast<int>(len));
7070

7171
tvinsert.item.pszText = w_msg;
7272
item = (HTREEITEM)SendDlgItemMessage(hWndDlg, IDC_TREE1, TVM_INSERTITEM, 0, (LPARAM)&tvinsert);
@@ -88,14 +88,16 @@ void JSONDialog::setJSON(char* json)
8888
drawTreeSaxParse();
8989
}
9090

91-
void JSONDialog::populateTreeUsingSax(HWND hWndDlg, HTREEITEM tree_root, char *json) {
91+
void JSONDialog::populateTreeUsingSax(HWND /*hWndDlg*/, HTREEITEM tree_root, char *json)
92+
{
9293
//Stopwatch sw;
9394
//sw.Start();
9495
TreeBuilder handler(this, tree_root);
9596
rapidjson::Reader reader;
9697

9798
rapidjson::StringStream ss(json);
98-
if (!reader.Parse<rapidjson::kParseNumbersAsStringsFlag>(ss, handler)) {
99+
if (!reader.Parse<rapidjson::kParseNumbersAsStringsFlag>(ss, handler))
100+
{
99101
::MessageBox(nppData._nppHandle, TEXT("Could not parse!!"), TEXT("JSON Viewer"), MB_OK | MB_ICONERROR);
100102

101103
//mark the error position
@@ -341,7 +343,8 @@ void JSONDialog::drawTreeSaxParse()
341343
HTREEITEM tree_root;
342344
tree_root = initTree(this->getHSelf());
343345

344-
if (strlen(curJSON) == 0) {
346+
if (strlen(curJSON) == 0)
347+
{
345348
insertToTree(this->getHSelf(), tree_root, "Error:Please select a JSON String.");
346349
TreeView_Expand(GetDlgItem(this->getHSelf(), IDC_TREE1), tree_root, TVE_EXPAND);
347350
return;

NppJSONViewer/JSONDialog.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ along with this program; if not, write to the Free Software
1717
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
*/
1919

20-
#ifndef JSONDIALOG_H
21-
#define JSONDIALOG_H
20+
#pragma once
2221

2322
#include "DockingDlgInterface.h"
2423
#include "PluginInterface.h"
@@ -28,31 +27,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2827

2928
class JSONDialog : public DockingDlgInterface
3029
{
31-
char *curJSON;
32-
HANDLE hTree;
30+
char *curJSON = nullptr;
31+
HANDLE hTree = nullptr;
3332
//void drawTree();
3433
void drawTreeSaxParse();
3534
HTREEITEM initTree(HWND hWndDlg);
36-
HTREEITEM insertToTree(HWND hWndDlg,HTREEITEM parent,const char *text);
35+
HTREEITEM insertToTree(HWND hWndDlg, HTREEITEM parent, const char *text);
3736
//void populateTree (HWND hWndDlg, HTREEITEM tree_root, json_t * json_root, int level);
3837
void populateTreeUsingSax(HWND hWndDlg, HTREEITEM tree_root, char * json);
39-
public :
40-
JSONDialog() : DockingDlgInterface(IDD_TREE){};
38+
public:
39+
JSONDialog() : DockingDlgInterface(IDD_TREE) {};
4140

4241
HTREEITEM insertToTree(HTREEITEM parent, const char *text);
4342

44-
virtual void display(bool toShow = true) const {
45-
DockingDlgInterface::display(toShow);
46-
};
43+
virtual void display(bool toShow = true) const
44+
{
45+
DockingDlgInterface::display(toShow);
46+
}
4747

48-
void setParent(HWND parent2set){
48+
void setParent(HWND parent2set)
49+
{
4950
_hParent = parent2set;
50-
};
51+
}
5152

5253
void setJSON(char *json);
5354

54-
protected :
55+
protected:
5556
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
5657
};
57-
58-
#endif //JSONDIALOG_H

NppJSONViewer/NPPJSONViewer.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
9999
<SDLCheck>true</SDLCheck>
100100
<MultiProcessorCompilation>true</MultiProcessorCompilation>
101+
<TreatWarningAsError>true</TreatWarningAsError>
101102
</ClCompile>
102103
<Link>
103104
<AdditionalDependencies>shlwapi.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -116,6 +117,7 @@
116117
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
117118
<SDLCheck>true</SDLCheck>
118119
<MultiProcessorCompilation>true</MultiProcessorCompilation>
120+
<TreatWarningAsError>true</TreatWarningAsError>
119121
</ClCompile>
120122
<Link>
121123
<AdditionalDependencies>shlwapi.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -136,6 +138,7 @@
136138
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
137139
<SDLCheck>true</SDLCheck>
138140
<MultiProcessorCompilation>true</MultiProcessorCompilation>
141+
<TreatWarningAsError>true</TreatWarningAsError>
139142
</ClCompile>
140143
<Link>
141144
<AdditionalDependencies>shlwapi.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -159,6 +162,7 @@
159162
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
160163
<SDLCheck>true</SDLCheck>
161164
<MultiProcessorCompilation>true</MultiProcessorCompilation>
165+
<TreatWarningAsError>true</TreatWarningAsError>
162166
</ClCompile>
163167
<Link>
164168
<AdditionalDependencies>shlwapi.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>

NppJSONViewer/PluginDefinition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void formatSelectedJSON() {
228228
rapidjson::StringBuffer sb;
229229
rapidjson::PrettyWriter<rapidjson::StringBuffer> pw(sb);
230230
bool useTabs = ::SendMessage(curScintilla, SCI_GETUSETABS, 0, 0);
231-
int indentLen = useTabs ? 1 : ::SendMessage(curScintilla, SCI_GETTABWIDTH, 0, 0);
231+
unsigned indentLen = useTabs ? 1 : static_cast<unsigned>(::SendMessage(curScintilla, SCI_GETTABWIDTH, 0, 0));
232232
char indentChar = useTabs ? '\t' : ' ';
233233
pw.SetIndent(indentChar, indentLen);
234234
rapidjson::StringStream ss(curJSON);

NppJSONViewer/StaticDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void StaticDialog::create(int dialogID, bool isRTL)
8080
{
8181
DWORD err = ::GetLastError();
8282
char errMsg[256];
83-
sprintf(errMsg, "CreateDialogParam() return NULL.\rGetLastError() == %u", err);
83+
sprintf(errMsg, "CreateDialogParam() return NULL.\rGetLastError() == %lu", err);
8484
::MessageBoxA(NULL, errMsg, "In StaticDialog::create()", MB_OK);
8585
return;
8686
}

0 commit comments

Comments
 (0)