From 50d18a06d57ce1bb6b8cd77230ff8d79968aebb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 8 Apr 2014 00:16:49 +0200 Subject: [PATCH] Context menu tweaks * Add create/copy instance actions to the context menu. * Context menu for the instance view background. * Top of the context menu is now a header, fixing the misclick problems. --- gui/MainWindow.cpp | 51 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index ce09c42d..19c5c66f 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -353,25 +353,52 @@ void MainWindow::skinJobFinished() void MainWindow::showInstanceContextMenu(const QPoint &pos) { - if (!view->indexAt(pos).isValid()) + QList actions; + + QAction *actionSep = new QAction("", this); + actionSep->setSeparator(true); + + bool onInstance = view->indexAt(pos).isValid(); + if (onInstance) { - return; + actions = ui->instanceToolBar->actions(); + + QAction *actionVoid = new QAction(m_selectedInstance->name(), this); + actionVoid->setEnabled(false); + + QAction *actionRename = new QAction(tr("Rename"), this); + actionRename->setToolTip(ui->actionRenameInstance->toolTip()); + + QAction *actionCopyInstance = new QAction(tr("Copy instance"), this); + actionCopyInstance->setToolTip(ui->actionCopyInstance->toolTip()); + + + connect(actionRename, SIGNAL(triggered(bool)), SLOT(on_actionRenameInstance_triggered())); + connect(actionCopyInstance, SIGNAL(triggered(bool)), SLOT(on_actionCopyInstance_triggered())); + + actions.replace(1, actionRename); + actions.prepend(actionSep); + actions.prepend(actionVoid); + actions.append(actionCopyInstance); } + else + { + QAction *actionVoid = new QAction(tr("MultiMC"), this); + actionVoid->setEnabled(false); - QList actions = ui->instanceToolBar->actions(); + QAction *actionCreateInstance = new QAction(tr("Create instance"), this); + actionCreateInstance->setToolTip(ui->actionAddInstance->toolTip()); - // HACK: Filthy rename button hack because the instance view is getting rewritten anyway - QAction *actionRename; - actionRename = new QAction(tr("Rename"), this); - actionRename->setToolTip(ui->actionRenameInstance->toolTip()); - - connect(actionRename, SIGNAL(triggered(bool)), SLOT(on_actionRenameInstance_triggered())); - - actions.replace(1, actionRename); + connect(actionCreateInstance, SIGNAL(triggered(bool)), SLOT(on_actionAddInstance_triggered())); + actions.prepend(actionSep); + actions.prepend(actionVoid); + actions.append(actionCreateInstance); + } QMenu myMenu; myMenu.addActions(actions); - myMenu.setEnabled(m_selectedInstance->canLaunch()); + if(onInstance) + myMenu.setEnabled(m_selectedInstance->canLaunch()); myMenu.exec(view->mapToGlobal(pos)); }