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

Method FormatJson

src/NppJsonViewer/JsonViewDlg.cpp:76–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76void JsonViewDlg::FormatJson()
77{
78 UpdateTitle();
79
80 const auto selectedData = m_pEditor->GetJsonText();
81 const auto selectedText = IsSelectionValidJson(selectedData);
82
83 if (!selectedText.has_value() || selectedText.value().empty())
84 {
85 const std::wstring msg = IsMultiSelection(selectedData) ? JSON_ERR_MULTI_SELECTION : JSON_ERR_PARSE;
86 ShowMessage(JSON_INFO_TITLE, msg, MB_OK | MB_ICONINFORMATION);
87 return;
88 }
89
90 auto [le, lf, indentChar, indentLen] = GetFormatSetting();
91
92 Result res = JsonHandler(m_pSetting->parseOptions).FormatJson(selectedText.value(), le, lf, indentChar, indentLen);
93
94 if (res.success)
95 {
96 m_pEditor->ReplaceSelection(res.response);
97 HighlightAsJson();
98 }
99 else
100 {
101 if (CheckForTokenUndefined(JsonViewDlg::eMethod::FormatJson, selectedText.value(), res, NULL))
102 return;
103
104 ReportError(res);
105 }
106
107 ReDrawJsonTree();
108}
109
110void JsonViewDlg::CompressJson()
111{

Callers 3

TEST_FFunction · 0.45
TEST_FFunction · 0.45

Calls 3

JsonHandlerClass · 0.85
GetJsonTextMethod · 0.80
ReplaceSelectionMethod · 0.80

Tested by 2

TEST_FFunction · 0.36
TEST_FFunction · 0.36