Merge branch 'PolyMC:develop' into account-list

This commit is contained in:
Gingeh 2022-07-01 10:43:41 +10:00 committed by GitHub
commit dbb63b97bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 55 deletions

View File

@ -224,6 +224,7 @@ public:
TranslatedAction actionMoreNews; TranslatedAction actionMoreNews;
TranslatedAction actionManageAccounts; TranslatedAction actionManageAccounts;
TranslatedAction actionLaunchInstance; TranslatedAction actionLaunchInstance;
TranslatedAction actionKillInstance;
TranslatedAction actionRenameInstance; TranslatedAction actionRenameInstance;
TranslatedAction actionChangeInstGroup; TranslatedAction actionChangeInstGroup;
TranslatedAction actionChangeInstIcon; TranslatedAction actionChangeInstIcon;
@ -282,27 +283,6 @@ public:
TranslatedToolbar instanceToolBar; TranslatedToolbar instanceToolBar;
TranslatedToolbar newsToolBar; TranslatedToolbar newsToolBar;
QVector<TranslatedToolbar *> all_toolbars; QVector<TranslatedToolbar *> all_toolbars;
bool m_kill = false;
void updateLaunchAction()
{
if(m_kill)
{
actionLaunchInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&Kill"));
actionLaunchInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Kill the running instance"));
}
else
{
actionLaunchInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&Launch"));
actionLaunchInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Launch the selected instance."));
}
actionLaunchInstance.retranslate();
}
void setLaunchAction(bool kill)
{
m_kill = kill;
updateLaunchAction();
}
void createMainToolbarActions(QMainWindow *MainWindow) void createMainToolbarActions(QMainWindow *MainWindow)
{ {
@ -508,6 +488,7 @@ public:
fileMenu->addAction(actionAddInstance); fileMenu->addAction(actionAddInstance);
fileMenu->addAction(actionLaunchInstance); fileMenu->addAction(actionLaunchInstance);
fileMenu->addAction(actionLaunchInstanceOffline); fileMenu->addAction(actionLaunchInstanceOffline);
fileMenu->addAction(actionKillInstance);
fileMenu->addAction(actionCloseWindow); fileMenu->addAction(actionCloseWindow);
fileMenu->addSeparator(); fileMenu->addSeparator();
fileMenu->addAction(actionEditInstance); fileMenu->addAction(actionEditInstance);
@ -585,10 +566,9 @@ public:
} }
// "Instance actions" are actions that require an instance to be selected (i.e. "new instance" is not here) // "Instance actions" are actions that require an instance to be selected (i.e. "new instance" is not here)
// Actions that also require other conditions (e.g. a running instance) won't be changed.
void setInstanceActionsEnabled(bool enabled) void setInstanceActionsEnabled(bool enabled)
{ {
actionLaunchInstance->setEnabled(enabled);
actionLaunchInstanceOffline->setEnabled(enabled);
actionEditInstance->setEnabled(enabled); actionEditInstance->setEnabled(enabled);
actionEditInstNotes->setEnabled(enabled); actionEditInstNotes->setEnabled(enabled);
actionMods->setEnabled(enabled); actionMods->setEnabled(enabled);
@ -675,6 +655,14 @@ public:
actionLaunchInstanceOffline.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Launch the selected instance in offline mode.")); actionLaunchInstanceOffline.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Launch the selected instance in offline mode."));
all_actions.append(&actionLaunchInstanceOffline); all_actions.append(&actionLaunchInstanceOffline);
actionKillInstance = TranslatedAction(MainWindow);
actionKillInstance->setObjectName(QStringLiteral("actionKillInstance"));
actionKillInstance->setDisabled(true);
actionKillInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "&Kill"));
actionKillInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Kill the running instance"));
actionKillInstance->setShortcut(QKeySequence(tr("Ctrl+K")));
all_actions.append(&actionKillInstance);
actionEditInstance = TranslatedAction(MainWindow); actionEditInstance = TranslatedAction(MainWindow);
actionEditInstance->setObjectName(QStringLiteral("actionEditInstance")); actionEditInstance->setObjectName(QStringLiteral("actionEditInstance"));
actionEditInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Edit Inst&ance...")); actionEditInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Edit Inst&ance..."));
@ -790,6 +778,7 @@ public:
instanceToolBar->addAction(actionLaunchInstance); instanceToolBar->addAction(actionLaunchInstance);
instanceToolBar->addAction(actionLaunchInstanceOffline); instanceToolBar->addAction(actionLaunchInstanceOffline);
instanceToolBar->addAction(actionKillInstance);
instanceToolBar->addSeparator(); instanceToolBar->addSeparator();
@ -1187,14 +1176,10 @@ void MainWindow::updateToolsMenu()
QToolButton *launchButton = dynamic_cast<QToolButton*>(ui->instanceToolBar->widgetForAction(ui->actionLaunchInstance)); QToolButton *launchButton = dynamic_cast<QToolButton*>(ui->instanceToolBar->widgetForAction(ui->actionLaunchInstance));
QToolButton *launchOfflineButton = dynamic_cast<QToolButton*>(ui->instanceToolBar->widgetForAction(ui->actionLaunchInstanceOffline)); QToolButton *launchOfflineButton = dynamic_cast<QToolButton*>(ui->instanceToolBar->widgetForAction(ui->actionLaunchInstanceOffline));
if(m_selectedInstance && m_selectedInstance->isRunning()) bool currentInstanceRunning = m_selectedInstance && m_selectedInstance->isRunning();
{
ui->actionLaunchInstance->setMenu(nullptr); ui->actionLaunchInstance->setDisabled(!m_selectedInstance || currentInstanceRunning);
ui->actionLaunchInstanceOffline->setMenu(nullptr); ui->actionLaunchInstanceOffline->setDisabled(!m_selectedInstance || currentInstanceRunning);
launchButton->setPopupMode(QToolButton::InstantPopup);
launchOfflineButton->setPopupMode(QToolButton::InstantPopup);
return;
}
QMenu *launchMenu = ui->actionLaunchInstance->menu(); QMenu *launchMenu = ui->actionLaunchInstance->menu();
QMenu *launchOfflineMenu = ui->actionLaunchInstanceOffline->menu(); QMenu *launchOfflineMenu = ui->actionLaunchInstanceOffline->menu();
@ -1222,6 +1207,9 @@ void MainWindow::updateToolsMenu()
normalLaunchOffline->setShortcut(QKeySequence(tr("Ctrl+Shift+O"))); normalLaunchOffline->setShortcut(QKeySequence(tr("Ctrl+Shift+O")));
if (m_selectedInstance) if (m_selectedInstance)
{ {
normalLaunch->setEnabled(m_selectedInstance->canLaunch());
normalLaunchOffline->setEnabled(m_selectedInstance->canLaunch());
connect(normalLaunch, &QAction::triggered, [this]() { connect(normalLaunch, &QAction::triggered, [this]() {
APPLICATION->launch(m_selectedInstance, true); APPLICATION->launch(m_selectedInstance, true);
}); });
@ -1252,6 +1240,9 @@ void MainWindow::updateToolsMenu()
} }
else if (m_selectedInstance) else if (m_selectedInstance)
{ {
profilerAction->setEnabled(m_selectedInstance->canLaunch());
profilerOfflineAction->setEnabled(m_selectedInstance->canLaunch());
connect(profilerAction, &QAction::triggered, [this, profiler]() connect(profilerAction, &QAction::triggered, [this, profiler]()
{ {
APPLICATION->launch(m_selectedInstance, true, profiler.get()); APPLICATION->launch(m_selectedInstance, true, profiler.get());
@ -2084,15 +2075,7 @@ void MainWindow::instanceActivated(QModelIndex index)
void MainWindow::on_actionLaunchInstance_triggered() void MainWindow::on_actionLaunchInstance_triggered()
{ {
if (!m_selectedInstance) if(m_selectedInstance && !m_selectedInstance->isRunning())
{
return;
}
if(m_selectedInstance->isRunning())
{
APPLICATION->kill(m_selectedInstance);
}
else
{ {
APPLICATION->launch(m_selectedInstance); APPLICATION->launch(m_selectedInstance);
} }
@ -2111,6 +2094,14 @@ void MainWindow::on_actionLaunchInstanceOffline_triggered()
} }
} }
void MainWindow::on_actionKillInstance_triggered()
{
if(m_selectedInstance && m_selectedInstance->isRunning())
{
APPLICATION->kill(m_selectedInstance);
}
}
void MainWindow::taskEnd() void MainWindow::taskEnd()
{ {
QObject *sender = QObject::sender(); QObject *sender = QObject::sender();
@ -2144,17 +2135,9 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
{ {
ui->instanceToolBar->setEnabled(true); ui->instanceToolBar->setEnabled(true);
ui->setInstanceActionsEnabled(true); ui->setInstanceActionsEnabled(true);
if(m_selectedInstance->isRunning()) ui->actionLaunchInstance->setEnabled(m_selectedInstance->canLaunch());
{
ui->actionLaunchInstance->setEnabled(true);
ui->setLaunchAction(true);
}
else
{
ui->actionLaunchInstance->setEnabled(m_selectedInstance->canLaunch());
ui->setLaunchAction(false);
}
ui->actionLaunchInstanceOffline->setEnabled(m_selectedInstance->canLaunch()); ui->actionLaunchInstanceOffline->setEnabled(m_selectedInstance->canLaunch());
ui->actionKillInstance->setEnabled(m_selectedInstance->isRunning());
ui->actionExportInstance->setEnabled(m_selectedInstance->canExport()); ui->actionExportInstance->setEnabled(m_selectedInstance->canExport());
ui->renameButton->setText(m_selectedInstance->name()); ui->renameButton->setText(m_selectedInstance->name());
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription()); m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
@ -2171,6 +2154,9 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
{ {
ui->instanceToolBar->setEnabled(false); ui->instanceToolBar->setEnabled(false);
ui->setInstanceActionsEnabled(false); ui->setInstanceActionsEnabled(false);
ui->actionLaunchInstance->setEnabled(false);
ui->actionLaunchInstanceOffline->setEnabled(false);
ui->actionKillInstance->setEnabled(false);
APPLICATION->settings()->set("SelectedInstance", QString()); APPLICATION->settings()->set("SelectedInstance", QString());
selectionBad(); selectionBad();
return; return;
@ -2200,6 +2186,7 @@ void MainWindow::selectionBad()
statusBar()->clearMessage(); statusBar()->clearMessage();
ui->instanceToolBar->setEnabled(false); ui->instanceToolBar->setEnabled(false);
ui->setInstanceActionsEnabled(false); ui->setInstanceActionsEnabled(false);
updateToolsMenu();
ui->renameButton->setText(tr("Rename Instance")); ui->renameButton->setText(tr("Rename Instance"));
updateInstanceToolIcon("grass"); updateInstanceToolIcon("grass");

View File

@ -148,6 +148,8 @@ private slots:
void on_actionLaunchInstanceOffline_triggered(); void on_actionLaunchInstanceOffline_triggered();
void on_actionKillInstance_triggered();
void on_actionDeleteInstance_triggered(); void on_actionDeleteInstance_triggered();
void deleteGroup(); void deleteGroup();

View File

@ -160,15 +160,15 @@ static auto sortFromIndex(int index) -> QString
{ {
switch(index){ switch(index){
default: default:
case 1: case 0:
return "relevance"; return "relevance";
case 2: case 1:
return "downloads"; return "downloads";
case 3: case 2:
return "follows"; return "follows";
case 4: case 3:
return "newest"; return "newest";
case 5: case 4:
return "updated"; return "updated";
} }