@@ -155,6 +155,72 @@ void JsonViewDlg::ValidateJson()
155155 }
156156}
157157
158+ void JsonViewDlg::DrawJsonTree ()
159+ {
160+ // Disable all buttons and treeView
161+ std::vector<DWORD> ctrls = {IDC_BTN_REFRESH, IDC_BTN_VALIDATE, IDC_BTN_FORMAT, IDC_BTN_SEARCH, IDC_EDT_SEARCH};
162+ EnableControls (ctrls, false );
163+
164+ HTREEITEM rootNode = nullptr ;
165+ rootNode = m_hTreeView->InitTree ();
166+
167+ const std::string txtForParsing = m_Editor->GetJsonText ();
168+
169+ if (txtForParsing.empty ())
170+ {
171+ m_hTreeView->InsertNode (JSON_ERR_PARSE, NULL , rootNode);
172+ }
173+ else
174+ {
175+ PopulateTreeUsingSax (rootNode, txtForParsing);
176+ }
177+
178+ m_hTreeView->Expand (rootNode);
179+
180+ // Enable all buttons and treeView
181+ EnableControls (ctrls, true );
182+ }
183+
184+ void JsonViewDlg::PopulateTreeUsingSax (HTREEITEM tree_root, const std::string &jsonText)
185+ {
186+ RapidJsonHandler handler (this , tree_root);
187+ rapidjson::StringBuffer sb;
188+
189+ Result res = JsonHandler (m_pSetting->parseOptions ).ParseJson (jsonText, sb, handler);
190+ if (!res.success )
191+ {
192+ // Mark the error position
193+ size_t start = m_Editor->GetSelectionStart ();
194+ size_t errPosition = start + static_cast <size_t >(res.error_pos );
195+ m_Editor->MakeSelection (errPosition, errPosition + 1 );
196+
197+ // Intimate user
198+ if (jsonText.empty ())
199+ {
200+ ShowMessage (JSON_ERROR_TITLE, JSON_ERR_PARSE, MB_OK | MB_ICONERROR);
201+ }
202+ else
203+ {
204+ std::string err = std::format (" \n\n Error: ({} : {})" , res.error_code , res.error_str );
205+ ShowMessage (JSON_ERROR_TITLE, (JSON_ERR_VALIDATE + StringHelper::ToWstring (err)).c_str (), MB_OK | MB_ICONERROR);
206+ }
207+ }
208+
209+ m_Editor->SetLangAsJson ();
210+ }
211+
212+ HTREEITEM JsonViewDlg::InsertToTree (HTREEITEM parent, const std::string &text)
213+ {
214+ auto wText = StringHelper::ToWstring (text);
215+ return m_hTreeView->InsertNode (wText, NULL , parent);
216+ }
217+
218+ void JsonViewDlg::UpdateNodePath (HTREEITEM htiNode)
219+ {
220+ std::wstring nodePath = m_hTreeView->GetNodePath (htiNode);
221+ SetDlgItemText (_hSelf, IDC_EDT_NODEPATH, nodePath.c_str ());
222+ }
223+
158224void JsonViewDlg::PrepareButtons ()
159225{
160226 // Refresh Button
@@ -272,72 +338,6 @@ void JsonViewDlg::AdjustDocPanelSize(int nWidth, int nHeight)
272338 }
273339}
274340
275- void JsonViewDlg::DrawJsonTree ()
276- {
277- // Disable all buttons and treeView
278- std::vector<DWORD> ctrls = { IDC_BTN_REFRESH , IDC_BTN_VALIDATE, IDC_BTN_FORMAT, IDC_BTN_SEARCH, IDC_EDT_SEARCH };
279- EnableControls (ctrls, false );
280-
281- HTREEITEM rootNode = nullptr ;
282- rootNode = m_hTreeView->InitTree ();
283-
284- const std::string txtForParsing = m_Editor->GetJsonText ();
285-
286- if (txtForParsing.empty ())
287- {
288- m_hTreeView->InsertNode (JSON_ERR_PARSE, NULL , rootNode);
289- }
290- else
291- {
292- PopulateTreeUsingSax (rootNode, txtForParsing);
293- }
294-
295- m_hTreeView->Expand (rootNode);
296-
297- // Enable all buttons and treeView
298- EnableControls (ctrls, true );
299- }
300-
301- void JsonViewDlg::PopulateTreeUsingSax (HTREEITEM tree_root, const std::string &jsonText)
302- {
303- RapidJsonHandler handler (this , tree_root);
304- rapidjson::StringBuffer sb;
305-
306- Result res = JsonHandler (m_pSetting->parseOptions ).ParseJson (jsonText, sb, handler);
307- if (!res.success )
308- {
309- // Mark the error position
310- size_t start = m_Editor->GetSelectionStart ();
311- size_t errPosition = start + static_cast <size_t >(res.error_pos );
312- m_Editor->MakeSelection (errPosition, errPosition + 1 );
313-
314- // Intimate user
315- if (jsonText.empty ())
316- {
317- ShowMessage (JSON_ERROR_TITLE, JSON_ERR_PARSE, MB_OK | MB_ICONERROR);
318- }
319- else
320- {
321- std::string err = std::format (" \n\n Error: ({} : {})" , res.error_code , res.error_str );
322- ShowMessage (JSON_ERROR_TITLE, (JSON_ERR_VALIDATE + StringHelper::ToWstring (err)).c_str (), MB_OK | MB_ICONERROR);
323- }
324- }
325-
326- m_Editor->SetLangAsJson ();
327- }
328-
329- HTREEITEM JsonViewDlg::InsertToTree (HTREEITEM parent, const std::string& text)
330- {
331- auto wText = StringHelper::ToWstring (text);
332- return m_hTreeView->InsertNode (wText, NULL , parent);
333- }
334-
335- void JsonViewDlg::UpdateNodePath (HTREEITEM htiNode)
336- {
337- std::wstring nodePath = m_hTreeView->GetNodePath (htiNode);
338- SetDlgItemText (_hSelf, IDC_EDT_NODEPATH, nodePath.c_str ());
339- }
340-
341341void JsonViewDlg::ShowContextMenu (int x, int y)
342342{
343343 POINT p{
0 commit comments