MCPcopy Create free account
hub / github.com/NPP-JSONViewer/JSON-Viewer / DrawJsonTree

Method DrawJsonTree

src/NppJsonViewer/JsonViewDlg.cpp:336–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334}
335
336void JsonViewDlg::DrawJsonTree()
337{
338 UpdateTitle();
339
340 // Disable all buttons and treeView
341 std::vector<DWORD> ctrls = {IDC_BTN_REFRESH, IDC_BTN_VALIDATE, IDC_BTN_FORMAT, IDC_BTN_SEARCH, IDC_EDT_SEARCH};
342 EnableControls(ctrls, false);
343
344 HTREEITEM rootNode = nullptr;
345 rootNode = m_pTreeView->InitTree();
346
347 // Refresh the view
348 m_pEditor->RefreshViewHandle();
349 const auto selectedData = m_pEditor->GetJsonText();
350 const auto selectedText = IsSelectionValidJson(selectedData);
351
352 if (!selectedText.has_value() || selectedText.value().empty())
353 {
354 m_pTreeView->InsertNode(JSON_ERR_PARSE, NULL, rootNode);
355
356 if (IsMultiSelection(selectedData))
357 {
358 ShowMessage(JSON_INFO_TITLE, JSON_ERR_MULTI_SELECTION, MB_OK | MB_ICONINFORMATION);
359 }
360 }
361 else
362 {
363 auto res = PopulateTreeUsingSax(rootNode, selectedText.value());
364 if (res.has_value())
365 {
366 // This is the case when Notepad++ has JsonViewer Window opened for previous instance
367 // Later on second launch, don't show the error message as this could be some text file
368 // If it is real json file but has some error, then there must be more than 1 node exist.
369
370 if (!m_IsNppReady && m_pTreeView->GetNodeCount() <= 1)
371 {
372 m_pTreeView->InsertNode(JSON_ERR_VALIDATE, NULL, rootNode);
373 }
374 else
375 {
376 ShowMessage(JSON_ERROR_TITLE, res.value(), MB_OK | MB_ICONERROR);
377 }
378 }
379 }
380
381 m_pTreeView->Expand(rootNode);
382
383 // Enable all buttons and treeView
384 EnableControls(ctrls, true);
385}
386
387void JsonViewDlg::ReDrawJsonTree(bool bForce)
388{

Callers

nothing calls this directly

Calls 6

InitTreeMethod · 0.80
RefreshViewHandleMethod · 0.80
GetJsonTextMethod · 0.80
InsertNodeMethod · 0.80
GetNodeCountMethod · 0.80
ExpandMethod · 0.80

Tested by

no test coverage detected