diff --git a/aegisub/src/command/app.cpp b/aegisub/src/command/app.cpp index 6683eea6e..52a2dbb46 100644 --- a/aegisub/src/command/app.cpp +++ b/aegisub/src/command/app.cpp @@ -47,17 +47,18 @@ #include "../include/aegisub/context.h" #include "../main.h" -#include "../dialog_about.h" #include "../audio_controller.h" -#include "../frame_main.h" -#include "../video_context.h" -#include "../utils.h" +#include "../dialog_about.h" #include "../dialog_log.h" -#include "../preferences.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 /// @{ @@ -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); + } +} diff --git a/aegisub/src/command/audio.cpp b/aegisub/src/command/audio.cpp index 3fb32c01e..675ac7511 100644 --- a/aegisub/src/command/audio.cpp +++ b/aegisub/src/command/audio.cpp @@ -54,11 +54,11 @@ typedef SelectionController::Selection Selection; -namespace cmd { +namespace { + using cmd::Command; /// @defgroup cmd-audio Audio commands. /// @{ - /// Closes the currently open audio file. struct audio_close : public Command { 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); + } +} diff --git a/aegisub/src/command/automation.cpp b/aegisub/src/command/automation.cpp index 48436af15..e0e5905bb 100644 --- a/aegisub/src/command/automation.cpp +++ b/aegisub/src/command/automation.cpp @@ -50,7 +50,8 @@ #include "../video_context.h" #include "../frame_main.h" -namespace cmd { +namespace { + using cmd::Command; /// @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); + } +} diff --git a/aegisub/src/command/command.cpp b/aegisub/src/command/command.cpp index 79e81d71d..cf988b6d4 100644 --- a/aegisub/src/command/command.cpp +++ b/aegisub/src/command/command.cpp @@ -19,111 +19,92 @@ /// @ingroup command #include "command.h" +#include "icon.h" #include namespace cmd { + static std::map cmd_map; + typedef std::map::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 call(agi::Context *c, const int id) { return cm->call(c, id); } -int count() { return cm->count(); } -Command* get(std::string name) { return cm->get(name); } + void reg(Command *cmd) { + cmd_map[cmd->name()] = cmd; + } + int id(std::string const& name) { + return distance(cmd_map.begin(), find_command(name)); + } -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."); + int count() { + return cmd_map.size(); + } + + Command *get(std::string const& name) { + return find_command(name)->second; + } + + void call(agi::Context *c, int id) { + std::map::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 diff --git a/aegisub/src/command/command.h b/aegisub/src/command/command.h index fe171d8f6..5cfdd8da2 100644 --- a/aegisub/src/command/command.h +++ b/aegisub/src/command/command.h @@ -21,15 +21,17 @@ #ifndef AGI_PRE #include +#include + +#include #endif #include -#include "icon.h" - namespace agi { struct Context; } 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(CommandIconInvalid, CommandError, "command/icon/invalid") @@ -49,23 +51,6 @@ struct cname : public Command { \ /// Commands 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 class Command { public: @@ -82,38 +67,32 @@ namespace cmd { virtual void operator()(agi::Context *c)=0; /// Destructor - virtual ~Command() {}; + virtual ~Command() { }; }; + /// Init all builtin commands. + void init_builtin_commands(); - /// Manager for commands - class CommandManager { - typedef std::map cmdMap; ///< Map to hold commands. - typedef std::pair cmdPair; ///< Pair for command insertion. - cmdMap map; ///< Actual map. + /// Register a command. + /// @param cmd Command object. + void reg(Command *cmd); - public: - /// Register a command. - /// @param cmd Command object. - void reg(Command *cmd); + /// Retrieve an ID for event usage or otherwise + /// @param name Command name + /// @return Command ID + /// @note This is guaranteed to be unique. + int id(std::string const& name); - /// Retrieve an ID for event usage or otherwise - /// @param name Command name - /// @return Command ID - /// @note This is guaranteed to be unique. - int id(std::string name); + /// Call a command. + /// @param c Current Context. + /// @param id ID for Command to call. + void call(agi::Context *c, int id); - /// Call a command. - /// @param c Current Context. - /// @param id ID for Command to call. - void call(agi::Context *c, const int id); + /// Count number of commands. + /// @return ID number. + int count(); - /// Count number of commands. - /// @return ID number. - int count() { return map.size(); } - - /// Retrieve a Command object. - /// @param Command object. - Command* get(std::string name); - }; + /// Retrieve a Command object. + /// @param Command object. + Command* get(std::string const& name); } // namespace cmd diff --git a/aegisub/src/command/edit.cpp b/aegisub/src/command/edit.cpp index 87d462a5b..bc668e699 100644 --- a/aegisub/src/command/edit.cpp +++ b/aegisub/src/command/edit.cpp @@ -53,11 +53,11 @@ #include "../subs_grid.h" #include "../video_context.h" -namespace cmd { +namespace { + using cmd::Command; /// @defgroup cmd-edit Editing commands. /// @{ - /// Copy subtitles. struct edit_line_copy : public Command { CMD_NAME("edit/line/copy") @@ -339,26 +339,26 @@ struct edit_undo : public Command { } }; +} /// @} -/// Init edit/ commands -void init_edit(CommandManager *cm) { - cm->reg(new edit_line_copy()); - cm->reg(new edit_line_cut()); - cm->reg(new edit_line_delete()); - cm->reg(new edit_line_duplicate()); - cm->reg(new edit_line_duplicate_shift()); - cm->reg(new edit_line_join_as_karaoke()); - cm->reg(new edit_line_join_concatenate()); - cm->reg(new edit_line_join_keep_first()); - cm->reg(new edit_line_paste()); - cm->reg(new edit_line_paste_over()); - cm->reg(new edit_line_recombine()); - cm->reg(new edit_line_split_by_karaoke()); - cm->reg(new edit_line_swap()); - cm->reg(new edit_redo()); - cm->reg(new edit_search_replace()); - cm->reg(new edit_undo()); +namespace cmd { + void init_edit() { + reg(new edit_line_copy); + reg(new edit_line_cut); + reg(new edit_line_delete); + reg(new edit_line_duplicate); + reg(new edit_line_duplicate_shift); + reg(new edit_line_join_as_karaoke); + reg(new edit_line_join_concatenate); + reg(new edit_line_join_keep_first); + reg(new edit_line_paste); + reg(new edit_line_paste_over); + reg(new edit_line_recombine); + reg(new edit_line_split_by_karaoke); + reg(new edit_line_swap); + reg(new edit_redo); + reg(new edit_search_replace); + reg(new edit_undo); + } } - -} // namespace cmd diff --git a/aegisub/src/command/grid.cpp b/aegisub/src/command/grid.cpp index 1241993b5..b12c2d63a 100644 --- a/aegisub/src/command/grid.cpp +++ b/aegisub/src/command/grid.cpp @@ -38,9 +38,6 @@ #include "../config.h" -#ifndef AGI_PRE -#endif - #include "command.h" #include "../ass_dialogue.h" @@ -51,8 +48,8 @@ #include "../frame_main.h" #include "../utils.h" - -namespace cmd { +namespace { + using cmd::Command; /// @defgroup cmd-grid Subtitle grid commands. /// @{ @@ -195,20 +192,18 @@ struct grid_swap_down : public Command { } } }; - +} /// @} - -/// Init grid/ commands. -void init_grid(CommandManager *cm) { - cm->reg(new grid_line_next); - cm->reg(new grid_line_prev); - cm->reg(new grid_swap_down); - cm->reg(new grid_swap_up); - cm->reg(new grid_tag_cycle_hiding); - cm->reg(new grid_tags_hide); - cm->reg(new grid_tags_show); - cm->reg(new grid_tags_simplify); +namespace cmd { + void init_grid() { + reg(new grid_line_next); + reg(new grid_line_prev); + reg(new grid_swap_down); + reg(new grid_swap_up); + reg(new grid_tag_cycle_hiding); + reg(new grid_tags_hide); + reg(new grid_tags_show); + reg(new grid_tags_simplify); + } } - -} // namespace cmd diff --git a/aegisub/src/command/help.cpp b/aegisub/src/command/help.cpp index 103834ffd..900ed8de3 100644 --- a/aegisub/src/command/help.cpp +++ b/aegisub/src/command/help.cpp @@ -50,12 +50,11 @@ #include "../help_button.h" // help_contents #include "../main.h" -namespace cmd { +namespace { + using cmd::Command; /// @defgroup cmd-help Help commands. /// @{ - - /// Visit Aegisub's bug tracker. struct help_bugs : public Command { CMD_NAME("help/bugs") @@ -157,18 +156,17 @@ struct help_website : public Command { AegisubApp::OpenURL(_T("http://www.aegisub.org/")); } }; - +} /// @} -/// Init help/ commands. -void init_help(CommandManager *cm) { - cm->reg(new help_bugs); - cm->reg(new help_contents); - cm->reg(new help_files); - cm->reg(new help_forums); - cm->reg(new help_irc); - cm->reg(new help_video); - cm->reg(new help_website); +namespace cmd { + void init_help() { + reg(new help_bugs); + reg(new help_contents); + reg(new help_files); + reg(new help_forums); + reg(new help_irc); + reg(new help_video); + reg(new help_website); + } } - -} // namespace cmd diff --git a/aegisub/src/command/icon.cpp b/aegisub/src/command/icon.cpp index 830576192..f4a932d1b 100644 --- a/aegisub/src/command/icon.cpp +++ b/aegisub/src/command/icon.cpp @@ -39,7 +39,7 @@ typedef std::pair iconPair; iconMap icon16; 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 // concerned about it. diff --git a/aegisub/src/command/icon.h b/aegisub/src/command/icon.h index b3f76565e..201c931a1 100644 --- a/aegisub/src/command/icon.h +++ b/aegisub/src/command/icon.h @@ -18,8 +18,6 @@ /// @brief Icon for commands. /// @ingroup command -#pragma once - #ifndef AGI_PRE #include #endif @@ -31,5 +29,5 @@ DEFINE_SIMPLE_EXCEPTION_NOINNER(IconInvalid, IconError, "icon/invalid") namespace icon { void icon_init(); - wxBitmap* get(std::string name, const int size); -} // namespace cmd + wxBitmap* get(std::string const& name, int size); +} diff --git a/aegisub/src/command/keyframe.cpp b/aegisub/src/command/keyframe.cpp index 452ae0caa..af1455168 100644 --- a/aegisub/src/command/keyframe.cpp +++ b/aegisub/src/command/keyframe.cpp @@ -49,7 +49,8 @@ #include "../compat.h" #include "../video_context.h" -namespace cmd { +namespace { + using cmd::Command; /// @defgroup cmd-keyframed Keyframe commands. /// @{ @@ -106,14 +107,13 @@ struct keyframe_save : public Command { c->videoController->SaveKeyframes(filename); } }; - +} /// @} -/// Init keyframe/ commands. -void init_keyframe(CommandManager *cm) { - cm->reg(new keyframe_close()); - cm->reg(new keyframe_open()); - cm->reg(new keyframe_save()); +namespace cmd { + void init_keyframe() { + reg(new keyframe_close); + reg(new keyframe_open); + reg(new keyframe_save); + } } - -} // namespace cmd diff --git a/aegisub/src/command/menu_.cpp b/aegisub/src/command/menu_.cpp index 32abc0e7e..eb4410b81 100644 --- a/aegisub/src/command/menu_.cpp +++ b/aegisub/src/command/menu_.cpp @@ -43,7 +43,8 @@ #include "../include/aegisub/context.h" -namespace cmd { +namespace { + using cmd::Command; /// @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_set_zoom, "main/video/set zoom", "Set Zoom", "Set Zoom", "Set zoom level."); COMMAND_GROUP(main_view, "main/view", "View", "View", "View options."); - +} /// @} -/// Init menu/ commands. -void init_menu(CommandManager *cm) { - cm->reg(new main_audio()); - cm->reg(new main_automation()); - cm->reg(new main_edit()); - cm->reg(new main_edit_sort_lines()); - cm->reg(new main_file()); - cm->reg(new main_help()); - cm->reg(new main_subtitle()); - cm->reg(new main_subtitle_insert_lines()); - cm->reg(new main_subtitle_join_lines()); - cm->reg(new main_subtitle_sort_lines()); - cm->reg(new main_timing()); - cm->reg(new main_timing_make_times_continuous()); - cm->reg(new main_video()); - cm->reg(new main_video_override_ar()); - cm->reg(new main_video_set_zoom()); - cm->reg(new main_view()); +namespace cmd { + void init_menu() { + reg(new main_audio); + reg(new main_automation); + reg(new main_edit); + reg(new main_edit_sort_lines); + reg(new main_file); + reg(new main_help); + reg(new main_subtitle); + reg(new main_subtitle_insert_lines); + reg(new main_subtitle_join_lines); + reg(new main_subtitle_sort_lines); + reg(new main_timing); + reg(new main_timing_make_times_continuous); + reg(new main_video); + reg(new main_video_override_ar); + reg(new main_video_set_zoom); + reg(new main_view); + } } - -} // namespace cmd diff --git a/aegisub/src/command/recent.cpp b/aegisub/src/command/recent.cpp index 4a7ca92de..e0888bc4f 100644 --- a/aegisub/src/command/recent.cpp +++ b/aegisub/src/command/recent.cpp @@ -51,7 +51,8 @@ #include "../compat.h" #include "../video_context.h" -namespace cmd { +namespace { + using cmd::Command; /// @defgroup cmd-recent MRU (Most Recently Used) commands. /// @{ @@ -134,25 +135,24 @@ public: full_name = ss.str(); } }; - +} /// @} -/// Init recent/ commands. -void init_recent(CommandManager *cm) { - cm->reg(new recent_audio()); - cm->reg(new recent_keyframe()); - cm->reg(new recent_subtitle()); - cm->reg(new recent_timecode()); - cm->reg(new recent_video()); +namespace cmd { + void init_recent() { + reg(new recent_audio); + reg(new recent_keyframe); + reg(new recent_subtitle); + reg(new recent_timecode); + reg(new recent_video); - /// @todo 16 is an implementation detail that maybe needs to be exposed - for (int i = 0; i < 16; ++i) { - cm->reg(new mru_wrapper(i)); - cm->reg(new mru_wrapper(i)); - cm->reg(new mru_wrapper(i)); - cm->reg(new mru_wrapper(i)); - cm->reg(new mru_wrapper(i)); + /// @todo 16 is an implementation detail that maybe needs to be exposed + for (int i = 0; i < 16; ++i) { + reg(new mru_wrapper(i)); + reg(new mru_wrapper(i)); + reg(new mru_wrapper(i)); + reg(new mru_wrapper(i)); + reg(new mru_wrapper(i)); + } } } - -} // namespace cmd diff --git a/aegisub/src/command/subtitle.cpp b/aegisub/src/command/subtitle.cpp index beb408024..10f0cd421 100644 --- a/aegisub/src/command/subtitle.cpp +++ b/aegisub/src/command/subtitle.cpp @@ -62,12 +62,11 @@ #include "../video_context.h" #include "../utils.h" - -namespace cmd { +namespace { + using cmd::Command; /// @defgroup cmd-subtitle Subtitle commands. /// @{ - /// Open the attachment list. struct subtitle_attachment : public Command { CMD_NAME("subtitle/attachment") @@ -406,30 +405,29 @@ struct subtitle_tags_show : public Command { //XXX: see grid.cpp:grid_tags_hide() } }; +} /// @} -/// Init subtitle/ commands. -void init_subtitle(CommandManager *cm) { - cm->reg(new subtitle_attachment); - cm->reg(new subtitle_find); - cm->reg(new subtitle_find_next); - cm->reg(new subtitle_insert_after); - cm->reg(new subtitle_insert_after_videotime); - cm->reg(new subtitle_insert_before); - cm->reg(new subtitle_insert_before_videotime); - cm->reg(new subtitle_new); - cm->reg(new subtitle_open); - cm->reg(new subtitle_open_charset); - cm->reg(new subtitle_open_video); - cm->reg(new subtitle_properties); - cm->reg(new subtitle_save); - cm->reg(new subtitle_save_as); - cm->reg(new subtitle_select_all); - cm->reg(new subtitle_select_visible); - cm->reg(new subtitle_spellcheck); - cm->reg(new subtitle_tags_show); +namespace cmd { + void init_subtitle() { + reg(new subtitle_attachment); + reg(new subtitle_find); + reg(new subtitle_find_next); + reg(new subtitle_insert_after); + reg(new subtitle_insert_after_videotime); + reg(new subtitle_insert_before); + reg(new subtitle_insert_before_videotime); + reg(new subtitle_new); + reg(new subtitle_open); + reg(new subtitle_open_charset); + reg(new subtitle_open_video); + reg(new subtitle_properties); + reg(new subtitle_save); + reg(new subtitle_save_as); + reg(new subtitle_select_all); + reg(new subtitle_select_visible); + reg(new subtitle_spellcheck); + reg(new subtitle_tags_show); + } } - - -} // namespace cmd diff --git a/aegisub/src/command/time.cpp b/aegisub/src/command/time.cpp index 6647f1f94..9b5f4a19d 100644 --- a/aegisub/src/command/time.cpp +++ b/aegisub/src/command/time.cpp @@ -55,11 +55,11 @@ #include "../subs_grid.h" #include "../video_context.h" -namespace cmd { +namespace { + using cmd::Command; /// @defgroup cmd-time Time manipulation commands. /// @{ - /// Changes times of subs so end times begin on next's start time. struct time_continuous_end : public Command { CMD_NAME("time/continuous/end") @@ -342,26 +342,26 @@ struct time_prev : public Command { c->audioController->PlayPrimaryRange(); } }; +} /// @} -/// Init time/ commands. -void init_time(CommandManager *cm) { - cm->reg(new time_add_lead_in); - cm->reg(new time_add_lead_out); - cm->reg(new time_continuous_end); - cm->reg(new time_continuous_start); - cm->reg(new time_frame_current); - cm->reg(new time_next); - cm->reg(new time_prev); - cm->reg(new time_shift); - cm->reg(new time_snap_end_video); - cm->reg(new time_snap_frame); - cm->reg(new time_snap_scene); - cm->reg(new time_snap_start_video); - cm->reg(new time_sort_end); - cm->reg(new time_sort_start); - cm->reg(new time_sort_style); +namespace cmd { + void init_time() { + reg(new time_add_lead_in); + reg(new time_add_lead_out); + reg(new time_continuous_end); + reg(new time_continuous_start); + reg(new time_frame_current); + reg(new time_next); + reg(new time_prev); + reg(new time_shift); + reg(new time_snap_end_video); + reg(new time_snap_frame); + reg(new time_snap_scene); + reg(new time_snap_start_video); + reg(new time_sort_end); + reg(new time_sort_start); + reg(new time_sort_style); + } } - -} // namespace cmd diff --git a/aegisub/src/command/timecode.cpp b/aegisub/src/command/timecode.cpp index 8084bd907..f8b4e00f3 100644 --- a/aegisub/src/command/timecode.cpp +++ b/aegisub/src/command/timecode.cpp @@ -50,11 +50,11 @@ #include "../compat.h" #include "../subs_edit_box.h" -namespace cmd { +namespace { + using cmd::Command; /// @defgroup cmd-timecode Timecode commands. /// @{ - /// Closes the currently open timecodes file. struct timecode_close : public Command { CMD_NAME("timecode/close") @@ -104,14 +104,13 @@ struct timecode_save : public Command { } } }; - +} /// @} -/// Init timecode/ commands. -void init_timecode(CommandManager *cm) { - cm->reg(new timecode_close()); - cm->reg(new timecode_open()); - cm->reg(new timecode_save()); +namespace cmd { + void init_timecode() { + reg(new timecode_close); + reg(new timecode_open); + reg(new timecode_save); + } } - -} // namespace cmd diff --git a/aegisub/src/command/tool.cpp b/aegisub/src/command/tool.cpp index b4c907827..757a5a437 100644 --- a/aegisub/src/command/tool.cpp +++ b/aegisub/src/command/tool.cpp @@ -59,7 +59,8 @@ #include "../dialog_kara_timing_copy.h" #include "../subs_grid.h" -namespace cmd { +namespace { + using cmd::Command; /// @defgroup cmd-tool Various tool and utilities /// @{ @@ -201,22 +202,20 @@ struct tool_translation_assistant : public Command { DialogTranslation(c, start, true).ShowModal(); } }; - +} /// @} -/// Init tool/ commands. -void init_tool(CommandManager *cm) { - cm->reg(new tool_assdraw()); - cm->reg(new tool_export()); - cm->reg(new tool_font_collector()); - cm->reg(new tool_line_select()); - cm->reg(new tool_resampleres()); - cm->reg(new tool_style_assistant()); - cm->reg(new tool_style_manager()); - cm->reg(new tool_time_kanji()); - cm->reg(new tool_time_postprocess()); - cm->reg(new tool_translation_assistant()); +namespace cmd { + void init_tool() { + reg(new tool_assdraw); + reg(new tool_export); + reg(new tool_font_collector); + reg(new tool_line_select); + reg(new tool_resampleres); + reg(new tool_style_assistant); + reg(new tool_style_manager); + reg(new tool_time_kanji); + reg(new tool_time_postprocess); + reg(new tool_translation_assistant); + } } - - -} // namespace cmd diff --git a/aegisub/src/command/video.cpp b/aegisub/src/command/video.cpp index beafddc71..34f276ca2 100644 --- a/aegisub/src/command/video.cpp +++ b/aegisub/src/command/video.cpp @@ -38,9 +38,6 @@ #include "../config.h" -#ifndef AGI_PRE -#endif - #include "command.h" #include "../ass_dialogue.h" @@ -60,7 +57,8 @@ #include "../video_display.h" #include "../video_slider.h" -namespace cmd { +namespace { + using cmd::Command; /// @defgroup cmd-video Video commands. /// @{ @@ -600,43 +598,43 @@ struct video_zoom_out : public Command { c->videoBox->videoDisplay->SetZoom(c->videoBox->videoDisplay->GetZoom() - .125); } }; +} /// @} -/// Init video/ commands. -void init_video(CommandManager *cm) { - cm->reg(new video_aspect_cinematic); - cm->reg(new video_aspect_custom); - cm->reg(new video_aspect_default); - cm->reg(new video_aspect_full); - cm->reg(new video_aspect_wide); - cm->reg(new video_close); - cm->reg(new video_detach); - cm->reg(new video_details); - cm->reg(new video_focus_seek); - cm->reg(new video_frame_next); - cm->reg(new video_frame_next_boundary); - cm->reg(new video_frame_next_keyframe); - cm->reg(new video_frame_next_large); - cm->reg(new video_frame_prev); - cm->reg(new video_frame_prev_boundary); - cm->reg(new video_frame_prev_keyframe); - cm->reg(new video_frame_prev_large); - cm->reg(new video_jump); - cm->reg(new video_jump_end); - cm->reg(new video_jump_start); - cm->reg(new video_open); - cm->reg(new video_open_dummy); - cm->reg(new video_opt_autoscroll); - cm->reg(new video_play); - cm->reg(new video_play_line); - cm->reg(new video_show_overscan); - cm->reg(new video_stop); - cm->reg(new video_zoom_100); - cm->reg(new video_zoom_200); - cm->reg(new video_zoom_50); - cm->reg(new video_zoom_in); - cm->reg(new video_zoom_out); +namespace cmd { + void init_video() { + reg(new video_aspect_cinematic); + reg(new video_aspect_custom); + reg(new video_aspect_default); + reg(new video_aspect_full); + reg(new video_aspect_wide); + reg(new video_close); + reg(new video_detach); + reg(new video_details); + reg(new video_focus_seek); + reg(new video_frame_next); + reg(new video_frame_next_boundary); + reg(new video_frame_next_keyframe); + reg(new video_frame_next_large); + reg(new video_frame_prev); + reg(new video_frame_prev_boundary); + reg(new video_frame_prev_keyframe); + reg(new video_frame_prev_large); + reg(new video_jump); + reg(new video_jump_end); + reg(new video_jump_start); + reg(new video_open); + reg(new video_open_dummy); + reg(new video_opt_autoscroll); + reg(new video_play); + reg(new video_play_line); + reg(new video_show_overscan); + reg(new video_stop); + reg(new video_zoom_100); + reg(new video_zoom_200); + reg(new video_zoom_50); + reg(new video_zoom_in); + reg(new video_zoom_out); + } } - -} // namespace cmd diff --git a/aegisub/src/main.cpp b/aegisub/src/main.cpp index 2802bf313..ba7c278cb 100644 --- a/aegisub/src/main.cpp +++ b/aegisub/src/main.cpp @@ -185,11 +185,8 @@ bool AegisubApp::OnInit() { config::path = new agi::Path(path.append("path.json"), GET_DEFAULT_CONFIG(default_path)); - // Init command manager - cmd::cm = new cmd::CommandManager(); - // Init commands. - cmd::init_command(cmd::cm); + cmd::init_builtin_commands(); // Init hotkeys. const std::string conf_user_hotkey(StandardPaths::DecodePath(_T("?user/hotkey.json")));