mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-02 13:09:27 +00:00
Add warning/error about overwritting the original file on Save Copy As
This commit is contained in:
parent
e78f4c79c8
commit
82e1377a41
@ -172,9 +172,11 @@ bool SaveFileBaseCommand::onEnabled(Context* context)
|
|||||||
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable);
|
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SaveFileBaseCommand::saveAsDialog(Context* context,
|
bool SaveFileBaseCommand::saveAsDialog(
|
||||||
const char* dlgTitle,
|
Context* context,
|
||||||
FileSelectorDelegate* delegate)
|
const std::string& dlgTitle,
|
||||||
|
const std::string& forbiddenFilename,
|
||||||
|
FileSelectorDelegate* delegate)
|
||||||
{
|
{
|
||||||
const Document* document = context->activeDocument();
|
const Document* document = context->activeDocument();
|
||||||
std::string filename;
|
std::string filename;
|
||||||
@ -193,6 +195,7 @@ bool SaveFileBaseCommand::saveAsDialog(Context* context,
|
|||||||
std::string exts = get_writable_extensions();
|
std::string exts = get_writable_extensions();
|
||||||
filename = document->filename();
|
filename = document->filename();
|
||||||
|
|
||||||
|
again:;
|
||||||
FileSelectorFiles newfilename;
|
FileSelectorFiles newfilename;
|
||||||
if (!app::show_file_selector(
|
if (!app::show_file_selector(
|
||||||
dlgTitle, filename, exts,
|
dlgTitle, filename, exts,
|
||||||
@ -201,6 +204,15 @@ bool SaveFileBaseCommand::saveAsDialog(Context* context,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
filename = newfilename.front();
|
filename = newfilename.front();
|
||||||
|
if (base::normalize_path(forbiddenFilename) ==
|
||||||
|
base::normalize_path(filename)) {
|
||||||
|
ui::Alert::show("Overwrite Warning"
|
||||||
|
"<<You cannot save a copy with the same name (overwrite the original file)."
|
||||||
|
"<<Use File > Save menu option in that case."
|
||||||
|
"||&OK");
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
|
|
||||||
if (delegate &&
|
if (delegate &&
|
||||||
delegate->hasResizeCombobox()) {
|
delegate->hasResizeCombobox()) {
|
||||||
xscale = yscale = delegate->getResizeScale();
|
xscale = yscale = delegate->getResizeScale();
|
||||||
@ -431,7 +443,8 @@ void SaveFileCopyAsCommand::onExecute(Context* context)
|
|||||||
docPref.saveCopy.filename());
|
docPref.saveCopy.filename());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saveAsDialog(context, "Save Copy As", delegate)) {
|
if (saveAsDialog(context, "Save Copy As",
|
||||||
|
oldFilename, delegate)) {
|
||||||
docPref.saveCopy.filename(document->filename());
|
docPref.saveCopy.filename(document->filename());
|
||||||
if (delegate) {
|
if (delegate) {
|
||||||
docPref.saveCopy.resizeScale(delegate->getResizeScale());
|
docPref.saveCopy.resizeScale(delegate->getResizeScale());
|
||||||
|
@ -29,7 +29,9 @@ namespace app {
|
|||||||
void onLoadParams(const Params& params) override;
|
void onLoadParams(const Params& params) override;
|
||||||
bool onEnabled(Context* context) 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);
|
FileSelectorDelegate* delegate = nullptr);
|
||||||
void saveDocumentInBackground(const Context* context,
|
void saveDocumentInBackground(const Context* context,
|
||||||
const app::Document* document,
|
const app::Document* document,
|
||||||
|
Loading…
Reference in New Issue
Block a user