summaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
authorTheBloke <devnull@localhost>2014-07-11 01:46:42 +0100
committerTheBloke <devnull@localhost>2014-07-11 01:46:42 +0100
commit1b4c07eb20a8951ac72accf8ead302d65c8a2de5 (patch)
tree343a0dc12aa563eaa5a0788b081f6ddd26979479 /src/mainwindow.cpp
parentd93df95dcfcaf0170f7fb273e9955ef6070fbaa5 (diff)
- 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
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp58
1 files changed, 41 insertions, 17 deletions
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 += "<li>" + name.replace(saveSuffix, "") + "</li>";
+ 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?<br><ul>%2</ul><br>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));
}