Skip to content

Commit 3f37522

Browse files
committed
Minor code enhancement
1 parent 5474077 commit 3f37522

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

src/NppJsonViewer/JsonViewDlg.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,18 +466,18 @@ void JsonViewDlg::AppendNodeCount(HTREEITEM node, unsigned elementCount, bool bA
466466
m_pTreeView->UpdateNodeText(node, txt);
467467
}
468468

469-
void JsonViewDlg::UpdateNodePath(HTREEITEM htiNode)
469+
void JsonViewDlg::UpdateNodePath(HTREEITEM htiNode) const
470470
{
471471
std::wstring nodePath = m_pTreeView->GetNodePath(htiNode);
472472
CUtility::SetEditCtrlText(::GetDlgItem(_hSelf, IDC_EDT_NODEPATH), nodePath);
473473
}
474474

475-
void JsonViewDlg::GoToLine(size_t nLineToGo)
475+
void JsonViewDlg::GoToLine(size_t nLineToGo) const
476476
{
477477
m_pEditor->GoToLine(nLineToGo);
478478
}
479479

480-
void JsonViewDlg::GoToPosition(size_t nLineToGo, size_t nPos, size_t nLen)
480+
void JsonViewDlg::GoToPosition(size_t nLineToGo, size_t nPos, size_t nLen) const
481481
{
482482
m_pEditor->GoToPosition(nLineToGo, nPos, nLen);
483483
}
@@ -673,7 +673,7 @@ void JsonViewDlg::AdjustDocPanelSize(int nWidth, int nHeight)
673673
const auto moveWindowIDs = {IDC_BTN_SEARCH};
674674

675675
// elements which requires both resizing and move
676-
const auto resizeAndmoveWindowIDs = {IDC_EDT_NODEPATH};
676+
const auto resizeAndMoveWindowIDs = {IDC_EDT_NODEPATH};
677677

678678
const UINT flags = SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_SHOWWINDOW;
679679

@@ -700,7 +700,7 @@ void JsonViewDlg::AdjustDocPanelSize(int nWidth, int nHeight)
700700
::SetWindowPos(hWnd, NULL, rc.left + addWidth, rc.top, 0, 0, SWP_NOSIZE | flags);
701701
}
702702

703-
for (int id : resizeAndmoveWindowIDs)
703+
for (int id : resizeAndMoveWindowIDs)
704704
{
705705
HWND hWnd = GetDlgItem(_hSelf, id);
706706

@@ -895,7 +895,7 @@ void JsonViewDlg::EnableControls(const std::vector<DWORD>& ids, bool enable)
895895
EnableWindow(GetDlgItem(getHSelf(), id), enable ? TRUE : FALSE);
896896
}
897897

898-
void JsonViewDlg::HandleTreeEvents(LPARAM lParam)
898+
void JsonViewDlg::HandleTreeEvents(LPARAM lParam) const
899899
{
900900
LPNMHDR lpnmh = reinterpret_cast<LPNMHDR>(lParam);
901901
if (!lpnmh || lpnmh->idFrom != IDC_TREE)
@@ -1029,7 +1029,7 @@ INT_PTR JsonViewDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
10291029
// Save ourselves in GWLP_USERDATA.
10301030
::SetWindowLongPtr(getHSelf(), GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
10311031

1032-
m_pTreeView->OnInit(getHSelf());
1032+
m_pTreeView->OnInit(getHSelf(), IDC_TREE);
10331033

10341034
PrepareButtons();
10351035

src/NppJsonViewer/JsonViewDlg.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ class JsonViewDlg
5959

6060
void ValidateJson();
6161

62-
void UpdateNodePath(HTREEITEM htiNode);
63-
void GoToLine(size_t nLineToGo);
64-
void GoToPosition(size_t nLineToGo, size_t nPos, size_t nLen);
62+
void UpdateNodePath(HTREEITEM htiNode) const;
63+
void GoToLine(size_t nLineToGo) const;
64+
void GoToPosition(size_t nLineToGo, size_t nPos, size_t nLen) const;
6565

6666
void SearchInTree();
6767

@@ -89,7 +89,7 @@ class JsonViewDlg
8989
void ShowControls(const std::vector<DWORD>& ids, bool show);
9090
void EnableControls(const std::vector<DWORD>& ids, bool enable);
9191

92-
void HandleTreeEvents(LPARAM lParam);
92+
void HandleTreeEvents(LPARAM lParam) const;
9393

9494
auto GetFormatSetting() const -> std::tuple<LE, LF, char, unsigned>;
9595

src/NppJsonViewer/TreeViewCtrl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
#include "TreeViewCtrl.h"
44
#include "Define.h"
5-
#include "resource.h"
65

76

8-
void TreeViewCtrl::OnInit(HWND hParent)
7+
void TreeViewCtrl::OnInit(HWND hParent, int ctrlID)
98
{
9+
m_nCtrlID = ctrlID;
1010
m_hParent = hParent;
11-
m_hTree = GetDlgItem(m_hParent, IDC_TREE);
11+
m_hTree = GetDlgItem(m_hParent, m_nCtrlID);
1212
}
1313

1414
auto TreeViewCtrl::InitTree() -> HTREEITEM
@@ -43,7 +43,7 @@ auto TreeViewCtrl::InsertNode(const std::wstring& text, LPARAM lparam, HTREEITEM
4343
tvInsert.item.pszText = const_cast<LPTSTR>(text.c_str());
4444
tvInsert.item.lParam = lparam;
4545

46-
HTREEITEM item = reinterpret_cast<HTREEITEM>(SendDlgItemMessage(m_hParent, IDC_TREE, TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(&tvInsert)));
46+
HTREEITEM item = reinterpret_cast<HTREEITEM>(SendDlgItemMessage(m_hParent, m_nCtrlID, TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(&tvInsert)));
4747

4848
return item;
4949
}

src/NppJsonViewer/TreeViewCtrl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ class TreeViewCtrl
1111
{
1212
HWND m_hTree = nullptr;
1313
HWND m_hParent = nullptr;
14+
int m_nCtrlID = 0;
1415
size_t m_nMaxNodeTextLength = 0;
1516

1617
public:
1718
TreeViewCtrl() = default;
1819
~TreeViewCtrl() = default;
1920

20-
void OnInit(HWND hParent);
21+
void OnInit(HWND hParent, int ctrlID);
2122

2223
HWND GetTreeViewHandle() const
2324
{

0 commit comments

Comments
 (0)