summaryrefslogtreecommitdiffstats
path: root/application
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
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')
-rw-r--r--application/MainWindow.cpp57
-rw-r--r--application/MainWindow.h2
-rw-r--r--application/dialogs/NewInstanceDialog.cpp7
-rw-r--r--application/dialogs/NewInstanceDialog.h2
-rw-r--r--application/groupview/GroupView.cpp26
-rw-r--r--application/groupview/GroupView.h6
6 files changed, 86 insertions, 14 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();
diff --git a/application/MainWindow.h b/application/MainWindow.h
index 363d163e..e3fb0467 100644
--- a/application/MainWindow.h
+++ b/application/MainWindow.h
@@ -105,6 +105,8 @@ private slots:
void on_actionDeleteInstance_triggered();
+ void on_actionDeleteGroup_triggered();
+
void on_actionExportInstance_triggered();
void on_actionRenameInstance_triggered();
diff --git a/application/dialogs/NewInstanceDialog.cpp b/application/dialogs/NewInstanceDialog.cpp
index 0d54172d..a883d1dc 100644
--- a/application/dialogs/NewInstanceDialog.cpp
+++ b/application/dialogs/NewInstanceDialog.cpp
@@ -55,7 +55,7 @@ public:
}
};
-NewInstanceDialog::NewInstanceDialog(QWidget *parent)
+NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, QWidget *parent)
: QDialog(parent), ui(new Ui::NewInstanceDialog)
{
ui->setupUi(this);
@@ -79,11 +79,10 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent)
auto groupList = QStringList(groups.toList());
groupList.sort(Qt::CaseInsensitive);
groupList.removeOne("");
- QString oldValue = MMC->settings()->get("LastUsedGroupForNewInstance").toString();
- groupList.push_front(oldValue);
+ groupList.push_front(initialGroup);
groupList.push_front("");
ui->groupBox->addItems(groupList);
- int index = groupList.indexOf(oldValue);
+ int index = groupList.indexOf(initialGroup);
if(index == -1)
{
index = 0;
diff --git a/application/dialogs/NewInstanceDialog.h b/application/dialogs/NewInstanceDialog.h
index 1a2be10c..578b2c45 100644
--- a/application/dialogs/NewInstanceDialog.h
+++ b/application/dialogs/NewInstanceDialog.h
@@ -29,7 +29,7 @@ class NewInstanceDialog : public QDialog
Q_OBJECT
public:
- explicit NewInstanceDialog(QWidget *parent = 0);
+ explicit NewInstanceDialog(const QString & initialGroup, QWidget *parent = 0);
~NewInstanceDialog();
void updateDialogState();
diff --git a/application/groupview/GroupView.cpp b/application/groupview/GroupView.cpp
index ab9e71cf..aa85bec7 100644
--- a/application/groupview/GroupView.cpp
+++ b/application/groupview/GroupView.cpp
@@ -188,18 +188,31 @@ VisualGroup *GroupView::category(const QString &cat) const
return nullptr;
}
-VisualGroup *GroupView::categoryAt(const QPoint &pos) const
+VisualGroup *GroupView::categoryAt(const QPoint &pos, VisualGroup::HitResults & result) const
{
for (auto group : m_groups)
{
- if(group->hitScan(pos) & VisualGroup::CheckboxHit)
+ result = group->hitScan(pos);
+ if(result != VisualGroup::NoHit)
{
return group;
}
}
+ result = VisualGroup::NoHit;
return nullptr;
}
+QString GroupView::groupNameAt(const QPoint &point)
+{
+ VisualGroup::HitResults hitresult;
+ auto group = categoryAt(point + offset(), hitresult);
+ if(group && (hitresult & (VisualGroup::HeaderHit | VisualGroup::BodyHit)))
+ {
+ return group->text;
+ }
+ return QString();
+}
+
int GroupView::calculateItemsPerRow() const
{
return qFloor((qreal)(contentWidth()) / (qreal)(itemWidth() + m_spacing));
@@ -228,8 +241,9 @@ void GroupView::mousePressEvent(QMouseEvent *event)
m_pressedAlreadySelected = selectionModel()->isSelected(m_pressedIndex);
m_pressedPosition = geometryPos;
- m_pressedCategory = categoryAt(geometryPos);
- if (m_pressedCategory)
+ VisualGroup::HitResults hitresult;
+ m_pressedCategory = categoryAt(geometryPos, hitresult);
+ if (m_pressedCategory && hitresult & VisualGroup::CheckboxHit)
{
setState(m_pressedCategory->collapsed ? ExpandingState : CollapsingState);
event->accept();
@@ -325,8 +339,10 @@ void GroupView::mouseReleaseEvent(QMouseEvent *event)
QPoint geometryPos = event->pos() + offset();
QPersistentModelIndex index = indexAt(visualPos);
+ VisualGroup::HitResults hitresult;
+
bool click = (index == m_pressedIndex && index.isValid()) ||
- (m_pressedCategory && m_pressedCategory == categoryAt(geometryPos));
+ (m_pressedCategory && m_pressedCategory == categoryAt(geometryPos, hitresult));
if (click && m_pressedCategory)
{
diff --git a/application/groupview/GroupView.h b/application/groupview/GroupView.h
index b97d3a3c..a3863b6d 100644
--- a/application/groupview/GroupView.h
+++ b/application/groupview/GroupView.h
@@ -4,6 +4,7 @@
#include <QLineEdit>
#include <QScrollBar>
#include <QCache>
+#include "VisualGroup.h"
struct GroupViewRoles
{
@@ -15,8 +16,6 @@ struct GroupViewRoles
};
};
-struct VisualGroup;
-
class GroupView : public QAbstractItemView
{
Q_OBJECT
@@ -33,6 +32,7 @@ public:
virtual QRect visualRect(const QModelIndex &index) const override;
/// get the model index at the specified visual point
virtual QModelIndex indexAt(const QPoint &point) const override;
+ QString groupNameAt(const QPoint &point);
void setSelection(const QRect &rect,
const QItemSelectionModel::SelectionFlags commands) override;
@@ -102,7 +102,7 @@ private:
VisualGroup *category(const QModelIndex &index) const;
VisualGroup *category(const QString &cat) const;
- VisualGroup *categoryAt(const QPoint &pos) const;
+ VisualGroup *categoryAt(const QPoint &pos, VisualGroup::HitResults & result) const;
int itemsPerRow() const
{