Skip to content

Commit 472caf9

Browse files
committed
When file type is json, then error message is shown twice on npp launch if viewer dock was kept once on previous instance
1 parent 70f83f1 commit 472caf9

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

NppJSONViewer/NppJsonViewer/JsonViewDlg.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
#include <format>
99

1010

11-
JsonViewDlg::JsonViewDlg(HINSTANCE hIntance, const NppData &nppData, int nCmdId, std::shared_ptr<Setting> &pSetting)
12-
: m_NppData(nppData)
13-
, DockingDlgInterface(IDD_TREEDLG)
11+
JsonViewDlg::JsonViewDlg(HINSTANCE hIntance, const NppData &nppData, const bool &isReady, int nCmdId, std::shared_ptr<Setting> &pSetting)
12+
: DockingDlgInterface(IDD_TREEDLG)
13+
, m_NppData(nppData)
14+
, m_IsNppReady(isReady)
1415
, m_nDlgId(nCmdId)
1516
, m_Editor(std::make_unique<ScintillaEditor>(nppData))
1617
, m_hTreeView(std::make_unique<TreeViewCtrl>())
@@ -576,7 +577,8 @@ auto JsonViewDlg::CopyPath() const -> std::wstring
576577

577578
int JsonViewDlg::ShowMessage(const std::wstring &title, const std::wstring &msg, int flag, bool bDontShow)
578579
{
579-
return !bDontShow ? ::MessageBox(_hParent, msg.c_str(), title.c_str(), flag) : IDOK;
580+
// Don't show message untill NPP ready message is received.
581+
return (!bDontShow && m_IsNppReady) ? ::MessageBox(_hParent, msg.c_str(), title.c_str(), flag) : IDOK;
580582
}
581583

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

NppJSONViewer/NppJsonViewer/JsonViewDlg.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class JsonViewDlg : public DockingDlgInterface
2020
};
2121

2222
public:
23-
JsonViewDlg(HINSTANCE hIntance, const NppData &nppData, int nCmdId, std::shared_ptr<Setting> &pSetting);
23+
JsonViewDlg(HINSTANCE hIntance, const NppData &nppData, const bool &isReady, int nCmdId, std::shared_ptr<Setting> &pSetting);
2424
virtual ~JsonViewDlg();
2525

2626
void ShowDlg(bool bShow);
@@ -73,9 +73,10 @@ class JsonViewDlg : public DockingDlgInterface
7373
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
7474

7575
private:
76-
int m_nDlgId = -1;
77-
NppData m_NppData = {};
78-
HICON m_hBtnIcon[4] = {};
76+
int m_nDlgId = -1;
77+
NppData m_NppData = {};
78+
HICON m_hBtnIcon[4] = {};
79+
const bool &m_IsNppReady;
7980

8081
// To handle doc panel resizing
8182
LONG m_lfDeltaWidth = 0;

NppJSONViewer/NppJsonViewer/NppJsonPlugin.cpp

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

7171
case NPPN_READY:
7272
{
73+
m_bNppReady = true;
7374
// This is work arround where dialog does not show tree on launch
7475
if (m_pJsonViewDlg && m_pJsonViewDlg->isVisible() && !m_bAboutToClose)
7576
{
@@ -101,7 +102,7 @@ void NppJsonPlugin::SetMenuIcon()
101102
{
102103
if (m_hMenuIcon.hToolbarIcon || m_hMenuIcon.hToolbarBmp)
103104
{
104-
toolbarIcons tbIcon;
105+
toolbarIcons tbIcon {};
105106
tbIcon.hToolbarBmp = m_hMenuIcon.hToolbarBmp;
106107
tbIcon.hToolbarIcon = m_hMenuIcon.hToolbarIcon;
107108
auto nCommandId = m_shortcutCommands.GetCommandID(CallBackID::SHOW_DOC_PANEL);
@@ -155,7 +156,7 @@ void NppJsonPlugin::ConstructJsonDlg()
155156
{
156157
ConstructSetting();
157158
auto nCmdId = m_shortcutCommands.GetCommandID(CallBackID::SHOW_DOC_PANEL);
158-
m_pJsonViewDlg = std::make_unique<JsonViewDlg>(reinterpret_cast<HINSTANCE>(m_hModule), m_NppData, nCmdId, m_pSetting);
159+
m_pJsonViewDlg = std::make_unique<JsonViewDlg>(reinterpret_cast<HINSTANCE>(m_hModule), m_NppData, m_bNppReady, nCmdId, m_pSetting);
159160
}
160161
}
161162

NppJSONViewer/NppJsonViewer/NppJsonPlugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class NppJsonPlugin
8787
NppData m_NppData = {};
8888
std::wstring m_configPath;
8989
bool m_bAboutToClose = false;
90+
bool m_bNppReady = false;
9091
std::unique_ptr<AboutDlg> m_pAboutDlg = nullptr;
9192
std::unique_ptr<JsonViewDlg> m_pJsonViewDlg = nullptr;
9293
std::unique_ptr<SettingsDlg> m_pSettingsDlg = nullptr;

0 commit comments

Comments
 (0)