Skip to content

Commit

Permalink
GH-2150 Split out custom commands into a custom widget
Browse files Browse the repository at this point in the history
Now it is used from a global page and from a sub-page in the instance settings.
  • Loading branch information
peterix committed Feb 16, 2018
1 parent a7957f2 commit 65bca65
Show file tree
Hide file tree
Showing 13 changed files with 689 additions and 166 deletions.
5 changes: 5 additions & 0 deletions application/CMakeLists.txt
Expand Up @@ -101,6 +101,8 @@ SET(MULTIMC_SOURCES
# GUI - global settings pages
pages/global/AccountListPage.cpp
pages/global/AccountListPage.h
pages/global/CustomCommandsPage.cpp
pages/global/CustomCommandsPage.h
pages/global/ExternalToolsPage.cpp
pages/global/ExternalToolsPage.h
pages/global/JavaPage.cpp
Expand Down Expand Up @@ -155,6 +157,8 @@ SET(MULTIMC_SOURCES
# GUI - widgets
widgets/Common.cpp
widgets/Common.h
widgets/CustomCommands.cpp
widgets/CustomCommands.h
widgets/FocusLineEdit.cpp
widgets/FocusLineEdit.h
widgets/IconLabel.cpp
Expand Down Expand Up @@ -232,6 +236,7 @@ SET(MULTIMC_UIS
dialogs/SkinUploadDialog.ui

# Widgets/other
widgets/CustomCommands.ui
widgets/MCModInfoFrame.ui
)

Expand Down
3 changes: 3 additions & 0 deletions application/MultiMC.cpp
Expand Up @@ -11,6 +11,7 @@
#include "pages/global/AccountListPage.h"
#include "pages/global/PasteEEPage.h"
#include "pages/global/PackagesPage.h"
#include "pages/global/CustomCommandsPage.h"

#include "themes/ITheme.h"
#include "themes/SystemTheme.h"
Expand Down Expand Up @@ -65,6 +66,7 @@
#include <ganalytics.h>
#include <sys.h>


#if defined Q_OS_WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
Expand Down Expand Up @@ -514,6 +516,7 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
m_globalSettingsProvider->addPage<MultiMCPage>();
m_globalSettingsProvider->addPage<MinecraftPage>();
m_globalSettingsProvider->addPage<JavaPage>();
m_globalSettingsProvider->addPage<CustomCommandsPage>();
m_globalSettingsProvider->addPage<ProxyPage>();
// m_globalSettingsProvider->addPage<PackagesPage>();
m_globalSettingsProvider->addPage<ExternalToolsPage>();
Expand Down
22 changes: 13 additions & 9 deletions application/pages/InstanceSettingsPage.cpp
Expand Up @@ -12,6 +12,7 @@
#include <java/JavaInstallList.h>
#include <FileSystem.h>
#include <sys.h>
#include <widgets/CustomCommands.h>

InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
: QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst)
Expand Down Expand Up @@ -130,13 +131,13 @@ void InstanceSettingsPage::applySettings()
m_settings->reset("OverrideJava");

// Custom Commands
bool custcmd = ui->customCommandsGroupBox->isChecked();
bool custcmd = ui->customCommands->checked();
m_settings->set("OverrideCommands", custcmd);
if (custcmd)
{
m_settings->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text());
m_settings->set("WrapperCommand", ui->wrapperCmdTextBox->text());
m_settings->set("PostExitCommand", ui->postExitCmdTextBox->text());
m_settings->set("PreLaunchCommand", ui->customCommands->prelaunchCommand());
m_settings->set("WrapperCommand", ui->customCommands->wrapperCommand());
m_settings->set("PostExitCommand", ui->customCommands->postexitCommand());
}
else
{
Expand Down Expand Up @@ -187,11 +188,14 @@ void InstanceSettingsPage::loadSettings()
ui->javaArgumentsGroupBox->setChecked(overrideArgs);
ui->jvmArgsTextBox->setPlainText(m_settings->get("JvmArgs").toString());

// Custom Commands
ui->customCommandsGroupBox->setChecked(m_settings->get("OverrideCommands").toBool());
ui->preLaunchCmdTextBox->setText(m_settings->get("PreLaunchCommand").toString());
ui->wrapperCmdTextBox->setText(m_settings->get("WrapperCommand").toString());
ui->postExitCmdTextBox->setText(m_settings->get("PostExitCommand").toString());
// Custom commands
ui->customCommands->initialize(
true,
m_settings->get("OverrideCommands").toBool(),
m_settings->get("PreLaunchCommand").toString(),
m_settings->get("WrapperCommand").toString(),
m_settings->get("PostExitCommand").toString()
);
}

void InstanceSettingsPage::on_javaDetectBtn_clicked()
Expand Down
96 changes: 13 additions & 83 deletions application/pages/InstanceSettingsPage.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>458</width>
<height>508</height>
<width>553</width>
<height>583</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down Expand Up @@ -42,7 +42,7 @@
<bool>true</bool>
</property>
<property name="title">
<string>Java ins&amp;tallation</string>
<string>Java insta&amp;llation</string>
</property>
<property name="checkable">
<bool>true</bool>
Expand Down Expand Up @@ -196,7 +196,7 @@
<bool>true</bool>
</property>
<property name="title">
<string>Java arguments</string>
<string>Java argumen&amp;ts</string>
</property>
<property name="checkable">
<bool>true</bool>
Expand Down Expand Up @@ -363,88 +363,22 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QGroupBox" name="customCommandsGroupBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Cus&amp;tom Commands</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="2" column="0">
<widget class="QLabel" name="labelPostExitCmd">
<property name="text">
<string>Post-exit command:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="preLaunchCmdTextBox"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelPreLaunchCmd">
<property name="text">
<string>Pre-launch command:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="postExitCmdTextBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelWrapperCmd">
<property name="text">
<string>Wrapper command:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="wrapperCmdTextBox"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="labelCustomCmdsDescription">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Pre-launch command runs before the instance launches and post-exit command runs after it exits.&lt;/p&gt;&lt;p&gt;Both will be run in MultiMC's working folder with extra environment variables:&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;INST_NAME - Name of the instance&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;INST_ID - ID of the instance&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;INST_DIR - absolute path of the instance&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;INST_MC_DIR - absolute path of minecraft&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;INST_JAVA - java binary used for launch&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;INST_JAVA_ARGS - command-line parameters used for launch&lt;/li&gt;&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacerMinecraft_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>88</width>
<height>186</height>
</size>
</property>
</spacer>
<widget class="CustomCommands" name="customCommands" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>CustomCommands</class>
<extends>QWidget</extends>
<header>widgets/CustomCommands.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>settingsTabs</tabstop>
<tabstop>javaSettingsGroupBox</tabstop>
Expand All @@ -466,10 +400,6 @@
<tabstop>showConsoleCheck</tabstop>
<tabstop>autoCloseConsoleCheck</tabstop>
<tabstop>showConsoleErrorCheck</tabstop>
<tabstop>customCommandsGroupBox</tabstop>
<tabstop>preLaunchCmdTextBox</tabstop>
<tabstop>wrapperCmdTextBox</tabstop>
<tabstop>postExitCmdTextBox</tabstop>
</tabstops>
<resources/>
<connections/>
Expand Down
50 changes: 50 additions & 0 deletions application/pages/global/CustomCommandsPage.cpp
@@ -0,0 +1,50 @@
#include "CustomCommandsPage.h"
#include <QVBoxLayout>
#include <QTabWidget>
#include <QTabBar>

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()
);
}
55 changes: 55 additions & 0 deletions 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 <memory>
#include <QDialog>

#include "pages/BasePage.h"
#include <MultiMC.h>
#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;
};
15 changes: 0 additions & 15 deletions application/pages/global/JavaPage.cpp
Expand Up @@ -22,7 +22,6 @@
#include <QDir>

#include "dialogs/VersionSelectDialog.h"
#include <ColumnResizer.h>

#include "java/JavaUtils.h"
#include "java/JavaInstallList.h"
Expand All @@ -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();
Expand Down Expand Up @@ -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()
{
Expand All @@ -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()
Expand Down

0 comments on commit 65bca65

Please sign in to comment.