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:
BigBahss 2020-12-02 03:39:08 -05:00
parent 9da465fe53
commit afc0c0c501
8 changed files with 32 additions and 9 deletions

View file

@ -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`. - 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 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 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 ### Changed
- Holding `shift` now toggles "Smart Path" drawing; when the "Smart Paths" checkbox is checked, holding `shift` will temporarily disable it. - Holding `shift` now toggles "Smart Path" drawing; when the "Smart Paths" checkbox is checked, holding `shift` will temporarily disable it.

View file

@ -225,11 +225,17 @@ Respawn NPC
Open Map Scripts 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| .. |open-map-scripts-button|
image:: images/editing-map-events/open-map-scripts-button.png 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 Tool Buttons
------------ ------------

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View file

@ -31,7 +31,7 @@ determined by this file.
``monitor_files``, 1, global, yes, Whether porymap will monitor changes to project files ``monitor_files``, 1, global, yes, Whether porymap will monitor changes to project files
``region_map_dimensions``, 32x20, global, yes, The dimensions of the region map tilemap ``region_map_dimensions``, 32x20, global, yes, The dimensions of the region map tilemap
``theme``, default, global, yes, The color theme for porymap windows and widgets ``theme``, default, global, yes, The color theme for porymap windows and widgets
``text_editor_goto_line``, , global, yes, Optional command that will be executed when clicking ``Open Map Scripts``. ``text_editor_goto_line``, , global, yes, The command that will be executed when clicking the tool-button next the ``Script`` combo-box.
``text_editor_open_directory``, , global, yes, The command that will be executed when clicking ``Open Project in Text Editor``. ``text_editor_open_directory``, , global, yes, The command that will be executed when clicking ``Open Project in Text Editor``.
``base_game_version``, , project, no, The base pret repo for this project ``base_game_version``, , project, no, The base pret repo for this project
``use_encounter_json``, 1, project, yes, Enables wild encounter table editing ``use_encounter_json``, 1, project, yes, Enables wild encounter table editing

View file

@ -155,7 +155,8 @@ public:
void scaleMapView(int); void scaleMapView(int);
public slots: public slots:
void openMapScripts() const; void openMapScripts(const QString &scriptLabel) const;
void openMapScripts() const { openMapScripts(QString()); }
void openProjectInTextEditor() const; void openProjectInTextEditor() const;
void maskNonVisibleConnectionTiles(); void maskNonVisibleConnectionTiles();

View file

@ -422,6 +422,9 @@ bool ParseUtil::ensureFieldsExist(QJsonObject obj, QList<QString> fields) {
} }
int ParseUtil::getScriptLineNumber(const QString &filePath, const QString &scriptLabel) { int ParseUtil::getScriptLineNumber(const QString &filePath, const QString &scriptLabel) {
if (scriptLabel.isEmpty())
return 0;
if (filePath.endsWith(".inc")) if (filePath.endsWith(".inc"))
return getRawScriptLineNumber(readTextFile(filePath), scriptLabel); return getRawScriptLineNumber(readTextFile(filePath), scriptLabel);
else if (filePath.endsWith(".pory")) else if (filePath.endsWith(".pory"))

View file

@ -2026,7 +2026,7 @@ void Editor::deleteEvent(Event *event) {
//updateSelectedObjects(); //updateSelectedObjects();
} }
void Editor::openMapScripts() const { void Editor::openMapScripts(const QString &scriptLabel) const {
const QString scriptsPath = project->getMapScriptsFilePath(map->name); const QString scriptsPath = project->getMapScriptsFilePath(map->name);
QString command = porymapConfig.getTextEditorGotoLine(); QString command = porymapConfig.getTextEditorGotoLine();
if (command.isEmpty()) { if (command.isEmpty()) {
@ -2035,8 +2035,6 @@ void Editor::openMapScripts() const {
} else { } else {
if (command.contains("%F")) { if (command.contains("%F")) {
if (command.contains("%L")) { 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); const int lineNum = ParseUtil::getScriptLineNumber(scriptsPath, scriptLabel);
command.replace("%L", QString::number(lineNum)); command.replace("%L", QString::number(lineNum));
} }

View file

@ -169,7 +169,7 @@ void MainWindow::initEditor() {
connect(this->editor, SIGNAL(currentMetatilesSelectionChanged()), this, SLOT(currentMetatilesSelectionChanged())); connect(this->editor, SIGNAL(currentMetatilesSelectionChanged()), this, SLOT(currentMetatilesSelectionChanged()));
connect(this->editor, SIGNAL(wildMonDataChanged()), this, SLOT(onWildMonDataChanged())); connect(this->editor, SIGNAL(wildMonDataChanged()), this, SLOT(onWildMonDataChanged()));
connect(this->editor, &Editor::mapRulerStatusChanged, this, &MainWindow::onMapRulerStatusChanged); 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); connect(ui->actionOpen_Project_in_Text_Editor, &QAction::triggered, this->editor, &Editor::openProjectInTextEditor);
this->loadUserSettings(); this->loadUserSettings();
@ -1866,7 +1866,22 @@ void MainWindow::updateSelectedObjects() {
} else { } else {
combo->setCurrentText(value); combo->setCurrentText(value);
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); fl->addRow(new QLabel(field_labels[key], widget), combo);
}
widget->setLayout(fl); widget->setLayout(fl);
frame->layout()->addWidget(widget); frame->layout()->addWidget(widget);