X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fcontent_panel.cc;h=a6338ecfd090f99b2f6def10683abadf16559817;hb=df17bbd25da69fc38eb2dcd8b4a2531cf0bab0bc;hp=3dc0e2b63e50e9788b0a44956e5d592c4cb69271;hpb=9cb73fbc0fa4643612f01665bc6d9fc430656f32;p=dcpomatic.git diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index 3dc0e2b63..a6338ecfd 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -22,7 +22,7 @@ #include "wx_util.h" #include "video_panel.h" #include "audio_panel.h" -#include "caption_panel.h" +#include "text_panel.h" #include "timing_panel.h" #include "timeline_dialog.h" #include "image_sequence_dialog.h" @@ -39,8 +39,8 @@ #include "lib/config.h" #include "lib/log.h" #include "lib/compose.hpp" -#include "lib/text_caption_file_content.h" -#include "lib/plain_text_file.h" +#include "lib/string_text_file_content.h" +#include "lib/string_text_file.h" #include #include #include @@ -52,6 +52,7 @@ using std::list; using std::string; using std::cout; using std::vector; +using std::max; using std::exception; using boost::shared_ptr; using boost::weak_ptr; @@ -63,6 +64,7 @@ using boost::optional; ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr film, FilmViewer* viewer) : _timeline_dialog (0) , _parent (n) + , _last_selected_tab (0) , _film (film) , _film_viewer (viewer) , _generally_sensitive (true) @@ -125,8 +127,10 @@ ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr film, FilmVie _panels.push_back (_video_panel); _audio_panel = new AudioPanel (this); _panels.push_back (_audio_panel); - _caption_panel = new CaptionPanel (this); - _panels.push_back (_caption_panel); + for (int i = 0; i < CAPTION_COUNT; ++i) { + _caption_panel[i] = new TextPanel (this, static_cast(i)); + _panels.push_back (_caption_panel[i]); + } _timing_panel = new TimingPanel (this, _film_viewer); _panels.push_back (_timing_panel); @@ -191,12 +195,12 @@ ContentPanel::selected_audio () } ContentList -ContentPanel::selected_subtitle () +ContentPanel::selected_caption () { ContentList sc; BOOST_FOREACH (shared_ptr i, selected ()) { - if (i->subtitle) { + if (!i->caption.empty()) { sc.push_back (i); } } @@ -255,14 +259,14 @@ ContentPanel::selection_changed () } optional go_to; - BOOST_FOREACH (shared_ptr i, selected ()) { + BOOST_FOREACH (shared_ptr i, selected()) { DCPTime p; p = i->position(); - if (dynamic_pointer_cast(i) && i->paths_valid()) { + if (dynamic_pointer_cast(i) && i->paths_valid()) { /* Rather special case; if we select a text subtitle file jump to its first subtitle. */ - TextCaptionFile ts (dynamic_pointer_cast(i)); + StringTextFile ts (dynamic_pointer_cast(i)); if (ts.first()) { p += DCPTime(ts.first().get(), _film->active_frame_rate_change(i->position())); } @@ -277,7 +281,106 @@ ContentPanel::selection_changed () } if (_timeline_dialog) { - _timeline_dialog->set_selection (selected ()); + _timeline_dialog->set_selection (selected()); + } + + /* Make required tabs visible */ + + if (_notebook->GetPageCount() > 1) { + /* There's more than one tab in the notebook so the current selection could be meaningful + to the user; store it so that we can try to restore it later. + */ + _last_selected_tab = 0; + if (_notebook->GetSelection() != wxNOT_FOUND) { + _last_selected_tab = _notebook->GetPage(_notebook->GetSelection()); + } + } + + bool have_video = false; + bool have_audio = false; + bool have_caption[CAPTION_COUNT] = { false, false }; + BOOST_FOREACH (shared_ptr i, selected()) { + if (i->video) { + have_video = true; + } + if (i->audio) { + have_audio = true; + } + BOOST_FOREACH (shared_ptr j, i->caption) { + have_caption[j->original_type()] = true; + } + } + + bool video_panel = false; + bool audio_panel = false; + bool caption_panel[CAPTION_COUNT] = { false, false }; + for (size_t i = 0; i < _notebook->GetPageCount(); ++i) { + if (_notebook->GetPage(i) == _video_panel) { + video_panel = true; + } else if (_notebook->GetPage(i) == _audio_panel) { + audio_panel = true; + } + for (int j = 0; j < CAPTION_COUNT; ++j) { + if (_notebook->GetPage(i) == _caption_panel[j]) { + caption_panel[j] = true; + } + } + } + + int off = 0; + + if (have_video != video_panel) { + if (video_panel) { + _notebook->RemovePage (off); + } + if (have_video) { + _notebook->InsertPage (off, _video_panel, _video_panel->name()); + } + } + + if (have_video) { + ++off; + } + + if (have_audio != audio_panel) { + if (audio_panel) { + _notebook->RemovePage (off); + } + if (have_audio) { + _notebook->InsertPage (off, _audio_panel, _audio_panel->name()); + } + } + + if (have_audio) { + ++off; + } + + for (int i = 0; i < CAPTION_COUNT; ++i) { + if (have_caption[i] != caption_panel[i]) { + if (caption_panel[i]) { + _notebook->RemovePage (off); + } + if (have_caption[i]) { + _notebook->InsertPage (off, _caption_panel[i], _caption_panel[i]->name()); + } + } + if (have_caption[i]) { + ++off; + } + } + + /* Set up the tab selection */ + + bool done = false; + for (size_t i = 0; i < _notebook->GetPageCount(); ++i) { + if (_notebook->GetPage(i) == _last_selected_tab) { + _notebook->SetSelection (i); + done = true; + } + } + + if (!done) { + _notebook->SetSelection (0); } SelectionChanged (); @@ -447,7 +550,9 @@ ContentPanel::setup_sensitivity () _video_panel->Enable (_generally_sensitive && video_selection.size() > 0); _audio_panel->Enable (_generally_sensitive && audio_selection.size() > 0); - _caption_panel->Enable (_generally_sensitive && selection.size() == 1 && selection.front()->subtitle); + for (int i = 0; i < CAPTION_COUNT; ++i) { + _caption_panel[i]->Enable (_generally_sensitive && selection.size() == 1 && !selection.front()->caption.empty()); + } _timing_panel->Enable (_generally_sensitive); }