From 7d071da093ec20e0a3917491f3b3e83964646c13 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Thu, 26 Aug 2021 10:00:36 +0200 Subject: [PATCH] UI: Add the rename action in the MainWindow for AbstractDocument --- rsc/VivyRessources.qrc | 2 ++ rsc/icons/breeze-dark/edit-rename.svg | 13 +++++++++++ rsc/icons/breeze-light/edit-rename.svg | 13 +++++++++++ src/UI/MainWindow.cc | 30 +++++++++++++++++++++++--- src/UI/MainWindow.hh | 1 + src/VivyApplication.hh | 1 + 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 rsc/icons/breeze-dark/edit-rename.svg create mode 100644 rsc/icons/breeze-light/edit-rename.svg diff --git a/rsc/VivyRessources.qrc b/rsc/VivyRessources.qrc index 9078302c..f86514d8 100644 --- a/rsc/VivyRessources.qrc +++ b/rsc/VivyRessources.qrc @@ -33,6 +33,7 @@ <file alias="document-open.svg">icons/breeze-dark/document-open.svg</file> <file alias="document-save.svg">icons/breeze-dark/document-save.svg</file> <file alias="document-save-as.svg">icons/breeze-dark/document-save-as.svg</file> + <file alias="document-rename.svg">icons/breeze-dark/edit-rename.svg</file> <file alias="folder.svg">icons/breeze-dark/folder.svg</file> <file alias="text-x-generic.svg">icons/breeze-dark/text-x-generic.svg</file> <file alias="help-about.svg">icons/breeze-dark/help-about.svg</file> @@ -45,6 +46,7 @@ <file alias="document-open.svg">icons/breeze-light/document-open.svg</file> <file alias="document-save.svg">icons/breeze-light/document-save.svg</file> <file alias="document-save-as.svg">icons/breeze-light/document-save-as.svg</file> + <file alias="document-rename.svg">icons/breeze-light/edit-rename.svg</file> <file alias="folder.svg">icons/breeze-light/folder.svg</file> <file alias="text-x-generic.svg">icons/breeze-light/text-x-generic.svg</file> <file alias="help-about.svg">icons/breeze-light/help-about.svg</file> diff --git a/rsc/icons/breeze-dark/edit-rename.svg b/rsc/icons/breeze-dark/edit-rename.svg new file mode 100644 index 00000000..6a844965 --- /dev/null +++ b/rsc/icons/breeze-dark/edit-rename.svg @@ -0,0 +1,13 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"> + <defs id="defs3051"> + <style type="text/css" id="current-color-scheme"> + .ColorScheme-Text { + color:#eff0f1; + } + </style> + </defs> + <path style="fill:currentColor;fill-opacity:1;stroke:none" + d="M 10.398438 2 L 5.2871094 7.1113281 L 2 10.398438 L 2 14 L 5.6015625 14 L 14 5.6015625 L 10.398438 2 z M 8.3496094 5.4902344 L 10.509766 7.6503906 L 7.3359375 10.826172 L 7.3359375 10.150391 L 6.3222656 10.171875 L 5.2871094 10.171875 L 5.2871094 9.1367188 L 5.2871094 8.5507812 L 6.7285156 7.1113281 L 8.3496094 5.4902344 z M 4.2734375 9.5644531 L 4.2734375 11.185547 L 5.3085938 11.185547 L 6.3007812 11.185547 L 6.3222656 11.837891 L 5.2421875 12.919922 L 3.8007812 12.919922 L 3.0800781 12.199219 L 3.0800781 10.757812 L 4.2734375 9.5644531 z " + class="ColorScheme-Text" + /> +</svg> diff --git a/rsc/icons/breeze-light/edit-rename.svg b/rsc/icons/breeze-light/edit-rename.svg new file mode 100644 index 00000000..18ccc58a --- /dev/null +++ b/rsc/icons/breeze-light/edit-rename.svg @@ -0,0 +1,13 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"> + <defs id="defs3051"> + <style type="text/css" id="current-color-scheme"> + .ColorScheme-Text { + color:#232629; + } + </style> + </defs> + <path style="fill:currentColor;fill-opacity:1;stroke:none" + d="M 10.398438 2 L 5.2871094 7.1113281 L 2 10.398438 L 2 14 L 5.6015625 14 L 14 5.6015625 L 10.398438 2 z M 8.3496094 5.4902344 L 10.509766 7.6503906 L 7.3359375 10.826172 L 7.3359375 10.150391 L 6.3222656 10.171875 L 5.2871094 10.171875 L 5.2871094 9.1367188 L 5.2871094 8.5507812 L 6.7285156 7.1113281 L 8.3496094 5.4902344 z M 4.2734375 9.5644531 L 4.2734375 11.185547 L 5.3085938 11.185547 L 6.3007812 11.185547 L 6.3222656 11.837891 L 5.2421875 12.919922 L 3.8007812 12.919922 L 3.0800781 12.199219 L 3.0800781 10.757812 L 4.2734375 9.5644531 z " + class="ColorScheme-Text" + /> +</svg> diff --git a/src/UI/MainWindow.cc b/src/UI/MainWindow.cc index d4a72f7f..40263baa 100644 --- a/src/UI/MainWindow.cc +++ b/src/UI/MainWindow.cc @@ -62,6 +62,7 @@ MainWindow::MainWindow() noexcept DCL_ACTION(openDocument, "&Open document", "Open a document", file); DCL_ACTION(saveFile, "&Save file", "Save the current document", file); DCL_ACTION(saveFileAs, "&Save file as", "Save the current document as", file); + DCL_ACTION(renameFile, "&Rename the file", "Rename the current document", file); fileMenu->addSeparator(); DCL_ACTION(loadSubDocumentAudio, "&Load audio", "Load an audio file as a sub-document", file); DCL_ACTION(loadSubDocumentVideo, "&Load video", "Load a vide file as a sub-document", file); @@ -73,6 +74,7 @@ MainWindow::MainWindow() noexcept ACTION_ADD_ICON(openDocument, VIVY_ICON_OPEN); ACTION_ADD_ICON(saveFile, VIVY_ICON_SAVE); ACTION_ADD_ICON(saveFileAs, VIVY_ICON_SAVE_AS); + ACTION_ADD_ICON(renameFile, VIVY_ICON_RENAME); ACTION_ADD_ICON(openDialogHelp, VIVY_ICON_ABOUT); ACTION_ADD_SHORTCUT(newDocument, QKeySequence::New); @@ -238,7 +240,6 @@ MainWindow::saveFile() noexcept { try { const auto document = getCurrentDocument(); - qDebug() << "Request to save the document" << document->getName(); document->save(); } @@ -247,19 +248,42 @@ MainWindow::saveFile() noexcept } } +void +MainWindow::renameFile() noexcept +{ + try { + const auto docView = getCurrentDocumentView(); + auto document = docView->getDocument(); + const QString filename = + dialogSaveFileName("Select the target file to rename the current file to", + QDir::homePath(), Utils::getVivyDocumentFileSuffixFilter()); + + if (filename.isEmpty()) + throw std::runtime_error("No filename passed"); + + else { + document->rename(filename); // Kubat: Save is called by rename! + emit docView->documentPropertyChanged(); + } + } + + catch (const std::runtime_error &e) { + qCritical() << "Failed to save current document:" << e.what(); + } +} + void MainWindow::saveFileAs() noexcept { try { const auto docView = getCurrentDocumentView(); auto document = docView->getDocument(); - qDebug() << "Request to save the document" << document->getName(); const QString filename = dialogSaveFileName("Select the target file to save into", QDir::homePath(), Utils::getVivyDocumentFileSuffixFilter()); if (filename.isEmpty()) - qWarning() << "Found an empty filename, don't open a file"; + throw std::runtime_error("No filename passed"); else { document->copy(filename); // Kubat: Save is called by copy! diff --git a/src/UI/MainWindow.hh b/src/UI/MainWindow.hh index 9f4c3d66..251e5afd 100644 --- a/src/UI/MainWindow.hh +++ b/src/UI/MainWindow.hh @@ -92,6 +92,7 @@ private slots: void saveFile() noexcept; void saveFileAs() noexcept; + void renameFile() noexcept; void openDialogHelp() noexcept; diff --git a/src/VivyApplication.hh b/src/VivyApplication.hh index 3826063a..4c98c7b3 100644 --- a/src/VivyApplication.hh +++ b/src/VivyApplication.hh @@ -16,6 +16,7 @@ #define VIVY_ICON_NEW ":icons/dark/document-new.svg" #define VIVY_ICON_SAVE ":icons/dark/document-save.svg" #define VIVY_ICON_SAVE_AS ":icons/dark/document-save-as.svg" +#define VIVY_ICON_RENAME ":icons/dark/document-rename.svg" #define VIVY_ICON_ABOUT ":icons/dark/help-about.svg" #define VIVY_ICON_FILE ":icons/dark/text-x-generic.svg" #define VIVY_ICON_FOLDER ":icons/dark/folder.svg" -- GitLab