mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -07:00
add local rename button to replays tab (#5331)
This commit is contained in:
parent
34d3d60f95
commit
024bef7ded
2 changed files with 36 additions and 1 deletions
|
|
@ -78,6 +78,9 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client) :
|
||||||
aOpenLocalReplay->setIcon(QPixmap("theme:icons/view"));
|
aOpenLocalReplay->setIcon(QPixmap("theme:icons/view"));
|
||||||
connect(aOpenLocalReplay, SIGNAL(triggered()), this, SLOT(actOpenLocalReplay()));
|
connect(aOpenLocalReplay, SIGNAL(triggered()), this, SLOT(actOpenLocalReplay()));
|
||||||
connect(localDirView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actOpenLocalReplay()));
|
connect(localDirView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actOpenLocalReplay()));
|
||||||
|
aRenameLocal = new QAction(this);
|
||||||
|
aRenameLocal->setIcon(QPixmap("theme:icons/pencil"));
|
||||||
|
connect(aRenameLocal, &QAction::triggered, this, &TabReplays::actRenameLocal);
|
||||||
aNewLocalFolder = new QAction(this);
|
aNewLocalFolder = new QAction(this);
|
||||||
aNewLocalFolder->setIcon(qApp->style()->standardIcon(QStyle::SP_FileDialogNewFolder));
|
aNewLocalFolder->setIcon(qApp->style()->standardIcon(QStyle::SP_FileDialogNewFolder));
|
||||||
connect(aNewLocalFolder, &QAction::triggered, this, &TabReplays::actNewLocalFolder);
|
connect(aNewLocalFolder, &QAction::triggered, this, &TabReplays::actNewLocalFolder);
|
||||||
|
|
@ -100,6 +103,7 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client) :
|
||||||
connect(aDeleteRemoteReplay, SIGNAL(triggered()), this, SLOT(actDeleteRemoteReplay()));
|
connect(aDeleteRemoteReplay, SIGNAL(triggered()), this, SLOT(actDeleteRemoteReplay()));
|
||||||
|
|
||||||
leftToolBar->addAction(aOpenLocalReplay);
|
leftToolBar->addAction(aOpenLocalReplay);
|
||||||
|
leftToolBar->addAction(aRenameLocal);
|
||||||
leftToolBar->addAction(aNewLocalFolder);
|
leftToolBar->addAction(aNewLocalFolder);
|
||||||
leftToolBar->addAction(aDeleteLocalReplay);
|
leftToolBar->addAction(aDeleteLocalReplay);
|
||||||
rightToolBar->addAction(aOpenRemoteReplay);
|
rightToolBar->addAction(aOpenRemoteReplay);
|
||||||
|
|
@ -159,6 +163,36 @@ void TabReplays::actOpenLocalReplay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabReplays::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 TabReplays::actNewLocalFolder()
|
void TabReplays::actNewLocalFolder()
|
||||||
{
|
{
|
||||||
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
|
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,14 @@ private:
|
||||||
RemoteReplayList_TreeWidget *serverDirView;
|
RemoteReplayList_TreeWidget *serverDirView;
|
||||||
QGroupBox *leftGroupBox, *rightGroupBox;
|
QGroupBox *leftGroupBox, *rightGroupBox;
|
||||||
|
|
||||||
QAction *aOpenLocalReplay, *aNewLocalFolder, *aDeleteLocalReplay;
|
QAction *aOpenLocalReplay, *aRenameLocal, *aNewLocalFolder, *aDeleteLocalReplay;
|
||||||
QAction *aOpenRemoteReplay, *aDownload, *aKeep, *aDeleteRemoteReplay;
|
QAction *aOpenRemoteReplay, *aDownload, *aKeep, *aDeleteRemoteReplay;
|
||||||
|
|
||||||
void downloadNodeAtIndex(const QModelIndex &curLeft, const QModelIndex &curRight);
|
void downloadNodeAtIndex(const QModelIndex &curLeft, const QModelIndex &curRight);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void actLocalDoubleClick(const QModelIndex &curLeft);
|
void actLocalDoubleClick(const QModelIndex &curLeft);
|
||||||
|
void actRenameLocal();
|
||||||
void actOpenLocalReplay();
|
void actOpenLocalReplay();
|
||||||
void actNewLocalFolder();
|
void actNewLocalFolder();
|
||||||
void actDeleteLocalReplay();
|
void actDeleteLocalReplay();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue