Simplify and clean up command management code

Originally committed to SVN as r5456.
This commit is contained in:
Thomas Goyne 2011-07-15 04:05:01 +00:00
parent e6dc86212b
commit 2eb4c856e8
19 changed files with 371 additions and 428 deletions

View file

@ -47,17 +47,18 @@
#include "../include/aegisub/context.h" #include "../include/aegisub/context.h"
#include "../main.h" #include "../main.h"
#include "../dialog_about.h"
#include "../audio_controller.h" #include "../audio_controller.h"
#include "../frame_main.h" #include "../dialog_about.h"
#include "../video_context.h"
#include "../utils.h"
#include "../dialog_log.h" #include "../dialog_log.h"
#include "../preferences.h"
#include "../dialog_version_check.h" #include "../dialog_version_check.h"
#include "../frame_main.h"
#include "../preferences.h"
#include "../utils.h"
#include "../video_context.h"
namespace {
using cmd::Command;
namespace cmd {
/// @defgroup cmd-app Application related /// @defgroup cmd-app Application related
/// @{ /// @{
@ -225,21 +226,20 @@ struct app_updates : public Command {
}; };
/// @} /// @}
/// Init app/ commands
void init_app(CommandManager *cm) {
cm->reg(new app_about());
cm->reg(new app_display_audio_subs());
cm->reg(new app_display_full());
cm->reg(new app_display_subs());
cm->reg(new app_display_video_subs());
cm->reg(new app_exit());
cm->reg(new app_language());
cm->reg(new app_log());
cm->reg(new app_new_window());
cm->reg(new app_options());
cm->reg(new app_updates());
} }
} // namespace cmd namespace cmd {
void init_app() {
reg(new app_about);
reg(new app_display_audio_subs);
reg(new app_display_full);
reg(new app_display_subs);
reg(new app_display_video_subs);
reg(new app_exit);
reg(new app_language);
reg(new app_log);
reg(new app_new_window);
reg(new app_options);
reg(new app_updates);
}
}

View file

@ -54,11 +54,11 @@
typedef SelectionController<AssDialogue>::Selection Selection; typedef SelectionController<AssDialogue>::Selection Selection;
namespace cmd { namespace {
using cmd::Command;
/// @defgroup cmd-audio Audio commands. /// @defgroup cmd-audio Audio commands.
/// @{ /// @{
/// Closes the currently open audio file. /// Closes the currently open audio file.
struct audio_close : public Command { struct audio_close : public Command {
CMD_NAME("audio/close") CMD_NAME("audio/close")
@ -342,29 +342,30 @@ struct audio_vertical_link : public Command {
/// @} /// @}
/// Init audio/ commands
void init_audio(CommandManager *cm) {
cm->reg(new audio_autocommit);
cm->reg(new audio_autonext);
cm->reg(new audio_autoscroll);
cm->reg(new audio_close);
cm->reg(new audio_commit);
cm->reg(new audio_go_to);
cm->reg(new audio_open);
cm->reg(new audio_open_blank);
cm->reg(new audio_open_noise);
cm->reg(new audio_open_video);
cm->reg(new audio_play_after);
cm->reg(new audio_play_before);
cm->reg(new audio_play_begin);
cm->reg(new audio_play_end);
cm->reg(new audio_play_selection);
cm->reg(new audio_play_to_end);
cm->reg(new audio_save_clip);
cm->reg(new audio_stop);
cm->reg(new audio_vertical_link);
cm->reg(new audio_view_spectrum);
cm->reg(new audio_view_waveform);
} }
} // namespace cmd namespace cmd {
void init_audio() {
reg(new audio_autocommit);
reg(new audio_autonext);
reg(new audio_autoscroll);
reg(new audio_close);
reg(new audio_commit);
reg(new audio_go_to);
reg(new audio_open);
reg(new audio_open_blank);
reg(new audio_open_noise);
reg(new audio_open_video);
reg(new audio_play_after);
reg(new audio_play_before);
reg(new audio_play_begin);
reg(new audio_play_end);
reg(new audio_play_selection);
reg(new audio_play_to_end);
reg(new audio_save_clip);
reg(new audio_stop);
reg(new audio_vertical_link);
reg(new audio_view_spectrum);
reg(new audio_view_waveform);
}
}

View file

@ -50,7 +50,8 @@
#include "../video_context.h" #include "../video_context.h"
#include "../frame_main.h" #include "../frame_main.h"
namespace cmd { namespace {
using cmd::Command;
/// @defgroup cmd-am Automation commands /// @defgroup cmd-am Automation commands
/// @{ /// @{
@ -98,11 +99,10 @@ struct am_manager : public Command {
}; };
/// @} /// @}
/// Init am/ commands. (automation)
void init_automation(CommandManager *cm) {
cm->reg(new am_manager());
} }
namespace cmd {
} // namespace cmd void init_automation() {
reg(new am_manager);
}
}

View file

@ -19,111 +19,92 @@
/// @ingroup command /// @ingroup command
#include "command.h" #include "command.h"
#include "icon.h"
#include <libaegisub/log.h> #include <libaegisub/log.h>
namespace cmd { namespace cmd {
static std::map<std::string, Command*> cmd_map;
typedef std::map<std::string, Command*>::iterator iterator;
CommandManager *cm; static iterator find_command(std::string const& name) {
iterator it = cmd_map.find(name);
if (it == cmd_map.end()) throw CommandNotFound("'" + name + "' is not a valid command name");
return it;
}
int id(std::string name) { return cm->id(name); } void reg(Command *cmd) {
void call(agi::Context *c, const int id) { return cm->call(c, id); } cmd_map[cmd->name()] = cmd;
int count() { return cm->count(); } }
Command* get(std::string name) { return cm->get(name); }
int id(std::string const& name) {
return distance(cmd_map.begin(), find_command(name));
}
wxBitmap* Command::Icon(int size) { int count() {
if (size == 16) { return cmd_map.size();
return icon::get(name(), 16); }
} else if (size == 24) {
return icon::get(name(), 24); Command *get(std::string const& name) {
} else { return find_command(name)->second;
throw CommandIconInvalid("Valid icon sizes are 16 or 24."); }
void call(agi::Context *c, int id) {
std::map<std::string, Command*>::iterator index(cmd_map.begin());
advance(index, id);
if (index != cmd_map.end()) {
LOG_D("event/command") << index->first << " " << "(Id: " << id << ")";
(*index->second)(c);
} else {
LOG_W("event/command/not_found") << "EVENT ID NOT FOUND: " << id;
// XXX: throw
}
}
wxBitmap* Command::Icon(int size) {
if (size == 16) {
return icon::get(name(), 16);
} else if (size == 24) {
return icon::get(name(), 24);
} else {
throw CommandIconInvalid("Valid icon sizes are 16 or 24.");
}
}
// 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_medusa();
void init_menu();
void init_recent();
void init_subtitle();
void init_time();
void init_timecode();
void init_tool();
void init_video();
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_menu();
init_recent();
init_subtitle();
init_time();
init_timecode();
init_tool();
init_video();
} }
} }
int CommandManager::id(std::string name) {
cmdMap::iterator index;
if ((index = map.find(name)) != map.end()) {
int id = std::distance(map.begin(), index);
return id;
}
// XXX: throw
printf("cmd::id NOT FOUND (%s)\n", name.c_str());
return 60003;
}
Command* CommandManager::get(std::string name) {
cmdMap::iterator index;
if ((index = map.find(name)) != map.end()) {
return index->second;
}
// XXX: throw
printf("cmd::id NOT FOUND (%s)\n", name.c_str());
return 0;
}
void CommandManager::call(agi::Context *c, const int id) {
cmdMap::iterator index(map.begin());
std::advance(index, id);
if (index != map.end()) {
LOG_D("event/command") << index->first << " " << "(Id: " << id << ")";
(*index->second)(c);
} else {
LOG_W("event/command/not_found") << "EVENT ID NOT FOUND: " << id;
// XXX: throw
}
}
void CommandManager::reg(Command *cmd) {
map.insert(cmdPair(cmd->name(), cmd));
}
// These forward declarations exist here since we don't want to expose
// them in a header, they're strictly internal-use.
void init_app(CommandManager *cm);
void init_audio(CommandManager *cm);
void init_automation(CommandManager *cm);
void init_command(CommandManager *cm);
void init_edit(CommandManager *cm);
void init_grid(CommandManager *cm);
void init_help(CommandManager *cm);
void init_keyframe(CommandManager *cm);
void init_medusa(CommandManager *cm);
void init_menu(CommandManager *cm);
void init_recent(CommandManager *cm);
void init_subtitle(CommandManager *cm);
void init_time(CommandManager *cm);
void init_timecode(CommandManager *cm);
void init_tool(CommandManager *cm);
void init_video(CommandManager *cm);
void init_command(CommandManager *cm) {
LOG_D("command/init") << "Populating command map";
init_app(cm);
init_audio(cm);
init_automation(cm);
init_edit(cm);
init_grid(cm);
init_help(cm);
init_keyframe(cm);
init_menu(cm);
init_recent(cm);
init_subtitle(cm);
init_time(cm);
init_timecode(cm);
init_tool(cm);
init_video(cm);
}
} // namespace cmd

View file

@ -21,15 +21,17 @@
#ifndef AGI_PRE #ifndef AGI_PRE
#include <map> #include <map>
#include <string>
#include <wx/string.h>
#endif #endif
#include <libaegisub/exception.h> #include <libaegisub/exception.h>
#include "icon.h"
namespace agi { struct Context; } namespace agi { struct Context; }
DEFINE_BASE_EXCEPTION_NOINNER(CommandError, agi::Exception) DEFINE_BASE_EXCEPTION_NOINNER(CommandError, agi::Exception)
DEFINE_SIMPLE_EXCEPTION_NOINNER(CommandNotFound, CommandError, "command/notfound")
DEFINE_SIMPLE_EXCEPTION_NOINNER(CommandIconNone, CommandError, "command/icon") DEFINE_SIMPLE_EXCEPTION_NOINNER(CommandIconNone, CommandError, "command/icon")
DEFINE_SIMPLE_EXCEPTION_NOINNER(CommandIconInvalid, CommandError, "command/icon/invalid") DEFINE_SIMPLE_EXCEPTION_NOINNER(CommandIconInvalid, CommandError, "command/icon/invalid")
@ -49,23 +51,6 @@ struct cname : public Command { \
/// Commands /// Commands
namespace cmd { namespace cmd {
class CommandManager;
class Command;
/// CommandManager instance.
extern CommandManager *cm;
/// Init all commands.
/// @param cm CommandManager instance.
void init_command(CommandManager *cm);
// The following are nothing more than glorified macros.
int id(std::string name); ///< @see CommandManager::id
void call(agi::Context *c, const int id); ///< @see CommandManager::call
int count(); ///< @see CommandManager::count
Command* get(std::string name); ///< @see CommandManager::get
/// Holds an individual Command /// Holds an individual Command
class Command { class Command {
public: public:
@ -82,38 +67,32 @@ namespace cmd {
virtual void operator()(agi::Context *c)=0; virtual void operator()(agi::Context *c)=0;
/// Destructor /// Destructor
virtual ~Command() {}; virtual ~Command() { };
}; };
/// Init all builtin commands.
void init_builtin_commands();
/// Manager for commands /// Register a command.
class CommandManager { /// @param cmd Command object.
typedef std::map<std::string, Command*> cmdMap; ///< Map to hold commands. void reg(Command *cmd);
typedef std::pair<std::string, Command*> cmdPair; ///< Pair for command insertion.
cmdMap map; ///< Actual map.
public: /// Retrieve an ID for event usage or otherwise
/// Register a command. /// @param name Command name
/// @param cmd Command object. /// @return Command ID
void reg(Command *cmd); /// @note This is guaranteed to be unique.
int id(std::string const& name);
/// Retrieve an ID for event usage or otherwise /// Call a command.
/// @param name Command name /// @param c Current Context.
/// @return Command ID /// @param id ID for Command to call.
/// @note This is guaranteed to be unique. void call(agi::Context *c, int id);
int id(std::string name);
/// Call a command. /// Count number of commands.
/// @param c Current Context. /// @return ID number.
/// @param id ID for Command to call. int count();
void call(agi::Context *c, const int id);
/// Count number of commands. /// Retrieve a Command object.
/// @return ID number. /// @param Command object.
int count() { return map.size(); } Command* get(std::string const& name);
/// Retrieve a Command object.
/// @param Command object.
Command* get(std::string name);
};
} // namespace cmd } // namespace cmd

View file

@ -53,11 +53,11 @@
#include "../subs_grid.h" #include "../subs_grid.h"
#include "../video_context.h" #include "../video_context.h"
namespace cmd { namespace {
using cmd::Command;
/// @defgroup cmd-edit Editing commands. /// @defgroup cmd-edit Editing commands.
/// @{ /// @{
/// Copy subtitles. /// Copy subtitles.
struct edit_line_copy : public Command { struct edit_line_copy : public Command {
CMD_NAME("edit/line/copy") CMD_NAME("edit/line/copy")
@ -339,26 +339,26 @@ struct edit_undo : public Command {
} }
}; };
}
/// @} /// @}
/// Init edit/ commands namespace cmd {
void init_edit(CommandManager *cm) { void init_edit() {
cm->reg(new edit_line_copy()); reg(new edit_line_copy);
cm->reg(new edit_line_cut()); reg(new edit_line_cut);
cm->reg(new edit_line_delete()); reg(new edit_line_delete);
cm->reg(new edit_line_duplicate()); reg(new edit_line_duplicate);
cm->reg(new edit_line_duplicate_shift()); reg(new edit_line_duplicate_shift);
cm->reg(new edit_line_join_as_karaoke()); reg(new edit_line_join_as_karaoke);
cm->reg(new edit_line_join_concatenate()); reg(new edit_line_join_concatenate);
cm->reg(new edit_line_join_keep_first()); reg(new edit_line_join_keep_first);
cm->reg(new edit_line_paste()); reg(new edit_line_paste);
cm->reg(new edit_line_paste_over()); reg(new edit_line_paste_over);
cm->reg(new edit_line_recombine()); reg(new edit_line_recombine);
cm->reg(new edit_line_split_by_karaoke()); reg(new edit_line_split_by_karaoke);
cm->reg(new edit_line_swap()); reg(new edit_line_swap);
cm->reg(new edit_redo()); reg(new edit_redo);
cm->reg(new edit_search_replace()); reg(new edit_search_replace);
cm->reg(new edit_undo()); reg(new edit_undo);
}
} }
} // namespace cmd

View file

@ -38,9 +38,6 @@
#include "../config.h" #include "../config.h"
#ifndef AGI_PRE
#endif
#include "command.h" #include "command.h"
#include "../ass_dialogue.h" #include "../ass_dialogue.h"
@ -51,8 +48,8 @@
#include "../frame_main.h" #include "../frame_main.h"
#include "../utils.h" #include "../utils.h"
namespace {
namespace cmd { using cmd::Command;
/// @defgroup cmd-grid Subtitle grid commands. /// @defgroup cmd-grid Subtitle grid commands.
/// @{ /// @{
@ -195,20 +192,18 @@ struct grid_swap_down : public Command {
} }
} }
}; };
}
/// @} /// @}
namespace cmd {
/// Init grid/ commands. void init_grid() {
void init_grid(CommandManager *cm) { reg(new grid_line_next);
cm->reg(new grid_line_next); reg(new grid_line_prev);
cm->reg(new grid_line_prev); reg(new grid_swap_down);
cm->reg(new grid_swap_down); reg(new grid_swap_up);
cm->reg(new grid_swap_up); reg(new grid_tag_cycle_hiding);
cm->reg(new grid_tag_cycle_hiding); reg(new grid_tags_hide);
cm->reg(new grid_tags_hide); reg(new grid_tags_show);
cm->reg(new grid_tags_show); reg(new grid_tags_simplify);
cm->reg(new grid_tags_simplify); }
} }
} // namespace cmd

View file

@ -50,12 +50,11 @@
#include "../help_button.h" // help_contents #include "../help_button.h" // help_contents
#include "../main.h" #include "../main.h"
namespace cmd { namespace {
using cmd::Command;
/// @defgroup cmd-help Help commands. /// @defgroup cmd-help Help commands.
/// @{ /// @{
/// Visit Aegisub's bug tracker. /// Visit Aegisub's bug tracker.
struct help_bugs : public Command { struct help_bugs : public Command {
CMD_NAME("help/bugs") CMD_NAME("help/bugs")
@ -157,18 +156,17 @@ struct help_website : public Command {
AegisubApp::OpenURL(_T("http://www.aegisub.org/")); AegisubApp::OpenURL(_T("http://www.aegisub.org/"));
} }
}; };
}
/// @} /// @}
/// Init help/ commands. namespace cmd {
void init_help(CommandManager *cm) { void init_help() {
cm->reg(new help_bugs); reg(new help_bugs);
cm->reg(new help_contents); reg(new help_contents);
cm->reg(new help_files); reg(new help_files);
cm->reg(new help_forums); reg(new help_forums);
cm->reg(new help_irc); reg(new help_irc);
cm->reg(new help_video); reg(new help_video);
cm->reg(new help_website); reg(new help_website);
}
} }
} // namespace cmd

View file

@ -39,7 +39,7 @@ typedef std::pair<std::string, wxBitmap*> iconPair;
iconMap icon16; iconMap icon16;
iconMap icon24; iconMap icon24;
wxBitmap* get(std::string name, const int size) { wxBitmap* get(std::string const& name, const int size) {
// XXX: This code will go away with dynamic icon generation so I'm not // XXX: This code will go away with dynamic icon generation so I'm not
// concerned about it. // concerned about it.

View file

@ -18,8 +18,6 @@
/// @brief Icon for commands. /// @brief Icon for commands.
/// @ingroup command /// @ingroup command
#pragma once
#ifndef AGI_PRE #ifndef AGI_PRE
#include <wx/bitmap.h> #include <wx/bitmap.h>
#endif #endif
@ -31,5 +29,5 @@ DEFINE_SIMPLE_EXCEPTION_NOINNER(IconInvalid, IconError, "icon/invalid")
namespace icon { namespace icon {
void icon_init(); void icon_init();
wxBitmap* get(std::string name, const int size); wxBitmap* get(std::string const& name, int size);
} // namespace cmd }

View file

@ -49,7 +49,8 @@
#include "../compat.h" #include "../compat.h"
#include "../video_context.h" #include "../video_context.h"
namespace cmd { namespace {
using cmd::Command;
/// @defgroup cmd-keyframed Keyframe commands. /// @defgroup cmd-keyframed Keyframe commands.
/// @{ /// @{
@ -106,14 +107,13 @@ struct keyframe_save : public Command {
c->videoController->SaveKeyframes(filename); c->videoController->SaveKeyframes(filename);
} }
}; };
}
/// @} /// @}
/// Init keyframe/ commands. namespace cmd {
void init_keyframe(CommandManager *cm) { void init_keyframe() {
cm->reg(new keyframe_close()); reg(new keyframe_close);
cm->reg(new keyframe_open()); reg(new keyframe_open);
cm->reg(new keyframe_save()); reg(new keyframe_save);
}
} }
} // namespace cmd

View file

@ -43,7 +43,8 @@
#include "../include/aegisub/context.h" #include "../include/aegisub/context.h"
namespace cmd { namespace {
using cmd::Command;
/// @defgroup cmd-menu Main menu dropdown and submenu related commands. /// @defgroup cmd-menu Main menu dropdown and submenu related commands.
/// @{ /// @{
@ -63,28 +64,27 @@ COMMAND_GROUP(main_video, "main/video", "&Video", "Video", "Video operations.");
COMMAND_GROUP(main_video_override_ar, "main/video/override ar", "Override AR", "Override AR", "Override Aspect Ratio"); COMMAND_GROUP(main_video_override_ar, "main/video/override ar", "Override AR", "Override AR", "Override Aspect Ratio");
COMMAND_GROUP(main_video_set_zoom, "main/video/set zoom", "Set Zoom", "Set Zoom", "Set zoom level."); COMMAND_GROUP(main_video_set_zoom, "main/video/set zoom", "Set Zoom", "Set Zoom", "Set zoom level.");
COMMAND_GROUP(main_view, "main/view", "View", "View", "View options."); COMMAND_GROUP(main_view, "main/view", "View", "View", "View options.");
}
/// @} /// @}
/// Init menu/ commands. namespace cmd {
void init_menu(CommandManager *cm) { void init_menu() {
cm->reg(new main_audio()); reg(new main_audio);
cm->reg(new main_automation()); reg(new main_automation);
cm->reg(new main_edit()); reg(new main_edit);
cm->reg(new main_edit_sort_lines()); reg(new main_edit_sort_lines);
cm->reg(new main_file()); reg(new main_file);
cm->reg(new main_help()); reg(new main_help);
cm->reg(new main_subtitle()); reg(new main_subtitle);
cm->reg(new main_subtitle_insert_lines()); reg(new main_subtitle_insert_lines);
cm->reg(new main_subtitle_join_lines()); reg(new main_subtitle_join_lines);
cm->reg(new main_subtitle_sort_lines()); reg(new main_subtitle_sort_lines);
cm->reg(new main_timing()); reg(new main_timing);
cm->reg(new main_timing_make_times_continuous()); reg(new main_timing_make_times_continuous);
cm->reg(new main_video()); reg(new main_video);
cm->reg(new main_video_override_ar()); reg(new main_video_override_ar);
cm->reg(new main_video_set_zoom()); reg(new main_video_set_zoom);
cm->reg(new main_view()); reg(new main_view);
}
} }
} // namespace cmd

View file

@ -51,7 +51,8 @@
#include "../compat.h" #include "../compat.h"
#include "../video_context.h" #include "../video_context.h"
namespace cmd { namespace {
using cmd::Command;
/// @defgroup cmd-recent MRU (Most Recently Used) commands. /// @defgroup cmd-recent MRU (Most Recently Used) commands.
/// @{ /// @{
@ -134,25 +135,24 @@ public:
full_name = ss.str(); full_name = ss.str();
} }
}; };
}
/// @} /// @}
/// Init recent/ commands. namespace cmd {
void init_recent(CommandManager *cm) { void init_recent() {
cm->reg(new recent_audio()); reg(new recent_audio);
cm->reg(new recent_keyframe()); reg(new recent_keyframe);
cm->reg(new recent_subtitle()); reg(new recent_subtitle);
cm->reg(new recent_timecode()); reg(new recent_timecode);
cm->reg(new recent_video()); reg(new recent_video);
/// @todo 16 is an implementation detail that maybe needs to be exposed /// @todo 16 is an implementation detail that maybe needs to be exposed
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
cm->reg(new mru_wrapper<recent_audio_entry>(i)); reg(new mru_wrapper<recent_audio_entry>(i));
cm->reg(new mru_wrapper<recent_keyframe_entry>(i)); reg(new mru_wrapper<recent_keyframe_entry>(i));
cm->reg(new mru_wrapper<recent_subtitle_entry>(i)); reg(new mru_wrapper<recent_subtitle_entry>(i));
cm->reg(new mru_wrapper<recent_timecode_entry>(i)); reg(new mru_wrapper<recent_timecode_entry>(i));
cm->reg(new mru_wrapper<recent_video_entry>(i)); reg(new mru_wrapper<recent_video_entry>(i));
}
} }
} }
} // namespace cmd

View file

@ -62,12 +62,11 @@
#include "../video_context.h" #include "../video_context.h"
#include "../utils.h" #include "../utils.h"
namespace {
namespace cmd { using cmd::Command;
/// @defgroup cmd-subtitle Subtitle commands. /// @defgroup cmd-subtitle Subtitle commands.
/// @{ /// @{
/// Open the attachment list. /// Open the attachment list.
struct subtitle_attachment : public Command { struct subtitle_attachment : public Command {
CMD_NAME("subtitle/attachment") CMD_NAME("subtitle/attachment")
@ -406,30 +405,29 @@ struct subtitle_tags_show : public Command {
//XXX: see grid.cpp:grid_tags_hide() //XXX: see grid.cpp:grid_tags_hide()
} }
}; };
}
/// @} /// @}
/// Init subtitle/ commands. namespace cmd {
void init_subtitle(CommandManager *cm) { void init_subtitle() {
cm->reg(new subtitle_attachment); reg(new subtitle_attachment);
cm->reg(new subtitle_find); reg(new subtitle_find);
cm->reg(new subtitle_find_next); reg(new subtitle_find_next);
cm->reg(new subtitle_insert_after); reg(new subtitle_insert_after);
cm->reg(new subtitle_insert_after_videotime); reg(new subtitle_insert_after_videotime);
cm->reg(new subtitle_insert_before); reg(new subtitle_insert_before);
cm->reg(new subtitle_insert_before_videotime); reg(new subtitle_insert_before_videotime);
cm->reg(new subtitle_new); reg(new subtitle_new);
cm->reg(new subtitle_open); reg(new subtitle_open);
cm->reg(new subtitle_open_charset); reg(new subtitle_open_charset);
cm->reg(new subtitle_open_video); reg(new subtitle_open_video);
cm->reg(new subtitle_properties); reg(new subtitle_properties);
cm->reg(new subtitle_save); reg(new subtitle_save);
cm->reg(new subtitle_save_as); reg(new subtitle_save_as);
cm->reg(new subtitle_select_all); reg(new subtitle_select_all);
cm->reg(new subtitle_select_visible); reg(new subtitle_select_visible);
cm->reg(new subtitle_spellcheck); reg(new subtitle_spellcheck);
cm->reg(new subtitle_tags_show); reg(new subtitle_tags_show);
}
} }
} // namespace cmd

View file

@ -55,11 +55,11 @@
#include "../subs_grid.h" #include "../subs_grid.h"
#include "../video_context.h" #include "../video_context.h"
namespace cmd { namespace {
using cmd::Command;
/// @defgroup cmd-time Time manipulation commands. /// @defgroup cmd-time Time manipulation commands.
/// @{ /// @{
/// Changes times of subs so end times begin on next's start time. /// Changes times of subs so end times begin on next's start time.
struct time_continuous_end : public Command { struct time_continuous_end : public Command {
CMD_NAME("time/continuous/end") CMD_NAME("time/continuous/end")
@ -342,26 +342,26 @@ struct time_prev : public Command {
c->audioController->PlayPrimaryRange(); c->audioController->PlayPrimaryRange();
} }
}; };
}
/// @} /// @}
/// Init time/ commands. namespace cmd {
void init_time(CommandManager *cm) { void init_time() {
cm->reg(new time_add_lead_in); reg(new time_add_lead_in);
cm->reg(new time_add_lead_out); reg(new time_add_lead_out);
cm->reg(new time_continuous_end); reg(new time_continuous_end);
cm->reg(new time_continuous_start); reg(new time_continuous_start);
cm->reg(new time_frame_current); reg(new time_frame_current);
cm->reg(new time_next); reg(new time_next);
cm->reg(new time_prev); reg(new time_prev);
cm->reg(new time_shift); reg(new time_shift);
cm->reg(new time_snap_end_video); reg(new time_snap_end_video);
cm->reg(new time_snap_frame); reg(new time_snap_frame);
cm->reg(new time_snap_scene); reg(new time_snap_scene);
cm->reg(new time_snap_start_video); reg(new time_snap_start_video);
cm->reg(new time_sort_end); reg(new time_sort_end);
cm->reg(new time_sort_start); reg(new time_sort_start);
cm->reg(new time_sort_style); reg(new time_sort_style);
}
} }
} // namespace cmd

View file

@ -50,11 +50,11 @@
#include "../compat.h" #include "../compat.h"
#include "../subs_edit_box.h" #include "../subs_edit_box.h"
namespace cmd { namespace {
using cmd::Command;
/// @defgroup cmd-timecode Timecode commands. /// @defgroup cmd-timecode Timecode commands.
/// @{ /// @{
/// Closes the currently open timecodes file. /// Closes the currently open timecodes file.
struct timecode_close : public Command { struct timecode_close : public Command {
CMD_NAME("timecode/close") CMD_NAME("timecode/close")
@ -104,14 +104,13 @@ struct timecode_save : public Command {
} }
} }
}; };
}
/// @} /// @}
/// Init timecode/ commands. namespace cmd {
void init_timecode(CommandManager *cm) { void init_timecode() {
cm->reg(new timecode_close()); reg(new timecode_close);
cm->reg(new timecode_open()); reg(new timecode_open);
cm->reg(new timecode_save()); reg(new timecode_save);
}
} }
} // namespace cmd

View file

@ -59,7 +59,8 @@
#include "../dialog_kara_timing_copy.h" #include "../dialog_kara_timing_copy.h"
#include "../subs_grid.h" #include "../subs_grid.h"
namespace cmd { namespace {
using cmd::Command;
/// @defgroup cmd-tool Various tool and utilities /// @defgroup cmd-tool Various tool and utilities
/// @{ /// @{
@ -201,22 +202,20 @@ struct tool_translation_assistant : public Command {
DialogTranslation(c, start, true).ShowModal(); DialogTranslation(c, start, true).ShowModal();
} }
}; };
}
/// @} /// @}
/// Init tool/ commands. namespace cmd {
void init_tool(CommandManager *cm) { void init_tool() {
cm->reg(new tool_assdraw()); reg(new tool_assdraw);
cm->reg(new tool_export()); reg(new tool_export);
cm->reg(new tool_font_collector()); reg(new tool_font_collector);
cm->reg(new tool_line_select()); reg(new tool_line_select);
cm->reg(new tool_resampleres()); reg(new tool_resampleres);
cm->reg(new tool_style_assistant()); reg(new tool_style_assistant);
cm->reg(new tool_style_manager()); reg(new tool_style_manager);
cm->reg(new tool_time_kanji()); reg(new tool_time_kanji);
cm->reg(new tool_time_postprocess()); reg(new tool_time_postprocess);
cm->reg(new tool_translation_assistant()); reg(new tool_translation_assistant);
}
} }
} // namespace cmd

View file

@ -38,9 +38,6 @@
#include "../config.h" #include "../config.h"
#ifndef AGI_PRE
#endif
#include "command.h" #include "command.h"
#include "../ass_dialogue.h" #include "../ass_dialogue.h"
@ -60,7 +57,8 @@
#include "../video_display.h" #include "../video_display.h"
#include "../video_slider.h" #include "../video_slider.h"
namespace cmd { namespace {
using cmd::Command;
/// @defgroup cmd-video Video commands. /// @defgroup cmd-video Video commands.
/// @{ /// @{
@ -600,43 +598,43 @@ struct video_zoom_out : public Command {
c->videoBox->videoDisplay->SetZoom(c->videoBox->videoDisplay->GetZoom() - .125); c->videoBox->videoDisplay->SetZoom(c->videoBox->videoDisplay->GetZoom() - .125);
} }
}; };
}
/// @} /// @}
/// Init video/ commands. namespace cmd {
void init_video(CommandManager *cm) { void init_video() {
cm->reg(new video_aspect_cinematic); reg(new video_aspect_cinematic);
cm->reg(new video_aspect_custom); reg(new video_aspect_custom);
cm->reg(new video_aspect_default); reg(new video_aspect_default);
cm->reg(new video_aspect_full); reg(new video_aspect_full);
cm->reg(new video_aspect_wide); reg(new video_aspect_wide);
cm->reg(new video_close); reg(new video_close);
cm->reg(new video_detach); reg(new video_detach);
cm->reg(new video_details); reg(new video_details);
cm->reg(new video_focus_seek); reg(new video_focus_seek);
cm->reg(new video_frame_next); reg(new video_frame_next);
cm->reg(new video_frame_next_boundary); reg(new video_frame_next_boundary);
cm->reg(new video_frame_next_keyframe); reg(new video_frame_next_keyframe);
cm->reg(new video_frame_next_large); reg(new video_frame_next_large);
cm->reg(new video_frame_prev); reg(new video_frame_prev);
cm->reg(new video_frame_prev_boundary); reg(new video_frame_prev_boundary);
cm->reg(new video_frame_prev_keyframe); reg(new video_frame_prev_keyframe);
cm->reg(new video_frame_prev_large); reg(new video_frame_prev_large);
cm->reg(new video_jump); reg(new video_jump);
cm->reg(new video_jump_end); reg(new video_jump_end);
cm->reg(new video_jump_start); reg(new video_jump_start);
cm->reg(new video_open); reg(new video_open);
cm->reg(new video_open_dummy); reg(new video_open_dummy);
cm->reg(new video_opt_autoscroll); reg(new video_opt_autoscroll);
cm->reg(new video_play); reg(new video_play);
cm->reg(new video_play_line); reg(new video_play_line);
cm->reg(new video_show_overscan); reg(new video_show_overscan);
cm->reg(new video_stop); reg(new video_stop);
cm->reg(new video_zoom_100); reg(new video_zoom_100);
cm->reg(new video_zoom_200); reg(new video_zoom_200);
cm->reg(new video_zoom_50); reg(new video_zoom_50);
cm->reg(new video_zoom_in); reg(new video_zoom_in);
cm->reg(new video_zoom_out); reg(new video_zoom_out);
}
} }
} // namespace cmd

View file

@ -185,11 +185,8 @@ bool AegisubApp::OnInit() {
config::path = new agi::Path(path.append("path.json"), GET_DEFAULT_CONFIG(default_path)); config::path = new agi::Path(path.append("path.json"), GET_DEFAULT_CONFIG(default_path));
// Init command manager
cmd::cm = new cmd::CommandManager();
// Init commands. // Init commands.
cmd::init_command(cmd::cm); cmd::init_builtin_commands();
// Init hotkeys. // Init hotkeys.
const std::string conf_user_hotkey(StandardPaths::DecodePath(_T("?user/hotkey.json"))); const std::string conf_user_hotkey(StandardPaths::DecodePath(_T("?user/hotkey.json")));