mirror of https://github.com/odrling/Aegisub
use agi::Context::Validate for subsgrid context menu item validation
Originally committed to SVN as r5460.
This commit is contained in:
parent
f098e2fac8
commit
ef4bfb1535
|
@ -175,6 +175,10 @@ struct audio_save_clip : public Command {
|
||||||
STR_DISP("Create audio clip")
|
STR_DISP("Create audio clip")
|
||||||
STR_HELP("Create an audio clip of the selected line")
|
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) {
|
void operator()(agi::Context *c) {
|
||||||
Selection sel = c->selectionController->GetSelectedSet();
|
Selection sel = c->selectionController->GetSelectedSet();
|
||||||
for (Selection::iterator it = sel.begin(); it != sel.end(); ++it) {
|
for (Selection::iterator it = sel.begin(); it != sel.end(); ++it) {
|
||||||
|
|
|
@ -133,9 +133,9 @@ void SubtitlesGrid::OnCommand(wxCommandEvent& event) {
|
||||||
event.Skip();
|
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);
|
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
|
/// @brief Popup menu
|
||||||
|
@ -166,68 +166,52 @@ void SubtitlesGrid::OnPopupMenu(bool alternate) {
|
||||||
return;
|
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;
|
wxMenu menu;
|
||||||
bool state;
|
|
||||||
|
|
||||||
// Insert
|
// Insert
|
||||||
state = (sels == 1);
|
append_command(menu, "subtitle/insert/before", context);
|
||||||
append_command(menu, "subtitle/insert/before", state);
|
append_command(menu, "subtitle/insert/after", context);
|
||||||
append_command(menu, "subtitle/insert/after", state);
|
append_command(menu, "subtitle/insert/before/videotime", context);
|
||||||
state = (sels == 1 && context->videoController->IsLoaded());
|
append_command(menu, "subtitle/insert/after/videotime", context);
|
||||||
append_command(menu, "subtitle/insert/before/videotime", state);
|
|
||||||
append_command(menu, "subtitle/insert/after/videotime", state);
|
|
||||||
menu.AppendSeparator();
|
menu.AppendSeparator();
|
||||||
|
|
||||||
// Duplicate selection
|
// Duplicate selection
|
||||||
append_command(menu, "edit/line/duplicate", state);
|
append_command(menu, "edit/line/duplicate", context);
|
||||||
append_command(menu, "edit/line/duplicate/shift", state);
|
append_command(menu, "edit/line/duplicate/shift", context);
|
||||||
|
|
||||||
// Swaps selection
|
// Swaps selection
|
||||||
state = (sels == 2);
|
append_command(menu, "edit/line/swap", context);
|
||||||
append_command(menu, "edit/line/swap", state);
|
|
||||||
|
|
||||||
// Join selection
|
// Join selection
|
||||||
state = (sels >= 2 && continuous);
|
append_command(menu, "edit/line/join/concatenate", context);
|
||||||
append_command(menu, "edit/line/join/concatenate", state);
|
append_command(menu, "edit/line/join/keep_first", context);
|
||||||
append_command(menu, "edit/line/join/keep_first", state);
|
append_command(menu, "edit/line/join/as_karaoke", context);
|
||||||
append_command(menu, "edit/line/join/as_karaoke", state);
|
|
||||||
menu.AppendSeparator();
|
menu.AppendSeparator();
|
||||||
|
|
||||||
// Adjoin selection
|
// Adjoin selection
|
||||||
state = (sels >= 1 && continuous);
|
append_command(menu, "time/continuous/start", context);
|
||||||
append_command(menu, "time/continuous/start", state);
|
append_command(menu, "time/continuous/end", context);
|
||||||
append_command(menu, "time/continuous/end", state);
|
|
||||||
|
|
||||||
// Recombine selection
|
// Recombine selection
|
||||||
state = (sels > 1);
|
append_command(menu, "edit/line/recombine", context);
|
||||||
append_command(menu, "edit/line/recombine", state);
|
|
||||||
menu.AppendSeparator();
|
menu.AppendSeparator();
|
||||||
|
|
||||||
//Make audio clip
|
//Make audio clip
|
||||||
state = context->audioController->IsAudioOpen();
|
append_command(menu, "audio/save/clip", context);
|
||||||
append_command(menu, "audio/save/clip", state);
|
|
||||||
menu.AppendSeparator();
|
menu.AppendSeparator();
|
||||||
|
|
||||||
|
|
||||||
// Copy/cut/paste
|
// Copy/cut/paste
|
||||||
append_command(menu, "edit/line/copy", true);
|
append_command(menu, "edit/line/copy", context);
|
||||||
append_command(menu, "edit/line/cut", true);
|
append_command(menu, "edit/line/cut", context);
|
||||||
append_command(menu, "edit/line/paste", true);
|
append_command(menu, "edit/line/paste", context);
|
||||||
menu.AppendSeparator();
|
menu.AppendSeparator();
|
||||||
|
|
||||||
// Delete
|
// Delete
|
||||||
append_command(menu, "edit/line/delete", true);
|
append_command(menu, "edit/line/delete", context);
|
||||||
|
|
||||||
PopupMenu(&menu);
|
PopupMenu(&menu);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief Process a show/hide column event
|
/// @brief Process a show/hide column event
|
||||||
/// @param event
|
/// @param event
|
||||||
|
|
Loading…
Reference in New Issue