Skip to content
Merged
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
35 changes: 15 additions & 20 deletions NppJSONViewer/PluginDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ void showJSONDialog(char *json)
jsonDialog.display();
}

void selectAllIfUnselectedAndSetCurJSON(size_t selectedTextLength, HWND curScintilla) {
if (selectedTextLength == 0) {
size_t allTextlength = ::SendMessage(curScintilla, SCI_GETLENGTH, 0, (LPARAM)curJSON);
::SendMessage(curScintilla, SCI_SETSELECTIONSTART, 0, (LPARAM)curJSON);
::SendMessage(curScintilla, SCI_SETSELECTIONEND, allTextlength, (LPARAM)curJSON);
curJSON = new CHAR[allTextlength];
} else {
curJSON = new CHAR[selectedTextLength+1];
}

::SendMessage(curScintilla, SCI_GETSELTEXT, 0, (LPARAM)curJSON);
}

void openJSONDialog()
{
// Get the current scintilla
Expand All @@ -180,18 +193,8 @@ void openJSONDialog()
}

size_t asciiTextLen = end - start;
/*
if (asciiTextLen == 0)
{
//MessageBox(nppData._nppHandle,TEXT("Please select a JSON string."),TEXT("JSON Viewer"),MB_OK|MB_ICONINFORMATION);
return;
}
*/
selectAllIfUnselectedAndSetCurJSON(asciiTextLen, curScintilla);


curJSON = new CHAR[asciiTextLen+1];

::SendMessage(curScintilla, SCI_GETSELTEXT, 0, (LPARAM)curJSON);
showJSONDialog(curJSON);
delete curJSON;
}
Expand All @@ -214,16 +217,8 @@ void formatSelectedJSON(){
}

size_t asciiTextLen = end - start;

if (asciiTextLen == 0)
{
//MessageBox(nppData._nppHandle,TEXT("Please select a JSON string."),TEXT("JSON Viewer"),MB_OK|MB_ICONINFORMATION);
return;
}

curJSON = new CHAR[asciiTextLen+1];
selectAllIfUnselectedAndSetCurJSON(asciiTextLen, curScintilla);

::SendMessage(curScintilla, SCI_GETSELTEXT, 0, (LPARAM)curJSON);
CHAR* fJson=json_format_string(curJSON);
::SendMessage(curScintilla,SCI_REPLACESEL,0,(LPARAM)fJson);

Expand Down