diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index f1061bdb..fd97121e 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -2639,6 +2639,8 @@ + + @@ -2905,6 +2907,11 @@ Export Map Stitch Image... + + + Edit Preferences... + + diff --git a/forms/preferenceeditor.ui b/forms/preferenceeditor.ui new file mode 100644 index 00000000..78b6da04 --- /dev/null +++ b/forms/preferenceeditor.ui @@ -0,0 +1,75 @@ + + + PreferenceEditor + + + + 0 + 0 + 480 + 320 + + + + Preferences + + + + + + + Preferred Text Editor + + + + + + Command + + + + + + + The command (including the necessary parameters) to perform the action. See the command parameter legend below for a list of supported parameter variables, which will be substituted when launching the command. When upper-case letters (e.g. %F, $D, %N) are used, the action will be applicable even if more than one item is selected. Esle the action will only be applicable f exactly one item is selected. + + + e.g. code --goto %F:%L + + + true + + + + + + + <html><head/><body><p>The command that will be executed when clicking the &quot;Open Map Scripts&quot; button. You may optionally include '%F' and '%L' in the command. '%F' will be substituted with the scripts file path and '%L' will be substituted with a line number. If '%L' is specified then the scripts file will be opened to map script cooresponding to the currently selected event (If the script can be found). If '%F' is <span style=" font-weight:600;">not</span> specified then the map scripts file path will be appended to the end of the command.</p></body></html> + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + diff --git a/include/mainwindow.h b/include/mainwindow.h index a9180402..7cc74e6a 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -21,6 +21,7 @@ #include "filterchildrenproxymodel.h" #include "newmappopup.h" #include "newtilesetdialog.h" +#include "preferenceeditor.h" namespace Ui { class MainWindow; @@ -226,6 +227,7 @@ private slots: void on_pushButton_ConfigureEncountersJSON_clicked(); void on_actionRegion_Map_Editor_triggered(); + void on_actionEdit_Preferences_triggered(); private: Ui::MainWindow *ui; @@ -234,6 +236,7 @@ private: MapImageExporter *mapImageExporter = nullptr; FilterChildrenProxyModel *mapListProxyModel; NewMapPopup *newmapprompt = nullptr; + PreferenceEditor *preferenceEditor = nullptr; QStandardItemModel *mapListModel; QList *mapGroupItemsList; QMap mapListIndexes; diff --git a/include/ui/preferenceeditor.h b/include/ui/preferenceeditor.h new file mode 100644 index 00000000..74085b6a --- /dev/null +++ b/include/ui/preferenceeditor.h @@ -0,0 +1,31 @@ +#ifndef PREFERENCES_H +#define PREFERENCES_H + +#include + +class QAbstractButton; + + +namespace Ui { +class PreferenceEditor; +} + +class PreferenceEditor : public QMainWindow +{ + Q_OBJECT + +public: + explicit PreferenceEditor(QWidget *parent = nullptr); + ~PreferenceEditor(); + +private: + Ui::PreferenceEditor *ui; + + void populateFields(); + void saveFields(); + +private slots: + void dialogButtonClicked(QAbstractButton *button); +}; + +#endif // PREFERENCES_H diff --git a/porymap.pro b/porymap.pro index 0da4a14b..806f3b5b 100644 --- a/porymap.pro +++ b/porymap.pro @@ -71,6 +71,7 @@ SOURCES += src/core/block.cpp \ src/ui/newtilesetdialog.cpp \ src/ui/flowlayout.cpp \ src/ui/mapruler.cpp \ + src/ui/preferenceeditor.cpp \ src/config.cpp \ src/editor.cpp \ src/main.cpp \ @@ -140,6 +141,7 @@ HEADERS += include/core/block.h \ include/ui/overlay.h \ include/ui/flowlayout.h \ include/ui/mapruler.h \ + include/ui/preferenceeditor.h \ include/config.h \ include/editor.h \ include/mainwindow.h \ @@ -156,7 +158,8 @@ FORMS += forms/mainwindow.ui \ forms/newmappopup.ui \ forms/aboutporymap.ui \ forms/newtilesetdialog.ui \ - forms/mapimageexporter.ui + forms/mapimageexporter.ui \ + forms/preferenceeditor.ui RESOURCES += \ resources/images.qrc \ diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f239d4d6..31ad9da1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2560,6 +2560,21 @@ void MainWindow::on_actionThemes_triggered() themeSelectorWindow.exec(); } +void MainWindow::on_actionEdit_Preferences_triggered() { + if (!preferenceEditor) { + preferenceEditor = new PreferenceEditor(this); + connect(preferenceEditor, &QObject::destroyed, [=](QObject *) { preferenceEditor = nullptr; }); + } + + if (!preferenceEditor->isVisible()) { + preferenceEditor->show(); + } else if (preferenceEditor->isMinimized()) { + preferenceEditor->showNormal(); + } else { + preferenceEditor->activateWindow(); + } +} + void MainWindow::on_pushButton_AddCustomHeaderField_clicked() { int rowIndex = this->ui->tableWidget_CustomHeaderFields->rowCount(); diff --git a/src/ui/preferenceeditor.cpp b/src/ui/preferenceeditor.cpp new file mode 100644 index 00000000..25476dfe --- /dev/null +++ b/src/ui/preferenceeditor.cpp @@ -0,0 +1,42 @@ +#include "preferenceeditor.h" +#include "ui_preferenceeditor.h" +#include "config.h" + +#include + + +PreferenceEditor::PreferenceEditor(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::PreferenceEditor) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + connect(ui->buttonBox, &QDialogButtonBox::clicked, + this, &PreferenceEditor::dialogButtonClicked); + populateFields(); +} + +PreferenceEditor::~PreferenceEditor() +{ + delete ui; +} + +void PreferenceEditor::populateFields() { + ui->lineEdit_TextEditor->setText(porymapConfig.getTextEditorCommand()); +} + +void PreferenceEditor::saveFields() { + porymapConfig.setTextEditorCommand(ui->lineEdit_TextEditor->text()); +} + +void PreferenceEditor::dialogButtonClicked(QAbstractButton *button) { + auto buttonRole = ui->buttonBox->buttonRole(button); + if (buttonRole == QDialogButtonBox::AcceptRole) { + saveFields(); + close(); + } else if (buttonRole == QDialogButtonBox::ApplyRole) { + saveFields(); + } else if (buttonRole == QDialogButtonBox::RejectRole) { + close(); + } +}