| 74 | } |
| 75 | |
| 76 | void 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 | |
| 110 | void JsonViewDlg::CompressJson() |
| 111 | { |