summaryrefslogtreecommitdiffstats
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index a52d3c5c..c1eddacd 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -27,6 +27,7 @@
#include <QMessageBox>
#include <QShortcut>
#include <QTimer>
+#include<QDebug>
/**
* @brief MainWindow::MainWindow handles all of the main functionality and also
@@ -915,6 +916,13 @@ void MainWindow::showContextMenu(const QPoint &pos) {
// SLOT(copyPasswordToClipboard()));
// }
contextMenu.addSeparator();
+ if (fileOrFolder.isDir()) {
+ QAction *renameFolder = contextMenu.addAction(tr("Rename folder"));
+ connect(renameFolder, &QAction::triggered, this, &MainWindow::renameFolder);
+ } else if (fileOrFolder.isFile()) {
+ QAction *renamePassword = contextMenu.addAction(tr("Rename password"));
+ connect(renamePassword, &QAction::triggered, this, &MainWindow::renamePassword);
+ }
QAction *deleteItem = contextMenu.addAction(tr("Delete"));
connect(deleteItem, &QAction::triggered, this, &MainWindow::onDelete);
}
@@ -966,6 +974,27 @@ void MainWindow::addFolder() {
}
/**
+ * @brief MainWindow::renameFolder rename an existing folder
+ */
+void MainWindow::renameFolder() {
+ bool ok;
+ QString srcDir = QDir::cleanPath(Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel));
+ QString srcDirName = QDir(srcDir).dirName();
+ QString newName =
+ QInputDialog::getText(this, tr("Rename file"),
+ tr("Rename Folder To: "),
+ QLineEdit::Normal,
+ srcDirName,
+ &ok);
+ if (!ok || newName.isEmpty())
+ return;
+ QString destDir = srcDir;
+ destDir.replace(srcDir.lastIndexOf(srcDirName), srcDirName.length(), newName);
+ QtPassSettings::getPass()->Move(srcDir, destDir);
+}
+
+
+/**
* @brief MainWindow::editPassword read password and open edit window via
* MainWindow::onEdit()
*/
@@ -978,6 +1007,29 @@ void MainWindow::editPassword(const QString &file) {
}
/**
+ * @brief MainWindow::renamePassword rename or move an existing password
+ */
+void MainWindow::renamePassword() {
+ bool ok;
+ QString file = getFile(ui->treeView->currentIndex(), false);
+ QString fileName = QFileInfo(file).baseName();
+ QString newName =
+ QInputDialog::getText(this, tr("Rename file"),
+ tr("Rename File To: "),
+ QLineEdit::Normal,
+ fileName,
+ &ok);
+ if (!ok || newName.isEmpty())
+ return;
+ qDebug() << fileName;
+ qDebug() << newName;
+ QString newFile = file;
+ newFile.replace(file.lastIndexOf(fileName), fileName.length(), newName);
+ qDebug() << newFile;
+ QtPassSettings::getPass()->Move(file, newFile);
+}
+
+/**
* @brief MainWindow::clearTemplateWidgets empty the template widget fields in
* the UI
*/