From c0b55690bc47102459ef7b1720d69945d6523d08 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Sun, 2 Dec 2018 20:26:26 -0600 Subject: Add "send to separator..." option for mods --- src/CMakeLists.txt | 3 ++ src/listdialog.cpp | 46 ++++++++++++++++++++++++++ src/listdialog.h | 25 ++++++++++++++ src/listdialog.ui | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/mainwindow.cpp | 57 +++++++++++++++++++++++++++++--- src/mainwindow.h | 1 + src/organizer.pro | 9 +++-- 7 files changed, 230 insertions(+), 7 deletions(-) create mode 100644 src/listdialog.cpp create mode 100644 src/listdialog.h create mode 100644 src/listdialog.ui (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 372b9519..3f004ddc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -91,6 +91,7 @@ SET(organizer_SRCS usvfsconnector.cpp eventfilter.cpp moshortcut.cpp + listdialog.cpp shared/windows_error.cpp shared/error_report.cpp @@ -185,6 +186,7 @@ SET(organizer_HDRS eventfilter.h descriptionpage.h moshortcut.h + listdialog.h shared/windows_error.h shared/error_report.h @@ -225,6 +227,7 @@ SET(organizer_UIS previewdialog.ui browserdialog.ui aboutdialog.ui + listdialog.ui ) SET(organizer_QRCS diff --git a/src/listdialog.cpp b/src/listdialog.cpp new file mode 100644 index 00000000..4acfa5de --- /dev/null +++ b/src/listdialog.cpp @@ -0,0 +1,46 @@ +/* +This file is part of Mod Organizer. + +Mod Organizer is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Mod Organizer is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Mod Organizer. If not, see . +*/ + +#include "listdialog.h" +#include "ui_listdialog.h" + +ListDialog::ListDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::ListDialog) +{ + ui->setupUi(this); +} + +ListDialog::~ListDialog() +{ + delete ui; +} + +void ListDialog::setChoices(QStringList choices) +{ + ui->listWidget->clear(); + ui->listWidget->addItems(choices); +} + +QString ListDialog::getChoice() const +{ + if (ui->listWidget->selectedItems().length()) { + return ui->listWidget->currentItem()->text(); + } else { + return ""; + } +} diff --git a/src/listdialog.h b/src/listdialog.h new file mode 100644 index 00000000..5e826a30 --- /dev/null +++ b/src/listdialog.h @@ -0,0 +1,25 @@ +#ifndef LISTDIALOG_H +#define LISTDIALOG_H + +#include + +namespace Ui { +class ListDialog; +} + +class ListDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ListDialog(QWidget *parent = nullptr); + ~ListDialog(); + + void setChoices(QStringList choices); + QString getChoice() const; + +private: + Ui::ListDialog *ui; +}; + +#endif // LISTDIALOG_H diff --git a/src/listdialog.ui b/src/listdialog.ui new file mode 100644 index 00000000..38819c87 --- /dev/null +++ b/src/listdialog.ui @@ -0,0 +1,96 @@ + + + ListDialog + + + + 0 + 0 + 260 + 340 + + + + Dialog + + + + + 90 + 299 + 161 + 32 + + + + Qt::LeftToRight + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 10 + 10 + 240 + 280 + + + + + 0 + 0 + + + + + 240 + 280 + + + + QAbstractItemView::ScrollPerPixel + + + + + + + buttonBox + accepted() + ListDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ListDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 704ce838..44fc0bf3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -85,6 +85,7 @@ along with Mod Organizer. If not, see . #include #include #include "localsavegames.h" +#include "listdialog.h" #include #include @@ -1149,7 +1150,7 @@ void MainWindow::on_profileBox_currentIndexChanged(int index) void MainWindow::updateTo(QTreeWidgetItem *subTree, const std::wstring &directorySoFar, const DirectoryEntry &directoryEntry, bool conflictsOnly) { bool isDirectory = false; - { + { for (const FileEntry::Ptr current : directoryEntry.getFiles()) { if (conflictsOnly && (current->getAlternatives().size() == 0)) { continue; @@ -3721,6 +3722,7 @@ void MainWindow::addModSendToContextMenu(QMenu *menu) sub_menu->addAction(tr("Top"), this, SLOT(sendSelectedModsToTop_clicked())); sub_menu->addAction(tr("Bottom"), this, SLOT(sendSelectedModsToBottom_clicked())); sub_menu->addAction(tr("Priority..."), this, SLOT(sendSelectedModsToPriority_clicked())); + sub_menu->addAction(tr("Separator..."), this, SLOT(sendSelectedModsToSeparator_clicked())); menu->addMenu(sub_menu); menu->addSeparator(); @@ -4574,7 +4576,7 @@ void MainWindow::on_dataTree_customContextMenuRequested(const QPoint &pos) m_ContextItem = dataTree->itemAt(pos.x(), pos.y()); QMenu menu; - if ((m_ContextItem != nullptr) && (m_ContextItem->childCount() == 0) + if ((m_ContextItem != nullptr) && (m_ContextItem->childCount() == 0) && (m_ContextItem->data(0, Qt::UserRole + 3).toBool() != true)) { menu.addAction(tr("Open/Execute"), this, SLOT(openDataFile())); menu.addAction(tr("Add as Executable"), this, SLOT(addAsExecutable())); @@ -5673,8 +5675,8 @@ void MainWindow::sendSelectedModsToPriority(int newPriority) QItemSelectionModel *selection = ui->modList->selectionModel(); if (selection->hasSelection() && selection->selectedRows().count() > 1) { std::vector modsToMove; - for (QModelIndex idx : selection->selectedRows()) { - modsToMove.push_back(idx.data().toInt()); + for (auto idx : selection->selectedRows(ModList::COL_PRIORITY)) { + modsToMove.push_back(m_OrganizerCore.currentProfile()->modIndexByPriority(idx.data().toInt())); } m_OrganizerCore.modList()->changeModPriority(modsToMove, newPriority); } else { @@ -5702,3 +5704,50 @@ void MainWindow::sendSelectedModsToPriority_clicked() sendSelectedModsToPriority(newPriority); } + +void MainWindow::sendSelectedModsToSeparator_clicked() +{ + QStringList separators; + for (auto mod : m_OrganizerCore.modList()->allMods()) { + ModInfo::Ptr modInfo = ModInfo::getByIndex(ModInfo::getIndex(mod)); + if (modInfo->hasFlag(ModInfo::FLAG_SEPARATOR)) { + separators << mod.chopped(10); + } + } + + ListDialog dialog(this); + dialog.setChoices(separators); + if (dialog.exec() == QDialog::Accepted) { + QString result = dialog.getChoice(); + if (!result.isEmpty()) { + result += "_separator"; + + int newPriority = INT_MAX; + bool foundSection = false; + for (auto mod : m_OrganizerCore.modsSortedByProfilePriority()) { + unsigned int modIndex = ModInfo::getIndex(mod); + ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex); + if (!foundSection && result.compare(mod) == 0) { + foundSection = true; + } else if (foundSection && modInfo->hasFlag(ModInfo::FLAG_SEPARATOR)) { + newPriority = m_OrganizerCore.currentProfile()->getModPriority(modIndex); + break; + } + } + + QItemSelectionModel *selection = ui->modList->selectionModel(); + if (selection->hasSelection() && selection->selectedRows().count() > 1) { + std::vector modsToMove; + for (QModelIndex idx : selection->selectedRows(ModList::COL_PRIORITY)) { + modsToMove.push_back(m_OrganizerCore.currentProfile()->modIndexByPriority(idx.data().toInt())); + } + m_OrganizerCore.modList()->changeModPriority(modsToMove, newPriority); + } else { + int oldPriority = m_OrganizerCore.currentProfile()->getModPriority(m_ContextRow); + if (oldPriority < newPriority) + --newPriority; + m_OrganizerCore.modList()->changeModPriority(m_ContextRow, newPriority); + } + } + } +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 06219a5a..62ffe3de 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -431,6 +431,7 @@ private slots: void sendSelectedModsToTop_clicked(); void sendSelectedModsToBottom_clicked(); void sendSelectedModsToPriority_clicked(); + void sendSelectedModsToSeparator_clicked(); // savegame context menu void deleteSavegame_clicked(); void fixMods_clicked(SaveGameInfo::MissingAssets const &missingAssets); diff --git a/src/organizer.pro b/src/organizer.pro index 0ef2638b..582fde9f 100644 --- a/src/organizer.pro +++ b/src/organizer.pro @@ -91,7 +91,8 @@ SOURCES += \ modinforegular.cpp \ modinfobackup.cpp \ modinfooverwrite.cpp \ - modinfoforeign.cpp + modinfoforeign.cpp \ + listdialog.cpp HEADERS += \ @@ -167,7 +168,8 @@ HEADERS += \ modinforegular.h \ modinfobackup.h \ modinfooverwrite.h \ - modinfoforeign.h + modinfoforeign.h \ + listdialog.h FORMS += \ transfersavesdialog.ui \ @@ -196,7 +198,8 @@ FORMS += \ problemsdialog.ui \ previewdialog.ui \ browserdialog.ui \ - aboutdialog.ui + aboutdialog.ui \ + listdialog.ui RESOURCES += \ resources.qrc \ -- cgit v1.3.1