mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Always load params when a command is executed
This is to avoid leaving commands with old params (a problem with keyboard shortcuts). To make sure, we've changed arguments from Params* to Params&, so we always have params to load. Also, in this change we introduce a new way to give parameters to executed commands from menu items using AppMenuItem::setContextParams(). Before showing a popup, we can call setContextParams() to give extra params to the command (e.g. the specific FrameTag to remove or change properties). In this way "contextparams" attribute for <item> in gui.xml is not available anymore.
This commit is contained in:
parent
50fd6e9e2f
commit
0cb4b2234d
@ -670,8 +670,8 @@
|
||||
</menu>
|
||||
|
||||
<menu id="frame_tag_popup">
|
||||
<item command="FrameTagProperties" text="Tag &Properties..." contextparams="true" />
|
||||
<item command="RemoveFrameTag" text="&Remove Tag" contextparams="true" />
|
||||
<item command="FrameTagProperties" text="Tag &Properties..." />
|
||||
<item command="RemoveFrameTag" text="&Remove Tag" />
|
||||
</menu>
|
||||
|
||||
</menus>
|
||||
|
@ -317,7 +317,7 @@ void App::initialize(const AppOptions& options)
|
||||
Params params;
|
||||
params.set("filename", fn.c_str());
|
||||
params.set("filename-format", fmt.c_str());
|
||||
ctx->executeCommand(saveAsCommand, ¶ms);
|
||||
ctx->executeCommand(saveAsCommand, params);
|
||||
|
||||
if (trim) { // Undo trim command
|
||||
ctx->executeCommand(undoCommand);
|
||||
@ -344,7 +344,7 @@ void App::initialize(const AppOptions& options)
|
||||
Params params;
|
||||
params.set("filename", value.value().c_str());
|
||||
params.set("filename-format", format.c_str());
|
||||
ctx->executeCommand(saveAsCommand, ¶ms);
|
||||
ctx->executeCommand(saveAsCommand, params);
|
||||
|
||||
if (trim) { // Undo trim command
|
||||
ctx->executeCommand(undoCommand);
|
||||
|
@ -141,17 +141,17 @@ bool AppMenus::rebuildRecentList()
|
||||
|
||||
for (; it != end; ++it) {
|
||||
const char* filename = it->c_str();
|
||||
|
||||
params.set("filename", filename);
|
||||
|
||||
menuitem = new AppMenuItem(
|
||||
base::get_file_name(filename).c_str(),
|
||||
cmd_open_file, ¶ms);
|
||||
cmd_open_file,
|
||||
params);
|
||||
submenu->addChild(menuitem);
|
||||
}
|
||||
}
|
||||
else {
|
||||
menuitem = new AppMenuItem("Nothing", NULL, NULL);
|
||||
menuitem = new AppMenuItem("Nothing", NULL, Params());
|
||||
menuitem->setEnabled(false);
|
||||
submenu->addChild(menuitem);
|
||||
}
|
||||
@ -215,8 +215,6 @@ Widget* AppMenus::convertXmlelemToMenuitem(TiXmlElement* elem)
|
||||
command_name ? CommandsModule::instance()->getCommandByName(command_name):
|
||||
NULL;
|
||||
|
||||
bool contextparams = bool_attr_is_true(elem, "contextparams");
|
||||
|
||||
// load params
|
||||
Params params;
|
||||
if (command) {
|
||||
@ -233,8 +231,7 @@ Widget* AppMenus::convertXmlelemToMenuitem(TiXmlElement* elem)
|
||||
}
|
||||
|
||||
// Create the item
|
||||
AppMenuItem* menuitem = new AppMenuItem(elem->Attribute("text"),
|
||||
command, (command && !contextparams ? ¶ms: nullptr));
|
||||
AppMenuItem* menuitem = new AppMenuItem(elem->Attribute("text"), command, params);
|
||||
if (!menuitem)
|
||||
return NULL;
|
||||
|
||||
@ -262,24 +259,25 @@ Widget* AppMenus::convertXmlelemToMenuitem(TiXmlElement* elem)
|
||||
|
||||
Widget* AppMenus::createInvalidVersionMenuitem()
|
||||
{
|
||||
AppMenuItem* menuitem = new AppMenuItem("WARNING!", NULL, NULL);
|
||||
AppMenuItem* menuitem = new AppMenuItem("WARNING!");
|
||||
Menu* subMenu = new Menu();
|
||||
subMenu->addChild(new AppMenuItem(PACKAGE " is using a customized gui.xml (maybe from your HOME directory).", NULL, NULL));
|
||||
subMenu->addChild(new AppMenuItem("You should update your customized gui.xml file to the new version to get", NULL, NULL));
|
||||
subMenu->addChild(new AppMenuItem("the latest commands available.", NULL, NULL));
|
||||
Params params;
|
||||
subMenu->addChild(new AppMenuItem(PACKAGE " is using a customized gui.xml (maybe from your HOME directory)."));
|
||||
subMenu->addChild(new AppMenuItem("You should update your customized gui.xml file to the new version to get"));
|
||||
subMenu->addChild(new AppMenuItem("the latest commands available."));
|
||||
subMenu->addChild(new Separator("", JI_HORIZONTAL));
|
||||
subMenu->addChild(new AppMenuItem("You can bypass this validation adding the correct version", NULL, NULL));
|
||||
subMenu->addChild(new AppMenuItem("number in <gui version=\"" VERSION "\"> element.", NULL, NULL));
|
||||
subMenu->addChild(new AppMenuItem("You can bypass this validation adding the correct version"));
|
||||
subMenu->addChild(new AppMenuItem("number in <gui version=\"" VERSION "\"> element."));
|
||||
menuitem->setSubmenu(subMenu);
|
||||
return menuitem;
|
||||
}
|
||||
|
||||
void AppMenus::applyShortcutToMenuitemsWithCommand(Command* command, Params* params, Key* key)
|
||||
void AppMenus::applyShortcutToMenuitemsWithCommand(Command* command, const Params& params, Key* key)
|
||||
{
|
||||
applyShortcutToMenuitemsWithCommand(m_rootMenu, command, params, key);
|
||||
}
|
||||
|
||||
void AppMenus::applyShortcutToMenuitemsWithCommand(Menu* menu, Command* command, Params* params, Key* key)
|
||||
void AppMenus::applyShortcutToMenuitemsWithCommand(Menu* menu, Command* command, const Params& params, Key* key)
|
||||
{
|
||||
UI_FOREACH_WIDGET(menu->getChildren(), it) {
|
||||
Widget* child = *it;
|
||||
@ -290,13 +288,12 @@ void AppMenus::applyShortcutToMenuitemsWithCommand(Menu* menu, Command* command,
|
||||
continue;
|
||||
|
||||
Command* mi_command = menuitem->getCommand();
|
||||
Params* mi_params = menuitem->getParams();
|
||||
const Params& mi_params = menuitem->getParams();
|
||||
|
||||
if ((mi_command) &&
|
||||
(base::string_to_lower(mi_command->short_name()) ==
|
||||
base::string_to_lower(command->short_name())) &&
|
||||
((mi_params && *mi_params == *params) ||
|
||||
(Params() == *params))) {
|
||||
(mi_params == params)) {
|
||||
// Set the keyboard shortcut to be shown in this menu-item
|
||||
menuitem->setKey(key);
|
||||
}
|
||||
|
@ -47,14 +47,14 @@ namespace app {
|
||||
Menu* getCelMovementPopupMenu() { return m_celMovementPopupMenu; }
|
||||
Menu* getFrameTagPopupMenu() { return m_frameTagPopupMenu; }
|
||||
|
||||
void applyShortcutToMenuitemsWithCommand(Command* command, Params* params, Key* key);
|
||||
void applyShortcutToMenuitemsWithCommand(Command* command, const Params& params, Key* key);
|
||||
|
||||
private:
|
||||
Menu* loadMenuById(TiXmlHandle& handle, const char *id);
|
||||
Menu* convertXmlelemToMenu(TiXmlElement* elem);
|
||||
Widget* convertXmlelemToMenuitem(TiXmlElement* elem);
|
||||
Widget* createInvalidVersionMenuitem();
|
||||
void applyShortcutToMenuitemsWithCommand(Menu* menu, Command* command, Params* params, Key* key);
|
||||
void applyShortcutToMenuitemsWithCommand(Menu* menu, Command* command, const Params& params, Key* key);
|
||||
|
||||
base::UniquePtr<Menu> m_rootMenu;
|
||||
MenuItem* m_recentListMenuitem;
|
||||
|
@ -28,8 +28,8 @@ public:
|
||||
Command* clone() const override { return new CancelCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
void onExecute(Context* context);
|
||||
void onLoadParams(const Params& params) override;
|
||||
void onExecute(Context* context) override;
|
||||
|
||||
private:
|
||||
Type m_type;
|
||||
@ -43,9 +43,9 @@ CancelCommand::CancelCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void CancelCommand::onLoadParams(Params* params)
|
||||
void CancelCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string type = params->get("type");
|
||||
std::string type = params.get("type");
|
||||
if (type == "noop") m_type = NoOp;
|
||||
else if (type == "all") m_type = All;
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ public:
|
||||
ChangeBrushCommand();
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
void onExecute(Context* context);
|
||||
std::string onGetFriendlyName() const;
|
||||
void onLoadParams(const Params& params) override;
|
||||
void onExecute(Context* context) override;
|
||||
std::string onGetFriendlyName() const override;
|
||||
};
|
||||
|
||||
ChangeBrushCommand::ChangeBrushCommand()
|
||||
@ -49,9 +49,9 @@ ChangeBrushCommand::ChangeBrushCommand()
|
||||
m_change = None;
|
||||
}
|
||||
|
||||
void ChangeBrushCommand::onLoadParams(Params* params)
|
||||
void ChangeBrushCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string change = params->get("change");
|
||||
std::string change = params.get("change");
|
||||
if (change == "increment-size") m_change = IncrementSize;
|
||||
else if (change == "decrement-size") m_change = DecrementSize;
|
||||
else if (change == "increment-angle") m_change = IncrementAngle;
|
||||
|
@ -37,9 +37,9 @@ public:
|
||||
ChangeColorCommand();
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
void onExecute(Context* context);
|
||||
std::string onGetFriendlyName() const;
|
||||
void onLoadParams(const Params& params) override;
|
||||
void onExecute(Context* context) override;
|
||||
std::string onGetFriendlyName() const override;
|
||||
};
|
||||
|
||||
ChangeColorCommand::ChangeColorCommand()
|
||||
@ -51,13 +51,13 @@ ChangeColorCommand::ChangeColorCommand()
|
||||
m_change = None;
|
||||
}
|
||||
|
||||
void ChangeColorCommand::onLoadParams(Params* params)
|
||||
void ChangeColorCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string target = params->get("target");
|
||||
std::string target = params.get("target");
|
||||
if (target == "foreground") m_background = false;
|
||||
else if (target == "background") m_background = true;
|
||||
|
||||
std::string change = params->get("change");
|
||||
std::string change = params.get("change");
|
||||
if (change == "increment-index") m_change = IncrementIndex;
|
||||
else if (change == "decrement-index") m_change = DecrementIndex;
|
||||
}
|
||||
|
@ -31,10 +31,10 @@ public:
|
||||
Command* clone() const override { return new ChangePixelFormatCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
bool onEnabled(Context* context);
|
||||
bool onChecked(Context* context);
|
||||
void onExecute(Context* context);
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
bool onChecked(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
};
|
||||
|
||||
ChangePixelFormatCommand::ChangePixelFormatCommand()
|
||||
@ -46,14 +46,14 @@ ChangePixelFormatCommand::ChangePixelFormatCommand()
|
||||
m_dithering = DitheringMethod::NONE;
|
||||
}
|
||||
|
||||
void ChangePixelFormatCommand::onLoadParams(Params* params)
|
||||
void ChangePixelFormatCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string format = params->get("format");
|
||||
std::string format = params.get("format");
|
||||
if (format == "rgb") m_format = IMAGE_RGB;
|
||||
else if (format == "grayscale") m_format = IMAGE_GRAYSCALE;
|
||||
else if (format == "indexed") m_format = IMAGE_INDEXED;
|
||||
|
||||
std::string dithering = params->get("dithering");
|
||||
std::string dithering = params.get("dithering");
|
||||
if (dithering == "ordered")
|
||||
m_dithering = DitheringMethod::ORDERED;
|
||||
else
|
||||
|
@ -142,7 +142,7 @@ private:
|
||||
Command* grid_settings_cmd =
|
||||
CommandsModule::instance()->getCommandByName(CommandId::GridSettings);
|
||||
|
||||
UIContext::instance()->executeCommand(grid_settings_cmd, NULL);
|
||||
UIContext::instance()->executeCommand(grid_settings_cmd);
|
||||
}
|
||||
}
|
||||
catch (LockedDocumentException& e) {
|
||||
|
@ -396,7 +396,7 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
|
||||
command = static_cast<SaveFileBaseCommand*>(CommandsModule::instance()
|
||||
->getCommandByName(CommandId::SaveFileCopyAs));
|
||||
|
||||
context->executeCommand(command, ¶ms);
|
||||
context->executeCommand(command, params);
|
||||
|
||||
// Always go back, as we are using "Save Copy As", so the user
|
||||
// wants to continue editing the original sprite.
|
||||
@ -407,7 +407,7 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
|
||||
command = static_cast<SaveFileBaseCommand*>(CommandsModule::instance()
|
||||
->getCommandByName(CommandId::SaveFileAs));
|
||||
|
||||
context->executeCommand(command, ¶ms);
|
||||
context->executeCommand(command, params);
|
||||
|
||||
// If the command was cancelled, we go back to the original
|
||||
// state, if the sprite sheet was saved then we don't undo
|
||||
@ -419,7 +419,7 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
|
||||
command = static_cast<SaveFileBaseCommand*>(CommandsModule::instance()
|
||||
->getCommandByName(CommandId::SaveFile));
|
||||
|
||||
context->executeCommand(command, ¶ms);
|
||||
context->executeCommand(command, params);
|
||||
|
||||
// Same case as "Save As"
|
||||
undo = (document->isModified());
|
||||
|
@ -42,8 +42,8 @@ public:
|
||||
Command* clone() const override { return new EyedropperCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
void onExecute(Context* context);
|
||||
void onLoadParams(const Params& params) override;
|
||||
void onExecute(Context* context) override;
|
||||
};
|
||||
|
||||
EyedropperCommand::EyedropperCommand()
|
||||
@ -54,9 +54,9 @@ EyedropperCommand::EyedropperCommand()
|
||||
m_background = false;
|
||||
}
|
||||
|
||||
void EyedropperCommand::onLoadParams(Params* params)
|
||||
void EyedropperCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string target = params->get("target");
|
||||
std::string target = params.get("target");
|
||||
if (target == "foreground") m_background = false;
|
||||
else if (target == "background") m_background = true;
|
||||
}
|
||||
|
@ -43,12 +43,12 @@ FlipCommand::FlipCommand()
|
||||
m_flipType = doc::algorithm::FlipHorizontal;
|
||||
}
|
||||
|
||||
void FlipCommand::onLoadParams(Params* params)
|
||||
void FlipCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string target = params->get("target");
|
||||
std::string target = params.get("target");
|
||||
m_flipMask = (target == "mask");
|
||||
|
||||
std::string orientation = params->get("orientation");
|
||||
std::string orientation = params.get("orientation");
|
||||
m_flipType = (orientation == "vertical" ? doc::algorithm::FlipVertical:
|
||||
doc::algorithm::FlipHorizontal);
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ namespace app {
|
||||
doc::algorithm::FlipType getFlipType() const { return m_flipType; }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
bool onEnabled(Context* context);
|
||||
void onExecute(Context* context);
|
||||
std::string onGetFriendlyName() const;
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
std::string onGetFriendlyName() const override;
|
||||
|
||||
private:
|
||||
bool m_flipMask;
|
||||
|
@ -35,9 +35,9 @@ public:
|
||||
Command* clone() const override { return new FramePropertiesCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
bool onEnabled(Context* context);
|
||||
void onExecute(Context* context);
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
|
||||
private:
|
||||
enum Target {
|
||||
@ -59,9 +59,9 @@ FramePropertiesCommand::FramePropertiesCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void FramePropertiesCommand::onLoadParams(Params* params)
|
||||
void FramePropertiesCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string frame = params->get("frame");
|
||||
std::string frame = params.get("frame");
|
||||
if (frame == "all") {
|
||||
m_target = ALL_FRAMES;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
Command* clone() const override { return new FrameTagPropertiesCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params) override;
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
|
||||
@ -52,11 +52,11 @@ FrameTagPropertiesCommand::FrameTagPropertiesCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void FrameTagPropertiesCommand::onLoadParams(Params* params)
|
||||
void FrameTagPropertiesCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
m_tagName = params->get("name");
|
||||
m_tagName = params.get("name");
|
||||
|
||||
std::string id = params->get("id");
|
||||
std::string id = params.get("id");
|
||||
if (!id.empty())
|
||||
m_tagId = ObjectId(base::convert_to<ObjectId>(id));
|
||||
else
|
||||
|
@ -117,8 +117,9 @@ protected:
|
||||
case kKeyDownMessage: {
|
||||
KeyMessage* keyMsg = static_cast<KeyMessage*>(msg);
|
||||
Command* command = NULL;
|
||||
Params params;
|
||||
KeyboardShortcuts::instance()
|
||||
->getCommandFromKeyMessage(msg, &command, NULL);
|
||||
->getCommandFromKeyMessage(msg, &command, ¶ms);
|
||||
|
||||
// Change frame
|
||||
if (command != NULL &&
|
||||
@ -126,7 +127,7 @@ protected:
|
||||
std::strcmp(command->short_name(), CommandId::GotoPreviousFrame) == 0 ||
|
||||
std::strcmp(command->short_name(), CommandId::GotoNextFrame) == 0 ||
|
||||
std::strcmp(command->short_name(), CommandId::GotoLastFrame) == 0)) {
|
||||
m_context->executeCommand(command);
|
||||
m_context->executeCommand(command, params);
|
||||
invalidate();
|
||||
m_render.reset(NULL); // Re-render
|
||||
}
|
||||
|
@ -108,9 +108,9 @@ public:
|
||||
Command* clone() const override { return new GotoFrameCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params) override
|
||||
void onLoadParams(const Params& params) override
|
||||
{
|
||||
std::string frame = params->get("frame");
|
||||
std::string frame = params.get("frame");
|
||||
if (!frame.empty()) m_frame = strtol(frame.c_str(), NULL, 10);
|
||||
else m_frame = 0;
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ protected:
|
||||
Command* openFile = CommandsModule::instance()->getCommandByName(CommandId::OpenFile);
|
||||
Params params;
|
||||
params.set("filename", "");
|
||||
openFile->loadParams(¶ms);
|
||||
openFile->loadParams(params);
|
||||
openFile->execute(m_context);
|
||||
|
||||
// The user have selected another document.
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
Command* clone() const override { return new LaunchCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params) override;
|
||||
void onLoadParams(const Params& params) override;
|
||||
void onExecute(Context* context) override;
|
||||
|
||||
private:
|
||||
@ -41,9 +41,9 @@ LaunchCommand::LaunchCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void LaunchCommand::onLoadParams(Params* params)
|
||||
void LaunchCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
m_path = params->get("path");
|
||||
m_path = params.get("path");
|
||||
|
||||
if (m_type == Url && !m_path.empty() && m_path[0] == '/') {
|
||||
m_path = WEBSITE + m_path.substr(1);
|
||||
|
@ -31,10 +31,9 @@ public:
|
||||
Command* clone() const override { return new LoadMaskCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
|
||||
bool onEnabled(Context* context);
|
||||
void onExecute(Context* context);
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
};
|
||||
|
||||
LoadMaskCommand::LoadMaskCommand()
|
||||
@ -45,9 +44,9 @@ LoadMaskCommand::LoadMaskCommand()
|
||||
m_filename = "";
|
||||
}
|
||||
|
||||
void LoadMaskCommand::onLoadParams(Params* params)
|
||||
void LoadMaskCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
m_filename = params->get("filename");
|
||||
m_filename = params.get("filename");
|
||||
}
|
||||
|
||||
bool LoadMaskCommand::onEnabled(Context* context)
|
||||
|
@ -34,19 +34,19 @@ MoveMaskCommand::MoveMaskCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void MoveMaskCommand::onLoadParams(Params* params)
|
||||
void MoveMaskCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string target = params->get("target");
|
||||
std::string target = params.get("target");
|
||||
if (target == "boundaries") m_target = Boundaries;
|
||||
else if (target == "content") m_target = Content;
|
||||
|
||||
std::string direction = params->get("direction");
|
||||
std::string direction = params.get("direction");
|
||||
if (direction == "left") m_direction = Left;
|
||||
else if (direction == "right") m_direction = Right;
|
||||
else if (direction == "up") m_direction = Up;
|
||||
else if (direction == "down") m_direction = Down;
|
||||
|
||||
std::string units = params->get("units");
|
||||
std::string units = params.get("units");
|
||||
if (units == "pixel") m_units = Pixel;
|
||||
else if (units == "tile-width") m_units = TileWidth;
|
||||
else if (units == "tile-height") m_units = TileHeight;
|
||||
@ -56,7 +56,7 @@ void MoveMaskCommand::onLoadParams(Params* params)
|
||||
else if (units == "viewport-width") m_units = ViewportWidth;
|
||||
else if (units == "viewport-height") m_units = ViewportHeight;
|
||||
|
||||
int quantity = params->get_as<int>("quantity");
|
||||
int quantity = params.get_as<int>("quantity");
|
||||
m_quantity = std::max<int>(1, quantity);
|
||||
}
|
||||
|
||||
|
@ -34,10 +34,10 @@ namespace app {
|
||||
Target getTarget() const { return m_target; }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
bool onEnabled(Context* context);
|
||||
void onExecute(Context* context);
|
||||
std::string onGetFriendlyName() const;
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
std::string onGetFriendlyName() const override;
|
||||
|
||||
private:
|
||||
Target m_target;
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
Command* clone() const override { return new NewFrameCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params) override;
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
std::string onGetFriendlyName() const override;
|
||||
@ -54,11 +54,11 @@ NewFrameCommand::NewFrameCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void NewFrameCommand::onLoadParams(Params* params)
|
||||
void NewFrameCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
m_content = Content::CurrentFrame;
|
||||
|
||||
std::string content = params->get("content");
|
||||
std::string content = params.get("content");
|
||||
if (content == "current") m_content = Content::CurrentFrame;
|
||||
else if (content == "empty") m_content = Content::EmptyFrame;
|
||||
}
|
||||
|
@ -37,9 +37,9 @@ public:
|
||||
Command* clone() const override { return new NewLayerCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
bool onEnabled(Context* context);
|
||||
void onExecute(Context* context);
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
|
||||
private:
|
||||
bool m_ask;
|
||||
@ -58,12 +58,12 @@ NewLayerCommand::NewLayerCommand()
|
||||
m_name = "";
|
||||
}
|
||||
|
||||
void NewLayerCommand::onLoadParams(Params* params)
|
||||
void NewLayerCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string ask = params->get("ask");
|
||||
std::string ask = params.get("ask");
|
||||
if (ask == "true") m_ask = true;
|
||||
|
||||
m_name = params->get("name");
|
||||
m_name = params.get("name");
|
||||
}
|
||||
|
||||
bool NewLayerCommand::onEnabled(Context* context)
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
Command* clone() const override { return new OpenFileCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params) override;
|
||||
void onLoadParams(const Params& params) override;
|
||||
void onExecute(Context* context) override;
|
||||
|
||||
private:
|
||||
@ -97,10 +97,10 @@ OpenFileCommand::OpenFileCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void OpenFileCommand::onLoadParams(Params* params)
|
||||
void OpenFileCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
m_filename = params->get("filename");
|
||||
m_folder = params->get("folder"); // Initial folder
|
||||
m_filename = params.get("filename");
|
||||
m_folder = params.get("folder"); // Initial folder
|
||||
}
|
||||
|
||||
void OpenFileCommand::onExecute(Context* context)
|
||||
|
@ -136,7 +136,7 @@ public:
|
||||
Command* clone() const override { return new PaletteEditorCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params) override;
|
||||
void onLoadParams(const Params& params) override;
|
||||
void onExecute(Context* context) override;
|
||||
|
||||
private:
|
||||
@ -157,21 +157,21 @@ PaletteEditorCommand::PaletteEditorCommand()
|
||||
m_background = false;
|
||||
}
|
||||
|
||||
void PaletteEditorCommand::onLoadParams(Params* params)
|
||||
void PaletteEditorCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string target = params->get("target");
|
||||
std::string target = params.get("target");
|
||||
if (target == "foreground") m_background = false;
|
||||
else if (target == "background") m_background = true;
|
||||
|
||||
std::string open_str = params->get("open");
|
||||
std::string open_str = params.get("open");
|
||||
if (open_str == "true") m_open = true;
|
||||
else m_open = false;
|
||||
|
||||
std::string close_str = params->get("close");
|
||||
std::string close_str = params.get("close");
|
||||
if (close_str == "true") m_close = true;
|
||||
else m_close = false;
|
||||
|
||||
std::string switch_str = params->get("switch");
|
||||
std::string switch_str = params.get("switch");
|
||||
if (switch_str == "true") m_switch = true;
|
||||
else m_switch = false;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
Command* clone() const override { return new RemoveFrameTagCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params) override;
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
|
||||
@ -47,11 +47,11 @@ RemoveFrameTagCommand::RemoveFrameTagCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void RemoveFrameTagCommand::onLoadParams(Params* params)
|
||||
void RemoveFrameTagCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
m_tagName = params->get("name");
|
||||
m_tagName = params.get("name");
|
||||
|
||||
std::string id = params->get("id");
|
||||
std::string id = params.get("id");
|
||||
if (!id.empty())
|
||||
m_tagId = ObjectId(base::convert_to<ObjectId>(id));
|
||||
else
|
||||
|
@ -38,10 +38,10 @@ public:
|
||||
Command* clone() const override { return new RotateCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
bool onEnabled(Context* context);
|
||||
void onExecute(Context* context);
|
||||
std::string onGetFriendlyName() const;
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
std::string onGetFriendlyName() const override;
|
||||
|
||||
private:
|
||||
bool m_flipMask;
|
||||
@ -180,13 +180,13 @@ RotateCommand::RotateCommand()
|
||||
m_angle = 0;
|
||||
}
|
||||
|
||||
void RotateCommand::onLoadParams(Params* params)
|
||||
void RotateCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string target = params->get("target");
|
||||
std::string target = params.get("target");
|
||||
m_flipMask = (target == "mask");
|
||||
|
||||
if (params->has_param("angle")) {
|
||||
m_angle = strtol(params->get("angle").c_str(), NULL, 10);
|
||||
if (params.has_param("angle")) {
|
||||
m_angle = strtol(params.get("angle").c_str(), NULL, 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,10 +111,10 @@ SaveFileBaseCommand::SaveFileBaseCommand(const char* short_name, const char* fri
|
||||
{
|
||||
}
|
||||
|
||||
void SaveFileBaseCommand::onLoadParams(Params* params)
|
||||
void SaveFileBaseCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
m_filename = params->get("filename");
|
||||
m_filenameFormat = params->get("filename-format");
|
||||
m_filename = params.get("filename");
|
||||
m_filenameFormat = params.get("filename-format");
|
||||
}
|
||||
|
||||
// Returns true if there is a current sprite to save.
|
||||
|
@ -25,7 +25,7 @@ namespace app {
|
||||
}
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params) override;
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
|
||||
void saveAsDialog(const ContextReader& reader, const char* dlgTitle, bool markAsSaved);
|
||||
|
@ -39,10 +39,10 @@ public:
|
||||
Command* clone() const override { return new ScrollCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
bool onEnabled(Context* context);
|
||||
void onExecute(Context* context);
|
||||
std::string onGetFriendlyName() const;
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
std::string onGetFriendlyName() const override;
|
||||
|
||||
private:
|
||||
Direction m_direction;
|
||||
@ -57,15 +57,15 @@ ScrollCommand::ScrollCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void ScrollCommand::onLoadParams(Params* params)
|
||||
void ScrollCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string direction = params->get("direction");
|
||||
std::string direction = params.get("direction");
|
||||
if (direction == "left") m_direction = Left;
|
||||
else if (direction == "right") m_direction = Right;
|
||||
else if (direction == "up") m_direction = Up;
|
||||
else if (direction == "down") m_direction = Down;
|
||||
|
||||
std::string units = params->get("units");
|
||||
std::string units = params.get("units");
|
||||
if (units == "pixel") m_units = Pixel;
|
||||
else if (units == "tile-width") m_units = TileWidth;
|
||||
else if (units == "tile-height") m_units = TileHeight;
|
||||
@ -75,7 +75,7 @@ void ScrollCommand::onLoadParams(Params* params)
|
||||
else if (units == "viewport-width") m_units = ViewportWidth;
|
||||
else if (units == "viewport-height") m_units = ViewportHeight;
|
||||
|
||||
int quantity = params->get_as<int>("quantity");
|
||||
int quantity = params.get_as<int>("quantity");
|
||||
m_quantity = std::max<int>(1, quantity);
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
Command* clone() const override { return new SetLoopSectionCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params) override;
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
|
||||
@ -51,15 +51,15 @@ SetLoopSectionCommand::SetLoopSectionCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void SetLoopSectionCommand::onLoadParams(Params* params)
|
||||
void SetLoopSectionCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string action = params->get("action");
|
||||
std::string action = params.get("action");
|
||||
if (action == "on") m_action = Action::On;
|
||||
else if (action == "off") m_action = Action::Off;
|
||||
else m_action = Action::Auto;
|
||||
|
||||
std::string begin = params->get("begin");
|
||||
std::string end = params->get("end");
|
||||
std::string begin = params.get("begin");
|
||||
std::string end = params.get("end");
|
||||
|
||||
m_begin = frame_t(strtol(begin.c_str(), NULL, 10));
|
||||
m_end = frame_t(strtol(end.c_str(), NULL, 10));
|
||||
|
@ -167,23 +167,23 @@ Command* SpriteSizeCommand::clone() const
|
||||
return new SpriteSizeCommand(*this);
|
||||
}
|
||||
|
||||
void SpriteSizeCommand::onLoadParams(Params* params)
|
||||
void SpriteSizeCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string width = params->get("width");
|
||||
std::string width = params.get("width");
|
||||
if (!width.empty()) {
|
||||
m_width = std::strtol(width.c_str(), NULL, 10);
|
||||
}
|
||||
else
|
||||
m_width = 0;
|
||||
|
||||
std::string height = params->get("height");
|
||||
std::string height = params.get("height");
|
||||
if (!height.empty()) {
|
||||
m_height = std::strtol(height.c_str(), NULL, 10);
|
||||
}
|
||||
else
|
||||
m_height = 0;
|
||||
|
||||
std::string resize_method = params->get("resize-method");
|
||||
std::string resize_method = params.get("resize-method");
|
||||
if (!resize_method.empty()) {
|
||||
if (resize_method == "bilinear")
|
||||
m_resizeMethod = doc::algorithm::RESIZE_METHOD_BILINEAR;
|
||||
|
@ -32,7 +32,7 @@ namespace app {
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void onLoadParams(Params* params) override;
|
||||
virtual void onLoadParams(const Params& params) override;
|
||||
virtual bool onEnabled(Context* context) override;
|
||||
virtual void onExecute(Context* context) override;
|
||||
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
Command* clone() const override { return new TimelineCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params) override;
|
||||
void onLoadParams(const Params& params) override;
|
||||
void onExecute(Context* context) override;
|
||||
|
||||
bool m_open;
|
||||
@ -44,17 +44,17 @@ TimelineCommand::TimelineCommand()
|
||||
m_switch = false;
|
||||
}
|
||||
|
||||
void TimelineCommand::onLoadParams(Params* params)
|
||||
void TimelineCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string open_str = params->get("open");
|
||||
std::string open_str = params.get("open");
|
||||
if (open_str == "true") m_open = true;
|
||||
else m_open = false;
|
||||
|
||||
std::string close_str = params->get("close");
|
||||
std::string close_str = params.get("close");
|
||||
if (close_str == "true") m_close = true;
|
||||
else m_close = false;
|
||||
|
||||
std::string switch_str = params->get("switch");
|
||||
std::string switch_str = params.get("switch");
|
||||
if (switch_str == "true") m_switch = true;
|
||||
else m_switch = false;
|
||||
}
|
||||
|
@ -26,10 +26,10 @@ public:
|
||||
Command* clone() const override { return new ZoomCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
bool onEnabled(Context* context);
|
||||
void onExecute(Context* context);
|
||||
std::string onGetFriendlyName() const;
|
||||
void onLoadParams(const Params& params) override;
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
std::string onGetFriendlyName() const override;
|
||||
|
||||
private:
|
||||
Action m_action;
|
||||
@ -43,14 +43,14 @@ ZoomCommand::ZoomCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void ZoomCommand::onLoadParams(Params* params)
|
||||
void ZoomCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
std::string action = params->get("action");
|
||||
std::string action = params.get("action");
|
||||
if (action == "in") m_action = In;
|
||||
else if (action == "out") m_action = Out;
|
||||
else if (action == "set") m_action = Set;
|
||||
|
||||
std::string percentage = params->get("percentage");
|
||||
std::string percentage = params.get("percentage");
|
||||
if (!percentage.empty()) {
|
||||
m_percentage = std::strtol(percentage.c_str(), NULL, 10);
|
||||
m_action = Set;
|
||||
|
@ -31,7 +31,7 @@ std::string Command::friendlyName() const
|
||||
return onGetFriendlyName();
|
||||
}
|
||||
|
||||
void Command::loadParams(Params* params)
|
||||
void Command::loadParams(const Params& params)
|
||||
{
|
||||
onLoadParams(params);
|
||||
}
|
||||
@ -66,7 +66,7 @@ void Command::execute(Context* context)
|
||||
/**
|
||||
* Converts specified parameters to class members.
|
||||
*/
|
||||
void Command::onLoadParams(Params* params)
|
||||
void Command::onLoadParams(const Params& params)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
@ -36,13 +36,13 @@ namespace app {
|
||||
const char* short_name() const { return m_short_name; }
|
||||
std::string friendlyName() const;
|
||||
|
||||
void loadParams(Params* params);
|
||||
void loadParams(const Params& params);
|
||||
bool isEnabled(Context* context);
|
||||
bool isChecked(Context* context);
|
||||
void execute(Context* context);
|
||||
|
||||
protected:
|
||||
virtual void onLoadParams(Params* params);
|
||||
virtual void onLoadParams(const Params& params);
|
||||
virtual bool onEnabled(Context* context);
|
||||
virtual bool onChecked(Context* context);
|
||||
virtual void onExecute(Context* context);
|
||||
|
@ -25,18 +25,14 @@ namespace app {
|
||||
const_iterator begin() const { return m_params.begin(); }
|
||||
const_iterator end() const { return m_params.end(); }
|
||||
|
||||
Params() { }
|
||||
Params(const Params& copy) : m_params(copy.m_params) { }
|
||||
virtual ~Params() { }
|
||||
|
||||
Params* clone() const {
|
||||
return new Params(*this);
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
return m_params.empty();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
return m_params.clear();
|
||||
}
|
||||
|
||||
bool has_param(const char* name) const {
|
||||
return m_params.find(name) != m_params.end();
|
||||
}
|
||||
@ -53,12 +49,17 @@ namespace app {
|
||||
return m_params[name] = value;
|
||||
}
|
||||
|
||||
std::string& get(const char* name) {
|
||||
const std::string& get(const char* name) const {
|
||||
return m_params[name];
|
||||
}
|
||||
|
||||
void operator|=(const Params& params) const {
|
||||
for (const auto& p : params)
|
||||
m_params[p.first] = p.second;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T get_as(const char* name) {
|
||||
const T get_as(const char* name) const {
|
||||
std::istringstream stream(m_params[name]);
|
||||
T value;
|
||||
stream >> value;
|
||||
@ -66,7 +67,7 @@ namespace app {
|
||||
}
|
||||
|
||||
private:
|
||||
Map m_params;
|
||||
mutable Map m_params;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
@ -69,7 +69,7 @@ void Context::executeCommand(const char* commandName)
|
||||
throw std::runtime_error("Invalid command name");
|
||||
}
|
||||
|
||||
void Context::executeCommand(Command* command, Params* params)
|
||||
void Context::executeCommand(Command* command, const Params& params)
|
||||
{
|
||||
Console console;
|
||||
|
||||
@ -81,8 +81,7 @@ void Context::executeCommand(Command* command, Params* params)
|
||||
try {
|
||||
m_flags.update(this);
|
||||
|
||||
if (params)
|
||||
command->loadParams(params);
|
||||
command->loadParams(params);
|
||||
|
||||
if (command->isEnabled(this)) {
|
||||
command->execute(this);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define APP_CONTEXT_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/commands/params.h"
|
||||
#include "app/context_flags.h"
|
||||
#include "base/disable_copying.h"
|
||||
#include "base/exception.h"
|
||||
@ -22,7 +23,6 @@ namespace app {
|
||||
class Document;
|
||||
class DocumentLocation;
|
||||
class ISettings;
|
||||
class Params;
|
||||
|
||||
class CommandPreconditionException : public base::Exception {
|
||||
public:
|
||||
@ -53,7 +53,7 @@ namespace app {
|
||||
DocumentLocation activeLocation() const;
|
||||
|
||||
void executeCommand(const char* commandName);
|
||||
virtual void executeCommand(Command* command, Params* params = NULL);
|
||||
virtual void executeCommand(Command* command, const Params& params = Params());
|
||||
|
||||
Signal1<void, Command*> BeforeCommandExecution;
|
||||
Signal1<void, Command*> AfterCommandExecution;
|
||||
|
@ -433,7 +433,7 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg)
|
||||
// Load the file
|
||||
else {
|
||||
params.set("filename", fn.c_str());
|
||||
ctx->executeCommand(cmd_open_file, ¶ms);
|
||||
ctx->executeCommand(cmd_open_file, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,17 +30,21 @@ namespace app {
|
||||
|
||||
using namespace ui;
|
||||
|
||||
AppMenuItem::AppMenuItem(const char* text, Command* command, const Params* params)
|
||||
// static
|
||||
Params AppMenuItem::s_contextParams;
|
||||
|
||||
AppMenuItem::AppMenuItem(const char* text, Command* command, const Params& params)
|
||||
: MenuItem(text)
|
||||
, m_key(NULL)
|
||||
, m_command(command)
|
||||
, m_params(params ? params->clone(): NULL)
|
||||
, m_params(params)
|
||||
{
|
||||
}
|
||||
|
||||
AppMenuItem::~AppMenuItem()
|
||||
// static
|
||||
void AppMenuItem::setContextParams(const Params& params)
|
||||
{
|
||||
delete m_params;
|
||||
s_contextParams = params;
|
||||
}
|
||||
|
||||
bool AppMenuItem::onProcessMessage(Message* msg)
|
||||
@ -50,6 +54,9 @@ bool AppMenuItem::onProcessMessage(Message* msg)
|
||||
case kCloseMessage:
|
||||
// disable the menu (the keyboard shortcuts are processed by "manager_msg_proc")
|
||||
setEnabled(false);
|
||||
|
||||
if (!s_contextParams.empty())
|
||||
s_contextParams.clear();
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -62,8 +69,11 @@ bool AppMenuItem::onProcessMessage(Message* msg)
|
||||
context->updateFlags();
|
||||
|
||||
if (m_command) {
|
||||
if (m_params)
|
||||
m_command->loadParams(m_params);
|
||||
Params params = m_params;
|
||||
if (!s_contextParams.empty())
|
||||
params |= s_contextParams;
|
||||
|
||||
m_command->loadParams(params);
|
||||
|
||||
setEnabled(m_command->isEnabled(context));
|
||||
setSelected(m_command->isChecked(context));
|
||||
@ -105,12 +115,15 @@ void AppMenuItem::onClick()
|
||||
MenuItem::onClick();
|
||||
|
||||
if (m_command) {
|
||||
if (m_params)
|
||||
m_command->loadParams(m_params);
|
||||
Params params = m_params;
|
||||
if (!s_contextParams.empty())
|
||||
params |= s_contextParams;
|
||||
|
||||
m_command->loadParams(params);
|
||||
|
||||
UIContext* context = UIContext::instance();
|
||||
if (m_command->isEnabled(context))
|
||||
context->executeCommand(m_command);
|
||||
context->executeCommand(m_command, params);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,12 +9,12 @@
|
||||
#define APP_UI_APP_MENUITEM_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/commands/params.h"
|
||||
#include "ui/menu.h"
|
||||
|
||||
namespace app {
|
||||
class Key;
|
||||
class Command;
|
||||
class Params;
|
||||
|
||||
// A widget that represent a menu item of the application.
|
||||
//
|
||||
@ -23,14 +23,15 @@ namespace app {
|
||||
// used to check the availability of the command).
|
||||
class AppMenuItem : public ui::MenuItem {
|
||||
public:
|
||||
AppMenuItem(const char* text, Command* command, const Params* params);
|
||||
~AppMenuItem();
|
||||
AppMenuItem(const char* text, Command* command = nullptr, const Params& params = Params());
|
||||
|
||||
Key* getKey() { return m_key; }
|
||||
void setKey(Key* key) { m_key = key; }
|
||||
|
||||
Command* getCommand() { return m_command; }
|
||||
Params* getParams() { return m_params; }
|
||||
const Params& getParams() const { return m_params; }
|
||||
|
||||
static void setContextParams(const Params& params);
|
||||
|
||||
protected:
|
||||
bool onProcessMessage(ui::Message* msg) override;
|
||||
@ -40,7 +41,9 @@ namespace app {
|
||||
private:
|
||||
Key* m_key;
|
||||
Command* m_command;
|
||||
Params* m_params;
|
||||
Params m_params;
|
||||
|
||||
static Params s_contextParams;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
@ -174,7 +174,7 @@ void ColorBar::onPaletteButtonClick()
|
||||
Params params;
|
||||
params.set("switch", "true");
|
||||
|
||||
UIContext::instance()->executeCommand(cmd_show_palette_editor, ¶ms);
|
||||
UIContext::instance()->executeCommand(cmd_show_palette_editor, params);
|
||||
}
|
||||
|
||||
void ColorBar::onPaletteButtonDropDownClick()
|
||||
|
@ -167,7 +167,7 @@ bool DrawingState::onKeyDown(Editor* editor, KeyMessage* msg)
|
||||
m_toolLoopManager->pressKey(msg->scancode());
|
||||
|
||||
Command* command = NULL;
|
||||
Params* params = NULL;
|
||||
Params params;
|
||||
if (KeyboardShortcuts::instance()
|
||||
->getCommandFromKeyMessage(msg, &command, ¶ms)) {
|
||||
// We accept zoom commands.
|
||||
|
@ -341,7 +341,7 @@ bool MovingPixelsState::onKeyDown(Editor* editor, KeyMessage* msg)
|
||||
}
|
||||
else {
|
||||
Command* command = NULL;
|
||||
Params* params = NULL;
|
||||
Params params;
|
||||
if (KeyboardShortcuts::instance()
|
||||
->getCommandFromKeyMessage(msg, &command, ¶ms)) {
|
||||
// We accept zoom commands.
|
||||
|
@ -455,7 +455,7 @@ void StandbyState::callEyedropper(Editor* editor)
|
||||
Params params;
|
||||
params.set("target", fg ? "foreground": "background");
|
||||
|
||||
UIContext::instance()->executeCommand(eyedropper_cmd, ¶ms);
|
||||
UIContext::instance()->executeCommand(eyedropper_cmd, params);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -97,7 +97,7 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg)
|
||||
((dz < 0) ? CommandId::GotoNextFrame:
|
||||
CommandId::GotoPreviousFrame);
|
||||
if (command)
|
||||
UIContext::instance()->executeCommand(command, NULL);
|
||||
UIContext::instance()->executeCommand(command);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -98,15 +98,13 @@ void HomeView::onWorkspaceViewSelected()
|
||||
void HomeView::onNewFile()
|
||||
{
|
||||
Command* command = CommandsModule::instance()->getCommandByName(CommandId::NewFile);
|
||||
Params params;
|
||||
UIContext::instance()->executeCommand(command, ¶ms);
|
||||
UIContext::instance()->executeCommand(command);
|
||||
}
|
||||
|
||||
void HomeView::onOpenFile()
|
||||
{
|
||||
Command* command = CommandsModule::instance()->getCommandByName(CommandId::OpenFile);
|
||||
Params params;
|
||||
UIContext::instance()->executeCommand(command, ¶ms);
|
||||
UIContext::instance()->executeCommand(command);
|
||||
}
|
||||
|
||||
void HomeView::onCheckingUpdates()
|
||||
|
@ -116,12 +116,12 @@ using namespace ui;
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Key
|
||||
|
||||
Key::Key(Command* command, const Params* params, KeyContext keyContext)
|
||||
Key::Key(Command* command, const Params& params, KeyContext keyContext)
|
||||
: m_type(KeyType::Command)
|
||||
, m_useUsers(false)
|
||||
, m_keycontext(keyContext)
|
||||
, m_command(command)
|
||||
, m_params(params ? params->clone(): NULL)
|
||||
, m_params(params)
|
||||
{
|
||||
}
|
||||
|
||||
@ -253,8 +253,7 @@ std::string Key::triggerString() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case KeyType::Command:
|
||||
if (m_params)
|
||||
m_command->loadParams(m_params);
|
||||
m_command->loadParams(m_params);
|
||||
return m_command->friendlyName();
|
||||
case KeyType::Tool:
|
||||
case KeyType::Quicktool: {
|
||||
@ -339,7 +338,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
|
||||
PRINTF(" - Shortcut for command `%s' <%s>\n", command_name, command_key);
|
||||
|
||||
// add the keyboard shortcut to the command
|
||||
Key* key = this->command(command_name, ¶ms, keycontext);
|
||||
Key* key = this->command(command_name, params, keycontext);
|
||||
if (key) {
|
||||
Accelerator accel(command_key);
|
||||
|
||||
@ -351,7 +350,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
|
||||
// is the only one that process keyboard shortcuts)
|
||||
if (key->accels().size() == 1) {
|
||||
AppMenus::instance()->applyShortcutToMenuitemsWithCommand(
|
||||
command, ¶ms, key);
|
||||
command, params, key);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -533,16 +532,14 @@ void KeyboardShortcuts::exportAccel(TiXmlElement& parent, Key* key, const ui::Ac
|
||||
if (keycontextStr)
|
||||
elem.SetAttribute("context", keycontextStr);
|
||||
|
||||
if (key->params()) {
|
||||
for (const auto& param : *key->params()) {
|
||||
if (param.second.empty())
|
||||
continue;
|
||||
for (const auto& param : key->params()) {
|
||||
if (param.second.empty())
|
||||
continue;
|
||||
|
||||
TiXmlElement paramElem("param");
|
||||
paramElem.SetAttribute("name", param.first.c_str());
|
||||
paramElem.SetAttribute("value", param.second.c_str());
|
||||
elem.InsertEndChild(paramElem);
|
||||
}
|
||||
TiXmlElement paramElem("param");
|
||||
paramElem.SetAttribute("name", param.first.c_str());
|
||||
paramElem.SetAttribute("value", param.second.c_str());
|
||||
elem.InsertEndChild(paramElem);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -572,8 +569,7 @@ void KeyboardShortcuts::reset()
|
||||
key->reset();
|
||||
}
|
||||
|
||||
Key* KeyboardShortcuts::command(const char* commandName,
|
||||
Params* params, KeyContext keyContext)
|
||||
Key* KeyboardShortcuts::command(const char* commandName, const Params& params, KeyContext keyContext)
|
||||
{
|
||||
Command* command = CommandsModule::instance()->getCommandByName(commandName);
|
||||
if (!command)
|
||||
@ -583,8 +579,7 @@ Key* KeyboardShortcuts::command(const char* commandName,
|
||||
if (key->type() == KeyType::Command &&
|
||||
key->keycontext() == keyContext &&
|
||||
key->command() == command &&
|
||||
((!params && key->params()->empty()) ||
|
||||
(params && *key->params() == *params))) {
|
||||
key->params() == params) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
@ -658,7 +653,7 @@ KeyContext KeyboardShortcuts::getCurrentKeyContext()
|
||||
return KeyContext::Normal;
|
||||
}
|
||||
|
||||
bool KeyboardShortcuts::getCommandFromKeyMessage(Message* msg, Command** command, Params** params)
|
||||
bool KeyboardShortcuts::getCommandFromKeyMessage(Message* msg, Command** command, Params* params)
|
||||
{
|
||||
for (Key* key : m_keys) {
|
||||
if (key->type() == KeyType::Command && key->isPressed(msg)) {
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define APP_UI_KEYBOARD_SHORTCUTS_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/commands/params.h"
|
||||
#include "base/convert_to.h"
|
||||
#include "base/disable_copying.h"
|
||||
#include "ui/accelerator.h"
|
||||
@ -65,7 +66,7 @@ namespace app {
|
||||
|
||||
class Key {
|
||||
public:
|
||||
Key(Command* command, const Params* params, KeyContext keyContext);
|
||||
Key(Command* command, const Params& params, KeyContext keyContext);
|
||||
Key(KeyType type, tools::Tool* tool);
|
||||
explicit Key(KeyAction action);
|
||||
|
||||
@ -89,7 +90,7 @@ namespace app {
|
||||
|
||||
// for KeyType::Command
|
||||
Command* command() const { return m_command; }
|
||||
Params* params() const { return m_params; }
|
||||
const Params& params() const { return m_params; }
|
||||
KeyContext keycontext() const { return m_keycontext; }
|
||||
// for KeyType::Tool or Quicktool
|
||||
tools::Tool* tool() const { return m_tool; }
|
||||
@ -108,7 +109,7 @@ namespace app {
|
||||
|
||||
// for KeyType::Command
|
||||
Command* m_command;
|
||||
Params* m_params;
|
||||
Params m_params;
|
||||
// for KeyType::Tool or Quicktool
|
||||
tools::Tool* m_tool;
|
||||
// for KeyType::Action
|
||||
@ -136,7 +137,7 @@ namespace app {
|
||||
void reset();
|
||||
|
||||
Key* command(const char* commandName,
|
||||
Params* params = NULL, KeyContext keyContext = KeyContext::Any);
|
||||
const Params& params = Params(), KeyContext keyContext = KeyContext::Any);
|
||||
Key* tool(tools::Tool* tool);
|
||||
Key* quicktool(tools::Tool* tool);
|
||||
Key* action(KeyAction action);
|
||||
@ -144,7 +145,7 @@ namespace app {
|
||||
void disableAccel(const ui::Accelerator& accel, KeyContext keyContext);
|
||||
|
||||
KeyContext getCurrentKeyContext();
|
||||
bool getCommandFromKeyMessage(ui::Message* msg, Command** command, Params** params);
|
||||
bool getCommandFromKeyMessage(ui::Message* msg, Command** command, Params* params);
|
||||
tools::Tool* getCurrentQuicktool(tools::Tool* currentTool);
|
||||
|
||||
private:
|
||||
|
@ -125,7 +125,7 @@ void RecentFilesListBox::onClick(const std::string& path)
|
||||
Command* command = CommandsModule::instance()->getCommandByName(CommandId::OpenFile);
|
||||
Params params;
|
||||
params.set("filename", path.c_str());
|
||||
UIContext::instance()->executeCommand(command, ¶ms);
|
||||
UIContext::instance()->executeCommand(command, params);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@ -151,7 +151,7 @@ void RecentFoldersListBox::onClick(const std::string& path)
|
||||
Command* command = CommandsModule::instance()->getCommandByName(CommandId::OpenFile);
|
||||
Params params;
|
||||
params.set("folder", path.c_str());
|
||||
UIContext::instance()->executeCommand(command, ¶ms);
|
||||
UIContext::instance()->executeCommand(command, params);
|
||||
}
|
||||
|
||||
} // namespace app
|
||||
|
@ -127,7 +127,7 @@ public:
|
||||
int frame = getTextInt();
|
||||
if (frame > 0) {
|
||||
params.set("frame", getText().c_str());
|
||||
UIContext::instance()->executeCommand(cmd, ¶ms);
|
||||
UIContext::instance()->executeCommand(cmd, params);
|
||||
}
|
||||
// Select the text again
|
||||
selectText(0, -1);
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "app/modules/gfx.h"
|
||||
#include "app/modules/gui.h"
|
||||
#include "app/transaction.h"
|
||||
#include "app/ui/app_menuitem.h"
|
||||
#include "app/ui/configure_timeline_popup.h"
|
||||
#include "app/ui/document_view.h"
|
||||
#include "app/ui/editor/editor.h"
|
||||
@ -610,15 +611,14 @@ bool Timeline::onProcessMessage(Message* msg)
|
||||
if (mouseMsg->right()) {
|
||||
Menu* popup_menu = AppMenus::instance()->getFrameTagPopupMenu();
|
||||
if (popup_menu) {
|
||||
CommandsModule::instance()->getCommandByName(CommandId::FrameTagProperties)->loadParams(¶ms);
|
||||
CommandsModule::instance()->getCommandByName(CommandId::RemoveFrameTag)->loadParams(¶ms);
|
||||
AppMenuItem::setContextParams(params);
|
||||
popup_menu->showPopup(mouseMsg->position());
|
||||
}
|
||||
}
|
||||
else if (mouseMsg->left()) {
|
||||
Command* command = CommandsModule::instance()
|
||||
->getCommandByName(CommandId::FrameTagProperties);
|
||||
UIContext::instance()->executeCommand(command, ¶ms);
|
||||
UIContext::instance()->executeCommand(command, params);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -668,7 +668,7 @@ bool Timeline::onProcessMessage(Message* msg)
|
||||
Params params;
|
||||
params.set("frame", "current");
|
||||
|
||||
UIContext::instance()->executeCommand(command, ¶ms);
|
||||
UIContext::instance()->executeCommand(command, params);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user