1+ #include < format>
2+ #include < regex>
3+
14#include " JsonViewDlg.h"
25#include " Define.h"
36#include " Utility.h"
47#include " StringHelper.h"
58#include " RapidJsonHandler.h"
69#include " ScintillaEditor.h"
710#include " Profile.h"
8- #include < format>
9- #include < regex>
11+
1012
1113constexpr int FILENAME_LEN_IN_TITLE = 16 ;
1214
@@ -171,14 +173,8 @@ bool JsonViewDlg::CheckForTokenUndefined(eMethod method, std::string selectedTex
171173 if (m_pSetting->parseOptions .bReplaceUndefined )
172174 {
173175 auto text = selectedText.substr (res.error_pos , 9 );
174- std::transform (
175- text.begin (),
176- text.end (),
177- text.begin (),
178- [](unsigned char c)
179- {
180- return (unsigned char )std::tolower (c);
181- });
176+ StringHelper::ToLower (text);
177+
182178 if (text == " undefined" )
183179 {
184180 try
@@ -390,10 +386,11 @@ auto JsonViewDlg::PopulateTreeUsingSax(HTREEITEM tree_root, const std::string& j
390386{
391387 std::optional<std::wstring> retVal = std::nullopt ;
392388
393- RapidJsonHandler handler (this , tree_root);
389+ auto pTS = std::make_shared<TrackingStream>(jsonText);
390+ RapidJsonHandler handler (this , tree_root, pTS);
394391 rapidjson::StringBuffer sb;
395392
396- Result res = JsonHandler (m_pSetting->parseOptions ).ParseJson <flgBaseReader>(jsonText, sb, handler);
393+ Result res = JsonHandler (m_pSetting->parseOptions ).ParseJson <flgBaseReader>(jsonText, sb, handler, pTS );
397394 if (!res.success )
398395 {
399396 if (CheckForTokenUndefined (JsonViewDlg::eMethod::ParseJson, jsonText, res, tree_root))
@@ -429,6 +426,13 @@ HTREEITEM JsonViewDlg::InsertToTree(HTREEITEM parent, const std::string& text)
429426 return m_hTreeView->InsertNode (wText, NULL , parent);
430427}
431428
429+ HTREEITEM JsonViewDlg::InsertToTree (HTREEITEM parent, const std::string& text, const Position& pos)
430+ {
431+ auto wText = StringHelper::ToWstring (text, CP_UTF8);
432+ auto lparam = new Position (pos);
433+ return m_hTreeView->InsertNode (wText, reinterpret_cast <LPARAM>(lparam), parent);
434+ }
435+
432436void JsonViewDlg::AppendNodeCount (HTREEITEM node, unsigned elementCount, bool bArray)
433437{
434438 if (!node)
@@ -450,6 +454,16 @@ void JsonViewDlg::UpdateNodePath(HTREEITEM htiNode)
450454 CUtility::SetEditCtrlText (::GetDlgItem (_hSelf, IDC_EDT_NODEPATH), nodePath);
451455}
452456
457+ void JsonViewDlg::GoToLine (size_t nLineToGo)
458+ {
459+ m_pEditor->GoToLine (0 , nLineToGo);
460+ }
461+
462+ void JsonViewDlg::GoToPosition (size_t nLineToGo, size_t nPos)
463+ {
464+ m_pEditor->GoToPosition (0 , nLineToGo, nPos);
465+ }
466+
453467void JsonViewDlg::SearchInTree ()
454468{
455469 std::wstring itemToSearch = CUtility::GetEditCtrlText (::GetDlgItem (_hSelf, IDC_EDT_SEARCH));
@@ -869,6 +883,20 @@ void JsonViewDlg::HandleTreeEvents(LPARAM lParam)
869883 if (!lpnmh || lpnmh->idFrom != IDC_TREE)
870884 return ; // Not click inside JsonTree
871885
886+ auto GetNodePosition = [this ](HTREEITEM hItem)
887+ {
888+ Position* pPosition = nullptr ;
889+ if (hItem != nullptr )
890+ {
891+ LPARAM nodePos = m_hTreeView->GetNodePos (hItem);
892+ if (nodePos != -1 )
893+ {
894+ pPosition = reinterpret_cast <Position*>(nodePos);
895+ }
896+ }
897+ return pPosition;
898+ };
899+
872900 switch (lpnmh->code )
873901 {
874902 case TVN_SELCHANGED:
@@ -878,6 +906,24 @@ void JsonViewDlg::HandleTreeEvents(LPARAM lParam)
878906 if (hItem && (pnmtv->action == TVC_BYMOUSE || pnmtv->action == TVC_BYKEYBOARD))
879907 {
880908 UpdateNodePath (hItem);
909+
910+ auto pPosition = GetNodePosition (hItem);
911+ if (pPosition != nullptr )
912+ {
913+ GoToLine (pPosition->nLine - 1 ); // line index start with 0 in editor, hence --
914+ }
915+ }
916+ }
917+ break ;
918+
919+ case NM_DBLCLK:
920+ {
921+ HTREEITEM hItem = m_hTreeView->GetSelection ();
922+
923+ auto pPosition = GetNodePosition (hItem);
924+ if (pPosition != nullptr )
925+ {
926+ GoToPosition (pPosition->nLine - 1 , pPosition->nColumn ); // line index start with 0 in editor, hence --
881927 }
882928 }
883929 break ;
0 commit comments