diff --git a/cockatrice/cockatrice.qrc b/cockatrice/cockatrice.qrc
index 7b42f69ca..970c25fc9 100644
--- a/cockatrice/cockatrice.qrc
+++ b/cockatrice/cockatrice.qrc
@@ -27,6 +27,7 @@
resources/icons/ready_start.svg
resources/icons/reload.svg
resources/icons/remove_row.svg
+ resources/icons/rename.svg
resources/icons/scales.svg
resources/icons/search.svg
resources/icons/settings.svg
diff --git a/cockatrice/resources/icons/rename.svg b/cockatrice/resources/icons/rename.svg
new file mode 100644
index 000000000..c68a00246
--- /dev/null
+++ b/cockatrice/resources/icons/rename.svg
@@ -0,0 +1,10 @@
+
+
diff --git a/cockatrice/src/client/tabs/tab_deck_storage.cpp b/cockatrice/src/client/tabs/tab_deck_storage.cpp
index 9d35819fc..5fa25be4f 100644
--- a/cockatrice/src/client/tabs/tab_deck_storage.cpp
+++ b/cockatrice/src/client/tabs/tab_deck_storage.cpp
@@ -106,6 +106,9 @@ TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor,
aOpenLocalDeck = new QAction(this);
aOpenLocalDeck->setIcon(QPixmap("theme:icons/pencil"));
connect(aOpenLocalDeck, SIGNAL(triggered()), this, SLOT(actOpenLocalDeck()));
+ aRenameLocal = new QAction(this);
+ aRenameLocal->setIcon(QPixmap("theme:icons/rename"));
+ connect(aRenameLocal, &QAction::triggered, this, &TabDeckStorage::actRenameLocal);
aUpload = new QAction(this);
aUpload->setIcon(QPixmap("theme:icons/arrow_right_green"));
connect(aUpload, SIGNAL(triggered()), this, SLOT(actUpload()));
@@ -136,6 +139,7 @@ TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor,
// Add actions to toolbars
leftToolBar->addAction(aOpenLocalDeck);
+ leftToolBar->addAction(aRenameLocal);
leftToolBar->addAction(aUpload);
leftToolBar->addAction(aNewLocalFolder);
leftToolBar->addAction(aDeleteLocalDeck);
@@ -164,6 +168,7 @@ void TabDeckStorage::retranslateUi()
rightGroupBox->setTitle(tr("Server deck storage"));
aOpenLocalDeck->setText(tr("Open in deck editor"));
+ aRenameLocal->setText(tr("Rename deck or folder"));
aUpload->setText(tr("Upload deck"));
aOpenRemoteDeck->setText(tr("Open in deck editor"));
aDownload->setText(tr("Download deck"));
@@ -247,6 +252,36 @@ void TabDeckStorage::actOpenLocalDeck()
}
}
+void TabDeckStorage::actRenameLocal()
+{
+ QModelIndexList curLefts = localDirView->selectionModel()->selectedRows();
+ for (const auto &curLeft : curLefts) {
+ const QFileInfo info = localDirModel->fileInfo(curLeft);
+
+ const QString oldName = info.baseName();
+ const QString title = info.isDir() ? tr("Rename local folder") : tr("Rename local file");
+
+ bool ok;
+ QString newName = QInputDialog::getText(this, title, tr("New name:"), QLineEdit::Normal, oldName, &ok);
+ if (!ok) { // terminate all remaining selections if user cancels
+ return;
+ }
+ if (newName.isEmpty() || oldName == newName) {
+ continue;
+ }
+
+ QString newFileName = newName;
+ if (!info.suffix().isEmpty()) {
+ newFileName += "." + info.suffix();
+ }
+ const QString newFilePath = QFileInfo(info.dir(), newFileName).filePath();
+
+ if (!QFile::rename(info.filePath(), newFilePath)) {
+ QMessageBox::critical(this, tr("Error"), tr("Rename failed"));
+ }
+ }
+}
+
void TabDeckStorage::actUpload()
{
QModelIndexList curLefts = localDirView->selectionModel()->selectedRows();
diff --git a/cockatrice/src/client/tabs/tab_deck_storage.h b/cockatrice/src/client/tabs/tab_deck_storage.h
index e9654609e..e207a1187 100644
--- a/cockatrice/src/client/tabs/tab_deck_storage.h
+++ b/cockatrice/src/client/tabs/tab_deck_storage.h
@@ -28,7 +28,7 @@ private:
RemoteDeckList_TreeWidget *serverDirView;
QGroupBox *leftGroupBox, *rightGroupBox;
- QAction *aOpenLocalDeck, *aUpload, *aNewLocalFolder, *aDeleteLocalDeck;
+ QAction *aOpenLocalDeck, *aRenameLocal, *aUpload, *aNewLocalFolder, *aDeleteLocalDeck;
QAction *aOpenDecksFolder;
QAction *aOpenRemoteDeck, *aDownload, *aNewFolder, *aDeleteRemoteDeck;
QString getTargetPath() const;
@@ -47,6 +47,8 @@ private slots:
void actLocalDoubleClick(const QModelIndex &curLeft);
void actOpenLocalDeck();
+ void actRenameLocal();
+
void actUpload();
void uploadFinished(const Response &r, const CommandContainer &commandContainer);