Skip to content

Commit 36617c6

Browse files
committed
Don't show error message on startup unless it is real json
1 parent d602ab4 commit 36617c6

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

NppJSONViewer/NppJsonViewer/JsonViewDlg.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,18 @@ void JsonViewDlg::DrawJsonTree()
159159
auto res = PopulateTreeUsingSax(rootNode, txtForParsing);
160160
if (res.has_value())
161161
{
162-
ShowMessage(JSON_ERROR_TITLE, res.value(), MB_OK | MB_ICONERROR);
162+
// This is the case when Notepad++ has JsonViewer Window opened for previous intance
163+
// Later on second launch, don't show the error message as this could be some text file
164+
// If it is real json file but has some error, then there must be more than 1 node exist.
165+
166+
if (!m_IsNppReady && m_hTreeView->GetNodeCount() <= 1)
167+
{
168+
m_hTreeView->InsertNode(JSON_ERR_VALIDATE, NULL, rootNode);
169+
}
170+
else
171+
{
172+
ShowMessage(JSON_ERROR_TITLE, res.value(), MB_OK | MB_ICONERROR);
173+
}
163174
}
164175
}
165176

@@ -585,8 +596,7 @@ auto JsonViewDlg::CopyPath() const -> std::wstring
585596

586597
int JsonViewDlg::ShowMessage(const std::wstring &title, const std::wstring &msg, int flag, bool bDontShow)
587598
{
588-
// Don't show message untill NPP ready message is received.
589-
return (!bDontShow && m_IsNppReady) ? ::MessageBox(_hParent, msg.c_str(), title.c_str(), flag) : IDOK;
599+
return !bDontShow ? ::MessageBox(_hParent, msg.c_str(), title.c_str(), flag) : IDOK;
590600
}
591601

592602
void JsonViewDlg::ReportError(const Result &result)

NppJSONViewer/NppJsonViewer/NppJsonPlugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void NppJsonPlugin::ProcessNotification(const SCNotification *notifyCode)
5555

5656
case NPPN_BUFFERACTIVATED:
5757
{
58-
if (m_pJsonViewDlg && !m_bAboutToClose)
58+
if (m_pJsonViewDlg && m_bNppReady && !m_bAboutToClose)
5959
{
6060
m_pJsonViewDlg->HandleTabActivated();
6161
}
@@ -70,12 +70,12 @@ void NppJsonPlugin::ProcessNotification(const SCNotification *notifyCode)
7070

7171
case NPPN_READY:
7272
{
73-
m_bNppReady = true;
7473
// This is work arround where dialog does not show tree on launch
7574
if (m_pJsonViewDlg && m_pJsonViewDlg->isVisible() && !m_bAboutToClose)
7675
{
7776
::SendMessage(m_pJsonViewDlg->getHSelf(), WM_COMMAND, IDC_BTN_REFRESH, 0);
7877
}
78+
m_bNppReady = true;
7979
break;
8080
}
8181

0 commit comments

Comments
 (0)