From 1b4c07eb20a8951ac72accf8ead302d65c8a2de5 Mon Sep 17 00:00:00 2001 From: TheBloke Date: Fri, 11 Jul 2014 01:46:42 +0100 Subject: - savegameList: Improved save game handling from MainWindow -- Save game deletion now does Recycle Bin delete (wishlist #675) -- Save game deletion now also deletes .skse file (bug #687) -- Can select and delete multiple save games (ExtendedSelection) (wishlist #675) -- Uses new SaveGame->saveFiles() method to get filenames (eg .ess & .skse) -- Context menu - "Fix Mods.." option only appears if 1 save is selected -- Context menu - delete menu option labelled "Delete save" or "Delete saves", according to 1 or >1 saves selected. -- Context menu - delete menu confirmation shows list of all selected saves --- src/mainwindow.cpp | 58 ++++++++++++++++++++++++++++++++++++++---------------- src/mainwindow.h | 2 +- src/mainwindow.ui | 6 ++++++ 3 files changed, 48 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9cbe9c40..344173d4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3884,26 +3884,42 @@ void MainWindow::on_categoriesList_itemSelectionChanged() void MainWindow::deleteSavegame_clicked() { - QListWidgetItem *selectedItem = ui->savegameList->item(m_SelectedSaveGame); - if (selectedItem == NULL) { + QItemSelectionModel *selection = ui->savegameList->selectionModel(); + + if (!selection->hasSelection()) return; - } - QString fileName = selectedItem->data(Qt::UserRole).toString(); + int selectedCount = selection->selectedRows().count(); + QString savesMsgLabel; + QRegExp saveSuffix(".ess$"); + QStringList deleteFiles; + + foreach (QModelIndex idx, selection->selectedRows()) { + QString name = idx.data().toString(); + QString filename = idx.data(Qt::UserRole).toString(); + + SaveGame *save = new SaveGame(this, filename); + savesMsgLabel += "
  • " + name.replace(saveSuffix, "") + "
  • "; + deleteFiles << save->saveFiles(); + } - if (QMessageBox::question(this, tr("Confirm"), tr("Really delete \"%1\"?").arg(selectedItem->text()), + if (QMessageBox::question(this, tr("Confirm"), tr("Are you sure you want to remove the following save%1?

    Removed saves will be sent to the Recycle Bin.") + .arg((selectedCount > 1) ? "s" : "") + .arg(savesMsgLabel), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { - shellDelete(QStringList() << fileName); + shellDelete(deleteFiles, true); // recycle bin delete. } } void MainWindow::fixMods_clicked() { - QListWidgetItem *selectedItem = ui->savegameList->item(m_SelectedSaveGame); - if (selectedItem == NULL) { - return; - } + QItemSelectionModel *selection = ui->savegameList->selectionModel(); + + if (!selection->hasSelection() || selection->selectedRows().count() > 1) + return; // Count should never be > 1 because of condition on context menu; check again just for safety. + + QListWidgetItem *selectedItem = ui->savegameList->item(selection->selectedRows().first().row()); // if required, parse the save game if (selectedItem->data(Qt::UserRole).isNull()) { @@ -3994,16 +4010,24 @@ void MainWindow::fixMods_clicked() void MainWindow::on_savegameList_customContextMenuRequested(const QPoint &pos) { - QListWidgetItem *selectedItem = ui->savegameList->itemAt(pos); - if (selectedItem == NULL) { - return; - } + QItemSelection currentSelection = ui->savegameList->selectionModel()->selection(); + + bool enableFixMods = false; + int selectedCount = currentSelection.count(); - m_SelectedSaveGame = ui->savegameList->row(selectedItem); + if ( selectedCount == 0) { + return; + } else if (currentSelection.count() == 1) + enableFixMods = true; QMenu menu; - menu.addAction(tr("Fix Mods..."), this, SLOT(fixMods_clicked())); - menu.addAction(tr("Delete"), this, SLOT(deleteSavegame_clicked())); + + if (enableFixMods) + menu.addAction(tr("Fix Mods..."), this, SLOT(fixMods_clicked())); + + QString deleteMenuLabel = tr("Delete save%1").arg((selectedCount > 1) ? "s" : ""); + + menu.addAction(deleteMenuLabel, this, SLOT(deleteSavegame_clicked())); menu.exec(ui->savegameList->mapToGlobal(pos)); } diff --git a/src/mainwindow.h b/src/mainwindow.h index cc144287..c1cfdb3c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -335,7 +335,7 @@ private: QTreeWidgetItem *m_ContextItem; QAction *m_ContextAction; - int m_SelectedSaveGame; + //int m_SelectedSaveGame; Settings m_Settings; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 1a45e21b..4201babf 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1100,6 +1100,12 @@ p, li { white-space: pre-wrap; } <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">If you click &quot;Fix Mods...&quot; in the context menu, MO will try to activate all mods and esps to fix those missing esps. It will not disable anything!</span></p></body></html> + + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::SelectRows + -- cgit v1.3.1