Command refresh and refactor, ui availability consistency (fix #3025)

This commit is contained in:
Christian Kaiser 2025-08-05 15:59:31 -03:00
parent 7434db6882
commit 366751d1f2
153 changed files with 536 additions and 525 deletions

View File

@ -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;

View File

@ -63,8 +63,7 @@ protected:
std::string onGetFriendlyName() const override;
};
AddColorCommand::AddColorCommand()
: CommandWithNewParams<AddColorParams>(CommandId::AddColor(), CmdUIOnlyFlag)
AddColorCommand::AddColorCommand() : CommandWithNewParams<AddColorParams>(CommandId::AddColor())
{
}

View File

@ -17,8 +17,7 @@
#include "ui/ui.h"
#include "advanced_mode.xml.h"
#include <cstdio>
#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.

View File

@ -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())
{
}

View File

@ -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)
{
}

View File

@ -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())
{
}

View File

@ -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 <string>
@ -42,7 +40,7 @@ private:
int m_opacity;
};
CelOpacityCommand::CelOpacityCommand() : Command(CommandId::CelOpacity(), CmdUIOnlyFlag)
CelOpacityCommand::CelOpacityCommand() : Command(CommandId::CelOpacity())
{
m_opacity = 255;
}

View File

@ -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)

View File

@ -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;

View File

@ -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");

View File

@ -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())
{
}

View File

@ -23,7 +23,7 @@ protected:
void onExecute(Context* ctx) override;
};
ClearCommand::ClearCommand() : Command(CommandId::Clear(), CmdUIOnlyFlag)
ClearCommand::ClearCommand() : Command(CommandId::Clear())
{
}

View File

@ -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);

View File

@ -23,8 +23,7 @@ protected:
void onExecute(Context* ctx) override;
};
ClearRecentFilesCommand::ClearRecentFilesCommand()
: Command(CommandId::ClearRecentFiles(), CmdUIOnlyFlag)
ClearRecentFilesCommand::ClearRecentFilesCommand() : Command(CommandId::ClearRecentFiles())
{
}

View File

@ -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 <memory>
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<bool>("quitting"); }
void onExecute(Context* context) override

View File

@ -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<ColorQuantizationParams>(CommandId::ColorQuantization(), CmdRecordableFlag)
: CommandWithNewParams<ColorQuantizationParams>(CommandId::ColorQuantization())
{
}

View File

@ -24,7 +24,7 @@ protected:
void onExecute(Context* context) override;
};
ContiguousFillCommand::ContiguousFillCommand() : Command(CommandId::ContiguousFill(), CmdUIOnlyFlag)
ContiguousFillCommand::ContiguousFillCommand() : Command(CommandId::ContiguousFill())
{
}

View File

@ -23,7 +23,7 @@ protected:
void onExecute(Context* ctx) override;
};
CopyCommand::CopyCommand() : Command(CommandId::Copy(), CmdUIOnlyFlag)
CopyCommand::CopyCommand() : Command(CommandId::Copy())
{
}

View File

@ -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)

View File

@ -24,7 +24,7 @@ protected:
void onExecute(Context* ctx) override;
};
CopyMergedCommand::CopyMergedCommand() : Command(CommandId::CopyMerged(), CmdUIOnlyFlag)
CopyMergedCommand::CopyMergedCommand() : Command(CommandId::CopyMerged())
{
}

View File

@ -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())
{
}

View File

@ -23,7 +23,7 @@ protected:
void onExecute(Context* ctx) override;
};
CutCommand::CutCommand() : Command(CommandId::Cut(), CmdUIOnlyFlag)
CutCommand::CutCommand() : Command(CommandId::Cut())
{
}

View File

@ -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())
{
}

View File

@ -29,8 +29,7 @@ protected:
void onExecute(Context* context);
};
DeveloperConsoleCommand::DeveloperConsoleCommand()
: Command(CommandId::DeveloperConsole(), CmdUIOnlyFlag)
DeveloperConsoleCommand::DeveloperConsoleCommand() : Command(CommandId::DeveloperConsole())
{
}

View File

@ -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);
}

View File

@ -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())
{
}

View File

@ -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 <cstdio>
namespace app {
using namespace ui;
@ -43,7 +40,7 @@ protected:
};
DuplicateSpriteCommand::DuplicateSpriteCommand()
: CommandWithNewParams<DuplicateSpriteParams>(CommandId::DuplicateSprite(), CmdRecordableFlag)
: CommandWithNewParams<DuplicateSpriteParams>(CommandId::DuplicateSprite())
{
}

View File

@ -13,8 +13,6 @@
#include "app/commands/command.h"
#include "app/ui/workspace.h"
#include <cstdio>
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())
{
}

View File

@ -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())
{
}

View File

@ -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())
{
}

View File

@ -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)
{
}

View File

@ -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;
}

View File

@ -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)
{
}

View File

@ -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())
{
}

View File

@ -36,7 +36,7 @@ protected:
bool m_visibleOnly;
};
FlattenLayersCommand::FlattenLayersCommand() : Command(CommandId::FlattenLayers(), CmdUIOnlyFlag)
FlattenLayersCommand::FlattenLayersCommand() : Command(CommandId::FlattenLayers())
{
m_visibleOnly = false;
}

View File

@ -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;

View File

@ -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)

View File

@ -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)

View File

@ -27,7 +27,7 @@ protected:
void onExecute(Context* context) override;
};
FullscreenModeCommand::FullscreenModeCommand() : Command(CommandId::FullscreenMode(), CmdUIOnlyFlag)
FullscreenModeCommand::FullscreenModeCommand() : Command(CommandId::FullscreenMode())
{
}

View File

@ -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())
{
}

View File

@ -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); }

View File

@ -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()

View File

@ -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())
{
}

View File

@ -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)

View File

@ -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()

View File

@ -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())
{
}

View File

@ -31,7 +31,7 @@ protected:
void onExecute(Context* context) override;
};
InvertMaskCommand::InvertMaskCommand() : Command(CommandId::InvertMask(), CmdRecordableFlag)
InvertMaskCommand::InvertMaskCommand() : Command(CommandId::InvertMask())
{
}

View File

@ -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");

View File

@ -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("")
{
}

View File

@ -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())
{
}

View File

@ -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())
{
}

View File

@ -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;
}

View File

@ -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)

View File

@ -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())
{
}

View File

@ -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);

View File

@ -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<bool>("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> 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;
}

View File

@ -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<bool>("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())

View File

@ -29,7 +29,7 @@ protected:
void onExecute(Context* context) override;
};
MaskAllCommand::MaskAllCommand() : Command(CommandId::MaskAll(), CmdRecordableFlag)
MaskAllCommand::MaskAllCommand() : Command(CommandId::MaskAll())
{
}

View File

@ -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())
{
}

View File

@ -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);

View File

@ -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())
{
}

View File

@ -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 <limits>
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<bool>("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;

View File

@ -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)

View File

@ -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())
{
}

View File

@ -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)

View File

@ -64,7 +64,7 @@ protected:
// static
int NewFileCommand::g_spriteCounter = 0;
NewFileCommand::NewFileCommand() : CommandWithNewParams(CommandId::NewFile(), CmdRecordableFlag)
NewFileCommand::NewFileCommand() : CommandWithNewParams(CommandId::NewFile())
{
}

View File

@ -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 <stdexcept>
namespace app {
@ -57,7 +47,7 @@ private:
Content m_content;
};
NewFrameCommand::NewFrameCommand() : Command(CommandId::NewFrame(), CmdRecordableFlag)
NewFrameCommand::NewFrameCommand() : Command(CommandId::NewFrame())
{
}

View File

@ -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 <stdexcept>
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)

View File

@ -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 <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
@ -99,7 +96,7 @@ private:
Place m_place;
};
NewLayerCommand::NewLayerCommand() : CommandWithNewParams(CommandId::NewLayer(), CmdRecordableFlag)
NewLayerCommand::NewLayerCommand() : CommandWithNewParams(CommandId::NewLayer())
{
}

View File

@ -23,8 +23,6 @@
#include "doc/sprite.h"
#include "fmt/format.h"
#include <cstdio>
namespace app {
using namespace doc;
@ -39,7 +37,7 @@ protected:
};
NewSpriteFromSelectionCommand::NewSpriteFromSelectionCommand()
: Command(CommandId::NewSpriteFromSelection(), CmdUIOnlyFlag)
: Command(CommandId::NewSpriteFromSelection())
{
}

View File

@ -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

View File

@ -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");

View File

@ -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)

View File

@ -32,7 +32,7 @@ protected:
// std::string onGetFriendlyName() const override;
};
OpenGroupCommand::OpenGroupCommand() : Command(CommandId::OpenGroup(), CmdRecordableFlag)
OpenGroupCommand::OpenGroupCommand() : Command(CommandId::OpenGroup())
{
}

View File

@ -25,7 +25,7 @@ protected:
void onExecute(Context* context) override;
};
OpenInFolderCommand::OpenInFolderCommand() : Command(CommandId::OpenInFolder(), CmdUIOnlyFlag)
OpenInFolderCommand::OpenInFolderCommand() : Command(CommandId::OpenInFolder())
{
}

View File

@ -33,8 +33,7 @@ protected:
void onExecute(Context* context);
};
OpenScriptFolderCommand::OpenScriptFolderCommand()
: Command(CommandId::OpenScriptFolder(), CmdUIOnlyFlag)
OpenScriptFolderCommand::OpenScriptFolderCommand() : Command(CommandId::OpenScriptFolder())
{
}

View File

@ -25,7 +25,7 @@ protected:
void onExecute(Context* context) override;
};
OpenWithAppCommand::OpenWithAppCommand() : Command(CommandId::OpenWithApp(), CmdUIOnlyFlag)
OpenWithAppCommand::OpenWithAppCommand() : Command(CommandId::OpenWithApp())
{
}

View File

@ -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();

View File

@ -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" ||

View File

@ -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<int>("size");
if (params.has_param("ui"))
m_ui = params.get_as<bool>("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();

View File

@ -31,7 +31,7 @@ private:
std::unique_ptr<gfx::Point> m_position;
};
PasteCommand::PasteCommand() : Command(CommandId::Paste(), CmdUIOnlyFlag)
PasteCommand::PasteCommand() : Command(CommandId::Paste())
{
}

View File

@ -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<bool> ui{ this, true, "ui" };
Param<app::Color> color{ this, app::Color::fromMask(), "color" };
Param<std::string> text{ this, "", "text" };
Param<std::string> fontName{ this, "Aseprite", "fontName" };
Param<double> fontSize{ this, 6, "fontSize" };
Param<int> x{ this, 0, "x" };
Param<int> y{ this, 0, "y" };
};
class PasteTextCommand : public CommandWithNewParams<PasteTextParams> {
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);

View File

@ -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())
{
}

View File

@ -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)

View File

@ -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())
{
}

View File

@ -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())
{
}

View File

@ -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)
{
}

View File

@ -105,7 +105,7 @@ protected:
void onExecute(Context* context) override;
};
RemoveLayerCommand::RemoveLayerCommand() : Command(CommandId::RemoveLayer(), CmdRecordableFlag)
RemoveLayerCommand::RemoveLayerCommand() : Command(CommandId::RemoveLayer())
{
}

View File

@ -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()));
}
}
}

View File

@ -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 <cstdio>
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())
{
}

View File

@ -27,8 +27,7 @@ protected:
virtual void onExecute(Context* context) override;
};
RepeatLastExportCommand::RepeatLastExportCommand()
: Command(CommandId::RepeatLastExport(), CmdRecordableFlag)
RepeatLastExportCommand::RepeatLastExportCommand() : Command(CommandId::RepeatLastExport())
{
}

View File

@ -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())
{
}

View File

@ -27,7 +27,7 @@ protected:
void onExecute(Context* context) override;
};
ReverseFramesCommand::ReverseFramesCommand() : Command(CommandId::ReverseFrames(), CmdUIOnlyFlag)
ReverseFramesCommand::ReverseFramesCommand() : Command(CommandId::ReverseFrames())
{
}

View File

@ -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);
}

View File

@ -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 <cstdio>
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())
{
}

View File

@ -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<SaveFileParams>(id, flags)
SaveFileBaseCommand::SaveFileBaseCommand(const char* id) : CommandWithNewParams<SaveFileParams>(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())
{
}

View File

@ -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;

View File

@ -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<bool> ui{ this, true, "ui" };
Param<std::string> filename{ this, "default.msk", "filename" };
};
class SaveMaskCommand : public CommandWithNewParams<SaveMaskParams> {
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));
}

View File

@ -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<bool> ui{ this, true, "ui" };
Param<std::string> filename{ this, "", "filename" };
Param<std::string> preset{ this, "", "preset" };
Param<bool> saveAsPreset{ this, false, "saveAsPreset" };
Param<int> columns{ this, 16, "columns" };
};
class SavePaletteCommand : public CommandWithNewParams<SavePaletteParams> {
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();
}

View File

@ -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)

Some files were not shown because too many files have changed in this diff Show More