mirror of https://github.com/aseprite/aseprite.git
Compare commits
2 Commits
736ddba6e0
...
275ab97611
| Author | SHA1 | Date |
|---|---|---|
|
|
275ab97611 | |
|
|
424ce6899a |
|
|
@ -17,6 +17,7 @@
|
||||||
#include "ver/info.h"
|
#include "ver/info.h"
|
||||||
|
|
||||||
#include "about.xml.h"
|
#include "about.xml.h"
|
||||||
|
#include "app/context.h"
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|
||||||
|
|
@ -27,6 +28,7 @@ public:
|
||||||
AboutCommand();
|
AboutCommand();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool onEnabled(Context* context) override;
|
||||||
void onExecute(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)
|
void AboutCommand::onExecute(Context* context)
|
||||||
{
|
{
|
||||||
gen::About window;
|
gen::About window;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
|
||||||
#include "advanced_mode.xml.h"
|
#include "advanced_mode.xml.h"
|
||||||
|
#include "app/context.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
|
@ -29,6 +30,7 @@ public:
|
||||||
AdvancedModeCommand();
|
AdvancedModeCommand();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool onEnabled(Context* context) override;
|
||||||
void onExecute(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)
|
void AdvancedModeCommand::onExecute(Context* context)
|
||||||
{
|
{
|
||||||
// Switch advanced mode.
|
// Switch advanced mode.
|
||||||
|
|
|
||||||
|
|
@ -390,8 +390,8 @@ CelPropertiesCommand::CelPropertiesCommand() : Command(CommandId::CelProperties(
|
||||||
|
|
||||||
bool CelPropertiesCommand::onEnabled(Context* context)
|
bool CelPropertiesCommand::onEnabled(Context* context)
|
||||||
{
|
{
|
||||||
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
return context->isUIAvailable() && context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
||||||
ContextFlags::ActiveLayerIsImage);
|
ContextFlags::ActiveLayerIsImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CelPropertiesCommand::onExecute(Context* context)
|
void CelPropertiesCommand::onExecute(Context* context)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#include "app/app.h"
|
#include "app/app.h"
|
||||||
#include "app/commands/command.h"
|
#include "app/commands/command.h"
|
||||||
#include "app/commands/params.h"
|
#include "app/commands/params.h"
|
||||||
|
#include "app/context.h"
|
||||||
#include "app/i18n/strings.h"
|
#include "app/i18n/strings.h"
|
||||||
#include "app/modules/palettes.h"
|
#include "app/modules/palettes.h"
|
||||||
#include "app/ui/color_bar.h"
|
#include "app/ui/color_bar.h"
|
||||||
|
|
@ -39,6 +40,7 @@ public:
|
||||||
ChangeColorCommand();
|
ChangeColorCommand();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool onEnabled(Context* context) override;
|
||||||
bool onNeedsParams() const override { return true; }
|
bool onNeedsParams() const override { return true; }
|
||||||
void onLoadParams(const Params& params) override;
|
void onLoadParams(const Params& params) override;
|
||||||
void onExecute(Context* context) override;
|
void onExecute(Context* context) override;
|
||||||
|
|
@ -51,6 +53,11 @@ ChangeColorCommand::ChangeColorCommand() : Command(CommandId::ChangeColor())
|
||||||
m_change = None;
|
m_change = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ChangeColorCommand::onEnabled(Context* context)
|
||||||
|
{
|
||||||
|
return context->isUIAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
void ChangeColorCommand::onLoadParams(const Params& params)
|
void ChangeColorCommand::onLoadParams(const Params& params)
|
||||||
{
|
{
|
||||||
std::string target = params.get("target");
|
std::string target = params.get("target");
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,14 @@ void FramePropertiesCommand::onLoadParams(const Params& params)
|
||||||
m_target = CURRENT_RANGE;
|
m_target = CURRENT_RANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int frameNumber = frame_t(base::convert_to<int>(frame));
|
const auto frameNumber = base::convert_to<frame_t>(frame);
|
||||||
// Will open with the default target (CURRENT_RANGE) if the frame number cannot be parsed.
|
if (frameNumber < 1) {
|
||||||
if (frameNumber < 1)
|
// Will open with the default target (CURRENT_RANGE) if the frame number cannot be parsed.
|
||||||
return;
|
m_frame = CURRENT_RANGE;
|
||||||
|
}
|
||||||
|
|
||||||
m_frame = frameNumber;
|
|
||||||
m_target = SPECIFIC_FRAME;
|
m_target = SPECIFIC_FRAME;
|
||||||
|
m_frame = frameNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FramePropertiesCommand::onEnabled(Context* context)
|
bool FramePropertiesCommand::onEnabled(Context* context)
|
||||||
|
|
|
||||||
|
|
@ -198,6 +198,8 @@ void Context::executeCommand(Command* command, const Params& params)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG(VERBOSE, "CTXT: Command %s is disabled\n", command->id().c_str());
|
LOG(VERBOSE, "CTXT: Command %s is disabled\n", command->id().c_str());
|
||||||
|
m_result = CommandResult(CommandResult::kDisabled);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterCommandExecution(ev);
|
AfterCommandExecution(ev);
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ public:
|
||||||
kError,
|
kError,
|
||||||
// Canceled by user.
|
// Canceled by user.
|
||||||
kCanceled,
|
kCanceled,
|
||||||
|
// Disabled.
|
||||||
|
kDisabled
|
||||||
};
|
};
|
||||||
|
|
||||||
CommandResult(Type type = Type::kOk) : m_type(type) {}
|
CommandResult(Type type = Type::kOk) : m_type(type) {}
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,17 @@ int Command_call(lua_State* L)
|
||||||
return 1;
|
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)
|
int AppCommand_index(lua_State* L)
|
||||||
{
|
{
|
||||||
const char* id = lua_tostring(L, 2);
|
const char* id = lua_tostring(L, 2);
|
||||||
|
|
@ -82,6 +93,11 @@ const luaL_Reg Command_methods[] = {
|
||||||
{ nullptr, nullptr }
|
{ nullptr, nullptr }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Property Command_properties[] = {
|
||||||
|
{ "enabled", Command_enabled, nullptr },
|
||||||
|
{ nullptr, nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
const luaL_Reg AppCommand_methods[] = {
|
const luaL_Reg AppCommand_methods[] = {
|
||||||
{ "__index", AppCommand_index },
|
{ "__index", AppCommand_index },
|
||||||
{ nullptr, nullptr }
|
{ nullptr, nullptr }
|
||||||
|
|
@ -95,6 +111,8 @@ DEF_MTNAME(AppCommand);
|
||||||
void register_app_command_object(lua_State* L)
|
void register_app_command_object(lua_State* L)
|
||||||
{
|
{
|
||||||
REG_CLASS(L, Command);
|
REG_CLASS(L, Command);
|
||||||
|
REG_CLASS_PROPERTIES(L, Command);
|
||||||
|
|
||||||
REG_CLASS(L, AppCommand);
|
REG_CLASS(L, AppCommand);
|
||||||
|
|
||||||
lua_getglobal(L, "app");
|
lua_getglobal(L, "app");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue