use agi::Context::Validate for subsgrid context menu item validation

Originally committed to SVN as r5460.
This commit is contained in:
Thomas Goyne 2011-07-15 04:05:31 +00:00
parent f098e2fac8
commit ef4bfb1535
2 changed files with 40 additions and 52 deletions

View file

@ -175,6 +175,10 @@ struct audio_save_clip : public Command {
STR_DISP("Create audio clip")
STR_HELP("Create an audio clip of the selected line")
bool Validate(const agi::Context *c) {
return c->audioController->IsAudioOpen() && !c->selectionController->GetSelectedSet().empty();
}
void operator()(agi::Context *c) {
Selection sel = c->selectionController->GetSelectedSet();
for (Selection::iterator it = sel.begin(); it != sel.end(); ++it) {

View file

@ -133,9 +133,9 @@ void SubtitlesGrid::OnCommand(wxCommandEvent& event) {
event.Skip();
}
static inline void append_command(wxMenu &menu, const char *name, bool state) {
static inline void append_command(wxMenu &menu, const char *name, const agi::Context *context) {
cmd::Command *c = cmd::get(name);
menu.Append(cmd::id(name), c->StrMenu(), c->StrHelp())->Enable(state);
menu.Append(cmd::id(name), c->StrMenu(), c->StrHelp())->Enable(c->Validate(context));
}
/// @brief Popup menu
@ -166,67 +166,51 @@ void SubtitlesGrid::OnPopupMenu(bool alternate) {
return;
}
// Get selections
bool continuous;
wxArrayInt selections = GetSelection(&continuous);
int sels = selections.Count();
// Show menu if at least one is selected
if (sels > 0) {
wxMenu menu;
bool state;
// Insert
state = (sels == 1);
append_command(menu, "subtitle/insert/before", state);
append_command(menu, "subtitle/insert/after", state);
state = (sels == 1 && context->videoController->IsLoaded());
append_command(menu, "subtitle/insert/before/videotime", state);
append_command(menu, "subtitle/insert/after/videotime", state);
append_command(menu, "subtitle/insert/before", context);
append_command(menu, "subtitle/insert/after", context);
append_command(menu, "subtitle/insert/before/videotime", context);
append_command(menu, "subtitle/insert/after/videotime", context);
menu.AppendSeparator();
// Duplicate selection
append_command(menu, "edit/line/duplicate", state);
append_command(menu, "edit/line/duplicate/shift", state);
append_command(menu, "edit/line/duplicate", context);
append_command(menu, "edit/line/duplicate/shift", context);
// Swaps selection
state = (sels == 2);
append_command(menu, "edit/line/swap", state);
append_command(menu, "edit/line/swap", context);
// Join selection
state = (sels >= 2 && continuous);
append_command(menu, "edit/line/join/concatenate", state);
append_command(menu, "edit/line/join/keep_first", state);
append_command(menu, "edit/line/join/as_karaoke", state);
append_command(menu, "edit/line/join/concatenate", context);
append_command(menu, "edit/line/join/keep_first", context);
append_command(menu, "edit/line/join/as_karaoke", context);
menu.AppendSeparator();
// Adjoin selection
state = (sels >= 1 && continuous);
append_command(menu, "time/continuous/start", state);
append_command(menu, "time/continuous/end", state);
append_command(menu, "time/continuous/start", context);
append_command(menu, "time/continuous/end", context);
// Recombine selection
state = (sels > 1);
append_command(menu, "edit/line/recombine", state);
append_command(menu, "edit/line/recombine", context);
menu.AppendSeparator();
//Make audio clip
state = context->audioController->IsAudioOpen();
append_command(menu, "audio/save/clip", state);
append_command(menu, "audio/save/clip", context);
menu.AppendSeparator();
// Copy/cut/paste
append_command(menu, "edit/line/copy", true);
append_command(menu, "edit/line/cut", true);
append_command(menu, "edit/line/paste", true);
append_command(menu, "edit/line/copy", context);
append_command(menu, "edit/line/cut", context);
append_command(menu, "edit/line/paste", context);
menu.AppendSeparator();
// Delete
append_command(menu, "edit/line/delete", true);
append_command(menu, "edit/line/delete", context);
PopupMenu(&menu);
}
}
/// @brief Process a show/hide column event