| 140 | } |
| 141 | |
| 142 | void 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 | |
| 176 | bool JsonViewDlg::CheckForTokenUndefined(eMethod method, std::string selectedText, Result& res, HTREEITEM tree_root) |
| 177 | { |