From afc0c0c501f1e4450df14c3ac390eab2dc6bcf09 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Wed, 2 Dec 2020 03:39:08 -0500 Subject: [PATCH] Add button next to script combo-box to open file to that script. Revert the behavior of Open Map Scripts button. --- CHANGELOG.md | 2 +- docsrc/manual/editing-map-events.rst | 8 +++++++- .../go-to-script-button.png | Bin 0 -> 4908 bytes docsrc/manual/settings-and-options.rst | 2 +- include/editor.h | 3 ++- src/core/parseutil.cpp | 3 +++ src/editor.cpp | 4 +--- src/mainwindow.cpp | 19 ++++++++++++++++-- 8 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 docsrc/manual/images/editing-map-events/go-to-script-button.png diff --git a/CHANGELOG.md b/CHANGELOG.md index c78b0d8c..e9b49704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - The window sizes and positions of the tileset editor, palette editor, and region map editor are now stored in `porymap.cfg`. - Add ruler tool for measuring metatile distance in events tab (Right-click to turn on/off, left-click to lock in place). - Add delete button to wild pokemon encounters tab. -- Add ability to specify preferred text editor commands in `Options -> Edit Preferences`. These allow `Open Map Scripts` to open directly to the script for the currently selected event, and to open the project root directory in a text editor directly from porymap. +- Add custom text editor commands in `Options -> Edit Preferences`, a tool-button next to the `Script` combo-box, and `Tools -> Open Project in Text Editor`. The tool-button will open the map's scripts file to the cooresponding script. ### Changed - Holding `shift` now toggles "Smart Path" drawing; when the "Smart Paths" checkbox is checked, holding `shift` will temporarily disable it. diff --git a/docsrc/manual/editing-map-events.rst b/docsrc/manual/editing-map-events.rst index e950e4e3..cc2f017a 100644 --- a/docsrc/manual/editing-map-events.rst +++ b/docsrc/manual/editing-map-events.rst @@ -225,11 +225,17 @@ Respawn NPC Open Map Scripts ---------------- -Clicking the ``Open Map Scripts`` button |open-map-scripts-button| will open the map's scripts file in your default text editor. If nothing happens when this button is clicked, you may need to associate a text editor with the `.inc` file extension (or `.pory` if you're using Porycript). `Alternatively`, you may specify a preferred text editor command in *Options -> Edit Preferences*. By specifying a text editor like this you can allow Porymap to open the scripts file directly to the script of the currently selected event. +Clicking the ``Open Map Scripts`` button |open-map-scripts-button| will open the map's scripts file in your default text editor. If nothing happens when this button is clicked, you may need to associate a text editor with the `.inc` file extension (or `.pory` if you're using Porycript). + +Additionally, if you specify a ``Goto Line Command`` in *Options -> Edit Preferences* then a tool-button will appear next to the `Script` combo-box for selected events. Clicking this button will open the map's scripts file directly to the cooresponding script (if the script can be found in that file). +|go-to-script-button| .. |open-map-scripts-button| image:: images/editing-map-events/open-map-scripts-button.png +.. |go-to-script-button| + image:: images/editing-map-events/go-to-script-button.png + Tool Buttons ------------ diff --git a/docsrc/manual/images/editing-map-events/go-to-script-button.png b/docsrc/manual/images/editing-map-events/go-to-script-button.png new file mode 100644 index 0000000000000000000000000000000000000000..859ed2f30da6e234ce8af5e232d795f87f5fc6cf GIT binary patch literal 4908 zcmV+{6VvR8P)2r`}uh=39qNys2%-S-Ehj0A$>Q+fCM$>#$(_nhB7 zzkBZe<@Y=5B7;oL00RR9qrZUr*cHIQz`*EBFr$WnfzhwPj2Z?8M!$mau`BQo60ul@ zf=nX**cHLR!01Z|L?WOlfzZL)$fPn9K-?sJXR#_oH5?8>5Tx_z-dSSbA`y#mc)Yrr z`p2#a1_nmY@VOjES9hhdqQGwyJjuzCNW=t!N^_b_DkG7}W>!{YbrN(oO3Hx(zfthK zs94y@M{pe?&QHat$xtAZH9mGNFfcHbLX)DyWY#E|nL^PbX=rdcoVFAcz|7K$fG05D zDl0^;SaU0@C%HNJj_IFDpBff*Vqkn;pnxj*VX@iJ@fjC42}$beEH+ztA#%l%)YZEN zu%C*jhJk_cnSr7oUxGY76;BNV0|TQ^z&te!42*XHeLp`7MbY<^pr{U*QNzH%_*B5- z@q-5%A;>=wWLoJSGRuInbKYgLu?mE&#ez$cj@JasOm?hAFGD(UVI2oZG!!{)&7gyr&PXq z6T0`WYUW$z>(I4N4WW+p-5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U=o93??s_p_#P(L9<1(_;IJdWBYiOow7IR z>gN+BA>D6Ns_DFP=MSdsQ;N@TJe1j}C_lz$P2c-!Ty6u3q6mUmS#@4GgrX>y+n|iE zhAn9SfQ+1Tc;lo2?84a4lld)^UY^AUtcm@&wfc~7Qx2|3`Ph}f_}}o}3ku{&$jYHl zn?2_}>+m7M&v&6eho2Z2{Sj^LUMz8Du~?nL&j}O1u4Xddvkry^2ALV@|C{g=0|TR< z^PZlXtPi$R1DSHWbbK6et*@EEz`*!Skh>^A&PSV~1s$Jpf~u;3&)24CDKA8>SOK3; zQ0=_k%%|e1;c!SJpQnz!PznR%bAZdPx3sYAIUfKDsDLjJ@OU`fKZ8s-9ImXibeM^$ zzP^4BgHPRxeOXqD!*%w|K9xQ-0FX$;G8y(-DGZGM23|!4L6FWbGnPqZQdA;-_nid@ zDyld 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")) diff --git a/src/editor.cpp b/src/editor.cpp index a83f03d0..ed0fd424 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -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)); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c0713226..ebb232e6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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);