From 5a7bd3db677b037191b7e61e52bad682e0faffb9 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sat, 9 Jan 2021 20:47:38 +0100 Subject: Re-add 'Create empty mod' and 'Create separator' to global mod list context menu. --- src/modlistcontextmenu.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/modlistcontextmenu.cpp') diff --git a/src/modlistcontextmenu.cpp b/src/modlistcontextmenu.cpp index f5307dc7..78949be3 100644 --- a/src/modlistcontextmenu.cpp +++ b/src/modlistcontextmenu.cpp @@ -27,6 +27,10 @@ ModListGlobalContextMenu::ModListGlobalContextMenu(OrganizerCore& core, ModListV addAction(tr("Create Separator"), [=]() { view->actions().createSeparator(index); }); } } + else { + addAction(tr("Create empty mod"), [=]() { view->actions().createEmptyMod(); }); + addAction(tr("Create Separator"), [=]() { view->actions().createSeparator(); }); + } if (view->hasCollapsibleSeparators()) { addSeparator(); -- cgit v1.3.1 From a952f51ef75420426e8ed65e8f78d990c10770b0 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sun, 10 Jan 2021 20:08:48 +0100 Subject: Change 'Create empty mod' depending on the currently selected mod. --- src/modlistcontextmenu.cpp | 9 +++++---- src/modlistview.cpp | 2 +- src/modlistviewactions.cpp | 31 ++++++++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 8 deletions(-) (limited to 'src/modlistcontextmenu.cpp') diff --git a/src/modlistcontextmenu.cpp b/src/modlistcontextmenu.cpp index 78949be3..97eef0eb 100644 --- a/src/modlistcontextmenu.cpp +++ b/src/modlistcontextmenu.cpp @@ -23,13 +23,14 @@ ModListGlobalContextMenu::ModListGlobalContextMenu(OrganizerCore& core, ModListV if (modIndex.isValid()) { auto info = ModInfo::getByIndex(modIndex.toInt()); if (!info->isBackup()) { - addAction(tr("Create empty mod"), [=]() { view->actions().createEmptyMod(index); }); - addAction(tr("Create Separator"), [=]() { view->actions().createSeparator(index); }); + addAction(info->isSeparator() ? tr("Create empty mod inside") : tr("Create empty mod before"), + [=]() { view->actions().createEmptyMod(index); }); + addAction(tr("Create separator before"), [=]() { view->actions().createSeparator(index); }); } } else { - addAction(tr("Create empty mod"), [=]() { view->actions().createEmptyMod(); }); - addAction(tr("Create Separator"), [=]() { view->actions().createSeparator(); }); + addAction(tr("Create empty mod at the end"), [=]() { view->actions().createEmptyMod(); }); + addAction(tr("Create separator at the end"), [=]() { view->actions().createSeparator(); }); } if (view->hasCollapsibleSeparators()) { diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 2fde97f6..5e3e6b58 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -396,7 +396,7 @@ void ModListView::scrollToAndSelect(const QModelIndex& index) scrollTo(index); setCurrentIndex(index); selectionModel()->select(index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); - QTimer::singleShot(0, [=] { setFocus(); }); + QTimer::singleShot(50, [=] { setFocus(); }); } void ModListView::refreshExpandedItems() diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index 9957618a..14c4ab46 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -97,8 +97,30 @@ void ModListViewActions::createEmptyMod(const QModelIndex& index) const } int newPriority = -1; - if (index.isValid() && m_view->sortColumn() == ModList::COL_PRIORITY) { - newPriority = m_core.currentProfile()->getModPriority(index.data(ModList::IndexRole).toInt()); + if (index.isValid() && index.data(ModList::IndexRole).isValid() + && m_view->sortColumn() == ModList::COL_PRIORITY) { + auto mIndex = index.data(ModList::IndexRole).toInt(); + auto info = ModInfo::getByIndex(mIndex); + newPriority = m_core.currentProfile()->getModPriority(mIndex); + if (info->isSeparator()) { + auto& ibp = m_core.currentProfile()->getAllIndexesByPriority(); + + // start right after the current priority and look for the next + // separator + auto it = ibp.find(newPriority + 1); + for (; it != ibp.end(); ++it) { + auto info = ModInfo::getByIndex(it->second); + if (info->isSeparator()) { + newPriority = it->first; + break; + } + } + + // no separator found, create at the end + if (it == ibp.end()) { + newPriority = -1; + } + } } IModInterface* newMod = m_core.createMod(name); @@ -108,9 +130,12 @@ void ModListViewActions::createEmptyMod(const QModelIndex& index) const m_core.refresh(); + const auto mIndex = ModInfo::getIndex(name); if (newPriority >= 0) { - m_core.modList()->changeModPriority(ModInfo::getIndex(name), newPriority); + m_core.modList()->changeModPriority(mIndex, newPriority); } + + m_view->scrollToAndSelect(m_view->indexModelToView(m_core.modList()->index(mIndex, 0))); } void ModListViewActions::createSeparator(const QModelIndex& index) const -- cgit v1.3.1