Add IsActive method to commands to indicate whether or not a radio/checkbox is currently selected

Originally committed to SVN as r5465.
This commit is contained in:
Thomas Goyne 2011-07-15 04:06:03 +00:00
parent ec2c36c743
commit 2b9d47b9fe
4 changed files with 92 additions and 0 deletions

View file

@ -153,6 +153,10 @@ struct audio_view_spectrum : public Command {
STR_HELP("Display audio as a frequency-power spectrograph.") STR_HELP("Display audio as a frequency-power spectrograph.")
CMD_TYPE(COMMAND_RADIO) CMD_TYPE(COMMAND_RADIO)
bool IsActive(const agi::Context *c) {
return OPT_GET("Audio/Spectrum")->GetBool();
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
OPT_SET("Audio/Spectrum")->SetBool(true); OPT_SET("Audio/Spectrum")->SetBool(true);
} }
@ -167,6 +171,10 @@ struct audio_view_waveform : public Command {
STR_HELP("Display audio as a linear amplitude graph.") STR_HELP("Display audio as a linear amplitude graph.")
CMD_TYPE(COMMAND_RADIO) CMD_TYPE(COMMAND_RADIO)
bool IsActive(const agi::Context *c) {
return !OPT_GET("Audio/Spectrum")->GetBool();
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
OPT_SET("Audio/Spectrum")->SetBool(false); OPT_SET("Audio/Spectrum")->SetBool(false);
} }
@ -338,6 +346,10 @@ struct audio_autoscroll : public Command {
STR_HELP("Auto scrolls audio display to selected line") STR_HELP("Auto scrolls audio display to selected line")
CMD_TYPE(COMMAND_TOGGLE) CMD_TYPE(COMMAND_TOGGLE)
bool IsActive(const agi::Context *c) {
return OPT_GET("Audio/Auto/Scroll")->GetBool();
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
toggle("Audio/Auto/Scroll"); toggle("Audio/Auto/Scroll");
} }
@ -351,6 +363,10 @@ struct audio_autocommit : public Command {
STR_HELP("Automatically commit all changes") STR_HELP("Automatically commit all changes")
CMD_TYPE(COMMAND_TOGGLE) CMD_TYPE(COMMAND_TOGGLE)
bool IsActive(const agi::Context *c) {
return OPT_GET("Audio/Auto/Commit")->GetBool();
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
toggle("Audio/Auto/Commit"); toggle("Audio/Auto/Commit");
} }
@ -364,6 +380,10 @@ struct audio_autonext : public Command {
STR_HELP("Auto goes to next line on commit") STR_HELP("Auto goes to next line on commit")
CMD_TYPE(COMMAND_TOGGLE) CMD_TYPE(COMMAND_TOGGLE)
bool IsActive(const agi::Context *c) {
return OPT_GET("Audio/Next Line on Commit")->GetBool();
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
toggle("Audio/Next Line on Commit"); toggle("Audio/Next Line on Commit");
} }
@ -377,6 +397,10 @@ struct audio_vertical_link : public Command {
STR_HELP("Link vertical zoom and volume sliders") STR_HELP("Link vertical zoom and volume sliders")
CMD_TYPE(COMMAND_TOGGLE) CMD_TYPE(COMMAND_TOGGLE)
bool IsActive(const agi::Context *c) {
return OPT_GET("Audio/Link")->GetBool();
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
toggle("Audio/Link"); toggle("Audio/Link");
} }

View file

@ -109,8 +109,20 @@ namespace cmd {
/// ///
/// Note that it is still legal to call commands when this returns /// Note that it is still legal to call commands when this returns
/// false. In this situation, commands should do nothing. /// false. In this situation, commands should do nothing.
///
/// This function should be overridden iff the command's type flags
/// include COMMAND_VALIDATE
virtual bool Validate(const agi::Context *c) { return true; } virtual bool Validate(const agi::Context *c) { return true; }
/// 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; }
/// Destructor /// Destructor
virtual ~Command() { }; virtual ~Command() { };
}; };

View file

@ -113,6 +113,10 @@ struct grid_tags_hide : public Command {
STR_HELP("Hide override tags in the subtitle grid.") STR_HELP("Hide override tags in the subtitle grid.")
CMD_TYPE(COMMAND_RADIO) CMD_TYPE(COMMAND_RADIO)
bool IsActive(const agi::Context *c) {
return OPT_GET("Subtitle/Grid/Hide Overrides")->GetInt() == 2;
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
OPT_SET("Subtitle/Grid/Hide Overrides")->SetInt(2); OPT_SET("Subtitle/Grid/Hide Overrides")->SetInt(2);
} }
@ -127,6 +131,10 @@ struct grid_tags_show : public Command {
STR_HELP("Show full override tags in the subtitle grid.") STR_HELP("Show full override tags in the subtitle grid.")
CMD_TYPE(COMMAND_RADIO) CMD_TYPE(COMMAND_RADIO)
bool IsActive(const agi::Context *c) {
return OPT_GET("Subtitle/Grid/Hide Overrides")->GetInt() == 0;
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
OPT_SET("Subtitle/Grid/Hide Overrides")->SetInt(0); OPT_SET("Subtitle/Grid/Hide Overrides")->SetInt(0);
} }
@ -141,6 +149,10 @@ struct grid_tags_simplify : public Command {
STR_HELP("Replace override tags in the subtitle grid with a simplified placeholder.") STR_HELP("Replace override tags in the subtitle grid with a simplified placeholder.")
CMD_TYPE(COMMAND_RADIO) CMD_TYPE(COMMAND_RADIO)
bool IsActive(const agi::Context *c) {
return OPT_GET("Subtitle/Grid/Hide Overrides")->GetInt() == 1;
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
OPT_SET("Subtitle/Grid/Hide Overrides")->SetInt(1); OPT_SET("Subtitle/Grid/Hide Overrides")->SetInt(1);
} }

View file

@ -85,6 +85,10 @@ struct video_aspect_cinematic : public validator_video_attached {
STR_HELP("Forces video to 2.35 aspect ratio.") STR_HELP("Forces video to 2.35 aspect ratio.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO) CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
bool IsActive(const agi::Context *c) {
return c->videoController->GetAspectRatioType() == 3;
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
c->videoController->Stop(); c->videoController->Stop();
c->videoController->SetAspectRatio(3); c->videoController->SetAspectRatio(3);
@ -100,6 +104,10 @@ struct video_aspect_custom : public validator_video_attached {
STR_HELP("Forces video to a custom aspect ratio.") STR_HELP("Forces video to a custom aspect ratio.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO) CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
bool IsActive(const agi::Context *c) {
return c->videoController->GetAspectRatioType() == 4;
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
c->videoController->Stop(); c->videoController->Stop();
@ -156,6 +164,10 @@ struct video_aspect_default : public validator_video_attached {
STR_HELP("Leave video on original aspect ratio.") STR_HELP("Leave video on original aspect ratio.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO) CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
bool IsActive(const agi::Context *c) {
return c->videoController->GetAspectRatioType() == 0;
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
c->videoController->Stop(); c->videoController->Stop();
c->videoController->SetAspectRatio(0); c->videoController->SetAspectRatio(0);
@ -171,6 +183,10 @@ struct video_aspect_full : public validator_video_attached {
STR_HELP("Forces video to 4:3 aspect ratio.") STR_HELP("Forces video to 4:3 aspect ratio.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO) CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
bool IsActive(const agi::Context *c) {
return c->videoController->GetAspectRatioType() == 1;
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
c->videoController->Stop(); c->videoController->Stop();
c->videoController->SetAspectRatio(1); c->videoController->SetAspectRatio(1);
@ -186,6 +202,10 @@ struct video_aspect_wide : public validator_video_attached {
STR_HELP("Forces video to 16:9 aspect ratio.") STR_HELP("Forces video to 16:9 aspect ratio.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO) CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
bool IsActive(const agi::Context *c) {
return c->videoController->GetAspectRatioType() == 2;
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
c->videoController->Stop(); c->videoController->Stop();
c->videoController->SetAspectRatio(2); c->videoController->SetAspectRatio(2);
@ -213,6 +233,10 @@ struct video_detach : public validator_video_loaded {
STR_HELP("Detach video, displaying it in a separate Window.") STR_HELP("Detach video, displaying it in a separate Window.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_TOGGLE) CMD_TYPE(COMMAND_VALIDATE | COMMAND_TOGGLE)
bool IsActive(const agi::Context *c) {
return !!c->detachedVideo;
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
wxGetApp().frame->DetachVideo(!c->detachedVideo); wxGetApp().frame->DetachVideo(!c->detachedVideo);
} }
@ -479,6 +503,10 @@ struct video_opt_autoscroll : public Command {
STR_HELP("Toggle autoscroll of video") STR_HELP("Toggle autoscroll of video")
CMD_TYPE(COMMAND_TOGGLE) CMD_TYPE(COMMAND_TOGGLE)
bool IsActive(const agi::Context *c) {
return OPT_GET("Video/Subtitle Sync")->GetBool();
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
OPT_SET("Video/Subtitle Sync")->SetBool(!OPT_GET("Video/Subtitle Sync")->GetBool()); OPT_SET("Video/Subtitle Sync")->SetBool(!OPT_GET("Video/Subtitle Sync")->GetBool());
} }
@ -516,6 +544,10 @@ struct video_show_overscan : public validator_video_loaded {
STR_HELP("Show a mask over the video, indicating areas that might get cropped off by overscan on televisions.") 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) CMD_TYPE(COMMAND_VALIDATE | COMMAND_TOGGLE)
bool IsActive(const agi::Context *c) {
return OPT_GET("Video/Overscan Mask")->GetBool();
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
OPT_SET("Video/Overscan Mask")->SetBool(!OPT_GET("Video/Overscan Mask")->GetBool()); OPT_SET("Video/Overscan Mask")->SetBool(!OPT_GET("Video/Overscan Mask")->GetBool());
c->videoBox->videoDisplay->Render(); c->videoBox->videoDisplay->Render();
@ -531,6 +563,10 @@ public:
STR_HELP("Set zoom to 100%.") STR_HELP("Set zoom to 100%.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO) CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
bool IsActive(const agi::Context *c) {
return c->videoBox->videoDisplay->GetZoom() == 1.;
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
c->videoController->Stop(); c->videoController->Stop();
c->videoBox->videoDisplay->SetZoom(1.); c->videoBox->videoDisplay->SetZoom(1.);
@ -559,6 +595,10 @@ public:
STR_HELP("Set zoom to 200%.") STR_HELP("Set zoom to 200%.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO) CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
bool IsActive(const agi::Context *c) {
return c->videoBox->videoDisplay->GetZoom() == 2.;
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
c->videoController->Stop(); c->videoController->Stop();
c->videoBox->videoDisplay->SetZoom(2.); c->videoBox->videoDisplay->SetZoom(2.);
@ -574,6 +614,10 @@ public:
STR_HELP("Set zoom to 50%.") STR_HELP("Set zoom to 50%.")
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO) CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
bool IsActive(const agi::Context *c) {
return c->videoBox->videoDisplay->GetZoom() == .5;
}
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
c->videoController->Stop(); c->videoController->Stop();
c->videoBox->videoDisplay->SetZoom(.5); c->videoBox->videoDisplay->SetZoom(.5);