Use agi::Context::Validate for the main frame's menus and toolbar

Originally committed to SVN as r5461.
This commit is contained in:
Thomas Goyne 2011-07-15 04:05:37 +00:00
parent ef4bfb1535
commit fdb6d108f8
1 changed files with 47 additions and 83 deletions

View File

@ -346,28 +346,29 @@ void FrameMain::DeInitContents() {
HelpButton::ClearPages(); HelpButton::ClearPages();
} }
static void validate_toolbar(wxToolBar *toolbar, const char *command, const agi::Context *context) {
toolbar->FindById(cmd::id(command))->Enable(cmd::get(command)->Validate(context));
}
/// @brief Update toolbar /// @brief Update toolbar
void FrameMain::UpdateToolbar() { void FrameMain::UpdateToolbar() {
// Collect flags
bool isVideo = context->videoController->IsLoaded();
int selRows = SubsGrid->GetNumberSelection();
// Update
wxToolBar* toolbar = GetToolBar(); wxToolBar* toolbar = GetToolBar();
toolbar->FindById(cmd::id("video/jump"))->Enable(isVideo); const agi::Context *c = context.get();
toolbar->FindById(cmd::id("video/zoom/in"))->Enable(isVideo && !context->detachedVideo); ZoomBox->Enable(context->videoController->IsLoaded() && !context->detachedVideo);
toolbar->FindById(cmd::id("video/zoom/out"))->Enable(isVideo && !context->detachedVideo);
ZoomBox->Enable(isVideo && !context->detachedVideo);
toolbar->FindById(cmd::id("video/jump/start"))->Enable(isVideo && selRows > 0); validate_toolbar(toolbar, "video/jump", c);
toolbar->FindById(cmd::id("video/jump/end"))->Enable(isVideo && selRows > 0); validate_toolbar(toolbar, "video/zoom/in", c);
validate_toolbar(toolbar, "video/zoom/out", c);
toolbar->FindById(cmd::id("time/snap/start_video"))->Enable(isVideo && selRows == 1); validate_toolbar(toolbar, "video/jump/start", c);
toolbar->FindById(cmd::id("time/snap/end_video"))->Enable(isVideo && selRows == 1); validate_toolbar(toolbar, "video/jump/end", c);
toolbar->FindById(cmd::id("subtitle/select/visible"))->Enable(isVideo); validate_toolbar(toolbar, "time/snap/start_video", c);
toolbar->FindById(cmd::id("time/snap/scene"))->Enable(isVideo && selRows > 0); validate_toolbar(toolbar, "time/snap/end_video", c);
toolbar->FindById(cmd::id("time/snap/frame"))->Enable(isVideo && selRows > 0);
validate_toolbar(toolbar, "subtitle/select/visible", c);
validate_toolbar(toolbar, "time/snap/scene", c);
validate_toolbar(toolbar, "time/snap/frame", c);
toolbar->Realize(); toolbar->Realize();
} }
@ -745,6 +746,10 @@ void FrameMain::RebuildRecentList(const char *root_command, const char *mru_name
} }
} }
static void validate(wxMenuBar *menu, const agi::Context *c, const char *command) {
menu->Enable(cmd::id(command), cmd::get(command)->Validate(c));
}
/// @brief Menu is being opened /// @brief Menu is being opened
/// @param event /// @param event
void FrameMain::OnMenuOpen (wxMenuEvent &event) { void FrameMain::OnMenuOpen (wxMenuEvent &event) {
@ -756,10 +761,8 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
// File menu // File menu
if (curMenu == menu::menu->GetMenu("main/file")) { if (curMenu == menu::menu->GetMenu("main/file")) {
// Rebuild recent
RebuildRecentList("recent/subtitle", "Subtitle"); RebuildRecentList("recent/subtitle", "Subtitle");
validate(MenuBar, context.get(), "subtitle/open/video");
MenuBar->Enable(cmd::id("subtitle/open/video"),context->videoController->HasSubtitles());
} }
// View menu // View menu
@ -777,11 +780,10 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
} }
// Video menu // Video menu
else if (curMenu == menu::menu->GetMenu("main/video")) { else if (curMenu == menu::menu->GetMenu("main/video")) {
// Set states validate(MenuBar, context.get(), "timecode/save");
MenuBar->Enable(cmd::id("timecode/save"),context->videoController->TimecodesLoaded()); validate(MenuBar, context.get(), "timecode/close");
MenuBar->Enable(cmd::id("timecode/close"),context->videoController->OverTimecodesLoaded()); validate(MenuBar, context.get(), "keyframe/close");
MenuBar->Enable(cmd::id("keyframe/close"),context->videoController->OverKeyFramesLoaded()); validate(MenuBar, context.get(), "keyframe/save");
MenuBar->Enable(cmd::id("keyframe/save"),context->videoController->KeyFramesLoaded());
// Set AR radio // Set AR radio
int arType = context->videoController->GetAspectRatioType(); int arType = context->videoController->GetAspectRatioType();
@ -809,61 +811,33 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
// Audio menu // Audio menu
else if (curMenu == menu::menu->GetMenu("main/audio")) { else if (curMenu == menu::menu->GetMenu("main/audio")) {
bool state = context->audioController->IsAudioOpen(); validate(MenuBar, context.get(), "audio/open/video");
bool vidstate = context->videoController->IsLoaded(); validate(MenuBar, context.get(), "audio/close");
MenuBar->Enable(cmd::id("audio/open/video"),vidstate);
MenuBar->Enable(cmd::id("audio/close"),state);
// Rebuild recent
RebuildRecentList("recent/audio", "Audio"); RebuildRecentList("recent/audio", "Audio");
} }
// Subtitles menu // Subtitles menu
else if (curMenu == menu::menu->GetMenu("main/subtitle")) { else if (curMenu == menu::menu->GetMenu("main/subtitle")) {
// Variables validate(MenuBar, context.get(), "main/subtitle/insert lines");
bool continuous; validate(MenuBar, context.get(), "edit/line/duplicate");
wxArrayInt sels = SubsGrid->GetSelection(&continuous); validate(MenuBar, context.get(), "edit/line/duplicate/shift");
int count = sels.Count(); validate(MenuBar, context.get(), "edit/line/swap");
bool state,state2; validate(MenuBar, context.get(), "edit/line/join/concatenate");
validate(MenuBar, context.get(), "edit/line/join/keep_first");
// Entries validate(MenuBar, context.get(), "edit/line/join/as_karaoke");
state = count > 0; validate(MenuBar, context.get(), "main/subtitle/join lines");
state2 = count > 0 && context->videoController->IsLoaded(); validate(MenuBar, context.get(), "edit/line/recombine");
MenuBar->Enable(cmd::id("main/subtitle/insert lines"),state);
state = count > 0 && continuous;
MenuBar->Enable(cmd::id("edit/line/duplicate"),state);
state = count > 0 && continuous && context->videoController->TimecodesLoaded();
MenuBar->Enable(cmd::id("edit/line/duplicate/shift"),state);
state = count == 2;
MenuBar->Enable(cmd::id("edit/line/swap"),state);
state = count >= 2 && continuous;
MenuBar->Enable(cmd::id("edit/line/join/concatenate"),state);
MenuBar->Enable(cmd::id("edit/line/join/keep_first"),state);
MenuBar->Enable(cmd::id("edit/line/join/as_karaoke"),state);
MenuBar->Enable(cmd::id("main/subtitle/join lines"),state);
state = (count == 2 || count == 3) && continuous;
MenuBar->Enable(cmd::id("edit/line/recombine"),state);
} }
// Timing menu // Timing menu
else if (curMenu == menu::menu->GetMenu("main/timing")) { else if (curMenu == menu::menu->GetMenu("main/timing")) {
// Variables validate(MenuBar, context.get(), "time/snap/start_video");
bool continuous; validate(MenuBar, context.get(), "time/snap/end_video");
wxArrayInt sels = SubsGrid->GetSelection(&continuous); validate(MenuBar, context.get(), "time/snap/scene");
int count = sels.Count(); validate(MenuBar, context.get(), "time/frame/current");
// Video related validate(MenuBar, context.get(), "time/continuous/start");
bool state = context->videoController->IsLoaded(); validate(MenuBar, context.get(), "time/continuous/end");
MenuBar->Enable(cmd::id("time/snap/start_video"),state);
MenuBar->Enable(cmd::id("time/snap/end_video"),state);
MenuBar->Enable(cmd::id("time/snap/scene"),state);
MenuBar->Enable(cmd::id("time/frame/current"),state);
// Other
state = count >= 2 && continuous;
MenuBar->Enable(cmd::id("time/continuous/start"),state);
MenuBar->Enable(cmd::id("time/continuous/end"),state);
} }
// Edit menu // Edit menu
@ -888,20 +862,10 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
item->SetItemLabel(redo_text); item->SetItemLabel(redo_text);
item->Enable(!context->ass->IsRedoStackEmpty()); item->Enable(!context->ass->IsRedoStackEmpty());
// Copy/cut/paste validate(MenuBar, context.get(), "edit/line/cut");
wxArrayInt sels = SubsGrid->GetSelection(); validate(MenuBar, context.get(), "edit/line/copy");
bool can_copy = (sels.Count() > 0); validate(MenuBar, context.get(), "edit/line/paste");
validate(MenuBar, context.get(), "edit/line/paste/over");
bool can_paste = true;
if (wxTheClipboard->Open()) {
can_paste = wxTheClipboard->IsSupported(wxDF_TEXT);
wxTheClipboard->Close();
}
MenuBar->Enable(cmd::id("edit/line/cut"),can_copy);
MenuBar->Enable(cmd::id("edit/line/copy"),can_copy);
MenuBar->Enable(cmd::id("edit/line/paste"),can_paste);
MenuBar->Enable(cmd::id("edit/line/paste/over"),can_copy&&can_paste);
} }
// Automation menu // Automation menu