Compare commits

..

2 Commits

Author SHA1 Message Date
Christian Kaiser 275ab97611
Merge 424ce6899a into 6d89a6bc15 2025-07-29 23:09:47 +00:00
Christian Kaiser 424ce6899a [WIP] Command refresh 2025-07-29 20:09:10 -03:00
8 changed files with 51 additions and 7 deletions

View File

@ -17,6 +17,7 @@
#include "ver/info.h"
#include "about.xml.h"
#include "app/context.h"
namespace app {
@ -27,6 +28,7 @@ public:
AboutCommand();
protected:
bool onEnabled(Context* context) override;
void onExecute(Context* context) override;
};
@ -34,6 +36,11 @@ AboutCommand::AboutCommand() : Command(CommandId::About())
{
}
bool AboutCommand::onEnabled(Context* context)
{
return context->isUIAvailable();
}
void AboutCommand::onExecute(Context* context)
{
gen::About window;

View File

@ -17,6 +17,7 @@
#include "ui/ui.h"
#include "advanced_mode.xml.h"
#include "app/context.h"
#include <cstdio>
@ -29,6 +30,7 @@ public:
AdvancedModeCommand();
protected:
bool onEnabled(Context* context) override;
void onExecute(Context* context) override;
};
@ -36,6 +38,11 @@ AdvancedModeCommand::AdvancedModeCommand() : Command(CommandId::AdvancedMode())
{
}
bool AdvancedModeCommand::onEnabled(Context* context)
{
return context->isUIAvailable();
}
void AdvancedModeCommand::onExecute(Context* context)
{
// Switch advanced mode.

View File

@ -390,8 +390,8 @@ 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

@ -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,6 +40,7 @@ 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;
@ -51,6 +53,11 @@ ChangeColorCommand::ChangeColorCommand() : Command(CommandId::ChangeColor())
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

@ -62,13 +62,14 @@ void FramePropertiesCommand::onLoadParams(const Params& params)
m_target = CURRENT_RANGE;
}
const int frameNumber = frame_t(base::convert_to<int>(frame));
// Will open with the default target (CURRENT_RANGE) if the frame number cannot be parsed.
if (frameNumber < 1)
return;
const auto frameNumber = base::convert_to<frame_t>(frame);
if (frameNumber < 1) {
// Will open with the default target (CURRENT_RANGE) if the frame number cannot be parsed.
m_frame = CURRENT_RANGE;
}
m_frame = frameNumber;
m_target = SPECIFIC_FRAME;
m_frame = frameNumber;
}
bool FramePropertiesCommand::onEnabled(Context* context)

View File

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

View File

@ -48,6 +48,8 @@ public:
kError,
// Canceled by user.
kCanceled,
// Disabled.
kDisabled
};
CommandResult(Type type = Type::kOk) : m_type(type) {}

View File

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