From 65bca654895c94e83ef25008dc1c44cc822cfbab Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sat, 17 Feb 2018 00:00:06 +0100 Subject: GH-2150 Split out custom commands into a custom widget Now it is used from a global page and from a sub-page in the instance settings. --- application/pages/global/CustomCommandsPage.cpp | 50 ++++++++++++++++ application/pages/global/CustomCommandsPage.h | 55 +++++++++++++++++ application/pages/global/JavaPage.cpp | 15 ----- application/pages/global/JavaPage.ui | 79 +++++++------------------ 4 files changed, 125 insertions(+), 74 deletions(-) create mode 100644 application/pages/global/CustomCommandsPage.cpp create mode 100644 application/pages/global/CustomCommandsPage.h (limited to 'application/pages/global') diff --git a/application/pages/global/CustomCommandsPage.cpp b/application/pages/global/CustomCommandsPage.cpp new file mode 100644 index 00000000..1352b6be --- /dev/null +++ b/application/pages/global/CustomCommandsPage.cpp @@ -0,0 +1,50 @@ +#include "CustomCommandsPage.h" +#include +#include +#include + +CustomCommandsPage::CustomCommandsPage(QWidget* parent): QWidget(parent) +{ + + auto verticalLayout = new QVBoxLayout(this); + verticalLayout->setObjectName(QStringLiteral("verticalLayout")); + verticalLayout->setContentsMargins(0, 0, 0, 0); + + auto tabWidget = new QTabWidget(this); + tabWidget->setObjectName(QStringLiteral("tabWidget")); + commands = new CustomCommands(this); + tabWidget->addTab(commands, "Foo"); + tabWidget->tabBar()->hide(); + verticalLayout->addWidget(tabWidget); + loadSettings(); +} + +CustomCommandsPage::~CustomCommandsPage() +{ +} + +bool CustomCommandsPage::apply() +{ + applySettings(); + return true; +} + +void CustomCommandsPage::applySettings() +{ + auto s = MMC->settings(); + s->set("PreLaunchCommand", commands->prelaunchCommand()); + s->set("WrapperCommand", commands->wrapperCommand()); + s->set("PostExitCommand", commands->postexitCommand()); +} + +void CustomCommandsPage::loadSettings() +{ + auto s = MMC->settings(); + commands->initialize( + false, + true, + s->get("PreLaunchCommand").toString(), + s->get("WrapperCommand").toString(), + s->get("PostExitCommand").toString() + ); +} diff --git a/application/pages/global/CustomCommandsPage.h b/application/pages/global/CustomCommandsPage.h new file mode 100644 index 00000000..52256ed3 --- /dev/null +++ b/application/pages/global/CustomCommandsPage.h @@ -0,0 +1,55 @@ +/* Copyright 2018-2018 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include "pages/BasePage.h" +#include +#include "widgets/CustomCommands.h" + +class CustomCommandsPage : public QWidget, public BasePage +{ + Q_OBJECT + +public: + explicit CustomCommandsPage(QWidget *parent = 0); + ~CustomCommandsPage(); + + QString displayName() const override + { + return tr("Custom Commands"); + } + QIcon icon() const override + { + return MMC->getThemedIcon("custom-commands"); + } + QString id() const override + { + return "custom-commands"; + } + QString helpPage() const override + { + return "Custom-commands"; + } + bool apply() override; + +private: + void applySettings(); + void loadSettings(); + CustomCommands * commands; +}; diff --git a/application/pages/global/JavaPage.cpp b/application/pages/global/JavaPage.cpp index 4aa0f184..57250c79 100644 --- a/application/pages/global/JavaPage.cpp +++ b/application/pages/global/JavaPage.cpp @@ -22,7 +22,6 @@ #include #include "dialogs/VersionSelectDialog.h" -#include #include "java/JavaUtils.h" #include "java/JavaInstallList.h" @@ -37,10 +36,6 @@ JavaPage::JavaPage(QWidget *parent) : QWidget(parent), ui(new Ui::JavaPage) ui->setupUi(this); ui->tabWidget->tabBar()->hide(); - auto resizer = new ColumnResizer(this); - resizer->addWidgetsFromLayout(ui->javaSettingsGroupBox->layout(), 0); - resizer->addWidgetsFromLayout(ui->customCommandsGroupBox->layout(), 0); - auto sysMB = Sys::getSystemRam() / Sys::megabyte; ui->maxMemSpinBox->setMaximum(sysMB); loadSettings(); @@ -80,11 +75,6 @@ void JavaPage::applySettings() s->set("JavaPath", ui->javaPathTextBox->text()); s->set("JvmArgs", ui->jvmArgsTextBox->text()); JavaCommon::checkJVMArgs(s->get("JvmArgs").toString(), this->parentWidget()); - - // Custom Commands - s->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text()); - s->set("WrapperCommand", ui->wrapperCmdTextBox->text()); - s->set("PostExitCommand", ui->postExitCmdTextBox->text()); } void JavaPage::loadSettings() { @@ -107,11 +97,6 @@ void JavaPage::loadSettings() // Java Settings ui->javaPathTextBox->setText(s->get("JavaPath").toString()); ui->jvmArgsTextBox->setText(s->get("JvmArgs").toString()); - - // Custom Commands - ui->preLaunchCmdTextBox->setText(s->get("PreLaunchCommand").toString()); - ui->wrapperCmdTextBox->setText(s->get("WrapperCommand").toString()); - ui->postExitCmdTextBox->setText(s->get("PostExitCommand").toString()); } void JavaPage::on_javaDetectBtn_clicked() diff --git a/application/pages/global/JavaPage.ui b/application/pages/global/JavaPage.ui index 9023b932..201b310c 100644 --- a/application/pages/global/JavaPage.ui +++ b/application/pages/global/JavaPage.ui @@ -7,7 +7,7 @@ 0 0 545 - 760 + 580 @@ -17,7 +17,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -217,62 +226,17 @@ - - - Custom Commands + + + Qt::Vertical - - - - - Post-exit command: - - - - - - - Pre-launch command: - - - - - - - - - - - - - Wrapper command: - - - - - - - - - - - - - - 0 - 0 - + + + 20 + 40 + - - <html><head/><body><p>Pre-launch command runs before the instance launches and post-exit command runs after it exits. Both will be run in MultiMC's working folder with INST_ID, INST_DIR, and INST_NAME as environment variables.</p><p>Wrapper command allows running java using an extra wrapper program (like 'optirun' on Linux)</p></body></html> - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - + @@ -289,9 +253,6 @@ jvmArgsTextBox javaDetectBtn javaTestBtn - preLaunchCmdTextBox - wrapperCmdTextBox - postExitCmdTextBox tabWidget -- cgit