summaryrefslogtreecommitdiffstats
path: root/application/MainWindow.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-04-11 01:30:50 +0200
committerPetr Mrázek <peterix@gmail.com>2016-04-11 01:30:50 +0200
commit432ec7417499c6fa6b0c2935c96ad5f3d1d097c1 (patch)
treeff18776574ceb0023bfa373dddc4601252776b72 /application/MainWindow.cpp
parentb795ad52099562a90b961e2e294daf6a3dc00883 (diff)
downloadMultiMC-432ec7417499c6fa6b0c2935c96ad5f3d1d097c1.tar
MultiMC-432ec7417499c6fa6b0c2935c96ad5f3d1d097c1.tar.gz
MultiMC-432ec7417499c6fa6b0c2935c96ad5f3d1d097c1.tar.lz
MultiMC-432ec7417499c6fa6b0c2935c96ad5f3d1d097c1.tar.xz
MultiMC-432ec7417499c6fa6b0c2935c96ad5f3d1d097c1.zip
GH-1404 allow deleting groups and creating instances in groups directly using context menu
Diffstat (limited to 'application/MainWindow.cpp')
-rw-r--r--application/MainWindow.cpp57
1 files changed, 56 insertions, 1 deletions
diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp
index ef758fae..f059b275 100644
--- a/application/MainWindow.cpp
+++ b/application/MainWindow.cpp
@@ -638,17 +638,34 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
}
else
{
+ auto group = view->groupNameAt(pos);
+
QAction *actionVoid = new QAction("MultiMC", this);
actionVoid->setEnabled(false);
QAction *actionCreateInstance = new QAction(tr("Create instance"), this);
actionCreateInstance->setToolTip(ui->actionAddInstance->toolTip());
+ if(!group.isNull())
+ {
+ QVariantMap data;
+ data["group"] = group;
+ actionCreateInstance->setData(data);
+ }
connect(actionCreateInstance, SIGNAL(triggered(bool)), SLOT(on_actionAddInstance_triggered()));
actions.prepend(actionSep);
actions.prepend(actionVoid);
actions.append(actionCreateInstance);
+ if(!group.isNull())
+ {
+ QAction *actionDeleteGroup = new QAction(tr("Delete group '%1'").arg(group), this);
+ QVariantMap data;
+ data["group"] = group;
+ actionDeleteGroup->setData(data);
+ connect(actionDeleteGroup, SIGNAL(triggered(bool)), SLOT(on_actionDeleteGroup_triggered()));
+ actions.append(actionDeleteGroup);
+ }
}
QMenu myMenu;
myMenu.addActions(actions);
@@ -1181,9 +1198,29 @@ void MainWindow::finalizeInstance(InstancePtr inst)
void MainWindow::on_actionAddInstance_triggered()
{
+ QString groupName;
+ do
+ {
+ QObject* obj = sender();
+ if(!obj)
+ break;
+ QAction *action = qobject_cast<QAction *>(obj);
+ if(!action)
+ break;
+ auto map = action->data().toMap();
+ if(!map.contains("group"))
+ break;
+ groupName = map["group"].toString();
+ } while(0);
+
waitForMinecraftVersions();
- NewInstanceDialog newInstDlg(this);
+ if(groupName.isEmpty())
+ {
+ groupName = MMC->settings()->get("LastUsedGroupForNewInstance").toString();
+ }
+
+ NewInstanceDialog newInstDlg(groupName, this);
if (!newInstDlg.exec())
return;
@@ -1320,6 +1357,24 @@ void MainWindow::on_actionChangeInstGroup_triggered()
m_selectedInstance->setGroupPost(name);
}
+void MainWindow::on_actionDeleteGroup_triggered()
+{
+ QObject* obj = sender();
+ if(!obj)
+ return;
+ QAction *action = qobject_cast<QAction *>(obj);
+ if(!action)
+ return;
+ auto map = action->data().toMap();
+ if(!map.contains("group"))
+ return;
+ QString groupName = map["group"].toString();
+ if(!groupName.isEmpty())
+ {
+ MMC->instances()->deleteGroup(groupName);
+ }
+}
+
void MainWindow::on_actionViewInstanceFolder_triggered()
{
QString str = MMC->settings()->get("InstanceDir").toString();