summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2021-01-01 20:59:30 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-02 15:38:19 +0100
commitc0ac46d5c020bfb9292a812b2c52dc3c6236c7b3 (patch)
tree3e41456b3253e34cb483974faf25577ec05cd60b /src
parentbd76c677307bf2106e0823477739680032a897d4 (diff)
Fix create empty mod/separator position.
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp2
-rw-r--r--src/modlistcontextmenu.cpp15
-rw-r--r--src/modlistcontextmenu.h10
-rw-r--r--src/modlistviewactions.cpp25
-rw-r--r--src/modlistviewactions.h6
5 files changed, 32 insertions, 26 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 10de1b84..23050467 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -366,7 +366,7 @@ MainWindow::MainWindow(Settings &settings
m_LinkStartMenu = linkMenu->addAction(QIcon(":/MO/gui/link"), tr("Start Menu"), this, SLOT(linkMenu()));
ui->linkButton->setMenu(linkMenu);
- ui->listOptionsBtn->setMenu(new ModListGlobalContextMenu(m_OrganizerCore, ui->modList, ui->listOptionsBtn));
+ ui->listOptionsBtn->setMenu(new ModListGlobalContextMenu(m_OrganizerCore, ui->modList, this));
ui->openFolderMenu->setMenu(openFolderMenu());
diff --git a/src/modlistcontextmenu.cpp b/src/modlistcontextmenu.cpp
index e557d7a0..f20586c4 100644
--- a/src/modlistcontextmenu.cpp
+++ b/src/modlistcontextmenu.cpp
@@ -10,11 +10,16 @@
using namespace MOBase;
ModListGlobalContextMenu::ModListGlobalContextMenu(OrganizerCore& core, ModListView* view, QWidget* parent)
+ : ModListGlobalContextMenu(core, view, QModelIndex(), parent)
+{
+}
+
+ModListGlobalContextMenu::ModListGlobalContextMenu(OrganizerCore& core, ModListView* view, const QModelIndex& index, QWidget* parent)
: QMenu(parent)
{
addAction(tr("Install Mod..."), [=]() { view->actions().installMod(); });
- addAction(tr("Create empty mod"), [=]() { view->actions().createEmptyMod(-1); });
- addAction(tr("Create Separator"), [=]() { view->actions().createSeparator(-1); });
+ addAction(tr("Create empty mod"), [=]() { view->actions().createEmptyMod(index); });
+ addAction(tr("Create Separator"), [=]() { view->actions().createSeparator(index); });
if (view->hasCollapsibleSeparators()) {
addSeparator();
@@ -24,14 +29,14 @@ ModListGlobalContextMenu::ModListGlobalContextMenu(OrganizerCore& core, ModListV
addSeparator();
- addAction(tr("Enable all visible"), [=]() {
+ addAction(tr("Enable all parent"), [=]() {
if (QMessageBox::question(view, tr("Confirm"), tr("Really enable all visible mods?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
view->enableAllVisible();
}
});
addAction(tr("Disable all visible"), [=]() {
- if (QMessageBox::question(view, tr("Confirm"), tr("Really disable all visible mods?"),
+ if (QMessageBox::question(parent, tr("Confirm"), tr("Really disable all visible mods?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
view->disableAllVisible();
}
@@ -171,7 +176,7 @@ ModListContextMenu::ModListContextMenu(
ModInfo::Ptr info = ModInfo::getByIndex(index.data(ModList::IndexRole).toInt());
- QMenu* allMods = new ModListGlobalContextMenu(core, view, view);
+ QMenu* allMods = new ModListGlobalContextMenu(core, view, m_index, view->topLevelWidget());
allMods->setTitle(tr("All Mods"));
addMenu(allMods);
diff --git a/src/modlistcontextmenu.h b/src/modlistcontextmenu.h
index 565aac97..2b3f9dcd 100644
--- a/src/modlistcontextmenu.h
+++ b/src/modlistcontextmenu.h
@@ -19,8 +19,14 @@ class ModListGlobalContextMenu : public QMenu
Q_OBJECT
public:
- ModListGlobalContextMenu(
- OrganizerCore& core, ModListView* modListView, QWidget* parent = nullptr);
+ ModListGlobalContextMenu(OrganizerCore& core, ModListView* view, QWidget* parent = nullptr);
+
+protected:
+
+ friend class ModListContextMenu;
+
+ // creates a "All mods" context menu for the given index (can be invalid).
+ ModListGlobalContextMenu(OrganizerCore& core, ModListView* view, const QModelIndex& index, QWidget* parent = nullptr);
};
diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp
index cb212e0b..9957618a 100644
--- a/src/modlistviewactions.cpp
+++ b/src/modlistviewactions.cpp
@@ -75,7 +75,7 @@ void ModListViewActions::installMod(const QString& archivePath) const
}
}
-void ModListViewActions::createEmptyMod(int modIndex) const
+void ModListViewActions::createEmptyMod(const QModelIndex& index) const
{
GuessedValue<QString> name;
name.setFilter(&fixDirectoryName);
@@ -97,8 +97,8 @@ void ModListViewActions::createEmptyMod(int modIndex) const
}
int newPriority = -1;
- if (modIndex >= 0 && m_view->sortColumn() == ModList::COL_PRIORITY) {
- newPriority = m_core.currentProfile()->getModPriority(modIndex);
+ if (index.isValid() && m_view->sortColumn() == ModList::COL_PRIORITY) {
+ newPriority = m_core.currentProfile()->getModPriority(index.data(ModList::IndexRole).toInt());
}
IModInterface* newMod = m_core.createMod(name);
@@ -113,12 +113,11 @@ void ModListViewActions::createEmptyMod(int modIndex) const
}
}
-void ModListViewActions::createSeparator(int modIndex) const
+void ModListViewActions::createSeparator(const QModelIndex& index) const
{
GuessedValue<QString> name;
name.setFilter(&fixDirectoryName);
- while (name->isEmpty())
- {
+ while (name->isEmpty()) {
bool ok;
name.update(QInputDialog::getText(m_parent, tr("Create Separator..."),
tr("This will create a new separator.\n"
@@ -126,28 +125,24 @@ void ModListViewActions::createSeparator(int modIndex) const
GUESS_USER);
if (!ok) { return; }
}
- if (m_core.modList()->getMod(name) != nullptr)
- {
+ if (m_core.modList()->getMod(name) != nullptr) {
reportError(tr("A separator with this name already exists"));
return;
}
name->append("_separator");
- if (m_core.modList()->getMod(name) != nullptr)
- {
+ if (m_core.modList()->getMod(name) != nullptr) {
return;
}
int newPriority = -1;
- if (modIndex >= 0 && m_view->sortColumn() == ModList::COL_PRIORITY)
- {
- newPriority = m_core.currentProfile()->getModPriority(modIndex);
+ if (index.isValid() && m_view->sortColumn() == ModList::COL_PRIORITY) {
+ newPriority = m_core.currentProfile()->getModPriority(index.data(ModList::IndexRole).toInt());
}
if (m_core.createMod(name) == nullptr) { return; }
m_core.refresh();
- if (newPriority >= 0)
- {
+ if (newPriority >= 0) {
m_core.modList()->changeModPriority(ModInfo::getIndex(name), newPriority);
}
diff --git a/src/modlistviewactions.h b/src/modlistviewactions.h
index 2850d30a..f1215cec 100644
--- a/src/modlistviewactions.h
+++ b/src/modlistviewactions.h
@@ -36,10 +36,10 @@ public:
void installMod(const QString& archivePath = "") const;
// create an empty mod/a separator before the given mod or at
- // the end of the list if the index is -1
+ // the end of the list if the index is invalid
//
- void createEmptyMod(int modIndex) const;
- void createSeparator(int modIndex) const;
+ void createEmptyMod(const QModelIndex& index = QModelIndex()) const;
+ void createSeparator(const QModelIndex& index = QModelIndex()) const;
// check all mods for update
//