Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
// Copyright (c) 2010, Amar Takhar <verm@aegisub.org>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
|
|
/// @file command.h
|
|
|
|
/// @brief Command base class and main header.
|
|
|
|
/// @ingroup command
|
|
|
|
|
2011-01-08 13:10:40 +01:00
|
|
|
#include <map>
|
2011-07-15 06:05:01 +02:00
|
|
|
#include <string>
|
2011-11-07 05:14:09 +01:00
|
|
|
#include <vector>
|
2011-07-15 06:05:01 +02:00
|
|
|
|
2011-07-16 08:42:55 +02:00
|
|
|
#include <wx/bitmap.h>
|
2014-05-17 17:03:37 +02:00
|
|
|
#include <wx/intl.h>
|
2011-07-15 06:05:01 +02:00
|
|
|
#include <wx/string.h>
|
2011-01-08 13:10:40 +01:00
|
|
|
|
|
|
|
#include <libaegisub/exception.h>
|
|
|
|
|
2011-01-16 08:16:00 +01:00
|
|
|
namespace agi { struct Context; }
|
2011-01-08 13:10:40 +01:00
|
|
|
|
2011-10-24 22:17:57 +02:00
|
|
|
#define CMD_NAME(a) const char* name() const { return a; }
|
2012-01-08 02:05:19 +01:00
|
|
|
#define STR_MENU(a) wxString StrMenu(const agi::Context *) const { return _(a); }
|
|
|
|
#define STR_DISP(a) wxString StrDisplay(const agi::Context *) const { return _(a); }
|
|
|
|
#define STR_HELP(a) wxString StrHelp() const { return _(a); }
|
2011-07-15 06:05:56 +02:00
|
|
|
#define CMD_TYPE(a) int Type() const { using namespace cmd; return a; }
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
|
2014-05-11 16:31:22 +02:00
|
|
|
#define CMD_ICON(icon) wxBitmap Icon(int size, wxLayoutDirection dir = wxLayout_LeftToRight) const override { \
|
|
|
|
if (size == 64) return GETIMAGEDIR(icon##_64, dir); \
|
|
|
|
if (size == 48) return GETIMAGEDIR(icon##_48, dir); \
|
|
|
|
if (size == 32) return GETIMAGEDIR(icon##_32, dir); \
|
|
|
|
if (size == 24) return GETIMAGEDIR(icon##_24, dir); \
|
|
|
|
return GETIMAGEDIR(icon##_16, dir); \
|
2013-12-25 22:36:37 +01:00
|
|
|
}
|
|
|
|
|
2011-01-16 08:15:40 +01:00
|
|
|
#define COMMAND_GROUP(cname, cmdname, menu, disp, help) \
|
2014-03-13 02:39:07 +01:00
|
|
|
struct cname final : public Command { \
|
2011-01-16 08:15:40 +01:00
|
|
|
CMD_NAME(cmdname) \
|
|
|
|
STR_MENU(menu) \
|
|
|
|
STR_DISP(disp) \
|
|
|
|
STR_HELP(help) \
|
|
|
|
void operator()(agi::Context *) { } \
|
|
|
|
}
|
|
|
|
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
/// Commands
|
|
|
|
namespace cmd {
|
2014-05-29 14:57:27 +02:00
|
|
|
DEFINE_EXCEPTION(CommandError, agi::Exception);
|
|
|
|
DEFINE_EXCEPTION(CommandNotFound, CommandError);
|
2014-01-04 01:56:18 +01:00
|
|
|
|
2011-07-15 06:05:56 +02:00
|
|
|
enum CommandFlags {
|
|
|
|
/// Default command type
|
|
|
|
COMMAND_NORMAL = 0,
|
|
|
|
|
|
|
|
/// Invoking this command toggles a setting of some sort. Any command
|
|
|
|
/// of this type should have IsActive implemented to signal the
|
|
|
|
/// current state of the thing being toggled, and invoking the command
|
|
|
|
/// twice should be a no-op
|
|
|
|
///
|
|
|
|
/// This is mutually exclusive with COMMAND_RADIO
|
|
|
|
COMMAND_TOGGLE = 1,
|
|
|
|
|
|
|
|
/// Invoking this command sets a setting to a specific value. Any
|
|
|
|
/// command of this type should have IsActive implemented, and if
|
|
|
|
/// IsActive returns true, invoking the command should have no effect
|
|
|
|
///
|
|
|
|
/// This is mutually exclusive with COMMAND_TOGGLE
|
|
|
|
COMMAND_RADIO = 2,
|
|
|
|
|
|
|
|
/// This command has an overridden Validate method
|
|
|
|
COMMAND_VALIDATE = 4,
|
|
|
|
|
|
|
|
/// This command's name may change based on the state of the project
|
|
|
|
COMMAND_DYNAMIC_NAME = 8,
|
|
|
|
|
2012-01-20 22:33:30 +01:00
|
|
|
/// This command's help string may change
|
|
|
|
COMMAND_DYNAMIC_HELP = 16,
|
|
|
|
|
2011-07-15 06:05:56 +02:00
|
|
|
/// This command's icon may change based on the state of the project
|
2012-01-20 22:33:30 +01:00
|
|
|
COMMAND_DYNAMIC_ICON = 32
|
2011-07-15 06:05:56 +02:00
|
|
|
};
|
|
|
|
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
/// Holds an individual Command
|
|
|
|
class Command {
|
|
|
|
public:
|
2011-08-27 08:29:36 +02:00
|
|
|
/// Command name
|
2011-10-24 22:17:57 +02:00
|
|
|
virtual const char* name() const=0;
|
2011-08-27 08:29:36 +02:00
|
|
|
/// String for menu purposes including accelerators, but not hotkeys
|
|
|
|
virtual wxString StrMenu(const agi::Context *) const=0;
|
|
|
|
/// Plain string for display purposes; should normally be the same as StrMenu
|
|
|
|
/// but without accelerators
|
|
|
|
virtual wxString StrDisplay(const agi::Context *) const=0;
|
2012-01-20 22:33:30 +01:00
|
|
|
/// Short help string describing what the command does
|
2011-08-27 08:29:36 +02:00
|
|
|
virtual wxString StrHelp() const=0;
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
|
2011-07-15 06:05:56 +02:00
|
|
|
/// Get this command's type flags
|
|
|
|
/// @return Bitmask of CommandFlags
|
|
|
|
virtual int Type() const { return COMMAND_NORMAL; }
|
|
|
|
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
/// Request icon.
|
|
|
|
/// @param size Icon size.
|
2014-05-11 16:31:22 +02:00
|
|
|
virtual wxBitmap Icon(int size, wxLayoutDirection = wxLayout_LeftToRight) const { return wxBitmap{}; }
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
|
|
|
|
/// Command function
|
|
|
|
virtual void operator()(agi::Context *c)=0;
|
|
|
|
|
2011-07-15 06:05:22 +02:00
|
|
|
/// Check whether or not it makes sense to call this command at this time
|
|
|
|
/// @param c Project context
|
|
|
|
///
|
|
|
|
/// This function should be very fast, as it is called whenever a menu
|
|
|
|
/// containing this command is opened and is called periodically for
|
|
|
|
/// any commands used in a toolbar
|
|
|
|
///
|
|
|
|
/// Note that it is still legal to call commands when this returns
|
|
|
|
/// false. In this situation, commands should do nothing.
|
2011-07-15 06:06:03 +02:00
|
|
|
///
|
|
|
|
/// This function should be overridden iff the command's type flags
|
|
|
|
/// include COMMAND_VALIDATE
|
2011-07-15 06:05:22 +02:00
|
|
|
virtual bool Validate(const agi::Context *c) { return true; }
|
|
|
|
|
2011-07-15 06:06:03 +02:00
|
|
|
/// Is the selectable value represented by this command currently selected?
|
|
|
|
/// @param c Project context
|
|
|
|
///
|
|
|
|
/// As with Validate, this function should be very fast.
|
|
|
|
///
|
|
|
|
/// This function should be overridden iff the command's type flags
|
|
|
|
/// include COMMAND_TOGGLE or COMMAND_RADIO
|
|
|
|
virtual bool IsActive(const agi::Context *c) { return false; }
|
|
|
|
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
/// Destructor
|
2014-04-25 19:01:07 +02:00
|
|
|
virtual ~Command() = default;
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
};
|
|
|
|
|
2011-07-15 06:05:01 +02:00
|
|
|
/// Init all builtin commands.
|
|
|
|
void init_builtin_commands();
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
|
2011-07-15 06:05:01 +02:00
|
|
|
/// Register a command.
|
2013-06-08 06:19:40 +02:00
|
|
|
/// @param cmd Command object to register.
|
2013-09-16 15:43:17 +02:00
|
|
|
void reg(std::unique_ptr<Command> cmd);
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
|
2011-09-28 21:48:02 +02:00
|
|
|
/// Unregister a command.
|
|
|
|
/// @param cmd Command name to unregister. The associated command object is deleted.
|
|
|
|
void unreg(std::string const& name);
|
|
|
|
|
2011-07-27 07:36:09 +02:00
|
|
|
/// Call a command.
|
|
|
|
/// @param name Name of the command to call.
|
|
|
|
/// @param c Current Context.
|
|
|
|
void call(std::string const& name, agi::Context *c);
|
|
|
|
|
2011-07-15 06:05:01 +02:00
|
|
|
/// Retrieve a Command object.
|
|
|
|
/// @param Command object.
|
|
|
|
Command* get(std::string const& name);
|
2011-07-15 19:36:17 +02:00
|
|
|
|
2011-10-28 22:40:20 +02:00
|
|
|
/// Get a list of registered command names
|
|
|
|
std::vector<std::string> get_registered_commands();
|
|
|
|
|
2011-09-28 21:48:02 +02:00
|
|
|
/// Unregister and deletes all commands
|
2011-07-15 19:36:17 +02:00
|
|
|
void clear();
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
} // namespace cmd
|