Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 55 additions & 58 deletions NppJSONViewer/DockingDlgInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef DOCKINGDLGINTERFACE_H
#define DOCKINGDLGINTERFACE_H
#pragma once

#include "StaticDialog.h"
#include "dockingResource.h"
Expand All @@ -29,95 +28,93 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
class DockingDlgInterface : public StaticDialog
{
public:
DockingDlgInterface(): StaticDialog() {};
DockingDlgInterface(int dlgID): StaticDialog(), _dlgID(dlgID) {};
DockingDlgInterface() : StaticDialog() {};
DockingDlgInterface(int dlgID) : StaticDialog(), _dlgID(dlgID) {};

virtual void init(HINSTANCE hInst, HWND parent)
{
StaticDialog::init(hInst, parent);
::GetModuleFileName((HMODULE)hInst, _moduleName, MAX_PATH);
lstrcpy(_moduleName, PathFindFileName(_moduleName));
}

void create(tTbData * data, bool isRTL = false){
void create(tTbData * data, bool isRTL = false)
{
StaticDialog::create(_dlgID, isRTL);
::GetWindowText(_hSelf, _pluginName, sizeof(_pluginName));

// user information
data->hClient = _hSelf;
data->pszName = _pluginName;
// user information
data->hClient = _hSelf;
data->pszName = _pluginName;

// supported features by plugin
data->uMask = 0;
data->uMask = 0;

// additional info
data->pszAddInfo = NULL;
data->pszAddInfo = NULL;
_data = data;

};
}

virtual void updateDockingDlg(void) {
virtual void updateDockingDlg(void)
{
::SendMessage(_hParent, NPPM_DMMUPDATEDISPINFO, 0, (LPARAM)_hSelf);
}

virtual void destroy() {
};
virtual void destroy() {}

virtual void display(bool toShow = true) const {
::SendMessage(_hParent, toShow?NPPM_DMMSHOW:NPPM_DMMHIDE, 0, (LPARAM)_hSelf);
};
virtual void display(bool toShow = true) const
{
::SendMessage(_hParent, toShow ? NPPM_DMMSHOW : NPPM_DMMHIDE, 0, (LPARAM)_hSelf);
}

const TCHAR * getPluginFileName() const {
return _moduleName;
};
const TCHAR * getPluginFileName() const { return _moduleName; }

protected :
protected:
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM /*wParam*/, LPARAM lParam)
{
switch (message)
switch (message)
{

case WM_NOTIFY:
{
LPNMHDR pnmh = (LPNMHDR)lParam;
case WM_NOTIFY:
{
LPNMHDR pnmh = (LPNMHDR)lParam;

if (pnmh->hwndFrom == _hParent)
if (pnmh->hwndFrom == _hParent)
{
switch (LOWORD(pnmh->code))
{
case DMN_CLOSE:
{
break;
}
case DMN_FLOAT:
{
_isFloating = true;
break;
}
case DMN_DOCK:
{
switch (LOWORD(pnmh->code))
{
case DMN_CLOSE:
{
break;
}
case DMN_FLOAT:
{
_isFloating = true;
break;
}
case DMN_DOCK:
{
_isFloating = false;
break;
}
default:
break;
}
_isFloating = false;
break;
}
default:
break;
}
break;
}
default:
break;
break;
}
default:
break;
}
return FALSE;
};

// Handles
HWND _HSource;
tTbData* _data;
int _dlgID;
bool _isFloating;
TCHAR _moduleName[MAX_PATH];
TCHAR _pluginName[MAX_PATH];
HWND _HSource = nullptr;
tTbData* _data = nullptr;
int _dlgID = 0;
bool _isFloating = false;
TCHAR _moduleName[MAX_PATH] = {};
TCHAR _pluginName[MAX_PATH] = {};
};

#endif // DOCKINGDLGINTERFACE_H
13 changes: 8 additions & 5 deletions NppJSONViewer/JSONDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ HTREEITEM JSONDialog::insertToTree(HWND hWndDlg,HTREEITEM parent, const char *te
tvinsert.hInsertAfter=TVI_LAST;
tvinsert.item.mask=TVIF_TEXT;

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

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

void JSONDialog::populateTreeUsingSax(HWND hWndDlg, HTREEITEM tree_root, char *json) {
void JSONDialog::populateTreeUsingSax(HWND /*hWndDlg*/, HTREEITEM tree_root, char *json)
{
//Stopwatch sw;
//sw.Start();
TreeBuilder handler(this, tree_root);
rapidjson::Reader reader;

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

//mark the error position
Expand Down Expand Up @@ -341,7 +343,8 @@ void JSONDialog::drawTreeSaxParse()
HTREEITEM tree_root;
tree_root = initTree(this->getHSelf());

if (strlen(curJSON) == 0) {
if (strlen(curJSON) == 0)
{
insertToTree(this->getHSelf(), tree_root, "Error:Please select a JSON String.");
TreeView_Expand(GetDlgItem(this->getHSelf(), IDC_TREE1), tree_root, TVE_EXPAND);
return;
Expand Down
29 changes: 14 additions & 15 deletions NppJSONViewer/JSONDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef JSONDIALOG_H
#define JSONDIALOG_H
#pragma once

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

class JSONDialog : public DockingDlgInterface
{
char *curJSON;
HANDLE hTree;
char *curJSON = nullptr;
HANDLE hTree = nullptr;
//void drawTree();
void drawTreeSaxParse();
HTREEITEM initTree(HWND hWndDlg);
HTREEITEM insertToTree(HWND hWndDlg,HTREEITEM parent,const char *text);
HTREEITEM insertToTree(HWND hWndDlg, HTREEITEM parent, const char *text);
//void populateTree (HWND hWndDlg, HTREEITEM tree_root, json_t * json_root, int level);
void populateTreeUsingSax(HWND hWndDlg, HTREEITEM tree_root, char * json);
public :
JSONDialog() : DockingDlgInterface(IDD_TREE){};
public:
JSONDialog() : DockingDlgInterface(IDD_TREE) {};

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

virtual void display(bool toShow = true) const {
DockingDlgInterface::display(toShow);
};
virtual void display(bool toShow = true) const
{
DockingDlgInterface::display(toShow);
}

void setParent(HWND parent2set){
void setParent(HWND parent2set)
{
_hParent = parent2set;
};
}

void setJSON(char *json);

protected :
protected:
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
};

#endif //JSONDIALOG_H
4 changes: 4 additions & 0 deletions NppJSONViewer/NPPJSONViewer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<SDLCheck>true</SDLCheck>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<AdditionalDependencies>shlwapi.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand All @@ -116,6 +117,7 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<SDLCheck>true</SDLCheck>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<AdditionalDependencies>shlwapi.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand All @@ -136,6 +138,7 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<SDLCheck>true</SDLCheck>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<AdditionalDependencies>shlwapi.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand All @@ -159,6 +162,7 @@
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<SDLCheck>true</SDLCheck>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<AdditionalDependencies>shlwapi.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down
2 changes: 1 addition & 1 deletion NppJSONViewer/PluginDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void formatSelectedJSON() {
rapidjson::StringBuffer sb;
rapidjson::PrettyWriter<rapidjson::StringBuffer> pw(sb);
bool useTabs = ::SendMessage(curScintilla, SCI_GETUSETABS, 0, 0);
int indentLen = useTabs ? 1 : ::SendMessage(curScintilla, SCI_GETTABWIDTH, 0, 0);
unsigned indentLen = useTabs ? 1 : static_cast<unsigned>(::SendMessage(curScintilla, SCI_GETTABWIDTH, 0, 0));
char indentChar = useTabs ? '\t' : ' ';
pw.SetIndent(indentChar, indentLen);
rapidjson::StringStream ss(curJSON);
Expand Down
2 changes: 1 addition & 1 deletion NppJSONViewer/StaticDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void StaticDialog::create(int dialogID, bool isRTL)
{
DWORD err = ::GetLastError();
char errMsg[256];
sprintf(errMsg, "CreateDialogParam() return NULL.\rGetLastError() == %u", err);
sprintf(errMsg, "CreateDialogParam() return NULL.\rGetLastError() == %lu", err);
::MessageBoxA(NULL, errMsg, "In StaticDialog::create()", MB_OK);
return;
}
Expand Down
Loading