From 82e1377a414a64407fccc0ce66a7f79545b0dc1a Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 8 Sep 2017 16:54:42 -0300 Subject: [PATCH] Add warning/error about overwritting the original file on Save Copy As --- src/app/commands/cmd_save_file.cpp | 21 +++++++++++++++++---- src/app/commands/cmd_save_file.h | 4 +++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/app/commands/cmd_save_file.cpp b/src/app/commands/cmd_save_file.cpp index af36ef65a..cd09c8eb4 100644 --- a/src/app/commands/cmd_save_file.cpp +++ b/src/app/commands/cmd_save_file.cpp @@ -172,9 +172,11 @@ bool SaveFileBaseCommand::onEnabled(Context* context) return context->checkFlags(ContextFlags::ActiveDocumentIsWritable); } -bool SaveFileBaseCommand::saveAsDialog(Context* context, - const char* dlgTitle, - FileSelectorDelegate* delegate) +bool SaveFileBaseCommand::saveAsDialog( + Context* context, + const std::string& dlgTitle, + const std::string& forbiddenFilename, + FileSelectorDelegate* delegate) { const Document* document = context->activeDocument(); std::string filename; @@ -193,6 +195,7 @@ bool SaveFileBaseCommand::saveAsDialog(Context* context, std::string exts = get_writable_extensions(); filename = document->filename(); + again:; FileSelectorFiles newfilename; if (!app::show_file_selector( dlgTitle, filename, exts, @@ -201,6 +204,15 @@ bool SaveFileBaseCommand::saveAsDialog(Context* context, return false; filename = newfilename.front(); + if (base::normalize_path(forbiddenFilename) == + base::normalize_path(filename)) { + ui::Alert::show("Overwrite Warning" + "< Save menu option in that case." + "||&OK"); + goto again; + } + if (delegate && delegate->hasResizeCombobox()) { xscale = yscale = delegate->getResizeScale(); @@ -431,7 +443,8 @@ void SaveFileCopyAsCommand::onExecute(Context* context) docPref.saveCopy.filename()); } - if (saveAsDialog(context, "Save Copy As", delegate)) { + if (saveAsDialog(context, "Save Copy As", + oldFilename, delegate)) { docPref.saveCopy.filename(document->filename()); if (delegate) { docPref.saveCopy.resizeScale(delegate->getResizeScale()); diff --git a/src/app/commands/cmd_save_file.h b/src/app/commands/cmd_save_file.h index b3d25c874..a670a3009 100644 --- a/src/app/commands/cmd_save_file.h +++ b/src/app/commands/cmd_save_file.h @@ -29,7 +29,9 @@ namespace app { void onLoadParams(const Params& params) override; bool onEnabled(Context* context) override; - bool saveAsDialog(Context* context, const char* dlgTitle, + bool saveAsDialog(Context* context, + const std::string& dlgTitle, + const std::string& forbiddenFilename = std::string(), FileSelectorDelegate* delegate = nullptr); void saveDocumentInBackground(const Context* context, const app::Document* document,