MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / displayCurrentFile

Method displayCurrentFile

source/json_tool/editor_gui.cpp:116–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116void 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
154void JsonEditor::updateValueEditor() {
155 FormattedJson value;

Callers

nothing calls this directly

Calls 10

strfFunction · 0.85
setFocusMethod · 0.80
parseFunction · 0.50
getMethod · 0.45
sizeMethod · 0.45
setTextMethod · 0.45
utf8PtrMethod · 0.45
setEnabledMethod · 0.45
reprMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected