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

Method SortJsonByKey

src/NppJsonViewer/JsonViewDlg.cpp:142–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142void JsonViewDlg::SortJsonByKey()
143{
144 UpdateTitle();
145
146 const auto selectedData = m_pEditor->GetJsonText();
147 const auto selectedText = IsSelectionValidJson(selectedData);
148
149 if (!selectedText.has_value() || selectedText.value().empty())
150 {
151 const std::wstring msg = IsMultiSelection(selectedData) ? JSON_ERR_MULTI_SELECTION : JSON_ERR_PARSE;
152 ShowMessage(JSON_INFO_TITLE, msg, MB_OK | MB_ICONINFORMATION);
153 return;
154 }
155
156 auto [le, lf, indentChar, indentLen] = GetFormatSetting();
157
158 Result res = JsonHandler(m_pSetting->parseOptions).SortJsonByKey(selectedText.value(), le, lf, indentChar, indentLen);
159
160 if (res.success)
161 {
162 m_pEditor->ReplaceSelection(res.response);
163 HighlightAsJson();
164 }
165 else
166 {
167 if (CheckForTokenUndefined(JsonViewDlg::eMethod::SortJsonByKey, selectedText.value(), res, NULL))
168 return;
169
170 ReportError(res);
171 }
172
173 ReDrawJsonTree();
174}
175
176bool JsonViewDlg::CheckForTokenUndefined(eMethod method, std::string selectedText, Result& res, HTREEITEM tree_root)
177{

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