From 3380bc75633c63e8569b76981ac29528c58943ce Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sun, 29 Dec 2013 17:51:16 +0100 Subject: [PATCH 1/5] Launch an editor for the custom.json file. Also allow overriding of the system default editor --- MultiMC.cpp | 18 +++++++++++++++ MultiMC.h | 11 +++++++--- gui/dialogs/OneSixModEditDialog.cpp | 10 +++++++++ gui/dialogs/OneSixModEditDialog.h | 1 + gui/dialogs/OneSixModEditDialog.ui | 14 ++++++++++++ gui/dialogs/SettingsDialog.cpp | 32 +++++++++++++++++++++++++++ gui/dialogs/SettingsDialog.h | 2 ++ gui/dialogs/SettingsDialog.ui | 34 +++++++++++++++++++++++++++-- 8 files changed, 117 insertions(+), 5 deletions(-) diff --git a/MultiMC.cpp b/MultiMC.cpp index 71d0e5a7..24cdd077 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "gui/dialogs/VersionSelectDialog.h" #include "logic/lists/InstanceList.h" @@ -382,6 +383,9 @@ void MultiMC::initGlobalSettings() m_settings->registerSetting(new Setting("CentralModsDir", "mods")); m_settings->registerSetting(new Setting("LWJGLDir", "lwjgl")); + // Editors + m_settings->registerSetting(new Setting("JsonEditor", QString())); + // Console m_settings->registerSetting(new Setting("ShowConsole", true)); m_settings->registerSetting(new Setting("AutoCloseConsole", true)); @@ -550,4 +554,18 @@ QString MultiMC::getExitUpdatePath() const return m_updateOnExitPath; } +void MultiMC::openJsonEditor(const QString &filename) +{ + const QString file = QDir::current().absoluteFilePath(filename); + if (m_settings->get("JsonEditor").toString().isEmpty()) + { + QDesktopServices::openUrl(QUrl::fromLocalFile(file)); + } + else + { + QProcess::startDetached(m_settings->get("JsonEditor").toString(), + QStringList() << file); + } +} + #include "MultiMC.moc" diff --git a/MultiMC.h b/MultiMC.h index 4a33fb69..17113181 100644 --- a/MultiMC.h +++ b/MultiMC.h @@ -6,7 +6,6 @@ #include "logger/QsLog.h" #include "logger/QsLogDest.h" - class MinecraftVersionList; class LWJGLVersionList; class HttpMetaCache; @@ -101,12 +100,12 @@ public: /*! * Installs update from the given update files directory. */ - void installUpdates(const QString& updateFilesDir, bool restartOnFinish=false); + void installUpdates(const QString &updateFilesDir, bool restartOnFinish = false); /*! * Sets MultiMC to install updates from the given directory when it exits. */ - void setUpdateOnExit(const QString& updateFilesDir); + void setUpdateOnExit(const QString &updateFilesDir); /*! * Gets the path to install updates from on exit. @@ -114,6 +113,12 @@ public: */ QString getExitUpdatePath() const; + /*! + * Opens a json file using either a system default editor, or, if note empty, the editor + * specified in the settings + */ + void openJsonEditor(const QString &filename); + private: void initLogger(); diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp index d8b84d3e..e575c868 100644 --- a/gui/dialogs/OneSixModEditDialog.cpp +++ b/gui/dialogs/OneSixModEditDialog.cpp @@ -97,6 +97,7 @@ void OneSixModEditDialog::updateVersionControls() ui->revertBtn->setEnabled(customVersion); ui->forgeBtn->setEnabled(true); ui->liteloaderBtn->setEnabled(LiteLoaderInstaller(m_inst->intendedVersionId()).canApply()); + ui->customEditorBtn->setEnabled(customVersion); } void OneSixModEditDialog::disableVersionControls() @@ -105,6 +106,7 @@ void OneSixModEditDialog::disableVersionControls() ui->revertBtn->setEnabled(false); ui->forgeBtn->setEnabled(false); ui->liteloaderBtn->setEnabled(false); + ui->customEditorBtn->setEnabled(false); } void OneSixModEditDialog::on_customizeBtn_clicked() @@ -134,6 +136,14 @@ void OneSixModEditDialog::on_revertBtn_clicked() } } +void OneSixModEditDialog::on_customEditorBtn_clicked() +{ + if (m_inst->versionIsCustom()) + { + MMC->openJsonEditor(m_inst->instanceRoot() + "/custom.json"); + } +} + void OneSixModEditDialog::on_forgeBtn_clicked() { VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); diff --git a/gui/dialogs/OneSixModEditDialog.h b/gui/dialogs/OneSixModEditDialog.h index 09bd7946..2510c59c 100644 --- a/gui/dialogs/OneSixModEditDialog.h +++ b/gui/dialogs/OneSixModEditDialog.h @@ -47,6 +47,7 @@ slots: void on_liteloaderBtn_clicked(); void on_customizeBtn_clicked(); void on_revertBtn_clicked(); + void on_customEditorBtn_clicked(); void updateVersionControls(); void disableVersionControls(); diff --git a/gui/dialogs/OneSixModEditDialog.ui b/gui/dialogs/OneSixModEditDialog.ui index ad20cd73..899e0cbf 100644 --- a/gui/dialogs/OneSixModEditDialog.ui +++ b/gui/dialogs/OneSixModEditDialog.ui @@ -143,6 +143,20 @@ + + + + Qt::Horizontal + + + + + + + Open custom.json + + + diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index 131cb5c3..a95a8e83 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -125,6 +125,23 @@ void SettingsDialog::on_lwjglDirBrowseBtn_clicked() } } +void SettingsDialog::on_jsonEditorBrowseBtn_clicked() +{ + QString raw_file = QFileDialog::getOpenFileName( + this, tr("JSON Editor"), + ui->jsonEditorTextBox->text().isEmpty() + ? QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation).first() + : ui->jsonEditorTextBox->text()); + QString cooked_file = NormalizePath(raw_file); + + // it has to exist and be an executable + if (!cooked_file.isEmpty() && QFileInfo(cooked_file).exists() && + QFileInfo(cooked_file).isExecutable()) + { + ui->jsonEditorTextBox->setText(cooked_file); + } +} + void SettingsDialog::on_maximizedCheckBox_clicked(bool checked) { Q_UNUSED(checked); @@ -172,6 +189,18 @@ void SettingsDialog::applySettings(SettingsObject *s) s->set("CentralModsDir", ui->modsDirTextBox->text()); s->set("LWJGLDir", ui->lwjglDirTextBox->text()); + // Editors + QString jsonEditor = ui->jsonEditorTextBox->text(); + if (!jsonEditor.isEmpty() && (!QFileInfo(jsonEditor).exists() || !QFileInfo(jsonEditor).isExecutable())) + { + QString found = QStandardPaths::findExecutable(jsonEditor); + if (!found.isEmpty()) + { + jsonEditor = found; + } + } + s->set("JsonEditor", jsonEditor); + // Console s->set("ShowConsole", ui->showConsoleCheck->isChecked()); s->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked()); @@ -226,6 +255,9 @@ void SettingsDialog::loadSettings(SettingsObject *s) ui->modsDirTextBox->setText(s->get("CentralModsDir").toString()); ui->lwjglDirTextBox->setText(s->get("LWJGLDir").toString()); + // Editors + ui->jsonEditorTextBox->setText(s->get("JsonEditor").toString()); + // Console ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool()); ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool()); diff --git a/gui/dialogs/SettingsDialog.h b/gui/dialogs/SettingsDialog.h index 36fc4797..01357c91 100644 --- a/gui/dialogs/SettingsDialog.h +++ b/gui/dialogs/SettingsDialog.h @@ -55,6 +55,8 @@ slots: void on_lwjglDirBrowseBtn_clicked(); + void on_jsonEditorBrowseBtn_clicked(); + void on_maximizedCheckBox_clicked(bool checked); void on_buttonBox_accepted(); diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui index 4d06d1f8..ca8c7391 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/dialogs/SettingsDialog.ui @@ -7,7 +7,7 @@ 0 0 526 - 599 + 628 @@ -39,7 +39,7 @@ General - + @@ -236,6 +236,36 @@ + + + + External Editors (leave empty for system default) + + + + + + true + + + + + + + JSON Editor: + + + + + + + ... + + + + + + From 5a7fc1e123b73c7b9448fba43236d7e675cb6470 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 30 Dec 2013 13:00:55 +0100 Subject: [PATCH 2/5] Use /usr/bin as default on linux --- gui/dialogs/SettingsDialog.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index a95a8e83..1ca0007c 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -130,7 +130,11 @@ void SettingsDialog::on_jsonEditorBrowseBtn_clicked() QString raw_file = QFileDialog::getOpenFileName( this, tr("JSON Editor"), ui->jsonEditorTextBox->text().isEmpty() + #if defined(Q_OS_LINUX) + ? QString("/usr/bin") + #else ? QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation).first() + #endif : ui->jsonEditorTextBox->text()); QString cooked_file = NormalizePath(raw_file); From c01678a3fa328e2f7b8f33bfe54733820802f7b7 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 30 Dec 2013 14:05:53 +0100 Subject: [PATCH 3/5] Don't use stuff that's new in 5.2 if we don't compile with that --- gui/dialogs/SettingsDialog.cpp | 4 ++++ gui/dialogs/SettingsDialog.ui | 6 +----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index 1ca0007c..2797fe4e 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -40,6 +40,10 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Se ui->sortingModeGroup->setId(ui->sortByNameBtn, Sort_Name); ui->sortingModeGroup->setId(ui->sortLastLaunchedBtn, Sort_LastLaunch); +#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + ui->jsonEditorTextBox->setClearButtonEnabled(true); +#endif + loadSettings(MMC->settings().get()); updateCheckboxStuff(); } diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui index ca8c7391..4c05b883 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/dialogs/SettingsDialog.ui @@ -243,11 +243,7 @@ - - - true - - + From 5d0868a056e3de295deaa94717b4023d07772c54 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 30 Dec 2013 14:45:59 +0100 Subject: [PATCH 4/5] Notify the user of any errors --- MultiMC.cpp | 8 ++++---- MultiMC.h | 2 +- gui/dialogs/OneSixModEditDialog.cpp | 5 ++++- gui/dialogs/SettingsDialog.cpp | 11 ++++++++++- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/MultiMC.cpp b/MultiMC.cpp index 24cdd077..865d0cf1 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -554,17 +554,17 @@ QString MultiMC::getExitUpdatePath() const return m_updateOnExitPath; } -void MultiMC::openJsonEditor(const QString &filename) +bool MultiMC::openJsonEditor(const QString &filename) { const QString file = QDir::current().absoluteFilePath(filename); if (m_settings->get("JsonEditor").toString().isEmpty()) { - QDesktopServices::openUrl(QUrl::fromLocalFile(file)); + return QDesktopServices::openUrl(QUrl::fromLocalFile(file)); } else { - QProcess::startDetached(m_settings->get("JsonEditor").toString(), - QStringList() << file); + return QProcess::startDetached(m_settings->get("JsonEditor").toString(), + QStringList() << file); } } diff --git a/MultiMC.h b/MultiMC.h index 17113181..602a4673 100644 --- a/MultiMC.h +++ b/MultiMC.h @@ -117,7 +117,7 @@ public: * Opens a json file using either a system default editor, or, if note empty, the editor * specified in the settings */ - void openJsonEditor(const QString &filename); + bool openJsonEditor(const QString &filename); private: void initLogger(); diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp index e575c868..3982f17d 100644 --- a/gui/dialogs/OneSixModEditDialog.cpp +++ b/gui/dialogs/OneSixModEditDialog.cpp @@ -140,7 +140,10 @@ void OneSixModEditDialog::on_customEditorBtn_clicked() { if (m_inst->versionIsCustom()) { - MMC->openJsonEditor(m_inst->instanceRoot() + "/custom.json"); + if (!MMC->openJsonEditor(m_inst->instanceRoot() + "/custom.json")) + { + QMessageBox::warning(this, tr("Error"), tr("Unable to open custom.json, check the settings")); + } } } diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index 2797fe4e..0d97a5a5 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -142,12 +142,21 @@ void SettingsDialog::on_jsonEditorBrowseBtn_clicked() : ui->jsonEditorTextBox->text()); QString cooked_file = NormalizePath(raw_file); + if (cooked_file.isEmpty()) + { + return; + } + // it has to exist and be an executable - if (!cooked_file.isEmpty() && QFileInfo(cooked_file).exists() && + if (QFileInfo(cooked_file).exists() && QFileInfo(cooked_file).isExecutable()) { ui->jsonEditorTextBox->setText(cooked_file); } + else + { + QMessageBox::warning(this, tr("Invalid"), tr("The file choosen does not seem to be an executable")); + } } void SettingsDialog::on_maximizedCheckBox_clicked(bool checked) From 76438f6afe4b29b3436bc32ba18e7f4dbdfa636d Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 30 Dec 2013 14:55:55 +0100 Subject: [PATCH 5/5] Fix spelling mistake --- gui/dialogs/SettingsDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index 0d97a5a5..30a973da 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -155,7 +155,7 @@ void SettingsDialog::on_jsonEditorBrowseBtn_clicked() } else { - QMessageBox::warning(this, tr("Invalid"), tr("The file choosen does not seem to be an executable")); + QMessageBox::warning(this, tr("Invalid"), tr("The file chosen does not seem to be an executable")); } }