Launch an editor for the custom.json file. Also allow overriding of the system default editor
This commit is contained in:
parent
654f444f55
commit
3380bc7563
18
MultiMC.cpp
18
MultiMC.cpp
@ -8,6 +8,7 @@
|
||||
#include <QLibraryInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QStringList>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#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"
|
||||
|
11
MultiMC.h
11
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();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
||||
|
@ -143,6 +143,20 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="customEditorBtn">
|
||||
<property name="text">
|
||||
<string>Open custom.json</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_7">
|
||||
<property name="orientation">
|
||||
|
@ -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());
|
||||
|
@ -55,6 +55,8 @@ slots:
|
||||
|
||||
void on_lwjglDirBrowseBtn_clicked();
|
||||
|
||||
void on_jsonEditorBrowseBtn_clicked();
|
||||
|
||||
void on_maximizedCheckBox_clicked(bool checked);
|
||||
|
||||
void on_buttonBox_accepted();
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>526</width>
|
||||
<height>599</height>
|
||||
<height>628</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -39,7 +39,7 @@
|
||||
<attribute name="title">
|
||||
<string>General</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="generalTabLayout">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="sortingModeBox">
|
||||
<property name="enabled">
|
||||
@ -236,6 +236,36 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="editorsBox">
|
||||
<property name="title">
|
||||
<string>External Editors (leave empty for system default)</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="foldersBoxLayout_2">
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="jsonEditorTextBox">
|
||||
<property name="clearButtonEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labelJsonEditor">
|
||||
<property name="text">
|
||||
<string>JSON Editor:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QToolButton" name="jsonEditorBrowseBtn">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="generalTabSpacer">
|
||||
<property name="orientation">
|
||||
|
Loading…
Reference in New Issue
Block a user