Minor changes in SaveFileCommand to use enums instead of bool params

This commit is contained in:
David Capello 2022-06-13 12:46:11 -03:00
parent 25fbe786f8
commit d160fb8b91
2 changed files with 24 additions and 14 deletions

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -129,8 +129,8 @@ std::string SaveFileBaseCommand::saveAsDialog(
Context* context, Context* context,
const std::string& dlgTitle, const std::string& dlgTitle,
const std::string& initialFilename, const std::string& initialFilename,
const bool markAsSaved, const MarkAsSaved markAsSaved,
const bool saveInBackground, const SaveInBackground saveInBackground,
const std::string& forbiddenFilename) const std::string& forbiddenFilename)
{ {
Doc* document = context->activeDocument(); Doc* document = context->activeDocument();
@ -170,7 +170,7 @@ std::string SaveFileBaseCommand::saveAsDialog(
#endif // ENABLE_UI #endif // ENABLE_UI
} }
if (saveInBackground) { if (saveInBackground == SaveInBackground::On) {
saveDocumentInBackground( saveDocumentInBackground(
context, document, context, document,
filename, markAsSaved); filename, markAsSaved);
@ -198,7 +198,7 @@ void SaveFileBaseCommand::saveDocumentInBackground(
const Context* context, const Context* context,
Doc* document, Doc* document,
const std::string& filename, const std::string& filename,
const bool markAsSaved) const MarkAsSaved markAsSaved)
{ {
if (!m_aniDir.empty()) { if (!m_aniDir.empty()) {
switch (convert_string_to_anidir(m_aniDir)) { switch (convert_string_to_anidir(m_aniDir)) {
@ -241,7 +241,7 @@ void SaveFileBaseCommand::saveDocumentInBackground(
} }
else if (context->isUIAvailable()) { else if (context->isUIAvailable()) {
App::instance()->recentFiles()->addRecentFile(filename); App::instance()->recentFiles()->addRecentFile(filename);
if (markAsSaved) { if (markAsSaved == MarkAsSaved::On) {
document->markAsSaved(); document->markAsSaved();
document->setFilename(filename); document->setFilename(filename);
document->incrementVersion(); document->incrementVersion();
@ -283,14 +283,16 @@ void SaveFileCommand::onExecute(Context* context)
saveDocumentInBackground( saveDocumentInBackground(
context, document, context, document,
documentReader->filename(), true); documentReader->filename(),
MarkAsSaved::On);
} }
// If the document isn't associated to a file, we must to show the // If the document isn't associated to a file, we must to show the
// save-as dialog to the user to select for first time the file-name // save-as dialog to the user to select for first time the file-name
// for this document. // for this document.
else { else {
saveAsDialog(context, "Save File", saveAsDialog(context, "Save File",
document->filename(), true); document->filename(),
MarkAsSaved::On);
} }
} }
@ -311,7 +313,8 @@ void SaveFileAsCommand::onExecute(Context* context)
{ {
Doc* document = context->activeDocument(); Doc* document = context->activeDocument();
saveAsDialog(context, "Save As", saveAsDialog(context, "Save As",
document->filename(), true); document->filename(),
MarkAsSaved::On);
} }
class SaveFileCopyAsCommand : public SaveFileBaseCommand { class SaveFileCopyAsCommand : public SaveFileBaseCommand {
@ -353,7 +356,9 @@ void SaveFileCopyAsCommand::onExecute(Context* context)
std::string result = std::string result =
saveAsDialog( saveAsDialog(
context, "Export", context, "Export",
win.outputFilenameValue(), false, false, win.outputFilenameValue(),
MarkAsSaved::Off,
SaveInBackground::Off,
(doc->isAssociatedToFile() ? doc->filename(): (doc->isAssociatedToFile() ? doc->filename():
std::string())); std::string()));
if (!result.empty()) if (!result.empty())
@ -461,7 +466,8 @@ void SaveFileCopyAsCommand::onExecute(Context* context)
PngEncoderOneAlphaPixel fixPng(isForTwitter); PngEncoderOneAlphaPixel fixPng(isForTwitter);
saveDocumentInBackground( saveDocumentInBackground(
context, doc, outputFilename, false); context, doc, outputFilename,
MarkAsSaved::Off);
} }
// Undo resize // Undo resize

View File

@ -1,4 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -18,6 +19,9 @@ namespace app {
class SaveFileBaseCommand : public Command { class SaveFileBaseCommand : public Command {
public: public:
enum class MarkAsSaved { Off, On };
enum class SaveInBackground { Off, On };
SaveFileBaseCommand(const char* id, CommandFlags flags); SaveFileBaseCommand(const char* id, CommandFlags flags);
protected: protected:
@ -28,14 +32,14 @@ namespace app {
Context* context, Context* context,
const std::string& dlgTitle, const std::string& dlgTitle,
const std::string& filename, const std::string& filename,
const bool markAsSaved, const MarkAsSaved markAsSaved,
const bool saveInBackground = true, const SaveInBackground saveInBackground = SaveInBackground::On,
const std::string& forbiddenFilename = std::string()); const std::string& forbiddenFilename = std::string());
void saveDocumentInBackground( void saveDocumentInBackground(
const Context* context, const Context* context,
Doc* document, Doc* document,
const std::string& filename, const std::string& filename,
const bool markAsSaved); const MarkAsSaved markAsSaved);
std::string m_filename; std::string m_filename;
std::string m_filenameFormat; std::string m_filenameFormat;