Skip to content

Commit

Permalink
Minor code enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
SinghRajenM committed Nov 11, 2024
1 parent 5474077 commit 3f37522
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/NppJsonViewer/JsonViewDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,18 +466,18 @@ void JsonViewDlg::AppendNodeCount(HTREEITEM node, unsigned elementCount, bool bA
m_pTreeView->UpdateNodeText(node, txt);
}

void JsonViewDlg::UpdateNodePath(HTREEITEM htiNode)
void JsonViewDlg::UpdateNodePath(HTREEITEM htiNode) const
{
std::wstring nodePath = m_pTreeView->GetNodePath(htiNode);
CUtility::SetEditCtrlText(::GetDlgItem(_hSelf, IDC_EDT_NODEPATH), nodePath);
}

void JsonViewDlg::GoToLine(size_t nLineToGo)
void JsonViewDlg::GoToLine(size_t nLineToGo) const
{
m_pEditor->GoToLine(nLineToGo);
}

void JsonViewDlg::GoToPosition(size_t nLineToGo, size_t nPos, size_t nLen)
void JsonViewDlg::GoToPosition(size_t nLineToGo, size_t nPos, size_t nLen) const
{
m_pEditor->GoToPosition(nLineToGo, nPos, nLen);
}
Expand Down Expand Up @@ -673,7 +673,7 @@ void JsonViewDlg::AdjustDocPanelSize(int nWidth, int nHeight)
const auto moveWindowIDs = {IDC_BTN_SEARCH};

// elements which requires both resizing and move
const auto resizeAndmoveWindowIDs = {IDC_EDT_NODEPATH};
const auto resizeAndMoveWindowIDs = {IDC_EDT_NODEPATH};

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

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

for (int id : resizeAndmoveWindowIDs)
for (int id : resizeAndMoveWindowIDs)
{
HWND hWnd = GetDlgItem(_hSelf, id);

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

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

m_pTreeView->OnInit(getHSelf());
m_pTreeView->OnInit(getHSelf(), IDC_TREE);

PrepareButtons();

Expand Down
8 changes: 4 additions & 4 deletions src/NppJsonViewer/JsonViewDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class JsonViewDlg

void ValidateJson();

void UpdateNodePath(HTREEITEM htiNode);
void GoToLine(size_t nLineToGo);
void GoToPosition(size_t nLineToGo, size_t nPos, size_t nLen);
void UpdateNodePath(HTREEITEM htiNode) const;
void GoToLine(size_t nLineToGo) const;
void GoToPosition(size_t nLineToGo, size_t nPos, size_t nLen) const;

void SearchInTree();

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

void HandleTreeEvents(LPARAM lParam);
void HandleTreeEvents(LPARAM lParam) const;

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

Expand Down
8 changes: 4 additions & 4 deletions src/NppJsonViewer/TreeViewCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

#include "TreeViewCtrl.h"
#include "Define.h"
#include "resource.h"


void TreeViewCtrl::OnInit(HWND hParent)
void TreeViewCtrl::OnInit(HWND hParent, int ctrlID)
{
m_nCtrlID = ctrlID;
m_hParent = hParent;
m_hTree = GetDlgItem(m_hParent, IDC_TREE);
m_hTree = GetDlgItem(m_hParent, m_nCtrlID);
}

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

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

return item;
}
Expand Down
3 changes: 2 additions & 1 deletion src/NppJsonViewer/TreeViewCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ class TreeViewCtrl
{
HWND m_hTree = nullptr;
HWND m_hParent = nullptr;
int m_nCtrlID = 0;
size_t m_nMaxNodeTextLength = 0;

public:
TreeViewCtrl() = default;
~TreeViewCtrl() = default;

void OnInit(HWND hParent);
void OnInit(HWND hParent, int ctrlID);

HWND GetTreeViewHandle() const
{
Expand Down

0 comments on commit 3f37522

Please sign in to comment.