mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-30 11:56:37 -05:00
Add button next to script combo-box to open file to that script.
Revert the behavior of Open Map Scripts button.
This commit is contained in:
@@ -422,6 +422,9 @@ bool ParseUtil::ensureFieldsExist(QJsonObject obj, QList<QString> fields) {
|
||||
}
|
||||
|
||||
int ParseUtil::getScriptLineNumber(const QString &filePath, const QString &scriptLabel) {
|
||||
if (scriptLabel.isEmpty())
|
||||
return 0;
|
||||
|
||||
if (filePath.endsWith(".inc"))
|
||||
return getRawScriptLineNumber(readTextFile(filePath), scriptLabel);
|
||||
else if (filePath.endsWith(".pory"))
|
||||
|
||||
@@ -2026,7 +2026,7 @@ void Editor::deleteEvent(Event *event) {
|
||||
//updateSelectedObjects();
|
||||
}
|
||||
|
||||
void Editor::openMapScripts() const {
|
||||
void Editor::openMapScripts(const QString &scriptLabel) const {
|
||||
const QString scriptsPath = project->getMapScriptsFilePath(map->name);
|
||||
QString command = porymapConfig.getTextEditorGotoLine();
|
||||
if (command.isEmpty()) {
|
||||
@@ -2035,8 +2035,6 @@ void Editor::openMapScripts() const {
|
||||
} else {
|
||||
if (command.contains("%F")) {
|
||||
if (command.contains("%L")) {
|
||||
const QString scriptLabel = selected_events->isEmpty() ?
|
||||
QString() : selected_events->first()->event->get("script_label");
|
||||
const int lineNum = ParseUtil::getScriptLineNumber(scriptsPath, scriptLabel);
|
||||
command.replace("%L", QString::number(lineNum));
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ void MainWindow::initEditor() {
|
||||
connect(this->editor, SIGNAL(currentMetatilesSelectionChanged()), this, SLOT(currentMetatilesSelectionChanged()));
|
||||
connect(this->editor, SIGNAL(wildMonDataChanged()), this, SLOT(onWildMonDataChanged()));
|
||||
connect(this->editor, &Editor::mapRulerStatusChanged, this, &MainWindow::onMapRulerStatusChanged);
|
||||
connect(ui->toolButton_Open_Scripts, &QToolButton::clicked, this->editor, &Editor::openMapScripts);
|
||||
connect(ui->toolButton_Open_Scripts, &QToolButton::pressed, this->editor, QOverload<>::of(&Editor::openMapScripts));
|
||||
connect(ui->actionOpen_Project_in_Text_Editor, &QAction::triggered, this->editor, &Editor::openProjectInTextEditor);
|
||||
|
||||
this->loadUserSettings();
|
||||
@@ -1866,7 +1866,22 @@ void MainWindow::updateSelectedObjects() {
|
||||
} else {
|
||||
combo->setCurrentText(value);
|
||||
|
||||
fl->addRow(new QLabel(field_labels[key], widget), combo);
|
||||
if (key == "script_label" && !porymapConfig.getTextEditorGotoLine().isEmpty()) {
|
||||
// Add tool button next to combo to open scripts file to combo's current script label.
|
||||
auto *hl = new QHBoxLayout();
|
||||
hl->setSpacing(3);
|
||||
auto *openScriptButton = new QToolButton(widget);
|
||||
openScriptButton->setFixedSize(combo->height(), combo->height());
|
||||
openScriptButton->setIcon(QFileIconProvider().icon(QFileIconProvider::File));
|
||||
openScriptButton->setToolTip("Go to this script definition in the map's scripts file.");
|
||||
connect(openScriptButton, &QToolButton::clicked,
|
||||
[this, combo]() { this->editor->openMapScripts(combo->currentText()); });
|
||||
hl->addWidget(combo);
|
||||
hl->addWidget(openScriptButton);
|
||||
fl->addRow(new QLabel(field_labels[key], widget), hl);
|
||||
} else {
|
||||
fl->addRow(new QLabel(field_labels[key], widget), combo);
|
||||
}
|
||||
widget->setLayout(fl);
|
||||
frame->layout()->addWidget(widget);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user