Add type flags to commands

Originally committed to SVN as r5464.
This commit is contained in:
Thomas Goyne 2011-07-15 04:05:56 +00:00
parent 0af7ae7fca
commit ec2c36c743
10 changed files with 87 additions and 4 deletions

View file

@ -81,6 +81,7 @@ struct app_display_audio_subs : public Command {
STR_MENU("Audio+Subs View")
STR_DISP("Audio+Subs View")
STR_HELP("Display audio and subtitles only.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
void operator()(agi::Context *c) {
wxGetApp().frame->SetDisplayMode(0,1);
@ -98,6 +99,7 @@ struct app_display_full : public Command {
STR_MENU("Full view")
STR_DISP("Full view")
STR_HELP("Display audio, video and subtitles.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
void operator()(agi::Context *c) {
wxGetApp().frame->SetDisplayMode(1,1);
@ -115,6 +117,7 @@ struct app_display_subs : public Command {
STR_MENU("Subs Only View")
STR_DISP("Subs Only View")
STR_HELP("Display subtitles only.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
void operator()(agi::Context *c) {
wxGetApp().frame->SetDisplayMode(0,0);
@ -128,6 +131,7 @@ struct app_display_video_subs : public Command {
STR_MENU("Video+Subs View")
STR_DISP("Video+Subs View")
STR_HELP("Display video and subtitles only.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
void operator()(agi::Context *c) {
wxGetApp().frame->SetDisplayMode(1,0);
@ -181,7 +185,6 @@ struct app_language : public Command {
}
};
/// Event log.
struct app_log : public Command {
CMD_NAME("app/log")

View file

@ -58,6 +58,7 @@ namespace {
using cmd::Command;
struct validate_audio_open : public Command {
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->audioController->IsAudioOpen();
}
@ -132,6 +133,7 @@ struct audio_open_video : public Command {
STR_MENU("Open Audio from &Video")
STR_DISP("Open Audio from Video")
STR_HELP("Opens the audio from the current video file.")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->videoController->IsLoaded();
@ -149,6 +151,7 @@ struct audio_view_spectrum : public Command {
STR_MENU("Spectrum Display")
STR_DISP("Spectrum Display")
STR_HELP("Display audio as a frequency-power spectrograph.")
CMD_TYPE(COMMAND_RADIO)
void operator()(agi::Context *c) {
OPT_SET("Audio/Spectrum")->SetBool(true);
@ -162,6 +165,7 @@ struct audio_view_waveform : public Command {
STR_MENU("Waveform Display")
STR_DISP("Waveform Display")
STR_HELP("Display audio as a linear amplitude graph.")
CMD_TYPE(COMMAND_RADIO)
void operator()(agi::Context *c) {
OPT_SET("Audio/Spectrum")->SetBool(false);
@ -174,6 +178,7 @@ struct audio_save_clip : public Command {
STR_MENU("Create audio clip")
STR_DISP("Create audio clip")
STR_HELP("Create an audio clip of the selected line")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->audioController->IsAudioOpen() && !c->selectionController->GetSelectedSet().empty();
@ -208,6 +213,7 @@ struct audio_stop : public Command {
STR_MENU("Stop playing")
STR_DISP("Stop playing")
STR_HELP("Stop")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->audioController->IsPlaying();
@ -330,6 +336,7 @@ struct audio_autoscroll : public Command {
STR_MENU("Auto scrolls audio display to selected line")
STR_DISP("Auto scrolls audio display to selected line")
STR_HELP("Auto scrolls audio display to selected line")
CMD_TYPE(COMMAND_TOGGLE)
void operator()(agi::Context *c) {
toggle("Audio/Auto/Scroll");
@ -342,6 +349,7 @@ struct audio_autocommit : public Command {
STR_MENU("Automatically commit all changes")
STR_DISP("Automatically commit all changes")
STR_HELP("Automatically commit all changes")
CMD_TYPE(COMMAND_TOGGLE)
void operator()(agi::Context *c) {
toggle("Audio/Auto/Commit");
@ -354,6 +362,7 @@ struct audio_autonext : public Command {
STR_MENU("Auto goes to next line on commit")
STR_DISP("Auto goes to next line on commit")
STR_HELP("Auto goes to next line on commit")
CMD_TYPE(COMMAND_TOGGLE)
void operator()(agi::Context *c) {
toggle("Audio/Next Line on Commit");
@ -366,6 +375,7 @@ struct audio_vertical_link : public Command {
STR_MENU("Link vertical zoom and volume sliders")
STR_DISP("Link vertical zoom and volume sliders")
STR_HELP("Link vertical zoom and volume sliders")
CMD_TYPE(COMMAND_TOGGLE)
void operator()(agi::Context *c) {
toggle("Audio/Link");

View file

@ -39,6 +39,7 @@ DEFINE_SIMPLE_EXCEPTION_NOINNER(CommandIconInvalid, CommandError, "command/icon/
#define STR_MENU(a) wxString StrMenu() const { return a; }
#define STR_DISP(a) wxString StrDisplay() const { return a; }
#define STR_HELP(a) wxString StrHelp() const { return a; }
#define CMD_TYPE(a) int Type() const { using namespace cmd; return a; }
#define COMMAND_GROUP(cname, cmdname, menu, disp, help) \
struct cname : public Command { \
@ -51,6 +52,35 @@ struct cname : public Command { \
/// Commands
namespace cmd {
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,
/// This command's icon may change based on the state of the project
COMMAND_DYNAMIC_ICON = 16
};
/// Holds an individual Command
class Command {
public:
@ -59,6 +89,10 @@ namespace cmd {
virtual wxString StrDisplay() const=0; ///< Plain string for display purposes.
virtual wxString StrHelp() const=0; ///< Short help string descripting the command purpose.
/// Get this command's type flags
/// @return Bitmask of CommandFlags
virtual int Type() const { return COMMAND_NORMAL; }
/// Request icon.
/// @param size Icon size.
wxBitmap* Icon(int size);

View file

@ -59,12 +59,14 @@ namespace {
/// @{
struct validate_sel_nonempty : public Command {
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->selectionController->GetSelectedSet().size() > 0;
}
};
struct validate_sel_multiple : public Command {
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->selectionController->GetSelectedSet().size() > 1;
}
@ -137,6 +139,7 @@ struct edit_line_duplicate_shift : public Command {
STR_MENU("&Duplicate and Shift by 1 Frame")
STR_DISP("Duplicate and Shift by 1 Frame")
STR_HELP("Duplicate lines and shift by one frame.")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return !c->selectionController->GetSelectedSet().empty() && c->videoController->IsLoaded();
@ -234,6 +237,7 @@ struct edit_line_paste : public Command {
STR_MENU("Paste Lines")
STR_DISP("Paste Lines")
STR_HELP("Paste subtitles.")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
if (wxTheClipboard->Open()) {
@ -260,6 +264,7 @@ struct edit_line_paste_over : public Command {
STR_MENU("Paste Lines Over..")
STR_DISP("Paste Lines Over")
STR_HELP("Paste subtitles over others.")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
if (wxTheClipboard->Open()) {
@ -317,6 +322,7 @@ struct edit_line_swap : public Command {
STR_MENU("Swap Lines")
STR_DISP("Swap Lines")
STR_HELP("Swaps the two selected lines.")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->selectionController->GetSelectedSet().size() == 2;
@ -342,6 +348,7 @@ struct edit_redo : public Command {
STR_MENU("&Redo")
STR_DISP("Redo")
STR_HELP("Redoes last action.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_DYNAMIC_NAME)
bool Validate(const agi::Context *c) {
return !c->ass->IsRedoStackEmpty();
@ -374,6 +381,7 @@ struct edit_undo : public Command {
STR_MENU("&Undo")
STR_DISP("Undo")
STR_HELP("Undoes last action.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_DYNAMIC_NAME)
bool Validate(const agi::Context *c) {
return !c->ass->IsUndoStackEmpty();

View file

@ -111,6 +111,7 @@ struct grid_tags_hide : public Command {
STR_MENU("Hide Tags")
STR_DISP("Hide Tags")
STR_HELP("Hide override tags in the subtitle grid.")
CMD_TYPE(COMMAND_RADIO)
void operator()(agi::Context *c) {
OPT_SET("Subtitle/Grid/Hide Overrides")->SetInt(2);
@ -124,6 +125,7 @@ struct grid_tags_show : public Command {
STR_MENU("Show Tags")
STR_DISP("Show Tags")
STR_HELP("Show full override tags in the subtitle grid.")
CMD_TYPE(COMMAND_RADIO)
void operator()(agi::Context *c) {
OPT_SET("Subtitle/Grid/Hide Overrides")->SetInt(0);
@ -137,6 +139,7 @@ struct grid_tags_simplify : public Command {
STR_MENU("Simplify Tags")
STR_DISP("Simplify Tags")
STR_HELP("Replace override tags in the subtitle grid with a simplified placeholder.")
CMD_TYPE(COMMAND_RADIO)
void operator()(agi::Context *c) {
OPT_SET("Subtitle/Grid/Hide Overrides")->SetInt(1);
@ -166,6 +169,7 @@ struct grid_swap_up : public Command {
STR_MENU("Move line up")
STR_DISP("Move line up")
STR_HELP("Move the selected line up one row")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(agi::Context *c) {
return c->selectionController->GetActiveLine() != 0;
@ -185,9 +189,10 @@ struct grid_swap_up : public Command {
/// Swap the active line with the dialogue line below it
struct grid_swap_down : public Command {
CMD_NAME("grid/swap/down")
STR_MENU("Move line down")
STR_DISP("Move line down")
STR_HELP("Move the selected line down one row")
STR_MENU("Move line down")
STR_DISP("Move line down")
STR_HELP("Move the selected line down one row")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(agi::Context *c) {
return c->selectionController->GetActiveLine() != 0;

View file

@ -61,6 +61,7 @@ struct keyframe_close : public Command {
STR_MENU("Close Keyframes")
STR_DISP("Close Keyframes")
STR_HELP("Closes the currently open keyframes list.")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->videoController->OverKeyFramesLoaded();
@ -102,6 +103,7 @@ struct keyframe_save : public Command {
STR_MENU("Save Keyframes..")
STR_DISP("Save Keyframes")
STR_HELP("Saves the current keyframe list.")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->videoController->KeyFramesLoaded();

View file

@ -68,12 +68,14 @@ namespace {
/// @{
struct validate_nonempty_selection : public Command {
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return !c->selectionController->GetSelectedSet().empty();
}
};
struct validate_nonempty_selection_video_loaded : public Command {
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->videoController->IsLoaded() && !c->selectionController->GetSelectedSet().empty();
}
@ -294,6 +296,7 @@ struct subtitle_open_video : public Command {
STR_MENU("Open Subtitles from &Video")
STR_DISP("Open Subtitles from Video")
STR_HELP("Opens the subtitles from the current video file.")
CMD_TYPE(COMMAND_VALIDATE)
void operator()(agi::Context *c) {
wxGetApp().frame->LoadSubtitles(c->videoController->videoName, "binary");
@ -388,6 +391,7 @@ struct subtitle_select_visible : public Command {
STR_MENU("Select Visible")
STR_DISP("Select Visible")
STR_HELP("Selects all lines that are currently visible on video frame.")
CMD_TYPE(COMMAND_VALIDATE)
void operator()(agi::Context *c) {
c->videoController->Stop();

View file

@ -59,12 +59,14 @@ namespace {
using cmd::Command;
struct validate_video_loaded : public Command {
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->videoController->IsLoaded();
}
};
struct validate_adjoinable : public Command {
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
SelectionController<AssDialogue>::Selection sel = c->selectionController->GetSelectedSet();
if (sel.size() < 2) return false;

View file

@ -61,6 +61,7 @@ struct timecode_close : public Command {
STR_MENU("Close Timecodes File")
STR_DISP("Close Timecodes File")
STR_HELP("Closes the currently open timecodes file.")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->videoController->OverTimecodesLoaded();
@ -97,6 +98,7 @@ struct timecode_save : public Command {
STR_MENU("Save Timecodes File..")
STR_DISP("Save Timecodes File")
STR_HELP("Saves a VFR timecodes v2 file.")
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->videoController->TimecodesLoaded();

View file

@ -64,12 +64,14 @@ namespace {
/// @{
struct validator_video_loaded : public Command {
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->videoController->IsLoaded();
}
};
struct validator_video_attached : public Command {
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(const agi::Context *c) {
return c->videoController->IsLoaded() && !c->detachedVideo;
}
@ -81,6 +83,7 @@ struct video_aspect_cinematic : public validator_video_attached {
STR_MENU("&Cinematic (2.35)")
STR_DISP("Cinematic (235)")
STR_HELP("Forces video to 2.35 aspect ratio.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
void operator()(agi::Context *c) {
c->videoController->Stop();
@ -95,6 +98,7 @@ struct video_aspect_custom : public validator_video_attached {
STR_MENU("Custom..")
STR_DISP("Custom")
STR_HELP("Forces video to a custom aspect ratio.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
void operator()(agi::Context *c) {
c->videoController->Stop();
@ -150,6 +154,7 @@ struct video_aspect_default : public validator_video_attached {
STR_MENU("&Default")
STR_DISP("Default")
STR_HELP("Leave video on original aspect ratio.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
void operator()(agi::Context *c) {
c->videoController->Stop();
@ -164,6 +169,7 @@ struct video_aspect_full : public validator_video_attached {
STR_MENU("&Fullscreen (4:3)")
STR_DISP("Fullscreen (4:3)")
STR_HELP("Forces video to 4:3 aspect ratio.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
void operator()(agi::Context *c) {
c->videoController->Stop();
@ -178,6 +184,7 @@ struct video_aspect_wide : public validator_video_attached {
STR_MENU("&Widescreen (16:9)")
STR_DISP("Widescreen (16:9)")
STR_HELP("Forces video to 16:9 aspect ratio.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
void operator()(agi::Context *c) {
c->videoController->Stop();
@ -204,6 +211,7 @@ struct video_detach : public validator_video_loaded {
STR_MENU("Detach Video")
STR_DISP("Detach Video")
STR_HELP("Detach video, displaying it in a separate Window.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_TOGGLE)
void operator()(agi::Context *c) {
wxGetApp().frame->DetachVideo(!c->detachedVideo);
@ -469,6 +477,7 @@ struct video_opt_autoscroll : public Command {
STR_MENU("Toggle autoscroll of video")
STR_DISP("Toggle autoscroll of video")
STR_HELP("Toggle autoscroll of video")
CMD_TYPE(COMMAND_TOGGLE)
void operator()(agi::Context *c) {
OPT_SET("Video/Subtitle Sync")->SetBool(!OPT_GET("Video/Subtitle Sync")->GetBool());
@ -505,6 +514,7 @@ struct video_show_overscan : public validator_video_loaded {
STR_MENU("Show Overscan Mask")
STR_DISP("Show Overscan Mask")
STR_HELP("Show a mask over the video, indicating areas that might get cropped off by overscan on televisions.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_TOGGLE)
void operator()(agi::Context *c) {
OPT_SET("Video/Overscan Mask")->SetBool(!OPT_GET("Video/Overscan Mask")->GetBool());
@ -519,6 +529,7 @@ public:
STR_MENU("&100%")
STR_DISP("100%")
STR_HELP("Set zoom to 100%.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
void operator()(agi::Context *c) {
c->videoController->Stop();
@ -546,6 +557,7 @@ public:
STR_MENU("&200%")
STR_DISP("200%")
STR_HELP("Set zoom to 200%.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
void operator()(agi::Context *c) {
c->videoController->Stop();
@ -560,6 +572,7 @@ public:
STR_MENU("&50%")
STR_DISP("50%")
STR_HELP("Set zoom to 50%.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
void operator()(agi::Context *c) {
c->videoController->Stop();