diff --git a/src/app/commands/cmd_about.cpp b/src/app/commands/cmd_about.cpp index d44a9686b..819adb4a2 100644 --- a/src/app/commands/cmd_about.cpp +++ b/src/app/commands/cmd_about.cpp @@ -11,12 +11,12 @@ #include "app/app.h" #include "app/commands/command.h" -#include "app/modules/gui.h" #include "app/ui/main_window.h" #include "fmt/format.h" #include "ver/info.h" #include "about.xml.h" +#include "app/context.h" namespace app { @@ -27,13 +27,19 @@ public: AboutCommand(); protected: + bool onEnabled(Context* context) override; void onExecute(Context* context) override; }; -AboutCommand::AboutCommand() : Command(CommandId::About(), CmdUIOnlyFlag) +AboutCommand::AboutCommand() : Command(CommandId::About()) { } +bool AboutCommand::onEnabled(Context* context) +{ + return context->isUIAvailable(); +} + void AboutCommand::onExecute(Context* context) { gen::About window; diff --git a/src/app/commands/cmd_add_color.cpp b/src/app/commands/cmd_add_color.cpp index 4ed1bdfa4..2e4f4148c 100644 --- a/src/app/commands/cmd_add_color.cpp +++ b/src/app/commands/cmd_add_color.cpp @@ -63,8 +63,7 @@ protected: std::string onGetFriendlyName() const override; }; -AddColorCommand::AddColorCommand() - : CommandWithNewParams(CommandId::AddColor(), CmdUIOnlyFlag) +AddColorCommand::AddColorCommand() : CommandWithNewParams(CommandId::AddColor()) { } diff --git a/src/app/commands/cmd_advanced_mode.cpp b/src/app/commands/cmd_advanced_mode.cpp index 59b7d8120..b93a2cc7b 100644 --- a/src/app/commands/cmd_advanced_mode.cpp +++ b/src/app/commands/cmd_advanced_mode.cpp @@ -17,8 +17,7 @@ #include "ui/ui.h" #include "advanced_mode.xml.h" - -#include +#include "app/context.h" namespace app { @@ -29,13 +28,19 @@ public: AdvancedModeCommand(); protected: + bool onEnabled(Context* context) override; void onExecute(Context* context) override; }; -AdvancedModeCommand::AdvancedModeCommand() : Command(CommandId::AdvancedMode(), CmdUIOnlyFlag) +AdvancedModeCommand::AdvancedModeCommand() : Command(CommandId::AdvancedMode()) { } +bool AdvancedModeCommand::onEnabled(Context* context) +{ + return context->isUIAvailable(); +} + void AdvancedModeCommand::onExecute(Context* context) { // Switch advanced mode. diff --git a/src/app/commands/cmd_background_from_layer.cpp b/src/app/commands/cmd_background_from_layer.cpp index ffce8e933..5442159b4 100644 --- a/src/app/commands/cmd_background_from_layer.cpp +++ b/src/app/commands/cmd_background_from_layer.cpp @@ -15,7 +15,6 @@ #include "app/modules/gui.h" #include "app/tx.h" #include "doc/layer.h" -#include "doc/sprite.h" namespace app { @@ -28,8 +27,7 @@ protected: void onExecute(Context* context) override; }; -BackgroundFromLayerCommand::BackgroundFromLayerCommand() - : Command(CommandId::BackgroundFromLayer(), CmdRecordableFlag) +BackgroundFromLayerCommand::BackgroundFromLayerCommand() : Command(CommandId::BackgroundFromLayer()) { } diff --git a/src/app/commands/cmd_cancel.cpp b/src/app/commands/cmd_cancel.cpp index 18f37a6a3..83f3b15e9 100644 --- a/src/app/commands/cmd_cancel.cpp +++ b/src/app/commands/cmd_cancel.cpp @@ -37,7 +37,7 @@ private: Type m_type; }; -CancelCommand::CancelCommand() : Command(CommandId::Cancel(), CmdUIOnlyFlag), m_type(NoOp) +CancelCommand::CancelCommand() : Command(CommandId::Cancel()), m_type(NoOp) { } diff --git a/src/app/commands/cmd_canvas_size.cpp b/src/app/commands/cmd_canvas_size.cpp index 20cce8826..f3ad7ea50 100644 --- a/src/app/commands/cmd_canvas_size.cpp +++ b/src/app/commands/cmd_canvas_size.cpp @@ -22,7 +22,6 @@ #include "app/ui/skin/skin_theme.h" #include "app/ui_context.h" #include "doc/image.h" -#include "doc/mask.h" #include "doc/sprite.h" #include "ui/ui.h" @@ -282,8 +281,7 @@ protected: void onExecute(Context* context) override; }; -CanvasSizeCommand::CanvasSizeCommand() - : CommandWithNewParams(CommandId::CanvasSize(), CmdRecordableFlag) +CanvasSizeCommand::CanvasSizeCommand() : CommandWithNewParams(CommandId::CanvasSize()) { } diff --git a/src/app/commands/cmd_cel_opacity.cpp b/src/app/commands/cmd_cel_opacity.cpp index 5773ea417..8119f0090 100644 --- a/src/app/commands/cmd_cel_opacity.cpp +++ b/src/app/commands/cmd_cel_opacity.cpp @@ -20,8 +20,6 @@ #include "app/tx.h" #include "app/ui/timeline/timeline.h" #include "doc/cel.h" -#include "doc/cels_range.h" -#include "doc/sprite.h" #include @@ -42,7 +40,7 @@ private: int m_opacity; }; -CelOpacityCommand::CelOpacityCommand() : Command(CommandId::CelOpacity(), CmdUIOnlyFlag) +CelOpacityCommand::CelOpacityCommand() : Command(CommandId::CelOpacity()) { m_opacity = 255; } diff --git a/src/app/commands/cmd_cel_properties.cpp b/src/app/commands/cmd_cel_properties.cpp index 140f6ec02..fd7b4f85d 100644 --- a/src/app/commands/cmd_cel_properties.cpp +++ b/src/app/commands/cmd_cel_properties.cpp @@ -23,7 +23,6 @@ #include "app/ui/timeline/timeline.h" #include "app/ui/user_data_view.h" #include "app/ui_context.h" -#include "base/mem_utils.h" #include "base/scoped_value.h" #include "doc/cel.h" #include "doc/cels_range.h" @@ -385,14 +384,14 @@ protected: void onExecute(Context* context) override; }; -CelPropertiesCommand::CelPropertiesCommand() : Command(CommandId::CelProperties(), CmdUIOnlyFlag) +CelPropertiesCommand::CelPropertiesCommand() : Command(CommandId::CelProperties()) { } bool CelPropertiesCommand::onEnabled(Context* context) { - return context->checkFlags(ContextFlags::ActiveDocumentIsWritable | - ContextFlags::ActiveLayerIsImage); + return context->isUIAvailable() && context->checkFlags(ContextFlags::ActiveDocumentIsWritable | + ContextFlags::ActiveLayerIsImage); } void CelPropertiesCommand::onExecute(Context* context) diff --git a/src/app/commands/cmd_change_brush.cpp b/src/app/commands/cmd_change_brush.cpp index 71e68d80e..22e570cb5 100644 --- a/src/app/commands/cmd_change_brush.cpp +++ b/src/app/commands/cmd_change_brush.cpp @@ -21,7 +21,6 @@ #include "app/tools/tool.h" #include "app/ui/context_bar.h" #include "app/ui/main_window.h" -#include "base/convert_to.h" #include "doc/algorithm/flip_image.h" #include "doc/brush.h" #include "doc/image_ref.h" @@ -64,7 +63,7 @@ private: int m_slot; }; -ChangeBrushCommand::ChangeBrushCommand() : Command(CommandId::ChangeBrush(), CmdUIOnlyFlag) +ChangeBrushCommand::ChangeBrushCommand() : Command(CommandId::ChangeBrush()) { m_change = None; m_slot = 0; diff --git a/src/app/commands/cmd_change_color.cpp b/src/app/commands/cmd_change_color.cpp index f5e4d8c1c..9c475a308 100644 --- a/src/app/commands/cmd_change_color.cpp +++ b/src/app/commands/cmd_change_color.cpp @@ -14,6 +14,7 @@ #include "app/app.h" #include "app/commands/command.h" #include "app/commands/params.h" +#include "app/context.h" #include "app/i18n/strings.h" #include "app/modules/palettes.h" #include "app/ui/color_bar.h" @@ -39,18 +40,24 @@ public: ChangeColorCommand(); protected: + bool onEnabled(Context* context) override; bool onNeedsParams() const override { return true; } void onLoadParams(const Params& params) override; void onExecute(Context* context) override; std::string onGetFriendlyName() const override; }; -ChangeColorCommand::ChangeColorCommand() : Command(CommandId::ChangeColor(), CmdUIOnlyFlag) +ChangeColorCommand::ChangeColorCommand() : Command(CommandId::ChangeColor()) { m_background = false; m_change = None; } +bool ChangeColorCommand::onEnabled(Context* context) +{ + return context->isUIAvailable(); +} + void ChangeColorCommand::onLoadParams(const Params& params) { std::string target = params.get("target"); diff --git a/src/app/commands/cmd_change_pixel_format.cpp b/src/app/commands/cmd_change_pixel_format.cpp index 7f44bf6df..00639e3b6 100644 --- a/src/app/commands/cmd_change_pixel_format.cpp +++ b/src/app/commands/cmd_change_pixel_format.cpp @@ -21,9 +21,7 @@ #include "app/i18n/strings.h" #include "app/load_matrix.h" #include "app/modules/gui.h" -#include "app/modules/palettes.h" #include "app/sprite_job.h" -#include "app/transaction.h" #include "app/ui/best_fit_criteria_selector.h" #include "app/ui/dithering_selector.h" #include "app/ui/editor/editor.h" @@ -37,12 +35,10 @@ #include "fmt/format.h" #include "render/dithering.h" #include "render/dithering_algorithm.h" -#include "render/ordered_dither.h" #include "render/quantization.h" #include "render/render.h" #include "render/task_delegate.h" #include "ui/listitem.h" -#include "ui/paint_event.h" #include "ui/size_hint_event.h" #include "color_mode.xml.h" @@ -507,7 +503,7 @@ private: }; ChangePixelFormatCommand::ChangePixelFormatCommand() - : CommandWithNewParams(CommandId::ChangePixelFormat(), CmdUIOnlyFlag) + : CommandWithNewParams(CommandId::ChangePixelFormat()) { } diff --git a/src/app/commands/cmd_clear.cpp b/src/app/commands/cmd_clear.cpp index fefd8b6b4..0f6da332d 100644 --- a/src/app/commands/cmd_clear.cpp +++ b/src/app/commands/cmd_clear.cpp @@ -23,7 +23,7 @@ protected: void onExecute(Context* ctx) override; }; -ClearCommand::ClearCommand() : Command(CommandId::Clear(), CmdUIOnlyFlag) +ClearCommand::ClearCommand() : Command(CommandId::Clear()) { } diff --git a/src/app/commands/cmd_clear_cel.cpp b/src/app/commands/cmd_clear_cel.cpp index b2061d0f8..7129fb66b 100644 --- a/src/app/commands/cmd_clear_cel.cpp +++ b/src/app/commands/cmd_clear_cel.cpp @@ -19,7 +19,6 @@ #include "app/ui/status_bar.h" #include "doc/cel.h" #include "doc/layer.h" -#include "doc/sprite.h" namespace app { @@ -32,7 +31,7 @@ protected: void onExecute(Context* context) override; }; -ClearCelCommand::ClearCelCommand() : Command(CommandId::ClearCel(), CmdRecordableFlag) +ClearCelCommand::ClearCelCommand() : Command(CommandId::ClearCel()) { } @@ -76,7 +75,7 @@ void ClearCelCommand::onExecute(Context* context) tx.commit(); } - if (nonEditableLayers) + if (context->isUIAvailable() && nonEditableLayers) StatusBar::instance()->showTip(1000, Strings::statusbar_tips_locked_layers()); update_screen_for_document(document); diff --git a/src/app/commands/cmd_clear_recent_files.cpp b/src/app/commands/cmd_clear_recent_files.cpp index 4c76380c2..06cb44d91 100644 --- a/src/app/commands/cmd_clear_recent_files.cpp +++ b/src/app/commands/cmd_clear_recent_files.cpp @@ -23,8 +23,7 @@ protected: void onExecute(Context* ctx) override; }; -ClearRecentFilesCommand::ClearRecentFilesCommand() - : Command(CommandId::ClearRecentFiles(), CmdUIOnlyFlag) +ClearRecentFilesCommand::ClearRecentFilesCommand() : Command(CommandId::ClearRecentFiles()) { } diff --git a/src/app/commands/cmd_close_file.cpp b/src/app/commands/cmd_close_file.cpp index 57e1ce8e5..48183618d 100644 --- a/src/app/commands/cmd_close_file.cpp +++ b/src/app/commands/cmd_close_file.cpp @@ -12,15 +12,9 @@ #include "app/app.h" #include "app/commands/command.h" #include "app/commands/commands.h" -#include "app/context_access.h" #include "app/ui/doc_view.h" -#include "app/ui/status_bar.h" #include "app/ui/workspace.h" #include "app/ui_context.h" -#include "doc/sprite.h" -#include "ui/ui.h" - -#include namespace app { @@ -28,7 +22,7 @@ using namespace ui; class CloseFileCommand : public Command { public: - CloseFileCommand() : Command(CommandId::CloseFile(), CmdUIOnlyFlag) {} + CloseFileCommand() : Command(CommandId::CloseFile()) {} protected: bool onEnabled(Context* context) override @@ -51,12 +45,15 @@ protected: class CloseAllFilesCommand : public Command { public: - CloseAllFilesCommand() : Command(CommandId::CloseAllFiles(), CmdRecordableFlag) - { - m_quitting = false; - } + CloseAllFilesCommand() : Command(CommandId::CloseAllFiles()) { m_quitting = false; } protected: + bool onEnabled(Context* context) override + { + // Null if we are in --batch mode + return App::instance()->workspace() != nullptr; + } + void onLoadParams(const Params& params) override { m_quitting = params.get_as("quitting"); } void onExecute(Context* context) override diff --git a/src/app/commands/cmd_color_quantization.cpp b/src/app/commands/cmd_color_quantization.cpp index dbd2d7e7c..ef476ee0d 100644 --- a/src/app/commands/cmd_color_quantization.cpp +++ b/src/app/commands/cmd_color_quantization.cpp @@ -21,7 +21,6 @@ #include "app/transaction.h" #include "app/ui/color_bar.h" #include "app/ui/rgbmap_algorithm_selector.h" -#include "app/ui_context.h" #include "doc/palette.h" #include "doc/sprite.h" #include "render/quantization.h" @@ -71,7 +70,7 @@ protected: }; ColorQuantizationCommand::ColorQuantizationCommand() - : CommandWithNewParams(CommandId::ColorQuantization(), CmdRecordableFlag) + : CommandWithNewParams(CommandId::ColorQuantization()) { } diff --git a/src/app/commands/cmd_contiguous_fill.cpp b/src/app/commands/cmd_contiguous_fill.cpp index 2a02336bb..7aed7a8f6 100644 --- a/src/app/commands/cmd_contiguous_fill.cpp +++ b/src/app/commands/cmd_contiguous_fill.cpp @@ -24,7 +24,7 @@ protected: void onExecute(Context* context) override; }; -ContiguousFillCommand::ContiguousFillCommand() : Command(CommandId::ContiguousFill(), CmdUIOnlyFlag) +ContiguousFillCommand::ContiguousFillCommand() : Command(CommandId::ContiguousFill()) { } diff --git a/src/app/commands/cmd_copy.cpp b/src/app/commands/cmd_copy.cpp index 3dabf25c5..627104400 100644 --- a/src/app/commands/cmd_copy.cpp +++ b/src/app/commands/cmd_copy.cpp @@ -23,7 +23,7 @@ protected: void onExecute(Context* ctx) override; }; -CopyCommand::CopyCommand() : Command(CommandId::Copy(), CmdUIOnlyFlag) +CopyCommand::CopyCommand() : Command(CommandId::Copy()) { } diff --git a/src/app/commands/cmd_copy_cel.cpp b/src/app/commands/cmd_copy_cel.cpp index 0b80a02cf..925c7e1e5 100644 --- a/src/app/commands/cmd_copy_cel.cpp +++ b/src/app/commands/cmd_copy_cel.cpp @@ -10,9 +10,7 @@ #include "app/app.h" #include "app/commands/command.h" -#include "app/context_access.h" #include "app/ui/timeline/timeline.h" -#include "ui/base.h" namespace app { @@ -25,13 +23,13 @@ protected: void onExecute(Context* context) override; }; -CopyCelCommand::CopyCelCommand() : Command(CommandId::CopyCel(), CmdUIOnlyFlag) +CopyCelCommand::CopyCelCommand() : Command(CommandId::CopyCel()) { } bool CopyCelCommand::onEnabled(Context* context) { - return App::instance()->timeline()->isMovingCel(); + return App::instance()->timeline() && App::instance()->timeline()->isMovingCel(); } void CopyCelCommand::onExecute(Context* context) diff --git a/src/app/commands/cmd_copy_merged.cpp b/src/app/commands/cmd_copy_merged.cpp index 6458a4dca..c70f1e398 100644 --- a/src/app/commands/cmd_copy_merged.cpp +++ b/src/app/commands/cmd_copy_merged.cpp @@ -24,7 +24,7 @@ protected: void onExecute(Context* ctx) override; }; -CopyMergedCommand::CopyMergedCommand() : Command(CommandId::CopyMerged(), CmdUIOnlyFlag) +CopyMergedCommand::CopyMergedCommand() : Command(CommandId::CopyMerged()) { } diff --git a/src/app/commands/cmd_crop.cpp b/src/app/commands/cmd_crop.cpp index 970472887..070d4b3d3 100644 --- a/src/app/commands/cmd_crop.cpp +++ b/src/app/commands/cmd_crop.cpp @@ -16,11 +16,7 @@ #include "app/modules/gui.h" #include "app/tx.h" #include "app/ui/color_bar.h" -#include "app/util/autocrop.h" -#include "doc/image.h" -#include "doc/layer.h" #include "doc/mask.h" -#include "doc/sprite.h" namespace app { @@ -37,7 +33,7 @@ private: gfx::Rect m_bounds; }; -CropSpriteCommand::CropSpriteCommand() : Command(CommandId::CropSprite(), CmdRecordableFlag) +CropSpriteCommand::CropSpriteCommand() : Command(CommandId::CropSprite()) { } @@ -95,8 +91,7 @@ private: bool m_byGrid = false; }; -AutocropSpriteCommand::AutocropSpriteCommand() - : Command(CommandId::AutocropSprite(), CmdRecordableFlag) +AutocropSpriteCommand::AutocropSpriteCommand() : Command(CommandId::AutocropSprite()) { } diff --git a/src/app/commands/cmd_cut.cpp b/src/app/commands/cmd_cut.cpp index ec3d370a8..50973c27d 100644 --- a/src/app/commands/cmd_cut.cpp +++ b/src/app/commands/cmd_cut.cpp @@ -23,7 +23,7 @@ protected: void onExecute(Context* ctx) override; }; -CutCommand::CutCommand() : Command(CommandId::Cut(), CmdUIOnlyFlag) +CutCommand::CutCommand() : Command(CommandId::Cut()) { } diff --git a/src/app/commands/cmd_deselect_mask.cpp b/src/app/commands/cmd_deselect_mask.cpp index 1ce6495e9..530b51f15 100644 --- a/src/app/commands/cmd_deselect_mask.cpp +++ b/src/app/commands/cmd_deselect_mask.cpp @@ -14,8 +14,6 @@ #include "app/context_access.h" #include "app/modules/gui.h" #include "app/tx.h" -#include "doc/mask.h" -#include "doc/sprite.h" namespace app { @@ -28,7 +26,7 @@ protected: void onExecute(Context* context) override; }; -DeselectMaskCommand::DeselectMaskCommand() : Command(CommandId::DeselectMask(), CmdRecordableFlag) +DeselectMaskCommand::DeselectMaskCommand() : Command(CommandId::DeselectMask()) { } diff --git a/src/app/commands/cmd_developer_console.cpp b/src/app/commands/cmd_developer_console.cpp index 821e1282e..1489653b2 100644 --- a/src/app/commands/cmd_developer_console.cpp +++ b/src/app/commands/cmd_developer_console.cpp @@ -29,8 +29,7 @@ protected: void onExecute(Context* context); }; -DeveloperConsoleCommand::DeveloperConsoleCommand() - : Command(CommandId::DeveloperConsole(), CmdUIOnlyFlag) +DeveloperConsoleCommand::DeveloperConsoleCommand() : Command(CommandId::DeveloperConsole()) { } diff --git a/src/app/commands/cmd_discard_brush.cpp b/src/app/commands/cmd_discard_brush.cpp index 49a1d45e1..ccbbd78d5 100644 --- a/src/app/commands/cmd_discard_brush.cpp +++ b/src/app/commands/cmd_discard_brush.cpp @@ -12,8 +12,6 @@ #include "app/app.h" #include "app/commands/command.h" #include "app/commands/commands.h" -#include "app/context_access.h" -#include "app/tools/tool_box.h" #include "app/ui/context_bar.h" #include "app/ui_context.h" @@ -28,12 +26,15 @@ protected: void onExecute(Context* context) override; }; -DiscardBrushCommand::DiscardBrushCommand() : Command(CommandId::DiscardBrush(), CmdUIOnlyFlag) +DiscardBrushCommand::DiscardBrushCommand() : Command(CommandId::DiscardBrush()) { } bool DiscardBrushCommand::onEnabled(Context* context) { + if (!context->isUIAvailable()) + return false; + ContextBar* ctxBar = App::instance()->contextBar(); return (ctxBar->activeBrush()->type() == kImageBrushType); } diff --git a/src/app/commands/cmd_duplicate_layer.cpp b/src/app/commands/cmd_duplicate_layer.cpp index 52a96a5a0..9b5a61bf2 100644 --- a/src/app/commands/cmd_duplicate_layer.cpp +++ b/src/app/commands/cmd_duplicate_layer.cpp @@ -10,16 +10,11 @@ #include "app/app.h" #include "app/commands/command.h" -#include "app/console.h" #include "app/context_access.h" #include "app/doc_api.h" -#include "app/doc_undo.h" #include "app/modules/gui.h" #include "app/tx.h" -#include "app/ui/editor/editor.h" #include "doc/layer.h" -#include "doc/sprite.h" -#include "ui/ui.h" namespace app { @@ -32,8 +27,7 @@ protected: void onExecute(Context* context) override; }; -DuplicateLayerCommand::DuplicateLayerCommand() - : Command(CommandId::DuplicateLayer(), CmdRecordableFlag) +DuplicateLayerCommand::DuplicateLayerCommand() : Command(CommandId::DuplicateLayer()) { } diff --git a/src/app/commands/cmd_duplicate_sprite.cpp b/src/app/commands/cmd_duplicate_sprite.cpp index 3d4047958..e4b025c89 100644 --- a/src/app/commands/cmd_duplicate_sprite.cpp +++ b/src/app/commands/cmd_duplicate_sprite.cpp @@ -16,13 +16,10 @@ #include "app/ini_file.h" #include "app/ui_context.h" #include "base/fs.h" -#include "doc/sprite.h" #include "ui/ui.h" #include "duplicate_sprite.xml.h" -#include - namespace app { using namespace ui; @@ -43,7 +40,7 @@ protected: }; DuplicateSpriteCommand::DuplicateSpriteCommand() - : CommandWithNewParams(CommandId::DuplicateSprite(), CmdRecordableFlag) + : CommandWithNewParams(CommandId::DuplicateSprite()) { } diff --git a/src/app/commands/cmd_duplicate_view.cpp b/src/app/commands/cmd_duplicate_view.cpp index 4f1ecedff..15c4008d3 100644 --- a/src/app/commands/cmd_duplicate_view.cpp +++ b/src/app/commands/cmd_duplicate_view.cpp @@ -13,8 +13,6 @@ #include "app/commands/command.h" #include "app/ui/workspace.h" -#include - namespace app { // using namespace ui; @@ -28,7 +26,7 @@ protected: void onExecute(Context* context) override; }; -DuplicateViewCommand::DuplicateViewCommand() : Command(CommandId::DuplicateView(), CmdUIOnlyFlag) +DuplicateViewCommand::DuplicateViewCommand() : Command(CommandId::DuplicateView()) { } diff --git a/src/app/commands/cmd_enter_license.cpp b/src/app/commands/cmd_enter_license.cpp index 342761c94..3b6fa0e96 100644 --- a/src/app/commands/cmd_enter_license.cpp +++ b/src/app/commands/cmd_enter_license.cpp @@ -5,7 +5,6 @@ // the End-User License Agreement for Aseprite. #include "app/commands/command.h" -#include "app/context.h" #ifdef ENABLE_DRM #include "app/ui/enter_license.h" @@ -24,7 +23,7 @@ protected: void onExecute(Context* context) override; }; -EnterLicenseCommand::EnterLicenseCommand() : Command(CommandId::EnterLicense(), CmdUIOnlyFlag) +EnterLicenseCommand::EnterLicenseCommand() : Command(CommandId::EnterLicense()) { } diff --git a/src/app/commands/cmd_exit.cpp b/src/app/commands/cmd_exit.cpp index bafd6981a..aa55cb565 100644 --- a/src/app/commands/cmd_exit.cpp +++ b/src/app/commands/cmd_exit.cpp @@ -16,7 +16,6 @@ #include "app/doc.h" #include "app/job.h" #include "app/ui/main_window.h" -#include "ui/alert.h" #ifdef ENABLE_SCRIPTING #include "app/commands/debugger.h" @@ -32,7 +31,7 @@ protected: void onExecute(Context* context) override; }; -ExitCommand::ExitCommand() : Command(CommandId::Exit(), CmdUIOnlyFlag) +ExitCommand::ExitCommand() : Command(CommandId::Exit()) { } diff --git a/src/app/commands/cmd_export_sprite_sheet.cpp b/src/app/commands/cmd_export_sprite_sheet.cpp index b24dc314e..bb40ec0c2 100644 --- a/src/app/commands/cmd_export_sprite_sheet.cpp +++ b/src/app/commands/cmd_export_sprite_sheet.cpp @@ -33,15 +33,12 @@ #include "app/ui/status_bar.h" #include "app/ui/timeline/timeline.h" #include "app/util/layer_utils.h" -#include "base/convert_to.h" #include "base/fs.h" #include "base/string.h" #include "base/thread.h" #include "doc/layer.h" -#include "doc/layer_tilemap.h" #include "doc/tag.h" #include "doc/tileset.h" -#include "doc/tilesets.h" #include "fmt/format.h" #include "ui/message.h" #include "ui/system.h" @@ -1187,8 +1184,7 @@ private: } // anonymous namespace -ExportSpriteSheetCommand::ExportSpriteSheetCommand(const char* id) - : CommandWithNewParams(id, CmdRecordableFlag) +ExportSpriteSheetCommand::ExportSpriteSheetCommand(const char* id) : CommandWithNewParams(id) { } diff --git a/src/app/commands/cmd_eyedropper.cpp b/src/app/commands/cmd_eyedropper.cpp index 330c6c8a7..476f234e8 100644 --- a/src/app/commands/cmd_eyedropper.cpp +++ b/src/app/commands/cmd_eyedropper.cpp @@ -17,7 +17,6 @@ #include "app/context.h" #include "app/pref/preferences.h" #include "app/site.h" -#include "app/tools/tool.h" #include "app/tools/tool_box.h" #include "app/ui/color_bar.h" #include "app/ui/editor/editor.h" @@ -28,7 +27,7 @@ namespace app { using namespace ui; -EyedropperCommand::EyedropperCommand() : Command(CommandId::Eyedropper(), CmdUIOnlyFlag) +EyedropperCommand::EyedropperCommand() : Command(CommandId::Eyedropper()) { m_background = false; } diff --git a/src/app/commands/cmd_fill_and_stroke.cpp b/src/app/commands/cmd_fill_and_stroke.cpp index 95c3cd4b3..c617c1e7a 100644 --- a/src/app/commands/cmd_fill_and_stroke.cpp +++ b/src/app/commands/cmd_fill_and_stroke.cpp @@ -39,7 +39,7 @@ private: }; FillCommand::FillCommand(Type type) - : Command(type == Stroke ? CommandId::Stroke() : CommandId::Fill(), CmdUIOnlyFlag) + : Command(type == Stroke ? CommandId::Stroke() : CommandId::Fill()) , m_type(type) { } diff --git a/src/app/commands/cmd_fit_screen.cpp b/src/app/commands/cmd_fit_screen.cpp index cc9072e20..bd09bf7de 100644 --- a/src/app/commands/cmd_fit_screen.cpp +++ b/src/app/commands/cmd_fit_screen.cpp @@ -11,7 +11,6 @@ #include "app/app.h" #include "app/commands/command.h" -#include "app/context_access.h" #include "app/ui/editor/editor.h" namespace app { @@ -25,7 +24,7 @@ protected: void onExecute(Context* context) override; }; -FitScreenCommand::FitScreenCommand() : Command(CommandId::FitScreen(), CmdUIOnlyFlag) +FitScreenCommand::FitScreenCommand() : Command(CommandId::FitScreen()) { } diff --git a/src/app/commands/cmd_flatten_layers.cpp b/src/app/commands/cmd_flatten_layers.cpp index 6f53390c8..3680d2568 100644 --- a/src/app/commands/cmd_flatten_layers.cpp +++ b/src/app/commands/cmd_flatten_layers.cpp @@ -36,7 +36,7 @@ protected: bool m_visibleOnly; }; -FlattenLayersCommand::FlattenLayersCommand() : Command(CommandId::FlattenLayers(), CmdUIOnlyFlag) +FlattenLayersCommand::FlattenLayersCommand() : Command(CommandId::FlattenLayers()) { m_visibleOnly = false; } diff --git a/src/app/commands/cmd_flip.cpp b/src/app/commands/cmd_flip.cpp index 8dc8d5a21..0bd14833f 100644 --- a/src/app/commands/cmd_flip.cpp +++ b/src/app/commands/cmd_flip.cpp @@ -20,7 +20,6 @@ #include "app/commands/params.h" #include "app/context_access.h" #include "app/doc_api.h" -#include "app/doc_range.h" #include "app/i18n/strings.h" #include "app/modules/gui.h" #include "app/tools/tool_box.h" @@ -38,11 +37,10 @@ #include "doc/layer.h" #include "doc/mask.h" #include "doc/sprite.h" -#include "gfx/size.h" namespace app { -FlipCommand::FlipCommand() : Command(CommandId::Flip(), CmdRecordableFlag) +FlipCommand::FlipCommand() : Command(CommandId::Flip()) { m_flipMask = false; m_flipType = doc::algorithm::FlipHorizontal; diff --git a/src/app/commands/cmd_frame_properties.cpp b/src/app/commands/cmd_frame_properties.cpp index 32a5ebc26..d6c24efb1 100644 --- a/src/app/commands/cmd_frame_properties.cpp +++ b/src/app/commands/cmd_frame_properties.cpp @@ -44,12 +44,11 @@ private: // Frame to be shown. It can be ALL_FRAMES, CURRENT_RANGE, or a // number indicating a specific frame (1 is the first frame). - Target m_target; - frame_t m_frame; + Target m_target = CURRENT_RANGE; + frame_t m_frame = 1; }; -FramePropertiesCommand::FramePropertiesCommand() - : Command(CommandId::FrameProperties(), CmdUIOnlyFlag) +FramePropertiesCommand::FramePropertiesCommand() : Command(CommandId::FrameProperties()) { } @@ -59,7 +58,7 @@ void FramePropertiesCommand::onLoadParams(const Params& params) if (frame == "all") { m_target = ALL_FRAMES; } - else if (frame == "current") { + else if (frame == "current" || !params.has_param("frame")) { m_target = CURRENT_RANGE; } else { @@ -70,7 +69,7 @@ void FramePropertiesCommand::onLoadParams(const Params& params) bool FramePropertiesCommand::onEnabled(Context* context) { - return context->checkFlags(ContextFlags::ActiveDocumentIsWritable); + return context->isUIAvailable() && context->checkFlags(ContextFlags::ActiveDocumentIsWritable); } void FramePropertiesCommand::onExecute(Context* context) diff --git a/src/app/commands/cmd_frame_tag_properties.cpp b/src/app/commands/cmd_frame_tag_properties.cpp index 0dfad1bd4..52e974f69 100644 --- a/src/app/commands/cmd_frame_tag_properties.cpp +++ b/src/app/commands/cmd_frame_tag_properties.cpp @@ -15,7 +15,6 @@ #include "app/cmd/set_tag_range.h" #include "app/cmd/set_tag_repeat.h" #include "app/cmd/set_user_data.h" -#include "app/color.h" #include "app/commands/command.h" #include "app/commands/params.h" #include "app/context_access.h" @@ -48,7 +47,7 @@ private: }; FrameTagPropertiesCommand::FrameTagPropertiesCommand() - : Command(CommandId::FrameTagProperties(), CmdUIOnlyFlag) + : Command(CommandId::FrameTagProperties()) , m_tagId(NullId) { } @@ -66,7 +65,7 @@ void FrameTagPropertiesCommand::onLoadParams(const Params& params) bool FrameTagPropertiesCommand::onEnabled(Context* context) { - return context->checkFlags(ContextFlags::ActiveDocumentIsWritable); + return context->isUIAvailable() && context->checkFlags(ContextFlags::ActiveDocumentIsWritable); } void FrameTagPropertiesCommand::onExecute(Context* context) diff --git a/src/app/commands/cmd_fullscreen_mode.cpp b/src/app/commands/cmd_fullscreen_mode.cpp index 96c724514..6da63f8c1 100644 --- a/src/app/commands/cmd_fullscreen_mode.cpp +++ b/src/app/commands/cmd_fullscreen_mode.cpp @@ -27,7 +27,7 @@ protected: void onExecute(Context* context) override; }; -FullscreenModeCommand::FullscreenModeCommand() : Command(CommandId::FullscreenMode(), CmdUIOnlyFlag) +FullscreenModeCommand::FullscreenModeCommand() : Command(CommandId::FullscreenMode()) { } diff --git a/src/app/commands/cmd_fullscreen_preview.cpp b/src/app/commands/cmd_fullscreen_preview.cpp index 96874c23a..eea755197 100644 --- a/src/app/commands/cmd_fullscreen_preview.cpp +++ b/src/app/commands/cmd_fullscreen_preview.cpp @@ -23,10 +23,7 @@ #include "app/ui/main_window.h" #include "app/ui/preview_editor.h" #include "app/ui/status_bar.h" -#include "app/util/conversion_to_surface.h" -#include "doc/image.h" #include "doc/palette.h" -#include "doc/primitives.h" #include "doc/sprite.h" #include "gfx/matrix.h" #include "os/surface.h" @@ -308,8 +305,7 @@ protected: void onExecute(Context* context) override; }; -FullscreenPreviewCommand::FullscreenPreviewCommand() - : Command(CommandId::FullscreenPreview(), CmdUIOnlyFlag) +FullscreenPreviewCommand::FullscreenPreviewCommand() : Command(CommandId::FullscreenPreview()) { } diff --git a/src/app/commands/cmd_goto_frame.cpp b/src/app/commands/cmd_goto_frame.cpp index b82ae136b..ea3cd7827 100644 --- a/src/app/commands/cmd_goto_frame.cpp +++ b/src/app/commands/cmd_goto_frame.cpp @@ -31,7 +31,7 @@ using namespace doc; class GotoCommand : public Command { protected: - GotoCommand(const char* id) : Command(id, CmdRecordableFlag) {} + GotoCommand(const char* id) : Command(id) {} bool onEnabled(Context* context) override { return (Editor::activeEditor() != nullptr); } diff --git a/src/app/commands/cmd_goto_layer.cpp b/src/app/commands/cmd_goto_layer.cpp index 55a15911a..ec74629d8 100644 --- a/src/app/commands/cmd_goto_layer.cpp +++ b/src/app/commands/cmd_goto_layer.cpp @@ -24,11 +24,7 @@ namespace app { class GotoLayerCommand : public Command { public: - GotoLayerCommand(int offset, const char* id, CommandFlags flags) - : Command(id, flags) - , m_offset(offset) - { - } + GotoLayerCommand(int offset, const char* id) : Command(id), m_offset(offset) {} protected: bool onEnabled(Context* context) override @@ -88,12 +84,12 @@ private: class GotoPreviousLayerCommand : public GotoLayerCommand { public: - GotoPreviousLayerCommand() : GotoLayerCommand(-1, "GotoPreviousLayer", CmdUIOnlyFlag) {} + GotoPreviousLayerCommand() : GotoLayerCommand(-1, CommandId::GotoPreviousLayer()) {} }; class GotoNextLayerCommand : public GotoLayerCommand { public: - GotoNextLayerCommand() : GotoLayerCommand(+1, "GotoNextLayer", CmdUIOnlyFlag) {} + GotoNextLayerCommand() : GotoLayerCommand(+1, CommandId::GotoNextLayer()) {} }; Command* CommandFactory::createGotoPreviousLayerCommand() diff --git a/src/app/commands/cmd_goto_tab.cpp b/src/app/commands/cmd_goto_tab.cpp index 1c8da8a02..1178ff460 100644 --- a/src/app/commands/cmd_goto_tab.cpp +++ b/src/app/commands/cmd_goto_tab.cpp @@ -24,7 +24,7 @@ protected: void onExecute(Context* context) override; }; -GotoNextTabCommand::GotoNextTabCommand() : Command(CommandId::GotoNextTab(), CmdUIOnlyFlag) +GotoNextTabCommand::GotoNextTabCommand() : Command(CommandId::GotoNextTab()) { } @@ -50,8 +50,7 @@ protected: void onExecute(Context* context) override; }; -GotoPreviousTabCommand::GotoPreviousTabCommand() - : Command(CommandId::GotoPreviousTab(), CmdRecordableFlag) +GotoPreviousTabCommand::GotoPreviousTabCommand() : Command(CommandId::GotoPreviousTab()) { } diff --git a/src/app/commands/cmd_grid.cpp b/src/app/commands/cmd_grid.cpp index 686ddc58f..b6f315145 100644 --- a/src/app/commands/cmd_grid.cpp +++ b/src/app/commands/cmd_grid.cpp @@ -15,13 +15,9 @@ #include "app/context.h" #include "app/context_access.h" #include "app/doc.h" -#include "app/find_widget.h" -#include "app/load_widget.h" #include "app/pref/preferences.h" #include "app/tx.h" #include "app/ui/status_bar.h" -#include "app/ui_context.h" -#include "doc/document.h" #include "doc/mask.h" #include "ui/window.h" @@ -36,7 +32,7 @@ using namespace gfx; class SnapToGridCommand : public Command { public: - SnapToGridCommand() : Command(CommandId::SnapToGrid(), CmdUIOnlyFlag) {} + SnapToGridCommand() : Command(CommandId::SnapToGrid()) {} protected: bool onChecked(Context* ctx) override @@ -51,13 +47,14 @@ protected: bool newValue = !docPref.grid.snap(); docPref.grid.snap(newValue); - StatusBar::instance()->showSnapToGridWarning(newValue); + if (ctx->isUIAvailable()) + StatusBar::instance()->showSnapToGridWarning(newValue); } }; class SelectionAsGridCommand : public Command { public: - SelectionAsGridCommand() : Command(CommandId::SelectionAsGrid(), CmdUIOnlyFlag) {} + SelectionAsGridCommand() : Command(CommandId::SelectionAsGrid()) {} protected: bool onEnabled(Context* ctx) override @@ -92,13 +89,13 @@ protected: void onExecute(Context* context) override; }; -GridSettingsCommand::GridSettingsCommand() : Command(CommandId::GridSettings(), CmdUIOnlyFlag) +GridSettingsCommand::GridSettingsCommand() : Command(CommandId::GridSettings()) { } bool GridSettingsCommand::onEnabled(Context* context) { - return true; + return context->isUIAvailable(); } void GridSettingsCommand::onExecute(Context* context) diff --git a/src/app/commands/cmd_home.cpp b/src/app/commands/cmd_home.cpp index 2bd528178..91a91e520 100644 --- a/src/app/commands/cmd_home.cpp +++ b/src/app/commands/cmd_home.cpp @@ -10,6 +10,7 @@ #include "app/app.h" #include "app/commands/command.h" +#include "app/context.h" #include "app/ui/main_window.h" namespace app { @@ -26,7 +27,7 @@ protected: bool onEnabled(Context* context) override; }; -HomeCommand::HomeCommand() : Command(CommandId::Home(), CmdUIOnlyFlag) +HomeCommand::HomeCommand() : Command(CommandId::Home()) { } @@ -41,7 +42,7 @@ void HomeCommand::onExecute(Context* context) bool HomeCommand::onEnabled(Context* context) { - return !App::instance()->mainWindow()->isHomeSelected(); + return context->isUIAvailable() && !App::instance()->mainWindow()->isHomeSelected(); } Command* CommandFactory::createHomeCommand() diff --git a/src/app/commands/cmd_import_sprite_sheet.cpp b/src/app/commands/cmd_import_sprite_sheet.cpp index 05e12bb76..78cae93f0 100644 --- a/src/app/commands/cmd_import_sprite_sheet.cpp +++ b/src/app/commands/cmd_import_sprite_sheet.cpp @@ -20,20 +20,14 @@ #include "app/doc_api.h" #include "app/i18n/strings.h" #include "app/modules/gui.h" -#include "app/modules/palettes.h" #include "app/pref/preferences.h" #include "app/tx.h" -#include "app/ui/drop_down_button.h" #include "app/ui/editor/editor.h" -#include "app/ui/editor/editor_decorator.h" #include "app/ui/editor/select_box_state.h" -#include "app/ui/editor/standby_state.h" #include "app/ui/workspace.h" #include "doc/cel.h" #include "doc/image.h" #include "doc/layer.h" -#include "doc/palette.h" -#include "doc/primitives.h" #include "doc/sprite.h" #include "render/render.h" #include "ui/ui.h" @@ -518,7 +512,7 @@ protected: }; ImportSpriteSheetCommand::ImportSpriteSheetCommand() - : CommandWithNewParams(CommandId::ImportSpriteSheet(), CmdRecordableFlag) + : CommandWithNewParams(CommandId::ImportSpriteSheet()) { } diff --git a/src/app/commands/cmd_invert_mask.cpp b/src/app/commands/cmd_invert_mask.cpp index c240b4d2a..d630903a2 100644 --- a/src/app/commands/cmd_invert_mask.cpp +++ b/src/app/commands/cmd_invert_mask.cpp @@ -31,7 +31,7 @@ protected: void onExecute(Context* context) override; }; -InvertMaskCommand::InvertMaskCommand() : Command(CommandId::InvertMask(), CmdRecordableFlag) +InvertMaskCommand::InvertMaskCommand() : Command(CommandId::InvertMask()) { } diff --git a/src/app/commands/cmd_keyboard_shortcuts.cpp b/src/app/commands/cmd_keyboard_shortcuts.cpp index e3d3042d0..c85fcc9d7 100644 --- a/src/app/commands/cmd_keyboard_shortcuts.cpp +++ b/src/app/commands/cmd_keyboard_shortcuts.cpp @@ -26,22 +26,17 @@ #include "app/ui/select_shortcut.h" #include "app/ui/separator_in_view.h" #include "app/ui/skin/skin_theme.h" -#include "base/fs.h" #include "base/pi.h" #include "base/scoped_value.h" -#include "base/split_string.h" -#include "base/string.h" #include "ui/alert.h" #include "ui/fit_bounds.h" #include "ui/graphics.h" #include "ui/listitem.h" #include "ui/message.h" #include "ui/paint_event.h" -#include "ui/resize_event.h" #include "ui/separator.h" #include "ui/size_hint_event.h" #include "ui/splitter.h" -#include "ui/system.h" #include "keyboard_shortcuts.xml.h" @@ -977,6 +972,7 @@ public: KeyboardShortcutsCommand(); protected: + bool onEnabled(Context* context) override; void onLoadParams(const Params& params) override; void onExecute(Context* context) override; @@ -986,11 +982,15 @@ private: std::string m_search; }; -KeyboardShortcutsCommand::KeyboardShortcutsCommand() - : Command(CommandId::KeyboardShortcuts(), CmdUIOnlyFlag) +KeyboardShortcutsCommand::KeyboardShortcutsCommand() : Command(CommandId::KeyboardShortcuts()) { } +bool KeyboardShortcutsCommand::onEnabled(Context* context) +{ + return context->isUIAvailable(); +} + void KeyboardShortcutsCommand::onLoadParams(const Params& params) { m_search = params.get("search"); diff --git a/src/app/commands/cmd_launch.cpp b/src/app/commands/cmd_launch.cpp index b9046eb7f..17382c1c4 100644 --- a/src/app/commands/cmd_launch.cpp +++ b/src/app/commands/cmd_launch.cpp @@ -34,10 +34,7 @@ private: std::string m_path; }; -LaunchCommand::LaunchCommand() - : Command(CommandId::Launch(), CmdUIOnlyFlag) - , m_type(Url) - , m_path("") +LaunchCommand::LaunchCommand() : Command(CommandId::Launch()), m_type(Url), m_path("") { } diff --git a/src/app/commands/cmd_layer_from_background.cpp b/src/app/commands/cmd_layer_from_background.cpp index 987d7ae61..38a9f6df5 100644 --- a/src/app/commands/cmd_layer_from_background.cpp +++ b/src/app/commands/cmd_layer_from_background.cpp @@ -14,8 +14,6 @@ #include "app/context_access.h" #include "app/modules/gui.h" #include "app/tx.h" -#include "doc/layer.h" -#include "doc/sprite.h" namespace app { @@ -28,8 +26,7 @@ protected: void onExecute(Context* context) override; }; -LayerFromBackgroundCommand::LayerFromBackgroundCommand() - : Command(CommandId::LayerFromBackground(), CmdRecordableFlag) +LayerFromBackgroundCommand::LayerFromBackgroundCommand() : Command(CommandId::LayerFromBackground()) { } diff --git a/src/app/commands/cmd_layer_lock.cpp b/src/app/commands/cmd_layer_lock.cpp index 672ca599a..cc6f421b6 100644 --- a/src/app/commands/cmd_layer_lock.cpp +++ b/src/app/commands/cmd_layer_lock.cpp @@ -9,11 +9,9 @@ #include "config.h" #endif -#include "app/app.h" #include "app/commands/command.h" #include "app/context_access.h" #include "app/modules/gui.h" -#include "doc/image.h" #include "doc/layer.h" namespace app { @@ -30,7 +28,7 @@ protected: void onExecute(Context* context) override; }; -LayerLockCommand::LayerLockCommand() : Command(CommandId::LayerLock(), CmdRecordableFlag) +LayerLockCommand::LayerLockCommand() : Command(CommandId::LayerLock()) { } diff --git a/src/app/commands/cmd_layer_opacity.cpp b/src/app/commands/cmd_layer_opacity.cpp index 60aeb92c3..92c5aeec4 100644 --- a/src/app/commands/cmd_layer_opacity.cpp +++ b/src/app/commands/cmd_layer_opacity.cpp @@ -9,7 +9,6 @@ #include "config.h" #endif -#include "app/app.h" #include "app/cmd/set_layer_opacity.h" #include "app/commands/command.h" #include "app/commands/params.h" @@ -40,7 +39,7 @@ private: int m_opacity; }; -LayerOpacityCommand::LayerOpacityCommand() : Command(CommandId::LayerOpacity(), CmdUIOnlyFlag) +LayerOpacityCommand::LayerOpacityCommand() : Command(CommandId::LayerOpacity()) { m_opacity = 255; } diff --git a/src/app/commands/cmd_layer_properties.cpp b/src/app/commands/cmd_layer_properties.cpp index dd06d370f..869a9b897 100644 --- a/src/app/commands/cmd_layer_properties.cpp +++ b/src/app/commands/cmd_layer_properties.cpp @@ -34,7 +34,6 @@ #include "app/ui_context.h" #include "base/convert_to.h" #include "base/scoped_value.h" -#include "doc/image.h" #include "doc/layer.h" #include "doc/layer_tilemap.h" #include "doc/sprite.h" @@ -500,14 +499,14 @@ private: bool m_remapAfterConfigure = false; }; -LayerPropertiesCommand::LayerPropertiesCommand() - : Command(CommandId::LayerProperties(), CmdRecordableFlag) +LayerPropertiesCommand::LayerPropertiesCommand() : Command(CommandId::LayerProperties()) { } bool LayerPropertiesCommand::onEnabled(Context* context) { - return context->checkFlags(ContextFlags::ActiveDocumentIsWritable | ContextFlags::HasActiveLayer); + return context->isUIAvailable() && + context->checkFlags(ContextFlags::ActiveDocumentIsWritable | ContextFlags::HasActiveLayer); } void LayerPropertiesCommand::onExecute(Context* context) diff --git a/src/app/commands/cmd_layer_visibility.cpp b/src/app/commands/cmd_layer_visibility.cpp index e9572966b..c812b03b1 100644 --- a/src/app/commands/cmd_layer_visibility.cpp +++ b/src/app/commands/cmd_layer_visibility.cpp @@ -12,7 +12,6 @@ #include "app/commands/command.h" #include "app/context_access.h" #include "app/modules/gui.h" -#include "doc/image.h" #include "doc/layer.h" namespace app { @@ -29,8 +28,7 @@ protected: void onExecute(Context* context) override; }; -LayerVisibilityCommand::LayerVisibilityCommand() - : Command(CommandId::LayerVisibility(), CmdRecordableFlag) +LayerVisibilityCommand::LayerVisibilityCommand() : Command(CommandId::LayerVisibility()) { } diff --git a/src/app/commands/cmd_link_cels.cpp b/src/app/commands/cmd_link_cels.cpp index 1baaef7a8..4d46093d9 100644 --- a/src/app/commands/cmd_link_cels.cpp +++ b/src/app/commands/cmd_link_cels.cpp @@ -18,7 +18,6 @@ #include "app/ui/status_bar.h" #include "doc/cel.h" #include "doc/layer.h" -#include "doc/sprite.h" namespace app { @@ -31,7 +30,7 @@ protected: void onExecute(Context* context) override; }; -LinkCelsCommand::LinkCelsCommand() : Command(CommandId::LinkCels(), CmdRecordableFlag) +LinkCelsCommand::LinkCelsCommand() : Command(CommandId::LinkCels()) { } @@ -88,7 +87,7 @@ void LinkCelsCommand::onExecute(Context* context) tx.commit(); } - if (nonEditableLayers) + if (context->isUIAvailable() && nonEditableLayers) StatusBar::instance()->showTip(1000, Strings::statusbar_tips_locked_layers()); update_screen_for_document(document); diff --git a/src/app/commands/cmd_load_mask.cpp b/src/app/commands/cmd_load_mask.cpp index 077ced661..387c766c8 100644 --- a/src/app/commands/cmd_load_mask.cpp +++ b/src/app/commands/cmd_load_mask.cpp @@ -26,6 +26,7 @@ namespace app { class LoadMaskCommand : public Command { std::string m_filename; + bool m_ui = true; public: LoadMaskCommand(); @@ -36,13 +37,16 @@ protected: void onExecute(Context* context) override; }; -LoadMaskCommand::LoadMaskCommand() : Command(CommandId::LoadMask(), CmdRecordableFlag) +LoadMaskCommand::LoadMaskCommand() : Command(CommandId::LoadMask()) { - m_filename = ""; } void LoadMaskCommand::onLoadParams(const Params& params) { + if (params.has_param("ui")) + m_ui = params.get_as("ui"); + else + m_ui = true; m_filename = params.get("filename"); } @@ -55,7 +59,7 @@ void LoadMaskCommand::onExecute(Context* context) { const ContextReader reader(context); - if (context->isUIAvailable()) { + if (context->isUIAvailable() && m_ui) { base::paths exts = { "msk" }; base::paths selectedFilename; if (!app::show_file_selector(Strings::load_selection_title(), @@ -70,7 +74,8 @@ void LoadMaskCommand::onExecute(Context* context) std::unique_ptr mask(load_msk_file(m_filename.c_str())); if (!mask) { - ui::Alert::show(Strings::alerts_error_loading_file(m_filename)); + if (context->isUIAvailable()) + ui::Alert::show(Strings::alerts_error_loading_file(m_filename)); return; } diff --git a/src/app/commands/cmd_load_palette.cpp b/src/app/commands/cmd_load_palette.cpp index 6d42d7174..f346aa701 100644 --- a/src/app/commands/cmd_load_palette.cpp +++ b/src/app/commands/cmd_load_palette.cpp @@ -37,14 +37,19 @@ protected: private: std::string m_preset; std::string m_filename; + bool m_ui = true; }; -LoadPaletteCommand::LoadPaletteCommand() : Command(CommandId::LoadPalette(), CmdRecordableFlag) +LoadPaletteCommand::LoadPaletteCommand() : Command(CommandId::LoadPalette()) { } void LoadPaletteCommand::onLoadParams(const Params& params) { + if (params.has_param("ui")) + m_ui = params.get_as("ui"); + else + m_ui = true; m_preset = params.get("preset"); m_filename = params.get("filename"); } @@ -58,20 +63,20 @@ void LoadPaletteCommand::onExecute(Context* context) if (!base::is_file(filename)) filename = get_preset_palette_filename(m_preset, ".gpl"); } - else if (!m_filename.empty()) { - filename = m_filename; - } - else if (context->isUIAvailable()) { - base::paths exts = get_readable_palette_extensions(); + else if (context->isUIAvailable() && m_ui) { + const base::paths exts = get_readable_palette_extensions(); base::paths filenames; if (app::show_file_selector(Strings::load_palette_title(), - "", + m_filename, exts, FileSelectorType::Open, filenames)) { filename = filenames.front(); } } + else if (!m_filename.empty()) { + filename = m_filename; + } // Do nothing if (filename.empty()) diff --git a/src/app/commands/cmd_mask_all.cpp b/src/app/commands/cmd_mask_all.cpp index 8dba4d296..c5876ed45 100644 --- a/src/app/commands/cmd_mask_all.cpp +++ b/src/app/commands/cmd_mask_all.cpp @@ -29,7 +29,7 @@ protected: void onExecute(Context* context) override; }; -MaskAllCommand::MaskAllCommand() : Command(CommandId::MaskAll(), CmdRecordableFlag) +MaskAllCommand::MaskAllCommand() : Command(CommandId::MaskAll()) { } diff --git a/src/app/commands/cmd_mask_by_color.cpp b/src/app/commands/cmd_mask_by_color.cpp index b3290ec3b..ff94ef176 100644 --- a/src/app/commands/cmd_mask_by_color.cpp +++ b/src/app/commands/cmd_mask_by_color.cpp @@ -15,7 +15,6 @@ #include "app/color_utils.h" #include "app/commands/command.h" #include "app/commands/new_params.h" -#include "app/console.h" #include "app/context.h" #include "app/context_access.h" #include "app/doc.h" @@ -26,9 +25,6 @@ #include "app/ui/color_bar.h" #include "app/ui/color_button.h" #include "app/ui/selection_mode_field.h" -#include "base/chrono.h" -#include "base/convert_to.h" -#include "base/scoped_value.h" #include "doc/image.h" #include "doc/mask.h" #include "doc/sprite.h" @@ -203,8 +199,7 @@ protected: void onExecute(Context* context) override; }; -MaskByColorCommand::MaskByColorCommand() - : CommandWithNewParams(CommandId::MaskByColor(), CmdUIOnlyFlag) +MaskByColorCommand::MaskByColorCommand() : CommandWithNewParams(CommandId::MaskByColor()) { } diff --git a/src/app/commands/cmd_mask_content.cpp b/src/app/commands/cmd_mask_content.cpp index d6ba1fd0c..fca54afb5 100644 --- a/src/app/commands/cmd_mask_content.cpp +++ b/src/app/commands/cmd_mask_content.cpp @@ -25,7 +25,6 @@ #include "doc/image.h" #include "doc/layer.h" #include "doc/mask.h" -#include "doc/sprite.h" namespace app { @@ -38,7 +37,7 @@ protected: void onExecute(Context* context) override; }; -MaskContentCommand::MaskContentCommand() : Command(CommandId::MaskContent(), CmdRecordableFlag) +MaskContentCommand::MaskContentCommand() : Command(CommandId::MaskContent()) { } @@ -87,9 +86,11 @@ void MaskContentCommand::onExecute(Context* context) } // Select marquee tool - if (tools::Tool* tool = App::instance()->toolBox()->getToolById( - tools::WellKnownTools::RectangularMarquee)) { - ToolBar::instance()->selectTool(tool); + if (context->isUIAvailable()) { + if (tools::Tool* tool = App::instance()->toolBox()->getToolById( + tools::WellKnownTools::RectangularMarquee)) { + ToolBar::instance()->selectTool(tool); + } } update_screen_for_document(document); diff --git a/src/app/commands/cmd_merge_down_layer.cpp b/src/app/commands/cmd_merge_down_layer.cpp index e05c95ab1..a86933f88 100644 --- a/src/app/commands/cmd_merge_down_layer.cpp +++ b/src/app/commands/cmd_merge_down_layer.cpp @@ -13,16 +13,12 @@ #include "app/cmd/flatten_layers.h" #include "app/commands/command.h" #include "app/context_access.h" -#include "app/doc.h" -#include "app/doc_api.h" #include "app/doc_range.h" #include "app/modules/gui.h" #include "app/pref/preferences.h" #include "app/tx.h" -#include "doc/blend_internals.h" #include "doc/layer.h" #include "doc/sprite.h" -#include "ui/ui.h" namespace app { @@ -35,8 +31,7 @@ protected: void onExecute(Context* context) override; }; -MergeDownLayerCommand::MergeDownLayerCommand() - : Command(CommandId::MergeDownLayer(), CmdRecordableFlag) +MergeDownLayerCommand::MergeDownLayerCommand() : Command(CommandId::MergeDownLayer()) { } diff --git a/src/app/commands/cmd_modify_selection.cpp b/src/app/commands/cmd_modify_selection.cpp index 6d70fb546..6c45c3821 100644 --- a/src/app/commands/cmd_modify_selection.cpp +++ b/src/app/commands/cmd_modify_selection.cpp @@ -18,16 +18,12 @@ #include "app/modules/gui.h" #include "app/pref/preferences.h" #include "app/tx.h" -#include "base/convert_to.h" #include "doc/algorithm/modify_selection.h" #include "doc/brush_type.h" #include "doc/mask.h" -#include "filters/neighboring_pixels.h" #include "modify_selection.xml.h" -#include - namespace app { using namespace doc; @@ -52,13 +48,15 @@ private: Modifier m_modifier; int m_quantity; doc::BrushType m_brushType; + bool m_ui; }; ModifySelectionCommand::ModifySelectionCommand() - : Command(CommandId::ModifySelection(), CmdRecordableFlag) + : Command(CommandId::ModifySelection()) , m_modifier(Modifier::Expand) , m_quantity(0) , m_brushType(doc::kCircleBrushType) + , m_ui(true) { } @@ -80,6 +78,11 @@ void ModifySelectionCommand::onLoadParams(const Params& params) m_brushType = doc::kCircleBrushType; else if (brush == "square") m_brushType = doc::kSquareBrushType; + + if (params.has_param("ui")) + m_ui = params.get_as("ui"); + else + m_ui = true; } bool ModifySelectionCommand::onEnabled(Context* context) @@ -92,7 +95,7 @@ void ModifySelectionCommand::onExecute(Context* context) int quantity = m_quantity; doc::BrushType brush = m_brushType; - if (quantity == 0) { + if (quantity == 0 && m_ui && context->isUIAvailable()) { Preferences& pref = Preferences::instance(); ModifySelectionWindow window; diff --git a/src/app/commands/cmd_move_cel.cpp b/src/app/commands/cmd_move_cel.cpp index 7324ec51a..deef6f985 100644 --- a/src/app/commands/cmd_move_cel.cpp +++ b/src/app/commands/cmd_move_cel.cpp @@ -12,7 +12,6 @@ #include "app/commands/command.h" #include "app/context_access.h" #include "app/ui/timeline/timeline.h" -#include "ui/base.h" namespace app { @@ -25,13 +24,13 @@ protected: void onExecute(Context* context) override; }; -MoveCelCommand::MoveCelCommand() : Command(CommandId::MoveCel(), CmdUIOnlyFlag) +MoveCelCommand::MoveCelCommand() : Command(CommandId::MoveCel()) { } bool MoveCelCommand::onEnabled(Context* context) { - return App::instance()->timeline()->isMovingCel(); + return context->isUIAvailable() && App::instance()->timeline()->isMovingCel(); } void MoveCelCommand::onExecute(Context* context) diff --git a/src/app/commands/cmd_move_mask.cpp b/src/app/commands/cmd_move_mask.cpp index 55292cb6f..d78822511 100644 --- a/src/app/commands/cmd_move_mask.cpp +++ b/src/app/commands/cmd_move_mask.cpp @@ -18,19 +18,15 @@ #include "app/doc_api.h" #include "app/i18n/strings.h" #include "app/modules/gui.h" -#include "app/pref/preferences.h" #include "app/tx.h" #include "app/ui/doc_view.h" #include "app/ui/editor/editor.h" #include "app/ui_context.h" -#include "base/convert_to.h" #include "doc/mask.h" -#include "doc/sprite.h" -#include "ui/view.h" namespace app { -MoveMaskCommand::MoveMaskCommand() : Command(CommandId::MoveMask(), CmdRecordableFlag) +MoveMaskCommand::MoveMaskCommand() : Command(CommandId::MoveMask()) { } diff --git a/src/app/commands/cmd_new_brush.cpp b/src/app/commands/cmd_new_brush.cpp index f1164c04c..50994ddb3 100644 --- a/src/app/commands/cmd_new_brush.cpp +++ b/src/app/commands/cmd_new_brush.cpp @@ -52,13 +52,13 @@ private: void selectPencilTool(); }; -NewBrushCommand::NewBrushCommand() : Command(CommandId::NewBrush(), CmdUIOnlyFlag) +NewBrushCommand::NewBrushCommand() : Command(CommandId::NewBrush()) { } bool NewBrushCommand::onEnabled(Context* context) { - return context->checkFlags(ContextFlags::ActiveDocumentIsWritable); + return context->isUIAvailable() && context->checkFlags(ContextFlags::ActiveDocumentIsWritable); } void NewBrushCommand::onExecute(Context* context) diff --git a/src/app/commands/cmd_new_file.cpp b/src/app/commands/cmd_new_file.cpp index ea4fabfa8..4b2421d0d 100644 --- a/src/app/commands/cmd_new_file.cpp +++ b/src/app/commands/cmd_new_file.cpp @@ -64,7 +64,7 @@ protected: // static int NewFileCommand::g_spriteCounter = 0; -NewFileCommand::NewFileCommand() : CommandWithNewParams(CommandId::NewFile(), CmdRecordableFlag) +NewFileCommand::NewFileCommand() : CommandWithNewParams(CommandId::NewFile()) { } diff --git a/src/app/commands/cmd_new_frame.cpp b/src/app/commands/cmd_new_frame.cpp index 58af3358c..a9714b2f4 100644 --- a/src/app/commands/cmd_new_frame.cpp +++ b/src/app/commands/cmd_new_frame.cpp @@ -10,28 +10,18 @@ #endif #include "app/app.h" -#include "app/color.h" #include "app/commands/command.h" #include "app/commands/params.h" -#include "app/console.h" #include "app/context_access.h" #include "app/doc_api.h" #include "app/i18n/strings.h" #include "app/modules/gui.h" #include "app/tx.h" -#include "app/ui/doc_view.h" -#include "app/ui/editor/editor.h" #include "app/ui/main_window.h" #include "app/ui/status_bar.h" #include "app/ui/timeline/timeline.h" -#include "app/ui_context.h" -#include "doc/cel.h" -#include "doc/image.h" #include "doc/layer.h" #include "doc/sprite.h" -#include "ui/ui.h" - -#include namespace app { @@ -57,7 +47,7 @@ private: Content m_content; }; -NewFrameCommand::NewFrameCommand() : Command(CommandId::NewFrame(), CmdRecordableFlag) +NewFrameCommand::NewFrameCommand() : Command(CommandId::NewFrame()) { } diff --git a/src/app/commands/cmd_new_frame_tag.cpp b/src/app/commands/cmd_new_frame_tag.cpp index a107ad8ba..9d84e09f6 100644 --- a/src/app/commands/cmd_new_frame_tag.cpp +++ b/src/app/commands/cmd_new_frame_tag.cpp @@ -9,7 +9,6 @@ #include "config.h" #endif -#include "app/app.h" #include "app/cmd/add_tag.h" #include "app/commands/command.h" #include "app/context.h" @@ -18,8 +17,6 @@ #include "app/ui/tag_window.h" #include "doc/tag.h" -#include - namespace app { using namespace doc; @@ -33,14 +30,14 @@ protected: void onExecute(Context* context) override; }; -NewFrameTagCommand::NewFrameTagCommand() : Command(CommandId::NewFrameTag(), CmdRecordableFlag) +NewFrameTagCommand::NewFrameTagCommand() : Command(CommandId::NewFrameTag()) { } bool NewFrameTagCommand::onEnabled(Context* context) { - return context->checkFlags(ContextFlags::ActiveDocumentIsWritable | - ContextFlags::HasActiveSprite); + return context->isUIAvailable() && context->checkFlags(ContextFlags::ActiveDocumentIsWritable | + ContextFlags::HasActiveSprite); } void NewFrameTagCommand::onExecute(Context* context) diff --git a/src/app/commands/cmd_new_layer.cpp b/src/app/commands/cmd_new_layer.cpp index 19d2e2046..2a610996f 100644 --- a/src/app/commands/cmd_new_layer.cpp +++ b/src/app/commands/cmd_new_layer.cpp @@ -21,9 +21,7 @@ #include "app/console.h" #include "app/context_access.h" #include "app/doc_api.h" -#include "app/find_widget.h" #include "app/i18n/strings.h" -#include "app/load_widget.h" #include "app/modules/gui.h" #include "app/pref/preferences.h" #include "app/restore_visible_layers.h" @@ -48,7 +46,6 @@ #include "new_layer.xml.h" #include -#include #include #include @@ -99,7 +96,7 @@ private: Place m_place; }; -NewLayerCommand::NewLayerCommand() : CommandWithNewParams(CommandId::NewLayer(), CmdRecordableFlag) +NewLayerCommand::NewLayerCommand() : CommandWithNewParams(CommandId::NewLayer()) { } diff --git a/src/app/commands/cmd_new_sprite_from_selection.cpp b/src/app/commands/cmd_new_sprite_from_selection.cpp index 880cb2633..7d84008de 100644 --- a/src/app/commands/cmd_new_sprite_from_selection.cpp +++ b/src/app/commands/cmd_new_sprite_from_selection.cpp @@ -23,8 +23,6 @@ #include "doc/sprite.h" #include "fmt/format.h" -#include - namespace app { using namespace doc; @@ -39,7 +37,7 @@ protected: }; NewSpriteFromSelectionCommand::NewSpriteFromSelectionCommand() - : Command(CommandId::NewSpriteFromSelection(), CmdUIOnlyFlag) + : Command(CommandId::NewSpriteFromSelection()) { } diff --git a/src/app/commands/cmd_onionskin.cpp b/src/app/commands/cmd_onionskin.cpp index a417f5f91..6721896d3 100644 --- a/src/app/commands/cmd_onionskin.cpp +++ b/src/app/commands/cmd_onionskin.cpp @@ -8,7 +8,6 @@ #include "config.h" #endif -#include "app/app.h" #include "app/commands/command.h" #include "app/context.h" #include "app/doc.h" @@ -20,7 +19,7 @@ using namespace gfx; class ShowOnionSkinCommand : public Command { public: - ShowOnionSkinCommand() : Command(CommandId::ShowOnionSkin(), CmdUIOnlyFlag) {} + ShowOnionSkinCommand() : Command(CommandId::ShowOnionSkin()) {} protected: bool onChecked(Context* context) override diff --git a/src/app/commands/cmd_open_browser.cpp b/src/app/commands/cmd_open_browser.cpp index 596a25183..0fff12365 100644 --- a/src/app/commands/cmd_open_browser.cpp +++ b/src/app/commands/cmd_open_browser.cpp @@ -22,6 +22,7 @@ public: OpenBrowserCommand(); protected: + bool onEnabled(Context* context) override; void onLoadParams(const Params& params) override; void onExecute(Context* context) override; std::string onGetFriendlyName() const override; @@ -31,10 +32,15 @@ private: std::string m_filename; }; -OpenBrowserCommand::OpenBrowserCommand() : Command(CommandId::OpenBrowser(), CmdUIOnlyFlag) +OpenBrowserCommand::OpenBrowserCommand() : Command(CommandId::OpenBrowser()) { } +bool OpenBrowserCommand::onEnabled(Context* context) +{ + return context->isUIAvailable(); +} + void OpenBrowserCommand::onLoadParams(const Params& params) { m_filename = params.get("filename"); diff --git a/src/app/commands/cmd_open_file.cpp b/src/app/commands/cmd_open_file.cpp index f8f088371..c52089ebf 100644 --- a/src/app/commands/cmd_open_file.cpp +++ b/src/app/commands/cmd_open_file.cpp @@ -19,14 +19,12 @@ #include "app/file/file.h" #include "app/file_selector.h" #include "app/i18n/strings.h" -#include "app/modules/gui.h" #include "app/pref/preferences.h" #include "app/recent_files.h" #include "app/ui/status_bar.h" #include "app/ui_context.h" #include "app/util/open_file_job.h" #include "base/fs.h" -#include "base/thread.h" #include "doc/sprite.h" #include "ui/ui.h" @@ -35,7 +33,7 @@ namespace app { OpenFileCommand::OpenFileCommand() - : Command(CommandId::OpenFile(), CmdRecordableFlag) + : Command(CommandId::OpenFile()) , m_ui(true) , m_repeatCheckbox(false) , m_oneFrame(false) diff --git a/src/app/commands/cmd_open_group.cpp b/src/app/commands/cmd_open_group.cpp index b6cea415e..b24bf5750 100644 --- a/src/app/commands/cmd_open_group.cpp +++ b/src/app/commands/cmd_open_group.cpp @@ -32,7 +32,7 @@ protected: // std::string onGetFriendlyName() const override; }; -OpenGroupCommand::OpenGroupCommand() : Command(CommandId::OpenGroup(), CmdRecordableFlag) +OpenGroupCommand::OpenGroupCommand() : Command(CommandId::OpenGroup()) { } diff --git a/src/app/commands/cmd_open_in_folder.cpp b/src/app/commands/cmd_open_in_folder.cpp index b9dd732c9..cfc800a2e 100644 --- a/src/app/commands/cmd_open_in_folder.cpp +++ b/src/app/commands/cmd_open_in_folder.cpp @@ -25,7 +25,7 @@ protected: void onExecute(Context* context) override; }; -OpenInFolderCommand::OpenInFolderCommand() : Command(CommandId::OpenInFolder(), CmdUIOnlyFlag) +OpenInFolderCommand::OpenInFolderCommand() : Command(CommandId::OpenInFolder()) { } diff --git a/src/app/commands/cmd_open_script_folder.cpp b/src/app/commands/cmd_open_script_folder.cpp index 38135939f..c6bfec94a 100644 --- a/src/app/commands/cmd_open_script_folder.cpp +++ b/src/app/commands/cmd_open_script_folder.cpp @@ -33,8 +33,7 @@ protected: void onExecute(Context* context); }; -OpenScriptFolderCommand::OpenScriptFolderCommand() - : Command(CommandId::OpenScriptFolder(), CmdUIOnlyFlag) +OpenScriptFolderCommand::OpenScriptFolderCommand() : Command(CommandId::OpenScriptFolder()) { } diff --git a/src/app/commands/cmd_open_with_app.cpp b/src/app/commands/cmd_open_with_app.cpp index ff1b908a4..73f2bc43d 100644 --- a/src/app/commands/cmd_open_with_app.cpp +++ b/src/app/commands/cmd_open_with_app.cpp @@ -25,7 +25,7 @@ protected: void onExecute(Context* context) override; }; -OpenWithAppCommand::OpenWithAppCommand() : Command(CommandId::OpenWithApp(), CmdUIOnlyFlag) +OpenWithAppCommand::OpenWithAppCommand() : Command(CommandId::OpenWithApp()) { } diff --git a/src/app/commands/cmd_options.cpp b/src/app/commands/cmd_options.cpp index 9f258f94b..2b4511c8e 100644 --- a/src/app/commands/cmd_options.cpp +++ b/src/app/commands/cmd_options.cpp @@ -37,7 +37,6 @@ #include "app/ui/sampling_selector.h" #include "app/ui/separator_in_view.h" #include "app/ui/skin/skin_theme.h" -#include "app/util/render_text.h" #include "base/convert_to.h" #include "base/fs.h" #include "base/string.h" @@ -2177,7 +2176,7 @@ private: std::string m_installExtensionFilename; }; -OptionsCommand::OptionsCommand() : Command(CommandId::Options(), CmdUIOnlyFlag) +OptionsCommand::OptionsCommand() : Command(CommandId::Options()) { Preferences& preferences = Preferences::instance(); diff --git a/src/app/commands/cmd_palette_editor.cpp b/src/app/commands/cmd_palette_editor.cpp index 3c2eb3fa1..91047cbb3 100644 --- a/src/app/commands/cmd_palette_editor.cpp +++ b/src/app/commands/cmd_palette_editor.cpp @@ -11,6 +11,7 @@ #include "app/commands/command.h" #include "app/commands/params.h" +#include "app/context.h" #include "app/i18n/strings.h" #include "app/ui/color_bar.h" #include "base/replace_string.h" @@ -23,6 +24,7 @@ public: PaletteEditorCommand(); protected: + bool onEnabled(Context* context) override; void onLoadParams(const Params& params) override; bool onChecked(Context* context) override; void onExecute(Context* context) override; @@ -34,14 +36,18 @@ private: bool m_background; }; -PaletteEditorCommand::PaletteEditorCommand() - : Command(CommandId::PaletteEditor(), CmdRecordableFlag) +PaletteEditorCommand::PaletteEditorCommand() : Command(CommandId::PaletteEditor()) { m_edit = true; m_popup = false; m_background = false; } +bool PaletteEditorCommand::onEnabled(Context* context) +{ + return context->isUIAvailable(); +} + void PaletteEditorCommand::onLoadParams(const Params& params) { m_edit = (params.empty() || params.get("edit") == "switch" || diff --git a/src/app/commands/cmd_palette_size.cpp b/src/app/commands/cmd_palette_size.cpp index 86e0e7a0b..79e2966ef 100644 --- a/src/app/commands/cmd_palette_size.cpp +++ b/src/app/commands/cmd_palette_size.cpp @@ -15,7 +15,6 @@ #include "app/context_access.h" #include "app/tx.h" #include "doc/palette.h" -#include "doc/sprite.h" #include "palette_size.xml.h" @@ -33,17 +32,21 @@ protected: void onExecute(Context* context) override; private: - int m_size; + int m_size = 0; + bool m_ui = true; }; -PaletteSizeCommand::PaletteSizeCommand() : Command(CommandId::PaletteSize(), CmdRecordableFlag) +PaletteSizeCommand::PaletteSizeCommand() : Command(CommandId::PaletteSize()) { - m_size = 0; } void PaletteSizeCommand::onLoadParams(const Params& params) { m_size = params.get_as("size"); + if (params.has_param("ui")) + m_ui = params.get_as("ui"); + else + m_ui = true; } bool PaletteSizeCommand::onEnabled(Context* context) @@ -59,7 +62,7 @@ void PaletteSizeCommand::onExecute(Context* context) Palette palette(*reader.palette()); int ncolors = (m_size != 0 ? m_size : palette.size()); - if (m_size == 0 && context->isUIAvailable()) { + if (m_size == 0 && m_ui && context->isUIAvailable()) { app::gen::PaletteSize window; window.colors()->setTextf("%d", ncolors); window.openWindowInForeground(); diff --git a/src/app/commands/cmd_paste.cpp b/src/app/commands/cmd_paste.cpp index 77762e78b..0604a5ebf 100644 --- a/src/app/commands/cmd_paste.cpp +++ b/src/app/commands/cmd_paste.cpp @@ -31,7 +31,7 @@ private: std::unique_ptr m_position; }; -PasteCommand::PasteCommand() : Command(CommandId::Paste(), CmdUIOnlyFlag) +PasteCommand::PasteCommand() : Command(CommandId::Paste()) { } diff --git a/src/app/commands/cmd_paste_text.cpp b/src/app/commands/cmd_paste_text.cpp index 976d1d3e3..d39f03c52 100644 --- a/src/app/commands/cmd_paste_text.cpp +++ b/src/app/commands/cmd_paste_text.cpp @@ -10,22 +10,27 @@ #endif #include "app/app.h" +#include "app/cmd/copy_region.h" +#include "app/cmd/patch_cel.h" #include "app/color_utils.h" #include "app/commands/command.h" +#include "app/commands/commands.h" +#include "app/commands/new_params.h" #include "app/console.h" #include "app/context.h" +#include "app/context_access.h" #include "app/pref/preferences.h" -#include "app/ui/drop_down_button.h" +#include "app/site.h" +#include "app/tx.h" #include "app/ui/editor/editor.h" #include "app/ui/timeline/timeline.h" #include "app/util/render_text.h" -#include "base/fs.h" -#include "base/string.h" #include "doc/image.h" #include "doc/image_ref.h" #include "render/dithering.h" -#include "render/ordered_dither.h" #include "render/quantization.h" +#include "render/rasterize.h" +#include "render/render.h" #include "ui/manager.h" #include "paste_text.xml.h" @@ -34,7 +39,17 @@ namespace app { static std::string last_text_used; -class PasteTextCommand : public Command { +struct PasteTextParams : public NewParams { + Param ui{ this, true, "ui" }; + Param color{ this, app::Color::fromMask(), "color" }; + Param text{ this, "", "text" }; + Param fontName{ this, "Aseprite", "fontName" }; + Param fontSize{ this, 6, "fontSize" }; + Param x{ this, 0, "x" }; + Param y{ this, 0, "y" }; +}; + +class PasteTextCommand : public CommandWithNewParams { public: PasteTextCommand(); @@ -43,7 +58,7 @@ protected: void onExecute(Context* ctx) override; }; -PasteTextCommand::PasteTextCommand() : Command(CommandId::PasteText(), CmdUIOnlyFlag) +PasteTextCommand::PasteTextCommand() : CommandWithNewParams(CommandId::PasteText()) { } @@ -66,55 +81,104 @@ public: void PasteTextCommand::onExecute(Context* ctx) { - auto editor = Editor::activeEditor(); - if (editor == nullptr) - return; + const bool ui = params().ui() && ctx->isUIAvailable(); - Preferences& pref = Preferences::instance(); FontInfo fontInfo = FontInfo::getFromPreferences(); - PasteTextWindow window(fontInfo, pref.colorBar.fgColor()); + Preferences& pref = Preferences::instance(); - window.userText()->setText(last_text_used); + std::string text; + app::Color color; + ui::Paint paint; - window.openWindowInForeground(); - if (window.closer() != window.ok()) - return; + if (ui) { + PasteTextWindow window(fontInfo, pref.colorBar.fgColor()); - last_text_used = window.userText()->text(); + window.userText()->setText(params().text().empty() ? last_text_used : params().text()); - fontInfo = window.fontInfo(); - fontInfo.updatePreferences(); + window.openWindowInForeground(); + if (window.closer() != window.ok()) + return; + + text = window.userText()->text(); + last_text_used = text; + color = window.fontColor()->getColor(); + paint = window.fontFace()->paint(); + + fontInfo = window.fontInfo(); + fontInfo.updatePreferences(); + } + else { + text = params().text(); + color = params().color.isSet() ? params().color() : pref.colorBar.fgColor(); + + FontInfo info(FontInfo::Type::Unknown, params().fontName(), params().fontSize()); + fontInfo = info; + } try { - std::string text = window.userText()->text(); - app::Color color = window.fontColor()->getColor(); - - ui::Paint paint = window.fontFace()->paint(); paint.color(color_utils::color_for_ui(color)); doc::ImageRef image = render_text(fontInfo, text, paint); - if (image) { - Sprite* sprite = editor->sprite(); - if (image->pixelFormat() != sprite->pixelFormat()) { - RgbMap* rgbmap = sprite->rgbMap(editor->frame()); - image.reset(render::convert_pixel_format(image.get(), - NULL, - sprite->pixelFormat(), - render::Dithering(), - rgbmap, - sprite->palette(editor->frame()), - false, - sprite->transparentColor())); - } + if (!image) + return; - // TODO we don't support pasting text in multiple cels at the - // moment, so we clear the range here (same as in - // clipboard::paste()) - if (auto timeline = App::instance()->timeline()) - timeline->clearAndInvalidateRange(); - - editor->pasteImage(image.get()); + auto site = ctx->activeSite(); + Sprite* sprite = site.sprite(); + if (image->pixelFormat() != sprite->pixelFormat()) { + RgbMap* rgbmap = sprite->rgbMap(site.frame()); + image.reset(render::convert_pixel_format(image.get(), + NULL, + sprite->pixelFormat(), + render::Dithering(), + rgbmap, + sprite->palette(site.frame()), + false, + sprite->transparentColor())); } + + // TODO we don't support pasting text in multiple cels at the + // moment, so we clear the range here (same as in + // clipboard::paste()) + if (auto timeline = App::instance()->timeline()) + timeline->clearAndInvalidateRange(); + + auto point = sprite->bounds().center() - gfx::Point(image->size().w / 2, image->size().h / 2); + if (params().x.isSet()) + point.x = params().x(); + if (params().y.isSet()) + point.y = params().y(); + + if (ui) { + // TODO: Do we want to make this selectable result available when not using UI? + Editor::activeEditor()->pasteImage(image.get(), nullptr, &point); + return; + } + + ContextWriter writer(ctx); + Tx tx(writer, "Paste Text"); + ImageRef finalImage = image; + if (writer.cel()->image()) { + gfx::Rect celRect(point, image->size()); + ASSERT(!celRect.isEmpty() && celRect.x >= 0 && celRect.y >= 0); + finalImage.reset( + doc::crop_image(writer.cel()->image(), celRect, writer.cel()->image()->maskColor())); + render::Render render; + render.setNewBlend(pref.experimental.newBlend()); + render.setBgOptions(render::BgOptions::MakeTransparent()); + render.renderImage(finalImage.get(), + image.get(), + writer.palette(), + 0, + 0, + 255, + doc::BlendMode::NORMAL); + } + + tx(new cmd::CopyRegion(writer.cel()->image(), + finalImage.get(), + gfx::Region(finalImage->bounds()), + point)); + tx.commit(); } catch (const std::exception& ex) { Console::showException(ex); diff --git a/src/app/commands/cmd_pixel_perfect_mode.cpp b/src/app/commands/cmd_pixel_perfect_mode.cpp index 7ed76ea6d..38ea1c9ac 100644 --- a/src/app/commands/cmd_pixel_perfect_mode.cpp +++ b/src/app/commands/cmd_pixel_perfect_mode.cpp @@ -10,8 +10,6 @@ #include "app/app.h" #include "app/commands/command.h" -#include "app/commands/params.h" -#include "app/context.h" #include "app/pref/preferences.h" #include "app/tools/freehand_algorithm.h" #include "app/tools/tool.h" @@ -28,8 +26,7 @@ protected: void onExecute(Context* context) override; }; -PixelPerfectModeCommand::PixelPerfectModeCommand() - : Command(CommandId::PixelPerfectMode(), CmdUIOnlyFlag) +PixelPerfectModeCommand::PixelPerfectModeCommand() : Command(CommandId::PixelPerfectMode()) { } diff --git a/src/app/commands/cmd_play_animation.cpp b/src/app/commands/cmd_play_animation.cpp index e085d63f9..b9f479c1a 100644 --- a/src/app/commands/cmd_play_animation.cpp +++ b/src/app/commands/cmd_play_animation.cpp @@ -34,13 +34,14 @@ protected: void onExecute(Context* ctx) override; }; -PlayAnimationCommand::PlayAnimationCommand() : Command(CommandId::PlayAnimation(), CmdUIOnlyFlag) +PlayAnimationCommand::PlayAnimationCommand() : Command(CommandId::PlayAnimation()) { } bool PlayAnimationCommand::onEnabled(Context* ctx) { - return ctx->checkFlags(ContextFlags::ActiveDocumentIsReadable | ContextFlags::HasActiveSprite); + return ctx->isUIAvailable() && + ctx->checkFlags(ContextFlags::ActiveDocumentIsReadable | ContextFlags::HasActiveSprite); } bool PlayAnimationCommand::onChecked(Context* ctx) @@ -85,13 +86,14 @@ protected: }; PlayPreviewAnimationCommand::PlayPreviewAnimationCommand() - : Command(CommandId::PlayPreviewAnimation(), CmdUIOnlyFlag) + : Command(CommandId::PlayPreviewAnimation()) { } bool PlayPreviewAnimationCommand::onEnabled(Context* ctx) { - return ctx->checkFlags(ContextFlags::ActiveDocumentIsWritable | ContextFlags::HasActiveSprite); + return ctx->isUIAvailable() && + ctx->checkFlags(ContextFlags::ActiveDocumentIsWritable | ContextFlags::HasActiveSprite); } bool PlayPreviewAnimationCommand::onChecked(Context* ctx) diff --git a/src/app/commands/cmd_refresh.cpp b/src/app/commands/cmd_refresh.cpp index 83439c4e4..b1320fd32 100644 --- a/src/app/commands/cmd_refresh.cpp +++ b/src/app/commands/cmd_refresh.cpp @@ -10,12 +10,10 @@ #endif #include "app/app.h" -#include "app/app_menus.h" #include "app/commands/command.h" #include "app/ui/main_menu_bar.h" #include "app/ui/main_window.h" #include "app/ui/status_bar.h" -#include "fmt/format.h" #include "ui/scale.h" #include "ui/system.h" #include "ui/theme.h" @@ -39,7 +37,7 @@ private: void postCancelMenuLoop(); }; -RefreshCommand::RefreshCommand() : Command(CommandId::Refresh(), CmdUIOnlyFlag) +RefreshCommand::RefreshCommand() : Command(CommandId::Refresh()) { } diff --git a/src/app/commands/cmd_remove_frame.cpp b/src/app/commands/cmd_remove_frame.cpp index 740034322..da31a5625 100644 --- a/src/app/commands/cmd_remove_frame.cpp +++ b/src/app/commands/cmd_remove_frame.cpp @@ -16,7 +16,6 @@ #include "app/modules/gui.h" #include "app/tx.h" #include "doc/sprite.h" -#include "ui/ui.h" namespace app { @@ -29,7 +28,7 @@ protected: void onExecute(Context* context) override; }; -RemoveFrameCommand::RemoveFrameCommand() : Command(CommandId::RemoveFrame(), CmdRecordableFlag) +RemoveFrameCommand::RemoveFrameCommand() : Command(CommandId::RemoveFrame()) { } diff --git a/src/app/commands/cmd_remove_frame_tag.cpp b/src/app/commands/cmd_remove_frame_tag.cpp index 5a1cf3199..4f4209404 100644 --- a/src/app/commands/cmd_remove_frame_tag.cpp +++ b/src/app/commands/cmd_remove_frame_tag.cpp @@ -15,7 +15,6 @@ #include "app/commands/params.h" #include "app/context.h" #include "app/context_access.h" -#include "app/loop_tag.h" #include "app/tx.h" #include "app/ui/timeline/timeline.h" #include "base/convert_to.h" @@ -38,7 +37,7 @@ private: }; RemoveFrameTagCommand::RemoveFrameTagCommand() - : Command(CommandId::RemoveFrameTag(), CmdRecordableFlag) + : Command(CommandId::RemoveFrameTag()) , m_tagId(NullId) { } diff --git a/src/app/commands/cmd_remove_layer.cpp b/src/app/commands/cmd_remove_layer.cpp index a7db748c8..3f85cef70 100644 --- a/src/app/commands/cmd_remove_layer.cpp +++ b/src/app/commands/cmd_remove_layer.cpp @@ -105,7 +105,7 @@ protected: void onExecute(Context* context) override; }; -RemoveLayerCommand::RemoveLayerCommand() : Command(CommandId::RemoveLayer(), CmdRecordableFlag) +RemoveLayerCommand::RemoveLayerCommand() : Command(CommandId::RemoveLayer()) { } diff --git a/src/app/commands/cmd_remove_slice.cpp b/src/app/commands/cmd_remove_slice.cpp index 07373e36e..a4c4f25c8 100644 --- a/src/app/commands/cmd_remove_slice.cpp +++ b/src/app/commands/cmd_remove_slice.cpp @@ -15,14 +15,12 @@ #include "app/commands/command.h" #include "app/context_access.h" #include "app/i18n/strings.h" -#include "app/modules/gui.h" #include "app/tx.h" #include "app/ui/status_bar.h" #include "base/convert_to.h" #include "doc/selected_objects.h" #include "doc/slice.h" #include "doc/sprite.h" -#include "ui/alert.h" #include "ui/widget.h" namespace app { @@ -41,7 +39,7 @@ private: ObjectId m_sliceId; }; -RemoveSliceCommand::RemoveSliceCommand() : Command(CommandId::RemoveSlice(), CmdRecordableFlag) +RemoveSliceCommand::RemoveSliceCommand() : Command(CommandId::RemoveSlice()) { } @@ -117,13 +115,15 @@ void RemoveSliceCommand::onExecute(Context* context) document->notifyGeneralUpdate(); } - StatusBar::instance()->invalidate(); - if (!sliceName.empty()) { - StatusBar::instance()->showTip(1000, Strings::remove_slice_x_removed(sliceName)); - } - else { - StatusBar::instance()->showTip(1000, - Strings::remove_slice_n_slices_removed(slicesToDelete.size())); + if (context->isUIAvailable()) { + StatusBar::instance()->invalidate(); + if (!sliceName.empty()) { + StatusBar::instance()->showTip(1000, Strings::remove_slice_x_removed(sliceName)); + } + else { + StatusBar::instance()->showTip(1000, + Strings::remove_slice_n_slices_removed(slicesToDelete.size())); + } } } diff --git a/src/app/commands/cmd_reopen_closed_file.cpp b/src/app/commands/cmd_reopen_closed_file.cpp index e8c272fdc..a8f22a7f1 100644 --- a/src/app/commands/cmd_reopen_closed_file.cpp +++ b/src/app/commands/cmd_reopen_closed_file.cpp @@ -8,14 +8,10 @@ #include "config.h" #endif -#include "app/app.h" #include "app/commands/command.h" #include "app/commands/commands.h" -#include "app/doc.h" #include "app/ui_context.h" -#include - namespace app { class ReopenClosedFileCommand : public Command { @@ -27,8 +23,7 @@ protected: void onExecute(Context* context) override; }; -ReopenClosedFileCommand::ReopenClosedFileCommand() - : Command(CommandId::ReopenClosedFile(), CmdUIOnlyFlag) +ReopenClosedFileCommand::ReopenClosedFileCommand() : Command(CommandId::ReopenClosedFile()) { } diff --git a/src/app/commands/cmd_repeat_last_export.cpp b/src/app/commands/cmd_repeat_last_export.cpp index 82dc747d3..a68dbdd6a 100644 --- a/src/app/commands/cmd_repeat_last_export.cpp +++ b/src/app/commands/cmd_repeat_last_export.cpp @@ -27,8 +27,7 @@ protected: virtual void onExecute(Context* context) override; }; -RepeatLastExportCommand::RepeatLastExportCommand() - : Command(CommandId::RepeatLastExport(), CmdRecordableFlag) +RepeatLastExportCommand::RepeatLastExportCommand() : Command(CommandId::RepeatLastExport()) { } diff --git a/src/app/commands/cmd_reselect_mask.cpp b/src/app/commands/cmd_reselect_mask.cpp index 517e6dae2..396729ba7 100644 --- a/src/app/commands/cmd_reselect_mask.cpp +++ b/src/app/commands/cmd_reselect_mask.cpp @@ -15,7 +15,6 @@ #include "app/modules/gui.h" #include "app/tx.h" #include "doc/mask.h" -#include "doc/sprite.h" namespace app { @@ -28,7 +27,7 @@ protected: void onExecute(Context* context) override; }; -ReselectMaskCommand::ReselectMaskCommand() : Command(CommandId::ReselectMask(), CmdRecordableFlag) +ReselectMaskCommand::ReselectMaskCommand() : Command(CommandId::ReselectMask()) { } diff --git a/src/app/commands/cmd_reverse_frames.cpp b/src/app/commands/cmd_reverse_frames.cpp index f30652205..16634fd8c 100644 --- a/src/app/commands/cmd_reverse_frames.cpp +++ b/src/app/commands/cmd_reverse_frames.cpp @@ -27,7 +27,7 @@ protected: void onExecute(Context* context) override; }; -ReverseFramesCommand::ReverseFramesCommand() : Command(CommandId::ReverseFrames(), CmdUIOnlyFlag) +ReverseFramesCommand::ReverseFramesCommand() : Command(CommandId::ReverseFrames()) { } diff --git a/src/app/commands/cmd_rotate.cpp b/src/app/commands/cmd_rotate.cpp index bc264f700..bbd284f3b 100644 --- a/src/app/commands/cmd_rotate.cpp +++ b/src/app/commands/cmd_rotate.cpp @@ -14,13 +14,11 @@ #include "app/commands/cmd_rotate.h" #include "app/commands/params.h" #include "app/doc_api.h" -#include "app/doc_range.h" #include "app/i18n/strings.h" #include "app/modules/gui.h" #include "app/sprite_job.h" #include "app/tools/tool_box.h" #include "app/tx.h" -#include "app/ui/color_bar.h" #include "app/ui/editor/editor.h" #include "app/ui/status_bar.h" #include "app/ui/timeline/timeline.h" @@ -31,7 +29,6 @@ #include "doc/image.h" #include "doc/mask.h" #include "doc/sprite.h" -#include "ui/ui.h" namespace app { @@ -166,7 +163,7 @@ protected: } }; -RotateCommand::RotateCommand() : Command(CommandId::Rotate(), CmdRecordableFlag) +RotateCommand::RotateCommand() : Command(CommandId::Rotate()) { m_ui = true; m_flipMask = false; @@ -190,6 +187,10 @@ void RotateCommand::onLoadParams(const Params& params) bool RotateCommand::onEnabled(Context* context) { + // Because we use the toolbar & editor to transform the selection, this won't work without a UI + if (m_flipMask && !context->isUIAvailable()) + return false; + return context->checkFlags(ContextFlags::ActiveDocumentIsWritable | ContextFlags::HasActiveSprite); } diff --git a/src/app/commands/cmd_run_script.cpp b/src/app/commands/cmd_run_script.cpp index 15540cc4f..721d94ef7 100644 --- a/src/app/commands/cmd_run_script.cpp +++ b/src/app/commands/cmd_run_script.cpp @@ -16,7 +16,6 @@ #include "app/app.h" #include "app/commands/command.h" #include "app/commands/params.h" -#include "app/console.h" #include "app/context.h" #include "app/i18n/strings.h" #include "app/pref/preferences.h" @@ -27,8 +26,6 @@ #include "fmt/format.h" #include "ui/manager.h" -#include - namespace app { class RunScriptCommand : public Command { @@ -46,7 +43,7 @@ private: Params m_params; }; -RunScriptCommand::RunScriptCommand() : Command(CommandId::RunScript(), CmdRecordableFlag) +RunScriptCommand::RunScriptCommand() : Command(CommandId::RunScript()) { } diff --git a/src/app/commands/cmd_save_file.cpp b/src/app/commands/cmd_save_file.cpp index cdebc7e2b..51b0e53fe 100644 --- a/src/app/commands/cmd_save_file.cpp +++ b/src/app/commands/cmd_save_file.cpp @@ -36,8 +36,6 @@ #include "app/ui/status_bar.h" #include "base/convert_to.h" #include "base/fs.h" -#include "base/scoped_value.h" -#include "base/thread.h" #include "doc/mask.h" #include "doc/sprite.h" #include "doc/tag.h" @@ -86,8 +84,7 @@ private: ////////////////////////////////////////////////////////////////////// -SaveFileBaseCommand::SaveFileBaseCommand(const char* id, CommandFlags flags) - : CommandWithNewParams(id, flags) +SaveFileBaseCommand::SaveFileBaseCommand(const char* id) : CommandWithNewParams(id) { } @@ -269,7 +266,7 @@ protected: void onExecute(Context* context) override; }; -SaveFileCommand::SaveFileCommand() : SaveFileBaseCommand(CommandId::SaveFile(), CmdRecordableFlag) +SaveFileCommand::SaveFileCommand() : SaveFileBaseCommand(CommandId::SaveFile()) { } @@ -310,8 +307,7 @@ protected: void onExecute(Context* context) override; }; -SaveFileAsCommand::SaveFileAsCommand() - : SaveFileBaseCommand(CommandId::SaveFileAs(), CmdRecordableFlag) +SaveFileAsCommand::SaveFileAsCommand() : SaveFileBaseCommand(CommandId::SaveFileAs()) { } @@ -335,8 +331,7 @@ private: void moveToUndoState(Doc* doc, const undo::UndoState* state); }; -SaveFileCopyAsCommand::SaveFileCopyAsCommand() - : SaveFileBaseCommand(CommandId::SaveFileCopyAs(), CmdRecordableFlag) +SaveFileCopyAsCommand::SaveFileCopyAsCommand() : SaveFileBaseCommand(CommandId::SaveFileCopyAs()) { } diff --git a/src/app/commands/cmd_save_file.h b/src/app/commands/cmd_save_file.h index eab6837f7..3c8fe56bc 100644 --- a/src/app/commands/cmd_save_file.h +++ b/src/app/commands/cmd_save_file.h @@ -67,7 +67,7 @@ public: enum class SaveInBackground { Off, On }; enum class ResizeOnTheFly { Off, On }; - SaveFileBaseCommand(const char* id, CommandFlags flags); + SaveFileBaseCommand(const char* id); protected: void onLoadParams(const Params& params) override; diff --git a/src/app/commands/cmd_save_mask.cpp b/src/app/commands/cmd_save_mask.cpp index 73aa56591..5805de879 100644 --- a/src/app/commands/cmd_save_mask.cpp +++ b/src/app/commands/cmd_save_mask.cpp @@ -10,18 +10,22 @@ #endif #include "app/commands/command.h" +#include "app/commands/new_params.h" #include "app/context_access.h" #include "app/file_selector.h" #include "app/i18n/strings.h" #include "app/util/msk_file.h" #include "base/fs.h" -#include "doc/mask.h" -#include "doc/sprite.h" #include "ui/alert.h" namespace app { -class SaveMaskCommand : public Command { +struct SaveMaskParams : public NewParams { + Param ui{ this, true, "ui" }; + Param filename{ this, "default.msk", "filename" }; +}; + +class SaveMaskCommand : public CommandWithNewParams { public: SaveMaskCommand(); @@ -30,7 +34,7 @@ protected: void onExecute(Context* context) override; }; -SaveMaskCommand::SaveMaskCommand() : Command(CommandId::SaveMask(), CmdUIOnlyFlag) +SaveMaskCommand::SaveMaskCommand() : CommandWithNewParams(CommandId::SaveMask()) { } @@ -41,21 +45,27 @@ bool SaveMaskCommand::onEnabled(Context* context) void SaveMaskCommand::onExecute(Context* context) { + const bool ui = (params().ui() && context->isUIAvailable()); + std::string filename = params().filename(); + const ContextReader reader(context); const Doc* document(reader.document()); - base::paths exts = { "msk" }; - base::paths selFilename; - if (!app::show_file_selector(Strings::save_selection_title(), - "default.msk", - exts, - FileSelectorType::Save, - selFilename)) - return; + if (ui) { + base::paths exts = { "msk" }; + base::paths selFilename; + if (!app::show_file_selector(Strings::save_selection_title(), + filename, + exts, + FileSelectorType::Save, + selFilename)) + return; - std::string filename = selFilename.front(); + filename = selFilename.front(); + } - if (save_msk_file(document->mask(), filename.c_str()) != 0) + const bool result = (save_msk_file(document->mask(), filename.c_str()) == 0); + if (!result && ui) ui::Alert::show(Strings::alerts_error_saving_file(filename)); } diff --git a/src/app/commands/cmd_save_palette.cpp b/src/app/commands/cmd_save_palette.cpp index 6f52f46ae..89fe5a718 100644 --- a/src/app/commands/cmd_save_palette.cpp +++ b/src/app/commands/cmd_save_palette.cpp @@ -10,8 +10,8 @@ #endif #include "app/app.h" -#include "app/commands/cmd_set_palette.h" #include "app/commands/commands.h" +#include "app/commands/new_params.h" #include "app/commands/params.h" #include "app/context.h" #include "app/doc.h" @@ -20,57 +20,61 @@ #include "app/i18n/strings.h" #include "app/modules/palettes.h" #include "base/fs.h" -#include "doc/palette.h" #include "ui/alert.h" namespace app { using namespace ui; -class SavePaletteCommand : public Command { +struct SavePaletteParams : public NewParams { + Param ui{ this, true, "ui" }; + Param filename{ this, "", "filename" }; + Param preset{ this, "", "preset" }; + Param saveAsPreset{ this, false, "saveAsPreset" }; + Param columns{ this, 16, "columns" }; +}; + +class SavePaletteCommand : public CommandWithNewParams { public: SavePaletteCommand(); protected: - void onLoadParams(const Params& params) override; - void onExecute(Context* context) override; + void onExecute(Context* ctx) override; std::string onGetFriendlyName() const override; - -private: - std::string m_preset; - bool m_saveAsPreset = false; }; -SavePaletteCommand::SavePaletteCommand() : Command(CommandId::SavePalette(), CmdRecordableFlag) +SavePaletteCommand::SavePaletteCommand() : CommandWithNewParams(CommandId::SavePalette()) { } -void SavePaletteCommand::onLoadParams(const Params& params) -{ - m_preset = params.get("preset"); - m_saveAsPreset = (params.get("saveAsPreset") == "true"); -} - void SavePaletteCommand::onExecute(Context* ctx) { const doc::Palette* palette = get_current_palette(); + const bool ui = (params().ui() && ctx->isUIAvailable()); std::string filename; - if (!m_preset.empty()) { - filename = get_preset_palette_filename(m_preset, ".ase"); + if (!params().preset().empty()) { + filename = get_preset_palette_filename(params().preset(), ".ase"); } else { base::paths exts = get_writable_palette_extensions(); - base::paths selFilename; - std::string initialPath = (m_saveAsPreset ? get_preset_palettes_dir() : ""); - if (!app::show_file_selector(Strings::save_palette_title(), - initialPath, - exts, - FileSelectorType::Save, - selFilename)) - return; - filename = selFilename.front(); + if (ui) { + base::paths selFilename; + std::string initialPath = params().saveAsPreset() ? get_preset_palettes_dir() : + params().filename(); + if (!app::show_file_selector(Strings::save_palette_title(), + initialPath, + exts, + FileSelectorType::Save, + selFilename)) + return; + + filename = selFilename.front(); + } + else { + filename = params().filename(); + } // Check that the file format supports saving indexed images/color // palettes (e.g. if the user specified .jpg we should show that @@ -84,28 +88,31 @@ void SavePaletteCommand::onExecute(Context* ctx) } } gfx::ColorSpaceRef colorSpace = nullptr; - auto activeDoc = ctx->activeDocument(); + auto* activeDoc = ctx->activeDocument(); if (activeDoc) colorSpace = activeDoc->sprite()->colorSpace(); - if (!save_palette(filename.c_str(), palette, 16, colorSpace)) // TODO 16 should be configurable + const bool result = save_palette(filename.c_str(), palette, params().columns(), colorSpace); + + if (ui && !result) ui::Alert::show(Strings::alerts_error_saving_file(filename)); - if (m_preset == get_default_palette_preset_name()) { + if (params().preset() == get_default_palette_preset_name()) { set_default_palette(palette); if (!activeDoc) set_current_palette(palette, false); } - if (m_saveAsPreset) { + + if (params().saveAsPreset()) { App::instance()->PalettePresetsChange(); } } std::string SavePaletteCommand::onGetFriendlyName() const { - if (m_preset == "default") + if (params().preset() == get_default_palette_preset_name()) return Strings::commands_SavePaletteAsDefault(); - else if (m_saveAsPreset) + if (params().saveAsPreset()) return Strings::commands_SavePaletteAsPreset(); return Command::onGetFriendlyName(); } diff --git a/src/app/commands/cmd_scroll.cpp b/src/app/commands/cmd_scroll.cpp index 66780f3f3..eb7484609 100644 --- a/src/app/commands/cmd_scroll.cpp +++ b/src/app/commands/cmd_scroll.cpp @@ -12,11 +12,9 @@ #include "app/app.h" #include "app/commands/command.h" #include "app/commands/move_thing.h" -#include "app/commands/params.h" #include "app/context_access.h" #include "app/i18n/strings.h" #include "app/ui/editor/editor.h" -#include "base/convert_to.h" #include "ui/view.h" namespace app { @@ -36,7 +34,7 @@ private: MoveThing m_moveThing; }; -ScrollCommand::ScrollCommand() : Command(CommandId::Scroll(), CmdUIOnlyFlag) +ScrollCommand::ScrollCommand() : Command(CommandId::Scroll()) { } @@ -47,7 +45,7 @@ void ScrollCommand::onLoadParams(const Params& params) bool ScrollCommand::onEnabled(Context* context) { - return context->checkFlags(ContextFlags::HasActiveDocument); + return context->isUIAvailable() && context->checkFlags(ContextFlags::HasActiveDocument); } void ScrollCommand::onExecute(Context* context) diff --git a/src/app/commands/cmd_scroll_center.cpp b/src/app/commands/cmd_scroll_center.cpp index 86b94e539..b39d9ce69 100644 --- a/src/app/commands/cmd_scroll_center.cpp +++ b/src/app/commands/cmd_scroll_center.cpp @@ -11,7 +11,6 @@ #include "app/app.h" #include "app/commands/command.h" -#include "app/context_access.h" #include "app/ui/editor/editor.h" namespace app { @@ -25,7 +24,7 @@ protected: void onExecute(Context* context) override; }; -ScrollCenterCommand::ScrollCenterCommand() : Command(CommandId::ScrollCenter(), CmdUIOnlyFlag) +ScrollCenterCommand::ScrollCenterCommand() : Command(CommandId::ScrollCenter()) { } diff --git a/src/app/commands/cmd_select_palette.cpp b/src/app/commands/cmd_select_palette.cpp index 63742a7df..a5d7a7954 100644 --- a/src/app/commands/cmd_select_palette.cpp +++ b/src/app/commands/cmd_select_palette.cpp @@ -17,7 +17,6 @@ #include "app/modules/palettes.h" #include "app/site.h" #include "doc/cel.h" -#include "doc/frame_range.h" #include "doc/image.h" #include "doc/layer.h" #include "doc/layer_tilemap.h" @@ -51,7 +50,7 @@ private: }; SelectPaletteColorsCommand::SelectPaletteColorsCommand() - : Command(CommandId::SelectPaletteColors(), CmdRecordableFlag) + : Command(CommandId::SelectPaletteColors()) , m_modifier(Modifier::UsedColors) { } diff --git a/src/app/commands/cmd_select_tile.cpp b/src/app/commands/cmd_select_tile.cpp index 53f211087..751126cef 100644 --- a/src/app/commands/cmd_select_tile.cpp +++ b/src/app/commands/cmd_select_tile.cpp @@ -19,7 +19,6 @@ #include "app/tx.h" #include "app/ui/editor/editor.h" #include "doc/mask.h" -#include "ui/system.h" namespace app { @@ -40,7 +39,7 @@ private: }; SelectTileCommand::SelectTileCommand() - : Command(CommandId::SelectTile(), CmdRecordableFlag) + : Command(CommandId::SelectTile()) , m_mode(gen::SelectionMode::DEFAULT) { } @@ -60,7 +59,8 @@ void SelectTileCommand::onLoadParams(const Params& params) bool SelectTileCommand::onEnabled(Context* ctx) { - return ctx->checkFlags(ContextFlags::ActiveDocumentIsWritable); + return ctx->checkFlags(ContextFlags::ActiveDocumentIsWritable) && ctx->isUIAvailable() && + Editor::activeEditor()->hasMouse(); } void SelectTileCommand::onExecute(Context* ctx) diff --git a/src/app/commands/cmd_set_color_selector.cpp b/src/app/commands/cmd_set_color_selector.cpp index 5732167bc..b76b44b7e 100644 --- a/src/app/commands/cmd_set_color_selector.cpp +++ b/src/app/commands/cmd_set_color_selector.cpp @@ -12,6 +12,7 @@ #include "app/app.h" #include "app/commands/command.h" #include "app/commands/params.h" +#include "app/context.h" #include "app/i18n/strings.h" #include "app/ui/color_bar.h" @@ -22,6 +23,7 @@ public: SetColorSelectorCommand(); protected: + bool onEnabled(Context* context) override; bool onNeedsParams() const override { return true; } void onLoadParams(const Params& params) override; bool onChecked(Context* context) override; @@ -33,11 +35,16 @@ private: }; SetColorSelectorCommand::SetColorSelectorCommand() - : Command(CommandId::SetColorSelector(), CmdUIOnlyFlag) + : Command(CommandId::SetColorSelector()) , m_type(ColorBar::ColorSelector::SPECTRUM) { } +bool SetColorSelectorCommand::onEnabled(Context* context) +{ + return context->isUIAvailable(); +} + void SetColorSelectorCommand::onLoadParams(const Params& params) { std::string type = params.get("type"); diff --git a/src/app/commands/cmd_set_ink_type.cpp b/src/app/commands/cmd_set_ink_type.cpp index fadd5a3a5..39906f431 100644 --- a/src/app/commands/cmd_set_ink_type.cpp +++ b/src/app/commands/cmd_set_ink_type.cpp @@ -28,17 +28,22 @@ public: SetInkTypeCommand(); protected: + bool onEnabled(Context* context) override; bool onNeedsParams() const override { return true; } bool onChecked(Context* context) override; void onExecute(Context* context) override; std::string onGetFriendlyName() const override; }; -SetInkTypeCommand::SetInkTypeCommand() - : CommandWithNewParams(CommandId::SetInkType(), CmdUIOnlyFlag) +SetInkTypeCommand::SetInkTypeCommand() : CommandWithNewParams(CommandId::SetInkType()) { } +bool SetInkTypeCommand::onEnabled(Context* context) +{ + return context->isUIAvailable(); +} + bool SetInkTypeCommand::onChecked(Context* context) { tools::Tool* tool = App::instance()->activeTool(); diff --git a/src/app/commands/cmd_set_loop_section.cpp b/src/app/commands/cmd_set_loop_section.cpp index 21e13bc46..5fd81437e 100644 --- a/src/app/commands/cmd_set_loop_section.cpp +++ b/src/app/commands/cmd_set_loop_section.cpp @@ -40,7 +40,7 @@ protected: }; SetLoopSectionCommand::SetLoopSectionCommand() - : Command(CommandId::SetLoopSection(), CmdRecordableFlag) + : Command(CommandId::SetLoopSection()) , m_action(Action::Auto) , m_begin(0) , m_end(0) @@ -129,7 +129,8 @@ void SetLoopSectionCommand::onExecute(Context* ctx) } } - App::instance()->timeline()->invalidate(); + if (App::instance()->timeline()) + App::instance()->timeline()->invalidate(); } Command* CommandFactory::createSetLoopSectionCommand() diff --git a/src/app/commands/cmd_set_palette.cpp b/src/app/commands/cmd_set_palette.cpp index 6badeabd1..bb482333a 100644 --- a/src/app/commands/cmd_set_palette.cpp +++ b/src/app/commands/cmd_set_palette.cpp @@ -12,7 +12,6 @@ #include "app/context_access.h" #include "app/doc_api.h" #include "app/file_selector.h" -#include "app/ini_file.h" #include "app/modules/palettes.h" #include "app/tx.h" #include "doc/palette.h" @@ -23,9 +22,7 @@ namespace app { using namespace ui; -SetPaletteCommand::SetPaletteCommand() - : Command(CommandId::SetPalette(), CmdRecordableFlag) - , m_palette(NULL) +SetPaletteCommand::SetPaletteCommand() : Command(CommandId::SetPalette()), m_palette(NULL) { } diff --git a/src/app/commands/cmd_set_palette_entry_size.cpp b/src/app/commands/cmd_set_palette_entry_size.cpp index b266e8b70..a9aaca230 100644 --- a/src/app/commands/cmd_set_palette_entry_size.cpp +++ b/src/app/commands/cmd_set_palette_entry_size.cpp @@ -12,6 +12,7 @@ #include "app/app.h" #include "app/commands/command.h" #include "app/commands/params.h" +#include "app/context.h" #include "app/ui/color_bar.h" namespace app { @@ -21,6 +22,7 @@ public: SetPaletteEntrySizeCommand(); protected: + bool onEnabled(Context* context) override; void onLoadParams(const Params& params) override; bool onChecked(Context* context) override; void onExecute(Context* context) override; @@ -32,11 +34,16 @@ private: }; SetPaletteEntrySizeCommand::SetPaletteEntrySizeCommand() - : Command(CommandId::SetPaletteEntrySize(), CmdUIOnlyFlag) + : Command(CommandId::SetPaletteEntrySize()) , m_size(7) { } +bool SetPaletteEntrySizeCommand::onEnabled(Context* context) +{ + return context->isUIAvailable(); +} + void SetPaletteEntrySizeCommand::onLoadParams(const Params& params) { if (params.has_param("size")) diff --git a/src/app/commands/cmd_set_same_ink.cpp b/src/app/commands/cmd_set_same_ink.cpp index 5fc23ec6b..7377c1874 100644 --- a/src/app/commands/cmd_set_same_ink.cpp +++ b/src/app/commands/cmd_set_same_ink.cpp @@ -11,7 +11,6 @@ #include "app/app.h" #include "app/commands/command.h" #include "app/commands/commands.h" -#include "app/commands/params.h" #include "app/pref/preferences.h" #include "app/tools/tool.h" #include "app/tools/tool_box.h" @@ -27,7 +26,7 @@ protected: void onExecute(Context* context) override; }; -SetSameInkCommand::SetSameInkCommand() : Command(CommandId::SetSameInk(), CmdUIOnlyFlag) +SetSameInkCommand::SetSameInkCommand() : Command(CommandId::SetSameInk()) { } diff --git a/src/app/commands/cmd_show.cpp b/src/app/commands/cmd_show.cpp index d2fb98a94..a15faad35 100644 --- a/src/app/commands/cmd_show.cpp +++ b/src/app/commands/cmd_show.cpp @@ -18,7 +18,7 @@ namespace app { class ShowExtrasCommand : public Command { public: - ShowExtrasCommand() : Command(CommandId::ShowExtras(), CmdUIOnlyFlag) {} + ShowExtrasCommand() : Command(CommandId::ShowExtras()) {} protected: bool onChecked(Context* ctx) override @@ -49,7 +49,7 @@ protected: class ShowLayerEdgesCommand : public Command { public: - ShowLayerEdgesCommand() : Command(CommandId::ShowLayerEdges(), CmdUIOnlyFlag) {} + ShowLayerEdgesCommand() : Command(CommandId::ShowLayerEdges()) {} protected: bool onChecked(Context* ctx) override @@ -67,7 +67,7 @@ protected: class ShowGridCommand : public Command { public: - ShowGridCommand() : Command(CommandId::ShowGrid(), CmdUIOnlyFlag) {} + ShowGridCommand() : Command(CommandId::ShowGrid()) {} protected: bool onChecked(Context* ctx) override @@ -85,7 +85,7 @@ protected: class ShowPixelGridCommand : public Command { public: - ShowPixelGridCommand() : Command(CommandId::ShowPixelGrid(), CmdUIOnlyFlag) {} + ShowPixelGridCommand() : Command(CommandId::ShowPixelGrid()) {} protected: bool onChecked(Context* ctx) override @@ -103,7 +103,7 @@ protected: class ShowSelectionEdgesCommand : public Command { public: - ShowSelectionEdgesCommand() : Command(CommandId::ShowSelectionEdges(), CmdUIOnlyFlag) {} + ShowSelectionEdgesCommand() : Command(CommandId::ShowSelectionEdges()) {} protected: bool onChecked(Context* ctx) override @@ -121,7 +121,7 @@ protected: class ShowBrushPreviewCommand : public Command { public: - ShowBrushPreviewCommand() : Command(CommandId::ShowBrushPreview(), CmdUIOnlyFlag) {} + ShowBrushPreviewCommand() : Command(CommandId::ShowBrushPreview()) {} protected: bool onChecked(Context* ctx) override @@ -146,10 +146,7 @@ protected: // Preview in the Preview window), not based on the active document. class ShowBrushPreviewInPreviewCommand : public Command { public: - ShowBrushPreviewInPreviewCommand() - : Command(CommandId::ShowBrushPreviewInPreview(), CmdUIOnlyFlag) - { - } + ShowBrushPreviewInPreviewCommand() : Command(CommandId::ShowBrushPreviewInPreview()) {} protected: bool onChecked(Context* ctx) override @@ -167,7 +164,7 @@ protected: class ShowAutoGuidesCommand : public Command { public: - ShowAutoGuidesCommand() : Command(CommandId::ShowAutoGuides(), CmdUIOnlyFlag) {} + ShowAutoGuidesCommand() : Command(CommandId::ShowAutoGuides()) {} protected: bool onChecked(Context* ctx) override @@ -185,7 +182,7 @@ protected: class ShowSlicesCommand : public Command { public: - ShowSlicesCommand() : Command(CommandId::ShowSlices(), CmdUIOnlyFlag) {} + ShowSlicesCommand() : Command(CommandId::ShowSlices()) {} protected: bool onChecked(Context* ctx) override @@ -203,7 +200,7 @@ protected: class ShowTileNumbersCommand : public Command { public: - ShowTileNumbersCommand() : Command(CommandId::ShowTileNumbers(), CmdUIOnlyFlag) {} + ShowTileNumbersCommand() : Command(CommandId::ShowTileNumbers()) {} protected: bool onChecked(Context* ctx) override diff --git a/src/app/commands/cmd_slice_properties.cpp b/src/app/commands/cmd_slice_properties.cpp index 27ce7e45c..8a42dd9a6 100644 --- a/src/app/commands/cmd_slice_properties.cpp +++ b/src/app/commands/cmd_slice_properties.cpp @@ -39,7 +39,7 @@ private: }; SlicePropertiesCommand::SlicePropertiesCommand() - : Command(CommandId::SliceProperties(), CmdUIOnlyFlag) + : Command(CommandId::SliceProperties()) , m_sliceId(NullId) { } @@ -57,7 +57,7 @@ void SlicePropertiesCommand::onLoadParams(const Params& params) bool SlicePropertiesCommand::onEnabled(Context* context) { - return context->checkFlags(ContextFlags::ActiveDocumentIsWritable); + return context->isUIAvailable() && context->checkFlags(ContextFlags::ActiveDocumentIsWritable); } void SlicePropertiesCommand::onExecute(Context* context) diff --git a/src/app/commands/cmd_sprite_properties.cpp b/src/app/commands/cmd_sprite_properties.cpp index 31fd74244..900acfbfb 100644 --- a/src/app/commands/cmd_sprite_properties.cpp +++ b/src/app/commands/cmd_sprite_properties.cpp @@ -30,7 +30,6 @@ #include "app/util/pixel_ratio.h" #include "app/util/tileset_utils.h" #include "base/mem_utils.h" -#include "doc/image.h" #include "doc/palette.h" #include "doc/sprite.h" #include "doc/tilesets.h" @@ -235,15 +234,14 @@ protected: void onExecute(Context* context) override; }; -SpritePropertiesCommand::SpritePropertiesCommand() - : Command(CommandId::SpriteProperties(), CmdUIOnlyFlag) +SpritePropertiesCommand::SpritePropertiesCommand() : Command(CommandId::SpriteProperties()) { } bool SpritePropertiesCommand::onEnabled(Context* context) { - return context->checkFlags(ContextFlags::ActiveDocumentIsWritable | - ContextFlags::HasActiveSprite); + return context->isUIAvailable() && context->checkFlags(ContextFlags::ActiveDocumentIsWritable | + ContextFlags::HasActiveSprite); } void SpritePropertiesCommand::onExecute(Context* context) diff --git a/src/app/commands/cmd_sprite_size.cpp b/src/app/commands/cmd_sprite_size.cpp index fa975d82b..a4665d301 100644 --- a/src/app/commands/cmd_sprite_size.cpp +++ b/src/app/commands/cmd_sprite_size.cpp @@ -372,7 +372,7 @@ protected: }; SpriteSizeCommand::SpriteSizeCommand() - : CommandWithNewParams(CommandId::SpriteSize(), CmdRecordableFlag) + : CommandWithNewParams(CommandId::SpriteSize()) { } diff --git a/src/app/commands/cmd_swap_checkerboard_colors.cpp b/src/app/commands/cmd_swap_checkerboard_colors.cpp index d9b5424c3..37939e0a2 100644 --- a/src/app/commands/cmd_swap_checkerboard_colors.cpp +++ b/src/app/commands/cmd_swap_checkerboard_colors.cpp @@ -8,11 +8,9 @@ #include "config.h" #endif -#include "app/app.h" #include "app/commands/command.h" #include "app/context.h" #include "app/ui/editor/editor.h" -#include "ui/base.h" namespace app { @@ -26,7 +24,7 @@ protected: }; SwapCheckerboardColorsCommand::SwapCheckerboardColorsCommand() - : Command(CommandId::SwapCheckerboardColors(), CmdUIOnlyFlag) + : Command(CommandId::SwapCheckerboardColors()) { } diff --git a/src/app/commands/cmd_switch_colors.cpp b/src/app/commands/cmd_switch_colors.cpp index 23a7b8ccc..514685a73 100644 --- a/src/app/commands/cmd_switch_colors.cpp +++ b/src/app/commands/cmd_switch_colors.cpp @@ -14,7 +14,6 @@ #include "app/ui/color_bar.h" #include "app/ui/context_bar.h" #include "app/ui/editor/editor.h" -#include "ui/base.h" namespace app { @@ -27,7 +26,7 @@ protected: void onExecute(Context* context) override; }; -SwitchColorsCommand::SwitchColorsCommand() : Command(CommandId::SwitchColors(), CmdUIOnlyFlag) +SwitchColorsCommand::SwitchColorsCommand() : Command(CommandId::SwitchColors()) { } diff --git a/src/app/commands/cmd_symmetry_mode.cpp b/src/app/commands/cmd_symmetry_mode.cpp index 43491f9e6..8adb69eaf 100644 --- a/src/app/commands/cmd_symmetry_mode.cpp +++ b/src/app/commands/cmd_symmetry_mode.cpp @@ -15,10 +15,8 @@ #include "app/context.h" #include "app/doc.h" #include "app/i18n/strings.h" -#include "app/modules/gui.h" #include "app/pref/preferences.h" #include "app/ui/context_bar.h" -#include "app/ui_context.h" namespace app { @@ -37,7 +35,7 @@ private: app::gen::SymmetryMode m_mode = app::gen::SymmetryMode::NONE; }; -SymmetryModeCommand::SymmetryModeCommand() : Command(CommandId::SymmetryMode(), CmdUIOnlyFlag) +SymmetryModeCommand::SymmetryModeCommand() : Command(CommandId::SymmetryMode()) { } @@ -120,7 +118,8 @@ void SymmetryModeCommand::onExecute(Context* ctx) // TODO Same with context bar, in the future the context bar could // be listening the DocPref changes to be automatically // invalidated (like it already does with symmetryMode.enabled) - App::instance()->contextBar()->updateForActiveTool(); + if (App::instance()->contextBar()) + App::instance()->contextBar()->updateForActiveTool(); } } diff --git a/src/app/commands/cmd_tiled_mode.cpp b/src/app/commands/cmd_tiled_mode.cpp index f06ebf64c..48a5f020f 100644 --- a/src/app/commands/cmd_tiled_mode.cpp +++ b/src/app/commands/cmd_tiled_mode.cpp @@ -35,7 +35,7 @@ protected: }; TiledModeCommand::TiledModeCommand() - : Command(CommandId::TiledMode(), CmdUIOnlyFlag) + : Command(CommandId::TiledMode()) , m_mode(filters::TiledMode::NONE) { } diff --git a/src/app/commands/cmd_timeline.cpp b/src/app/commands/cmd_timeline.cpp index 3be19233d..64cd78ea3 100644 --- a/src/app/commands/cmd_timeline.cpp +++ b/src/app/commands/cmd_timeline.cpp @@ -24,6 +24,7 @@ public: TimelineCommand(); protected: + bool onEnabled(Context* context) override; bool onNeedsParams() const override { return true; } void onLoadParams(const Params& params) override; void onExecute(Context* context) override; @@ -34,13 +35,18 @@ protected: bool m_switch; }; -TimelineCommand::TimelineCommand() : Command(CommandId::Timeline(), CmdUIOnlyFlag) +TimelineCommand::TimelineCommand() : Command(CommandId::Timeline()) { m_open = true; m_close = false; m_switch = false; } +bool TimelineCommand::onEnabled(Context* context) +{ + return context->isUIAvailable(); +} + void TimelineCommand::onLoadParams(const Params& params) { m_open = params.get_as("open"); diff --git a/src/app/commands/cmd_toggle_preview.cpp b/src/app/commands/cmd_toggle_preview.cpp index 9fd291b70..030e8d54a 100644 --- a/src/app/commands/cmd_toggle_preview.cpp +++ b/src/app/commands/cmd_toggle_preview.cpp @@ -26,14 +26,14 @@ protected: void onExecute(Context* context) override; }; -TogglePreviewCommand::TogglePreviewCommand() : Command(CommandId::TogglePreview(), CmdUIOnlyFlag) +TogglePreviewCommand::TogglePreviewCommand() : Command(CommandId::TogglePreview()) { } bool TogglePreviewCommand::onEnabled(Context* context) { - return context->checkFlags(ContextFlags::ActiveDocumentIsWritable | - ContextFlags::HasActiveSprite); + return context->isUIAvailable() && context->checkFlags(ContextFlags::ActiveDocumentIsWritable | + ContextFlags::HasActiveSprite); } bool TogglePreviewCommand::onChecked(Context* context) diff --git a/src/app/commands/cmd_toggle_tiles_mode.cpp b/src/app/commands/cmd_toggle_tiles_mode.cpp index 5cee869fa..f322a13d5 100644 --- a/src/app/commands/cmd_toggle_tiles_mode.cpp +++ b/src/app/commands/cmd_toggle_tiles_mode.cpp @@ -18,7 +18,7 @@ using namespace gfx; class ToggleTilesModeCommand : public Command { public: - ToggleTilesModeCommand() : Command(CommandId::ToggleTilesMode(), CmdUIOnlyFlag) {} + ToggleTilesModeCommand() : Command(CommandId::ToggleTilesMode()) {} protected: bool onChecked(Context* context) override diff --git a/src/app/commands/cmd_toggle_timeline_thumbnails.cpp b/src/app/commands/cmd_toggle_timeline_thumbnails.cpp index 31112f98b..b81bcb7d6 100644 --- a/src/app/commands/cmd_toggle_timeline_thumbnails.cpp +++ b/src/app/commands/cmd_toggle_timeline_thumbnails.cpp @@ -10,7 +10,6 @@ #include "config.h" #endif -#include "app/app.h" #include "app/commands/command.h" #include "app/context.h" #include "app/doc.h" @@ -22,9 +21,7 @@ using namespace gfx; class ToggleTimelineThumbnailsCommand : public Command { public: - ToggleTimelineThumbnailsCommand() : Command(CommandId::ToggleTimelineThumbnails(), CmdUIOnlyFlag) - { - } + ToggleTimelineThumbnailsCommand() : Command(CommandId::ToggleTimelineThumbnails()) {} protected: bool onChecked(Context* context) override diff --git a/src/app/commands/cmd_undo.cpp b/src/app/commands/cmd_undo.cpp index 96f31117e..0bf9d38d1 100644 --- a/src/app/commands/cmd_undo.cpp +++ b/src/app/commands/cmd_undo.cpp @@ -23,7 +23,6 @@ #include "base/thread.h" #include "doc/sprite.h" #include "ui/manager.h" -#include "ui/system.h" namespace app { @@ -42,7 +41,7 @@ private: }; UndoCommand::UndoCommand(Type type) - : Command((type == Undo ? CommandId::Undo() : CommandId::Redo()), CmdUIOnlyFlag) + : Command((type == Undo ? CommandId::Undo() : CommandId::Redo())) , m_type(type) { } diff --git a/src/app/commands/cmd_undo_history.cpp b/src/app/commands/cmd_undo_history.cpp index 5fac6f5b4..c02f51036 100644 --- a/src/app/commands/cmd_undo_history.cpp +++ b/src/app/commands/cmd_undo_history.cpp @@ -30,8 +30,6 @@ #include "base/mem_utils.h" #include "fmt/format.h" #include "text/font_metrics.h" -#include "ui/init_theme_event.h" -#include "ui/listitem.h" #include "ui/message.h" #include "ui/paint_event.h" #include "ui/scale.h" @@ -497,15 +495,21 @@ public: UndoHistoryCommand(); protected: + bool onEnabled(Context* context) override; void onExecute(Context* ctx) override; }; static UndoHistoryWindow* g_window = NULL; -UndoHistoryCommand::UndoHistoryCommand() : Command(CommandId::UndoHistory(), CmdUIOnlyFlag) +UndoHistoryCommand::UndoHistoryCommand() : Command(CommandId::UndoHistory()) { } +bool UndoHistoryCommand::onEnabled(Context* context) +{ + return context->isUIAvailable(); +} + void UndoHistoryCommand::onExecute(Context* ctx) { if (!g_window) diff --git a/src/app/commands/cmd_unlink_cel.cpp b/src/app/commands/cmd_unlink_cel.cpp index 25e751d44..61e82e642 100644 --- a/src/app/commands/cmd_unlink_cel.cpp +++ b/src/app/commands/cmd_unlink_cel.cpp @@ -19,7 +19,6 @@ #include "app/ui/status_bar.h" #include "doc/cel.h" #include "doc/layer.h" -#include "doc/sprite.h" namespace app { @@ -32,7 +31,7 @@ protected: void onExecute(Context* context) override; }; -UnlinkCelCommand::UnlinkCelCommand() : Command(CommandId::UnlinkCel(), CmdRecordableFlag) +UnlinkCelCommand::UnlinkCelCommand() : Command(CommandId::UnlinkCel()) { } diff --git a/src/app/commands/cmd_zoom.cpp b/src/app/commands/cmd_zoom.cpp index 96aee22c6..a7374c3a9 100644 --- a/src/app/commands/cmd_zoom.cpp +++ b/src/app/commands/cmd_zoom.cpp @@ -43,7 +43,7 @@ private: }; ZoomCommand::ZoomCommand() - : Command(CommandId::Zoom(), CmdUIOnlyFlag) + : Command(CommandId::Zoom()) , m_action(Action::In) , m_zoom(1, 1) , m_focus(Focus::Default) diff --git a/src/app/commands/command.cpp b/src/app/commands/command.cpp index f94ef5b8f..f6625f6af 100644 --- a/src/app/commands/command.cpp +++ b/src/app/commands/command.cpp @@ -16,7 +16,7 @@ namespace app { -Command::Command(const char* id, CommandFlags flags) : m_id(id), m_flags(flags) +Command::Command(const char* id) : m_id(id) { } diff --git a/src/app/commands/command.h b/src/app/commands/command.h index 9d01d385b..2f13a868e 100644 --- a/src/app/commands/command.h +++ b/src/app/commands/command.h @@ -20,14 +20,9 @@ namespace app { class Context; class Params; -enum CommandFlags { - CmdUIOnlyFlag = 0x00000001, - CmdRecordableFlag = 0x00000002, -}; - class Command { public: - Command(const char* id, CommandFlags flags); + Command(const char* id); virtual ~Command(); const std::string& id() const { return m_id; } @@ -55,7 +50,6 @@ private: void execute(Context* context); std::string m_id; - CommandFlags m_flags; }; } // namespace app diff --git a/src/app/commands/convert_layer.cpp b/src/app/commands/convert_layer.cpp index c80cab48d..4414bc4ba 100644 --- a/src/app/commands/convert_layer.cpp +++ b/src/app/commands/convert_layer.cpp @@ -79,7 +79,7 @@ private: }; ConvertLayerCommand::ConvertLayerCommand() - : CommandWithNewParams(CommandId::ConvertLayer(), CmdRecordableFlag) + : CommandWithNewParams(CommandId::ConvertLayer()) { } diff --git a/src/app/commands/copy_path.cpp b/src/app/commands/copy_path.cpp index 4586ebf9f..02c4602f7 100644 --- a/src/app/commands/copy_path.cpp +++ b/src/app/commands/copy_path.cpp @@ -26,7 +26,7 @@ protected: void onExecute(Context* ctx) override; }; -CopyPathCommand::CopyPathCommand() : Command(CommandId::CopyPath(), CmdRecordableFlag) +CopyPathCommand::CopyPathCommand() : Command(CommandId::CopyPath()) { } diff --git a/src/app/commands/debugger.cpp b/src/app/commands/debugger.cpp index fb66d9ffe..095fb1e25 100644 --- a/src/app/commands/debugger.cpp +++ b/src/app/commands/debugger.cpp @@ -775,7 +775,7 @@ private: bool m_fileOk = true; }; -DebuggerCommand::DebuggerCommand() : Command(CommandId::Debugger(), CmdRecordableFlag) +DebuggerCommand::DebuggerCommand() : Command(CommandId::Debugger()) { } diff --git a/src/app/commands/filters/cmd_brightness_contrast.cpp b/src/app/commands/filters/cmd_brightness_contrast.cpp index db7928bfc..a7e05babe 100644 --- a/src/app/commands/filters/cmd_brightness_contrast.cpp +++ b/src/app/commands/filters/cmd_brightness_contrast.cpp @@ -85,8 +85,7 @@ protected: }; BrightnessContrastCommand::BrightnessContrastCommand() - : CommandWithNewParams(CommandId::BrightnessContrast(), - CmdRecordableFlag) + : CommandWithNewParams(CommandId::BrightnessContrast()) { } diff --git a/src/app/commands/filters/cmd_color_curve.cpp b/src/app/commands/filters/cmd_color_curve.cpp index e1e4deefb..af12a9058 100644 --- a/src/app/commands/filters/cmd_color_curve.cpp +++ b/src/app/commands/filters/cmd_color_curve.cpp @@ -82,7 +82,7 @@ protected: }; ColorCurveCommand::ColorCurveCommand() - : CommandWithNewParams(CommandId::ColorCurve(), CmdRecordableFlag) + : CommandWithNewParams(CommandId::ColorCurve()) { } diff --git a/src/app/commands/filters/cmd_convolution_matrix.cpp b/src/app/commands/filters/cmd_convolution_matrix.cpp index 18a79de78..6185fc5b4 100644 --- a/src/app/commands/filters/cmd_convolution_matrix.cpp +++ b/src/app/commands/filters/cmd_convolution_matrix.cpp @@ -162,7 +162,7 @@ protected: }; ConvolutionMatrixCommand::ConvolutionMatrixCommand() - : CommandWithNewParams(CommandId::ConvolutionMatrix(), CmdRecordableFlag) + : CommandWithNewParams(CommandId::ConvolutionMatrix()) { } diff --git a/src/app/commands/filters/cmd_despeckle.cpp b/src/app/commands/filters/cmd_despeckle.cpp index c202db84a..8618c9f2a 100644 --- a/src/app/commands/filters/cmd_despeckle.cpp +++ b/src/app/commands/filters/cmd_despeckle.cpp @@ -106,8 +106,7 @@ protected: void onExecute(Context* context) override; }; -DespeckleCommand::DespeckleCommand() - : CommandWithNewParams(CommandId::Despeckle(), CmdRecordableFlag) +DespeckleCommand::DespeckleCommand() : CommandWithNewParams(CommandId::Despeckle()) { } diff --git a/src/app/commands/filters/cmd_hue_saturation.cpp b/src/app/commands/filters/cmd_hue_saturation.cpp index 9073b4099..044063eae 100644 --- a/src/app/commands/filters/cmd_hue_saturation.cpp +++ b/src/app/commands/filters/cmd_hue_saturation.cpp @@ -139,7 +139,7 @@ protected: }; HueSaturationCommand::HueSaturationCommand() - : CommandWithNewParams(CommandId::HueSaturation(), CmdRecordableFlag) + : CommandWithNewParams(CommandId::HueSaturation()) { } diff --git a/src/app/commands/filters/cmd_invert_color.cpp b/src/app/commands/filters/cmd_invert_color.cpp index bcf9024ee..7e58ca148 100644 --- a/src/app/commands/filters/cmd_invert_color.cpp +++ b/src/app/commands/filters/cmd_invert_color.cpp @@ -59,7 +59,7 @@ protected: }; InvertColorCommand::InvertColorCommand() - : CommandWithNewParams(CommandId::InvertColor(), CmdRecordableFlag) + : CommandWithNewParams(CommandId::InvertColor()) { } diff --git a/src/app/commands/filters/cmd_outline.cpp b/src/app/commands/filters/cmd_outline.cpp index 0ef971300..925895d61 100644 --- a/src/app/commands/filters/cmd_outline.cpp +++ b/src/app/commands/filters/cmd_outline.cpp @@ -195,8 +195,7 @@ protected: void onExecute(Context* context) override; }; -OutlineCommand::OutlineCommand() - : CommandWithNewParams(CommandId::Outline(), CmdRecordableFlag) +OutlineCommand::OutlineCommand() : CommandWithNewParams(CommandId::Outline()) { } diff --git a/src/app/commands/filters/cmd_replace_color.cpp b/src/app/commands/filters/cmd_replace_color.cpp index 6eb4d04d8..86c0619fc 100644 --- a/src/app/commands/filters/cmd_replace_color.cpp +++ b/src/app/commands/filters/cmd_replace_color.cpp @@ -158,7 +158,7 @@ protected: }; ReplaceColorCommand::ReplaceColorCommand() - : CommandWithNewParams(CommandId::ReplaceColor(), CmdRecordableFlag) + : CommandWithNewParams(CommandId::ReplaceColor()) { } diff --git a/src/app/commands/move_colors_command.cpp b/src/app/commands/move_colors_command.cpp index aa22189ac..bad3398bf 100644 --- a/src/app/commands/move_colors_command.cpp +++ b/src/app/commands/move_colors_command.cpp @@ -33,8 +33,7 @@ class MoveColorsCommand : public CommandWithNewParams { public: MoveColorsCommand(bool copy) : CommandWithNewParams( - (copy ? CommandId::CopyColors() : CommandId::MoveColors()), - CmdRecordableFlag) + (copy ? CommandId::CopyColors() : CommandId::MoveColors())) , m_copy(copy) { } diff --git a/src/app/commands/move_tiles_command.cpp b/src/app/commands/move_tiles_command.cpp index 45aa2cabd..b9b456987 100644 --- a/src/app/commands/move_tiles_command.cpp +++ b/src/app/commands/move_tiles_command.cpp @@ -31,8 +31,7 @@ class MoveTilesCommand : public CommandWithNewParams { public: MoveTilesCommand(const bool copy) : CommandWithNewParams( - (copy ? CommandId::CopyTiles() : CommandId::MoveTiles()), - CmdRecordableFlag) + (copy ? CommandId::CopyTiles() : CommandId::MoveTiles())) , m_copy(copy) { } diff --git a/src/app/commands/quick_command.cpp b/src/app/commands/quick_command.cpp index b3015a24e..da499421f 100644 --- a/src/app/commands/quick_command.cpp +++ b/src/app/commands/quick_command.cpp @@ -13,7 +13,7 @@ namespace app { QuickCommand::QuickCommand(const char* id, std::function execute) - : Command(id, CmdUIOnlyFlag) + : Command(id) , m_execute(execute) { } diff --git a/src/app/commands/screenshot.cpp b/src/app/commands/screenshot.cpp index cca841583..a9e59b624 100644 --- a/src/app/commands/screenshot.cpp +++ b/src/app/commands/screenshot.cpp @@ -58,7 +58,7 @@ protected: }; ScreenshotCommand::ScreenshotCommand() - : CommandWithNewParams(CommandId::Screenshot(), CmdUIOnlyFlag) + : CommandWithNewParams(CommandId::Screenshot()) { } diff --git a/src/app/commands/set_playback_speed.cpp b/src/app/commands/set_playback_speed.cpp index 84e58ff5b..02114aa86 100644 --- a/src/app/commands/set_playback_speed.cpp +++ b/src/app/commands/set_playback_speed.cpp @@ -31,7 +31,7 @@ protected: }; SetPlaybackSpeedCommand::SetPlaybackSpeedCommand() - : CommandWithNewParams(CommandId::SetPlaybackSpeed(), CmdUIOnlyFlag) + : CommandWithNewParams(CommandId::SetPlaybackSpeed()) { } diff --git a/src/app/commands/show_menu.cpp b/src/app/commands/show_menu.cpp index 4e0c844a6..3a0749191 100644 --- a/src/app/commands/show_menu.cpp +++ b/src/app/commands/show_menu.cpp @@ -33,8 +33,7 @@ protected: void openSubmenuById(Menu* menu, const std::string& id); }; -ShowMenuCommand::ShowMenuCommand() - : CommandWithNewParams(CommandId::ShowMenu(), CmdUIOnlyFlag) +ShowMenuCommand::ShowMenuCommand() : CommandWithNewParams(CommandId::ShowMenu()) { } diff --git a/src/app/commands/tileset_mode.cpp b/src/app/commands/tileset_mode.cpp index 614019c30..d91572481 100644 --- a/src/app/commands/tileset_mode.cpp +++ b/src/app/commands/tileset_mode.cpp @@ -20,10 +20,7 @@ using namespace gfx; class TilesetModeCommand : public Command { public: - TilesetModeCommand() : Command(CommandId::TilesetMode(), CmdUIOnlyFlag) - { - m_mode = TilesetMode::Auto; - } + TilesetModeCommand() : Command(CommandId::TilesetMode()) { m_mode = TilesetMode::Auto; } protected: void onLoadParams(const Params& params) override diff --git a/src/app/commands/toggle_other_layers_opacity.cpp b/src/app/commands/toggle_other_layers_opacity.cpp index c92ac8fec..64991eacf 100644 --- a/src/app/commands/toggle_other_layers_opacity.cpp +++ b/src/app/commands/toggle_other_layers_opacity.cpp @@ -39,8 +39,7 @@ private: }; ToggleOtherLayersOpacityCommand::ToggleOtherLayersOpacityCommand() - : CommandWithNewParams(CommandId::ToggleOtherLayersOpacity(), - CmdUIOnlyFlag) + : CommandWithNewParams(CommandId::ToggleOtherLayersOpacity()) { } diff --git a/src/app/commands/toggle_play_option.cpp b/src/app/commands/toggle_play_option.cpp index 1f7d02adc..cd96d6d81 100644 --- a/src/app/commands/toggle_play_option.cpp +++ b/src/app/commands/toggle_play_option.cpp @@ -39,7 +39,7 @@ protected: TogglePlayOptionCommand::TogglePlayOptionCommand(const char* id, Option* general, Option* preview) - : Command(id, CmdUIOnlyFlag) + : Command(id) , m_general(general) , m_preview(preview) { diff --git a/src/app/commands/toggle_workspace_layout.cpp b/src/app/commands/toggle_workspace_layout.cpp index 37bf194ab..5e54be315 100644 --- a/src/app/commands/toggle_workspace_layout.cpp +++ b/src/app/commands/toggle_workspace_layout.cpp @@ -10,6 +10,7 @@ #include "app/app.h" #include "app/commands/command.h" +#include "app/context.h" #include "app/ui/layout_selector.h" #include "app/ui/main_window.h" @@ -20,15 +21,21 @@ public: ToggleWorkspaceLayoutCommand(); protected: + bool onEnabled(Context* ctx) override; bool onChecked(Context* ctx) override; void onExecute(Context* ctx) override; }; ToggleWorkspaceLayoutCommand::ToggleWorkspaceLayoutCommand() - : Command(CommandId::ToggleWorkspaceLayout(), CmdUIOnlyFlag) + : Command(CommandId::ToggleWorkspaceLayout()) { } +bool ToggleWorkspaceLayoutCommand::onEnabled(Context* ctx) +{ + return ctx->isUIAvailable(); +} + bool ToggleWorkspaceLayoutCommand::onChecked(Context* ctx) { return App::instance()->mainWindow()->layoutSelector()->isSelectorVisible(); diff --git a/src/app/context.cpp b/src/app/context.cpp index 046e1bad9..4e77825ef 100644 --- a/src/app/context.cpp +++ b/src/app/context.cpp @@ -198,6 +198,8 @@ void Context::executeCommand(Command* command, const Params& params) } else { LOG(VERBOSE, "CTXT: Command %s is disabled\n", command->id().c_str()); + m_result = CommandResult(CommandResult::kDisabled); + return; } AfterCommandExecution(ev); diff --git a/src/app/context.h b/src/app/context.h index d42566940..9e0a84454 100644 --- a/src/app/context.h +++ b/src/app/context.h @@ -48,6 +48,8 @@ public: kError, // Canceled by user. kCanceled, + // Disabled. + kDisabled }; CommandResult(Type type = Type::kOk) : m_type(type) {} diff --git a/src/app/inline_command_execution.h b/src/app/inline_command_execution.h index 6ebd51bb7..5a6e9dd74 100644 --- a/src/app/inline_command_execution.h +++ b/src/app/inline_command_execution.h @@ -19,7 +19,7 @@ namespace app { class InlineCommandExecution : public Command { public: - InlineCommandExecution(Context* ctx) : Command("", CmdUIOnlyFlag), m_context(ctx) + InlineCommandExecution(Context* ctx) : Command(""), m_context(ctx) { CommandExecutionEvent ev(this, m_noParams); m_context->BeforeCommandExecution(ev); diff --git a/src/app/script/app_command_object.cpp b/src/app/script/app_command_object.cpp index 3c8d5a57c..fc919a6ec 100644 --- a/src/app/script/app_command_object.cpp +++ b/src/app/script/app_command_object.cpp @@ -63,6 +63,17 @@ int Command_call(lua_State* L) return 1; } +int Command_enabled(lua_State* L) +{ + app::Context* ctx = App::instance()->context(); + if (!ctx) + return 0; + + auto* command = get_ptr(L, 1); + lua_pushboolean(L, command->isEnabled(ctx)); + return 1; +} + int AppCommand_index(lua_State* L) { const char* id = lua_tostring(L, 2); @@ -82,6 +93,11 @@ const luaL_Reg Command_methods[] = { { nullptr, nullptr } }; +const Property Command_properties[] = { + { "enabled", Command_enabled, nullptr }, + { nullptr, nullptr, nullptr } +}; + const luaL_Reg AppCommand_methods[] = { { "__index", AppCommand_index }, { nullptr, nullptr } @@ -95,6 +111,8 @@ DEF_MTNAME(AppCommand); void register_app_command_object(lua_State* L) { REG_CLASS(L, Command); + REG_CLASS_PROPERTIES(L, Command); + REG_CLASS(L, AppCommand); lua_getglobal(L, "app"); diff --git a/src/app/script/plugin_class.cpp b/src/app/script/plugin_class.cpp index a10475c06..634e5c694 100644 --- a/src/app/script/plugin_class.cpp +++ b/src/app/script/plugin_class.cpp @@ -30,7 +30,7 @@ struct Plugin { class PluginCommand : public Command { public: PluginCommand(const std::string& id, const std::string& title, int onclickRef, int onenabledRef) - : Command(id.c_str(), CmdUIOnlyFlag) + : Command(id.c_str()) , m_title(title) , m_onclickRef(onclickRef) , m_onenabledRef(onenabledRef)