Disable progress bar in commands that can receive ui=false (fix #4165)

This commit is contained in:
David Capello 2024-05-09 14:26:29 -03:00
parent a1bd6f59aa
commit 0cc1161d64
13 changed files with 72 additions and 48 deletions

View File

@ -484,7 +484,8 @@ protected:
std::string onGetFriendlyName() const override; std::string onGetFriendlyName() const override;
private: private:
bool m_useUI; bool m_showDlg;
bool m_showProgress;
doc::PixelFormat m_format; doc::PixelFormat m_format;
render::Dithering m_dithering; render::Dithering m_dithering;
doc::RgbMapAlgorithm m_rgbmap; doc::RgbMapAlgorithm m_rgbmap;
@ -494,7 +495,8 @@ private:
ChangePixelFormatCommand::ChangePixelFormatCommand() ChangePixelFormatCommand::ChangePixelFormatCommand()
: Command(CommandId::ChangePixelFormat(), CmdUIOnlyFlag) : Command(CommandId::ChangePixelFormat(), CmdUIOnlyFlag)
{ {
m_useUI = true; m_showDlg = true;
m_showProgress = true;
m_format = IMAGE_RGB; m_format = IMAGE_RGB;
m_dithering = render::Dithering(); m_dithering = render::Dithering();
m_rgbmap = doc::RgbMapAlgorithm::DEFAULT; m_rgbmap = doc::RgbMapAlgorithm::DEFAULT;
@ -503,15 +505,20 @@ ChangePixelFormatCommand::ChangePixelFormatCommand()
void ChangePixelFormatCommand::onLoadParams(const Params& params) void ChangePixelFormatCommand::onLoadParams(const Params& params)
{ {
m_useUI = false; m_showDlg = false;
m_showProgress = true;
std::string format = params.get("format"); std::string format = params.get("format");
if (format == "rgb") m_format = IMAGE_RGB; if (format == "rgb") m_format = IMAGE_RGB;
else if (format == "grayscale" || else if (format == "grayscale" ||
format == "gray") m_format = IMAGE_GRAYSCALE; format == "gray") m_format = IMAGE_GRAYSCALE;
else if (format == "indexed") m_format = IMAGE_INDEXED; else if (format == "indexed") m_format = IMAGE_INDEXED;
else else {
m_useUI = true; m_showDlg = true;
}
if (params.has_param("ui"))
m_showDlg = m_showProgress = params.get_as<bool>("ui");
std::string dithering = params.get("dithering"); std::string dithering = params.get("dithering");
if (dithering == "ordered") if (dithering == "ordered")
@ -587,7 +594,7 @@ bool ChangePixelFormatCommand::onEnabled(Context* context)
if (!sprite) if (!sprite)
return false; return false;
if (m_useUI) if (m_showDlg)
return true; return true;
if (sprite->pixelFormat() == IMAGE_INDEXED && if (sprite->pixelFormat() == IMAGE_INDEXED &&
@ -600,7 +607,7 @@ bool ChangePixelFormatCommand::onEnabled(Context* context)
bool ChangePixelFormatCommand::onChecked(Context* context) bool ChangePixelFormatCommand::onChecked(Context* context)
{ {
if (m_useUI) if (m_showDlg)
return false; return false;
const ContextReader reader(context); const ContextReader reader(context);
@ -622,7 +629,7 @@ void ChangePixelFormatCommand::onExecute(Context* context)
bool flatten = false; bool flatten = false;
#ifdef ENABLE_UI #ifdef ENABLE_UI
if (m_useUI) { if (context->isUIAvailable() && m_showDlg) {
ColorModeWindow window(Editor::activeEditor()); ColorModeWindow window(Editor::activeEditor());
window.remapWindow(); window.remapWindow();
@ -651,7 +658,7 @@ void ChangePixelFormatCommand::onExecute(Context* context)
return; return;
{ {
SpriteJob job(context, doc, Strings::color_mode_title()); SpriteJob job(context, doc, Strings::color_mode_title(), m_showProgress);
Sprite* sprite(job.sprite()); Sprite* sprite(job.sprite());
// TODO this was moved in the main UI thread because // TODO this was moved in the main UI thread because
@ -691,7 +698,7 @@ std::string ChangePixelFormatCommand::onGetFriendlyName() const
{ {
std::string conversion; std::string conversion;
if (!m_useUI) { if (!m_showDlg) {
switch (m_format) { switch (m_format) {
case IMAGE_RGB: case IMAGE_RGB:
conversion = Strings::commands_ChangePixelFormat_RGB(); conversion = Strings::commands_ChangePixelFormat_RGB();

View File

@ -93,10 +93,7 @@ bool ColorQuantizationCommand::onEnabled(Context* ctx)
void ColorQuantizationCommand::onExecute(Context* ctx) void ColorQuantizationCommand::onExecute(Context* ctx)
{ {
#ifdef ENABLE_UI
const bool ui = (params().ui() && ctx->isUIAvailable()); const bool ui = (params().ui() && ctx->isUIAvailable());
#endif
auto& pref = Preferences::instance(); auto& pref = Preferences::instance();
bool withAlpha = params().withAlpha(); bool withAlpha = params().withAlpha();
int maxColors = params().maxColors(); int maxColors = params().maxColors();
@ -183,7 +180,7 @@ void ColorQuantizationCommand::onExecute(Context* ctx)
const Palette* curPalette = site.sprite()->palette(frame); const Palette* curPalette = site.sprite()->palette(frame);
Palette tmpPalette(frame, entries.picks()); Palette tmpPalette(frame, entries.picks());
SpriteJob job(ctx, doc, "Color Quantization"); SpriteJob job(ctx, doc, "Color Quantization", ui);
const bool newBlend = pref.experimental.newBlend(); const bool newBlend = pref.experimental.newBlend();
job.startJobWithCallback( job.startJobWithCallback(
[sprite, withAlpha, curPalette, &tmpPalette, &job, &entries, [sprite, withAlpha, curPalette, &tmpPalette, &job, &entries,

View File

@ -1193,8 +1193,9 @@ public:
ExportSpriteSheetJob( ExportSpriteSheetJob(
DocExporter& exporter, DocExporter& exporter,
const Site& site, const Site& site,
const ExportSpriteSheetParams& params) const ExportSpriteSheetParams& params,
: Job(Strings::export_sprite_sheet_generating().c_str()) const bool showProgress)
: Job(Strings::export_sprite_sheet_generating(), showProgress)
, m_exporter(exporter) , m_exporter(exporter)
, m_site(site) , m_site(site)
, m_params(params) { } , m_params(params) { }
@ -1373,7 +1374,9 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
std::unique_ptr<Doc> newDocument; std::unique_ptr<Doc> newDocument;
#ifdef ENABLE_UI #ifdef ENABLE_UI
if (context->isUIAvailable()) { if (context->isUIAvailable()) {
ExportSpriteSheetJob job(exporter, site, params); ExportSpriteSheetJob job(exporter, site, params,
// Progress bar can be disabled with ui=false
params.ui());
job.startJob(); job.startJob();
job.waitJob(); job.waitJob();

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2019-2024 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
@ -36,8 +36,8 @@ namespace app {
class OpenFileJob : public Job, public IFileOpProgress { class OpenFileJob : public Job, public IFileOpProgress {
public: public:
OpenFileJob(FileOp* fop) OpenFileJob(FileOp* fop, const bool showProgress)
: Job(Strings::open_file_loading().c_str()) : Job(Strings::open_file_loading(), showProgress)
, m_fop(fop) , m_fop(fop)
{ {
} }
@ -76,6 +76,7 @@ private:
OpenFileCommand::OpenFileCommand() OpenFileCommand::OpenFileCommand()
: Command(CommandId::OpenFile(), CmdRecordableFlag) : Command(CommandId::OpenFile(), CmdRecordableFlag)
, m_ui(true)
, m_repeatCheckbox(false) , m_repeatCheckbox(false)
, m_oneFrame(false) , m_oneFrame(false)
, m_seqDecision(gen::SequenceDecision::ASK) , m_seqDecision(gen::SequenceDecision::ASK)
@ -86,6 +87,12 @@ void OpenFileCommand::onLoadParams(const Params& params)
{ {
m_filename = params.get("filename"); m_filename = params.get("filename");
m_folder = params.get("folder"); // Initial folder m_folder = params.get("folder"); // Initial folder
if (params.has_param("ui"))
m_ui = params.get_as<bool>("ui");
else
m_ui = true;
m_repeatCheckbox = params.get_as<bool>("repeat_checkbox"); m_repeatCheckbox = params.get_as<bool>("repeat_checkbox");
m_oneFrame = params.get_as<bool>("oneframe"); m_oneFrame = params.get_as<bool>("oneframe");
@ -220,7 +227,7 @@ void OpenFileCommand::onExecute(Context* context)
m_usedFiles.push_back(fn); m_usedFiles.push_back(fn);
} }
OpenFileJob task(fop.get()); OpenFileJob task(fop.get(), m_ui);
task.showProgressWindow(); task.showProgressWindow();
// Post-load processing, it is called from the GUI because may require user intervention. // Post-load processing, it is called from the GUI because may require user intervention.

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020-2021 Igara Studio S.A. // Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2016-2018 David Capello // Copyright (C) 2016-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -36,6 +36,7 @@ namespace app {
private: private:
std::string m_filename; std::string m_filename;
std::string m_folder; std::string m_folder;
bool m_ui;
bool m_repeatCheckbox; bool m_repeatCheckbox;
bool m_oneFrame; bool m_oneFrame;
base::paths m_usedFiles; base::paths m_usedFiles;

View File

@ -46,8 +46,10 @@ public:
RotateJob(Context* ctx, Doc* doc, RotateJob(Context* ctx, Doc* doc,
const std::string& jobName, const std::string& jobName,
int angle, const CelList& cels, bool rotateSprite) int angle, const CelList& cels,
: SpriteJob(ctx, doc, jobName) const bool rotateSprite,
const bool showProgress)
: SpriteJob(ctx, doc, jobName, showProgress)
, m_cels(cels) , m_cels(cels)
, m_rotateSprite(rotateSprite) { , m_rotateSprite(rotateSprite) {
m_angle = angle; m_angle = angle;
@ -167,12 +169,18 @@ protected:
RotateCommand::RotateCommand() RotateCommand::RotateCommand()
: Command(CommandId::Rotate(), CmdRecordableFlag) : Command(CommandId::Rotate(), CmdRecordableFlag)
{ {
m_ui = true;
m_flipMask = false; m_flipMask = false;
m_angle = 0; m_angle = 0;
} }
void RotateCommand::onLoadParams(const Params& params) void RotateCommand::onLoadParams(const Params& params)
{ {
if (params.has_param("ui"))
m_ui = params.get_as<bool>("ui");
else
m_ui = true;
std::string target = params.get("target"); std::string target = params.get("target");
m_flipMask = (target == "mask"); m_flipMask = (target == "mask");
@ -238,7 +246,7 @@ void RotateCommand::onExecute(Context* context)
} }
{ {
RotateJob job(context, doc, friendlyName(), m_angle, cels, rotateSprite); RotateJob job(context, doc, friendlyName(), m_angle, cels, rotateSprite, m_ui);
job.startJob(); job.startJob();
job.waitJob(); job.waitJob();
} }

View File

@ -1,4 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -27,6 +28,7 @@ namespace app {
std::string onGetFriendlyName() const override; std::string onGetFriendlyName() const override;
private: private:
bool m_ui;
bool m_flipMask; bool m_flipMask;
int m_angle; int m_angle;
}; };

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2023 Igara Studio S.A. // Copyright (C) 2019-2024 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
@ -49,8 +49,8 @@ namespace app {
class SaveFileJob : public Job, public IFileOpProgress { class SaveFileJob : public Job, public IFileOpProgress {
public: public:
SaveFileJob(FileOp* fop) SaveFileJob(FileOp* fop, const bool showProgressBar)
: Job(Strings::save_file_saving().c_str()) : Job(Strings::save_file_saving(), showProgressBar)
, m_fop(fop) , m_fop(fop)
{ {
} }
@ -239,7 +239,7 @@ void SaveFileBaseCommand::saveDocumentInBackground(
if (resizeOnTheFly == ResizeOnTheFly::On) if (resizeOnTheFly == ResizeOnTheFly::On)
fop->setOnTheFlyScale(scale); fop->setOnTheFlyScale(scale);
SaveFileJob job(fop.get()); SaveFileJob job(fop.get(), params().ui());
job.showProgressWindow(); job.showProgressWindow();
if (fop->hasError()) { if (fop->hasError()) {

View File

@ -83,8 +83,9 @@ public:
SpriteSizeJob(Context* ctx, Doc* doc, SpriteSizeJob(Context* ctx, Doc* doc,
const int new_width, const int new_width,
const int new_height, const int new_height,
const ResizeMethod resize_method) const ResizeMethod resize_method,
: SpriteJob(ctx, doc, Strings::sprite_size_title()) { const bool showProgress)
: SpriteJob(ctx, doc, Strings::sprite_size_title(), showProgress) {
m_new_width = new_width; m_new_width = new_width;
m_new_height = new_height; m_new_height = new_height;
m_resize_method = resize_method; m_resize_method = resize_method;
@ -373,9 +374,7 @@ bool SpriteSizeCommand::onEnabled(Context* context)
void SpriteSizeCommand::onExecute(Context* context) void SpriteSizeCommand::onExecute(Context* context)
{ {
#ifdef ENABLE_UI
const bool ui = (params().ui() && context->isUIAvailable()); const bool ui = (params().ui() && context->isUIAvailable());
#endif
const Site site = context->activeSite(); const Site site = context->activeSite();
Doc* doc = site.document(); Doc* doc = site.document();
Sprite* sprite = site.sprite(); Sprite* sprite = site.sprite();
@ -465,7 +464,7 @@ void SpriteSizeCommand::onExecute(Context* context)
new_height = std::clamp(new_height, 1, DOC_SPRITE_MAX_HEIGHT); new_height = std::clamp(new_height, 1, DOC_SPRITE_MAX_HEIGHT);
{ {
SpriteSizeJob job(context, doc, new_width, new_height, resize_method); SpriteSizeJob job(context, doc, new_width, new_height, resize_method, ui);
job.startJob(); job.startJob();
job.waitJob(); job.waitJob();
} }

View File

@ -33,18 +33,19 @@ int Job::runningJobs()
return g_runningJobs; return g_runningJobs;
} }
Job::Job(const std::string& jobName) Job::Job(const std::string& jobName,
const bool showProgress)
{ {
m_last_progress = 0.0; m_last_progress = 0.0;
m_done_flag = false; m_done_flag = false;
m_canceled_flag = false; m_canceled_flag = false;
if (App::instance()->isGui()) { if (showProgress && App::instance()->isGui()) {
m_alert_window = ui::Alert::create( m_alert_window = ui::Alert::create(
fmt::format(Strings::alerts_job_working(), jobName)); fmt::format(Strings::alerts_job_working(), jobName));
m_alert_window->addProgress(); m_alert_window->addProgress();
m_timer.reset(new ui::Timer(kMonitoringPeriod, m_alert_window.get())); m_timer = std::make_unique<ui::Timer>(kMonitoringPeriod, m_alert_window.get());
m_timer->Tick.connect(&Job::onMonitoringTick, this); m_timer->Tick.connect(&Job::onMonitoringTick, this);
m_timer->start(); m_timer->start();
} }
@ -53,7 +54,7 @@ Job::Job(const std::string& jobName)
Job::~Job() Job::~Job()
{ {
if (App::instance()->isGui()) { if (App::instance()->isGui()) {
ASSERT(!m_timer->isRunning()); ASSERT(!m_timer || !m_timer->isRunning());
if (m_alert_window) if (m_alert_window)
m_alert_window->closeWindow(NULL); m_alert_window->closeWindow(NULL);

View File

@ -24,7 +24,10 @@ namespace app {
public: public:
static int runningJobs(); static int runningJobs();
Job(const std::string& jobName); Job(const std::string& jobName, bool showProgress);
Job() = delete;
Job(const Job&) = delete;
Job& operator==(const Job&) = delete;
virtual ~Job(); virtual ~Job();
// Starts the job calling onJob() event in another thread and // Starts the job calling onJob() event in another thread and
@ -68,12 +71,6 @@ namespace app {
bool m_done_flag; bool m_done_flag;
bool m_canceled_flag; bool m_canceled_flag;
std::exception_ptr m_error; std::exception_ptr m_error;
// these methods are privated and not defined
Job();
Job(const Job&);
Job& operator==(const Job&);
}; };
} // namespace app } // namespace app

View File

@ -16,8 +16,9 @@
namespace app { namespace app {
SpriteJob::SpriteJob(Context* ctx, Doc* doc, SpriteJob::SpriteJob(Context* ctx, Doc* doc,
const std::string& jobName) const std::string& jobName,
: Job(jobName) const bool showProgress)
: Job(jobName, showProgress)
, m_doc(doc) , m_doc(doc)
, m_sprite(doc->sprite()) , m_sprite(doc->sprite())
, m_tx(Tx::DontLockDoc, ctx, doc, jobName, ModifyDocument) , m_tx(Tx::DontLockDoc, ctx, doc, jobName, ModifyDocument)

View File

@ -37,7 +37,8 @@ class SpriteJob : public Job,
public render::TaskDelegate { public render::TaskDelegate {
public: public:
SpriteJob(Context* ctx, Doc* doc, SpriteJob(Context* ctx, Doc* doc,
const std::string& jobName); const std::string& jobName,
const bool showProgress);
~SpriteJob(); ~SpriteJob();
Doc* document() const { return m_doc; } Doc* document() const { return m_doc; }