From bc6d1b5304f715ad0d8be27efd6630f820572da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 6 Aug 2016 15:39:29 +0200 Subject: GH-338, GH-513, GH-700 Unify edit instance with console window * The resulting instance window can be closed at any point. * Main window is kept open and running instances are marked with a badge. * Multiple instances can now run from the same MultiMC - it's even more **multi** now. * MultiMC can be entirely closed, keeping Minecraft(s) running. --- application/pages/LogPage.cpp | 75 ++++++++++++++++++++++++++++++------------- application/pages/LogPage.h | 5 ++- 2 files changed, 57 insertions(+), 23 deletions(-) (limited to 'application/pages') diff --git a/application/pages/LogPage.cpp b/application/pages/LogPage.cpp index af96148b..de4ed4f3 100644 --- a/application/pages/LogPage.cpp +++ b/application/pages/LogPage.cpp @@ -12,40 +12,57 @@ #include "GuiUtil.h" #include -LogPage::LogPage(std::shared_ptr proc, QWidget *parent) - : QWidget(parent), ui(new Ui::LogPage), m_process(proc) +LogPage::LogPage(InstancePtr instance, QWidget *parent) + : QWidget(parent), ui(new Ui::LogPage), m_instance(instance) { ui->setupUi(this); ui->tabWidget->tabBar()->hide(); - connect(m_process.get(), SIGNAL(log(QString, MessageLevel::Enum)), this, - SLOT(write(QString, MessageLevel::Enum))); // create the format and set its font - defaultFormat = new QTextCharFormat(ui->text->currentCharFormat()); - QString fontFamily = MMC->settings()->get("ConsoleFont").toString(); - bool conversionOk = false; - int fontSize = MMC->settings()->get("ConsoleFontSize").toInt(&conversionOk); - if(!conversionOk) { - fontSize = 11; + defaultFormat = new QTextCharFormat(ui->text->currentCharFormat()); + QString fontFamily = MMC->settings()->get("ConsoleFont").toString(); + bool conversionOk = false; + int fontSize = MMC->settings()->get("ConsoleFontSize").toInt(&conversionOk); + if(!conversionOk) + { + fontSize = 11; + } + defaultFormat->setFont(QFont(fontFamily, fontSize)); } - defaultFormat->setFont(QFont(fontFamily, fontSize)); // ensure we don't eat all the RAM - auto lineSetting = MMC->settings()->getSetting("ConsoleMaxLines"); - int maxLines = lineSetting->get().toInt(&conversionOk); - if(!conversionOk) { - maxLines = lineSetting->defValue().toInt(); - qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines; + auto lineSetting = MMC->settings()->getSetting("ConsoleMaxLines"); + bool conversionOk = false; + int maxLines = lineSetting->get().toInt(&conversionOk); + if(!conversionOk) + { + maxLines = lineSetting->defValue().toInt(); + qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines; + } + ui->text->setMaximumBlockCount(maxLines); + + m_stopOnOverflow = MMC->settings()->get("ConsoleOverflowStop").toBool(); } - ui->text->setMaximumBlockCount(maxLines); - auto origForeground = ui->text->palette().color(ui->text->foregroundRole()); - auto origBackground = ui->text->palette().color(ui->text->backgroundRole()); - m_colors.reset(new LogColorCache(origForeground, origBackground)); + // set up instance and launch process recognition + { + auto launchTask = m_instance->getLaunchTask(); + if(launchTask) + { + on_InstanceLaunchTask_changed(launchTask); + } + connect(m_instance.get(), &BaseInstance::launchTaskChanged, + this, &LogPage::on_InstanceLaunchTask_changed); + } - m_stopOnOverflow = MMC->settings()->get("ConsoleOverflowStop").toBool(); + // set up text colors and adapt them to the current theme foreground and background + { + auto origForeground = ui->text->palette().color(ui->text->foregroundRole()); + auto origBackground = ui->text->palette().color(ui->text->backgroundRole()); + m_colors.reset(new LogColorCache(origForeground, origBackground)); + } auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this); connect(findShortcut, SIGNAL(activated()), SLOT(findActivated())); @@ -62,6 +79,20 @@ LogPage::~LogPage() delete defaultFormat; } +void LogPage::on_InstanceLaunchTask_changed(std::shared_ptr proc) +{ + if(m_process) + { + disconnect(m_process.get(), &LaunchTask::log, this, &LogPage::write); + } + m_process = proc; + if(m_process) + { + ui->text->clear(); + connect(m_process.get(), &LaunchTask::log, this, &LogPage::write); + } +} + bool LogPage::apply() { return true; @@ -69,7 +100,7 @@ bool LogPage::apply() bool LogPage::shouldDisplay() const { - return m_process->instance()->isRunning(); + return m_instance->isRunning() || ui->text->blockCount() > 1; } void LogPage::on_btnPaste_clicked() diff --git a/application/pages/LogPage.h b/application/pages/LogPage.h index 9b694323..e902ad13 100644 --- a/application/pages/LogPage.h +++ b/application/pages/LogPage.h @@ -34,7 +34,7 @@ class LogPage : public QWidget, public BasePage Q_OBJECT public: - explicit LogPage(std::shared_ptr proc, QWidget *parent = 0); + explicit LogPage(InstancePtr instance, QWidget *parent = 0); virtual ~LogPage(); virtual QString displayName() const override { @@ -77,8 +77,11 @@ private slots: void findNextActivated(); void findPreviousActivated(); + void on_InstanceLaunchTask_changed(std::shared_ptr proc); + private: Ui::LogPage *ui; + InstancePtr m_instance; std::shared_ptr m_process; int m_last_scroll_value = 0; bool m_scroll_active = true; -- cgit v1.2.3