Add "recent" param to SaveFile/ExportSpriteSheet to avoid adding the file to the list of recent files

This commit is contained in:
David Capello 2024-05-10 14:49:14 -03:00
parent 0cc1161d64
commit 3ea0437e1d
5 changed files with 24 additions and 5 deletions

View File

@ -1389,8 +1389,10 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
statusbar->showTip(1000, Strings::export_sprite_sheet_generated());
// Save the exported sprite sheet as a recent file
if (newDocument->isAssociatedToFile())
if (newDocument->isAssociatedToFile() &&
should_add_file_to_recents(context, params)) {
App::instance()->recentFiles()->addRecentFile(newDocument->filename());
}
// Copy background and grid preferences
DocumentPreferences& newDocPref(

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2022 Igara Studio S.A.
// Copyright (C) 2022-2024 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -19,6 +19,7 @@ namespace app {
struct ExportSpriteSheetParams : public NewParams {
Param<bool> ui { this, true, "ui" };
Param<bool> recent { this, true, "recent" };
Param<bool> askOverwrite { this, true, { "askOverwrite", "ask-overwrite" } };
Param<app::SpriteSheetType> type { this, app::SpriteSheetType::None, "type" };
Param<int> columns { this, 0, "columns" };

View File

@ -257,7 +257,7 @@ void SaveFileBaseCommand::saveDocumentInBackground(
document->impossibleToBackToSavedState();
}
else {
if (context->isUIAvailable() && params().ui())
if (should_add_file_to_recents(context, params()))
App::instance()->recentFiles()->addRecentFile(filename);
if (markAsSaved == MarkAsSaved::On) {

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2021-2022 Igara Studio S.A.
// Copyright (C) 2021-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -23,6 +23,7 @@ namespace app {
struct SaveFileParams : public NewParams {
Param<bool> ui { this, true, { "ui", "useUI" } };
Param<bool> recent { this, true, "recent" };
Param<std::string> filename { this, std::string(), "filename" };
Param<std::string> filenameFormat { this, std::string(), { "filenameFormat", "filename-format" } };
Param<std::string> tag { this, std::string(), { "tag", "frame-tag" } };

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -9,6 +9,7 @@
#include "app/commands/command.h"
#include "app/commands/params.h"
#include "app/context.h"
#include <map>
#include <string>
@ -152,6 +153,20 @@ namespace app {
T m_params;
};
// Common logic to know if we should add a file to recent files. We
// offer two params: "ui" and "recent", if "recent" is specified, we
// do what it says. In other case "ui" is like the default value of
// "recent", i.e. if there is ui=true, we add to recent, if there is
// ui=false, we don't add it.
template<typename T>
inline bool should_add_file_to_recents(const Context* ctx,
const T& params) {
ASSERT(ctx);
return (ctx->isUIAvailable()
&& ((params.recent.isSet() && params.recent()) ||
(!params.recent.isSet() && params.ui())));
}
} // namespace app
#endif