Skip to content

Commit debd5bc

Browse files
committed
Some more cleanup
1 parent 2961ac5 commit debd5bc

File tree

7 files changed

+7
-63
lines changed

7 files changed

+7
-63
lines changed

NppJSONViewer/NppJsonViewer/Define.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const TCHAR JSON_INFO_TITLE[] = TEXT("JSON Viewer: Information");
3636
const TCHAR JSON_ERR_PARSE[] = TEXT("Cannot parse JSON. Please select a JSON String.");
3737
const TCHAR JSON_ERR_VALIDATE[] = TEXT("There was an error while parsing JSON. Refer the current selection for possible problematic area.");
3838
const TCHAR JSON_ERR_VALIDATE_SUCCESS[] = TEXT("JSON looks good. No error found while validating it.");
39+
const TCHAR JSON_ERR_SAVE_SETTING[] = TEXT("Failed to save the setting. Please try again.");
3940

4041
const TCHAR STR_VERSION[] = TEXT("Version: ");
4142
const TCHAR STR_COPY[] = TEXT("Copy");

NppJSONViewer/NppJsonViewer/JsonViewDlg.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -300,23 +300,10 @@ void JsonViewDlg::PopulateTreeUsingSax(HTREEITEM tree_root, const std::string& j
300300
m_Editor->SetLangAsJson();
301301
}
302302

303-
HTREEITEM JsonViewDlg::InsertToTree(HWND hWndDlg, HTREEITEM parent, const std::string& text)
304-
{
305-
auto wText = StringHelper::ToWstring(text);
306-
307-
TV_INSERTSTRUCT tvinsert{};
308-
tvinsert.hParent = parent;
309-
tvinsert.hInsertAfter = TVI_LAST;
310-
tvinsert.item.mask = TVIF_TEXT;
311-
tvinsert.item.pszText = const_cast<LPWSTR>(wText.c_str());
312-
313-
HTREEITEM item = (HTREEITEM)SendDlgItemMessage(hWndDlg, IDC_TREE, TVM_INSERTITEM, 0, (LPARAM)&tvinsert);
314-
return item;
315-
}
316-
317303
HTREEITEM JsonViewDlg::InsertToTree(HTREEITEM parent, const std::string& text)
318304
{
319-
return InsertToTree(getHSelf(), parent, text);
305+
auto wText = StringHelper::ToWstring(text);
306+
return m_hTreeView->InsertNode(wText, NULL, parent);
320307
}
321308

322309
void JsonViewDlg::UpdateNodePath(HTREEITEM htiNode)

NppJSONViewer/NppJsonViewer/JsonViewDlg.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class JsonViewDlg : public DockingDlgInterface
2020
void FormatJson();
2121
void CompressJson();
2222

23-
// TODO : move to treeviewctrl class
24-
HTREEITEM InsertToTree(HWND hWndDlg, HTREEITEM parent, const std::string& text);
2523
HTREEITEM InsertToTree(HTREEITEM parent, const std::string& text);
2624

2725
private:

NppJSONViewer/NppJsonViewer/RapidJsonHandler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ class JsonViewDlg;
1010

1111
struct TreeNode
1212
{
13-
HTREEITEM subRoot;
14-
JsonNode node;
15-
int counter;
13+
HTREEITEM subRoot{};
14+
JsonNode node{};
15+
int counter{};
1616
};
1717

1818
class RapidJsonHandler :public rapidjson::BaseReaderHandler<rapidjson::UTF8<>, RapidJsonHandler>

NppJSONViewer/NppJsonViewer/SettingsDlg.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ INT_PTR SettingsDlg::run_dlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
6565
}
6666
else
6767
{
68-
::MessageBox(_hSelf, L"Failed to save the setting. Please try again.",
69-
L"Setting Save Error", MB_OK | MB_ICONERROR);
68+
::MessageBox(_hSelf, JSON_ERR_SAVE_SETTING, JSON_ERROR_TITLE, MB_OK | MB_ICONERROR);
7069
}
7170
return TRUE;
7271

NppJSONViewer/NppJsonViewer/TreeViewCtrl.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -44,45 +44,6 @@ auto TreeViewCtrl::InsertNode(const std::wstring& text, LPARAM lparam, HTREEITEM
4444
return item;
4545
}
4646

47-
void TreeViewCtrl::InsertItem(const void* jsonNode, HTREEITEM node)
48-
{
49-
if (!jsonNode || !node)
50-
return;
51-
52-
/*std::wstring txtToInsert = StringHelper::ToWstring(jsonNode->key);
53-
JsonNodeType valType = jsonNode->type;
54-
55-
if (valType == JsonNodeType::UNKNOWN || valType == JsonNodeType::NUMBER || valType == JsonNodeType::BOOL)
56-
{
57-
txtToInsert += TEXT(" : ");
58-
txtToInsert += StringHelper::ToWstring(jsonNode->value);
59-
InsertNode(txtToInsert, jsonNode->pos.line, node);
60-
}
61-
else if (valType == JsonNodeType::STRING)
62-
{
63-
txtToInsert += TEXT(" : ");
64-
txtToInsert += TEXT("\"");
65-
txtToInsert += StringHelper::ToWstring(jsonNode->value);
66-
txtToInsert += TEXT("\"");
67-
InsertNode(txtToInsert, jsonNode->pos.line, node);
68-
}
69-
else if (valType == JsonNodeType::OBJECT || valType == JsonNodeType::ARRAY)
70-
{
71-
if (valType == JsonNodeType::OBJECT)
72-
txtToInsert += TEXT(" : [Object]");
73-
if (valType == JsonNodeType::ARRAY)
74-
txtToInsert += TEXT(" : [Array]");
75-
76-
HTREEITEM newNode = InsertNode(txtToInsert, jsonNode->pos.line, node);
77-
78-
for (auto jsonNextNode : jsonNode->childs)
79-
{
80-
if (jsonNextNode)
81-
InsertItem(jsonNextNode, newNode);
82-
}
83-
}*/
84-
}
85-
8647
bool TreeViewCtrl::IsExpanded(HTREEITEM node) const
8748
{
8849
return TreeView_GetItemState(m_hTree, node, TVIS_EXPANDED) & TVIS_EXPANDED;

NppJSONViewer/NppJsonViewer/TreeViewCtrl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class TreeViewCtrl
1818

1919
auto InitTree()->HTREEITEM;
2020
auto InsertNode(const std::wstring& text, LPARAM lparam, HTREEITEM parentNode)->HTREEITEM;
21-
//void InsertItem(const JsonNode* jsonNode, HTREEITEM node);
22-
void InsertItem(const void* jsonNode, HTREEITEM node);
2321

2422
bool IsExpanded(HTREEITEM node) const;
2523
bool IsThisOrAnyChildExpanded(HTREEITEM node) const;

0 commit comments

Comments
 (0)