| 114 | } |
| 115 | |
| 116 | void JsonEditor::displayCurrentFile() { |
| 117 | String file = m_files.get(m_fileIndex); |
| 118 | |
| 119 | size_t progress = (m_fileIndex + 1) * 100 / m_files.size(); |
| 120 | String status = strf("Editing file {}/{} ({}%): {}", m_fileIndex + 1, m_files.size(), progress, file); |
| 121 | m_statusLabel->setText(status.utf8Ptr()); |
| 122 | |
| 123 | m_backButton->setEnabled(m_fileIndex != 0); |
| 124 | m_nextButton->setText(m_fileIndex == m_files.size() - 1 ? "Done" : "Next »"); |
| 125 | |
| 126 | m_pathLabel->setText(m_path->path().utf8Ptr()); |
| 127 | |
| 128 | m_imageLabel->setText("No preview"); |
| 129 | m_jsonDocument->setPlainText(""); |
| 130 | m_valueEditor->setText(""); |
| 131 | m_valueEditor->setEnabled(false); |
| 132 | |
| 133 | try { |
| 134 | m_currentJson = FormattedJson::parse(File::readFileString(file)); |
| 135 | |
| 136 | m_jsonDocument->setPlainText(m_currentJson.repr().utf8Ptr()); |
| 137 | |
| 138 | updateValueEditor(); |
| 139 | |
| 140 | updateImagePreview(); |
| 141 | |
| 142 | } catch (StarException const& e) { |
| 143 | // Something else went wrong (maybe while parsing the document) and allowing |
| 144 | // the user to edit this file might cause us to lose data. |
| 145 | m_errorDialog->showMessage(e.what()); |
| 146 | } |
| 147 | |
| 148 | m_jsonPreview->moveCursor(QTextCursor::Start); |
| 149 | |
| 150 | m_valueEditor->selectAll(); |
| 151 | m_valueEditor->setFocus(Qt::FocusReason::OtherFocusReason); |
| 152 | } |
| 153 | |
| 154 | void JsonEditor::updateValueEditor() { |
| 155 | FormattedJson value; |