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.
|
|
|
|
|
|
|
|
#include "command.h"
|
2011-08-27 08:29:36 +02:00
|
|
|
|
2012-04-10 22:40:54 +02:00
|
|
|
#include "../compat.h"
|
2014-05-29 17:28:37 +02:00
|
|
|
#include "../format.h"
|
2012-04-10 22:40:54 +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
|
|
|
#include <libaegisub/log.h>
|
|
|
|
|
2012-05-16 06:57:06 +02:00
|
|
|
#include <wx/intl.h>
|
|
|
|
|
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 {
|
2013-06-08 06:19:40 +02:00
|
|
|
static std::map<std::string, std::unique_ptr<Command>> cmd_map;
|
|
|
|
typedef std::map<std::string, std::unique_ptr<Command>>::iterator iterator;
|
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
|
|
|
static iterator find_command(std::string const& name) {
|
2013-11-21 18:13:36 +01:00
|
|
|
auto it = cmd_map.find(name);
|
2012-04-10 22:40:54 +02:00
|
|
|
if (it == cmd_map.end())
|
2014-05-29 17:28:37 +02:00
|
|
|
throw CommandNotFound(agi::format(_("'%s' is not a valid command name"), name));
|
2011-07-15 06:05:01 +02:00
|
|
|
return it;
|
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
|
|
|
}
|
|
|
|
|
2013-09-16 15:43:17 +02:00
|
|
|
void reg(std::unique_ptr<Command> cmd) {
|
2013-06-08 06:19:40 +02:00
|
|
|
cmd_map[cmd->name()] = std::move(cmd);
|
2011-09-28 21:48:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void unreg(std::string const& name) {
|
2013-06-08 06:19:40 +02:00
|
|
|
cmd_map.erase(find_command(name));
|
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
|
|
|
Command *get(std::string const& name) {
|
2013-06-08 06:19:40 +02:00
|
|
|
return find_command(name)->second.get();
|
2011-07-15 06:05:01 +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
|
|
|
|
2011-07-27 07:36:09 +02:00
|
|
|
void call(std::string const& name, agi::Context*c) {
|
2012-02-07 02:22:23 +01:00
|
|
|
Command &cmd = *find_command(name)->second;
|
|
|
|
if (cmd.Validate(c))
|
|
|
|
cmd(c);
|
2011-07-27 07:36:09 +02:00
|
|
|
}
|
|
|
|
|
2011-10-28 22:40:20 +02:00
|
|
|
std::vector<std::string> get_registered_commands() {
|
|
|
|
std::vector<std::string> ret;
|
|
|
|
ret.reserve(cmd_map.size());
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto const& it : cmd_map)
|
|
|
|
ret.push_back(it.first);
|
2011-10-28 22:40:20 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-15 06:05:01 +02:00
|
|
|
// These forward declarations exist here since we don't want to expose
|
|
|
|
// them in a header, they're strictly internal-use.
|
|
|
|
void init_app();
|
|
|
|
void init_audio();
|
|
|
|
void init_automation();
|
|
|
|
void init_command();
|
|
|
|
void init_edit();
|
|
|
|
void init_grid();
|
|
|
|
void init_help();
|
|
|
|
void init_keyframe();
|
|
|
|
void init_recent();
|
|
|
|
void init_subtitle();
|
|
|
|
void init_time();
|
|
|
|
void init_timecode();
|
|
|
|
void init_tool();
|
|
|
|
void init_video();
|
2011-11-06 18:18:20 +01:00
|
|
|
void init_visual_tools();
|
2011-07-15 06:05:01 +02:00
|
|
|
|
|
|
|
void init_builtin_commands() {
|
|
|
|
LOG_D("command/init") << "Populating command map";
|
|
|
|
init_app();
|
|
|
|
init_audio();
|
|
|
|
init_automation();
|
|
|
|
init_edit();
|
|
|
|
init_grid();
|
|
|
|
init_help();
|
|
|
|
init_keyframe();
|
|
|
|
init_recent();
|
|
|
|
init_subtitle();
|
|
|
|
init_time();
|
|
|
|
init_timecode();
|
|
|
|
init_tool();
|
|
|
|
init_video();
|
2011-11-06 18:18:20 +01:00
|
|
|
init_visual_tools();
|
2011-07-15 06:05:01 +02:00
|
|
|
}
|
2011-07-15 19:36:17 +02:00
|
|
|
|
|
|
|
void clear() {
|
|
|
|
cmd_map.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
|
|
|
}
|