+ _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;
+ EnumIndexedVector<bool, TextType> have_text;
+ for (auto i: selected()) {
+ if (i->video) {
+ have_video = true;
+ }
+ if (i->audio) {
+ have_audio = true;
+ }
+ for (auto j: i->text) {
+ have_text[static_cast<int>(j->original_type())] = true;
+ }
+ }
+
+ int off = 0;
+
+ if (have_video && !_video_panel) {
+ _video_panel = new VideoPanel (this);
+ _notebook->InsertPage (off, _video_panel, _video_panel->name());
+ _video_panel->create ();
+ } else if (!have_video && _video_panel) {
+ _notebook->DeletePage (off);
+ _video_panel = 0;
+ }
+
+ if (have_video) {
+ ++off;
+ }
+
+ if (have_audio && !_audio_panel) {
+ _audio_panel = new AudioPanel (this);
+ _notebook->InsertPage (off, _audio_panel, _audio_panel->name());
+ _audio_panel->create ();
+ } else if (!have_audio && _audio_panel) {
+ _notebook->DeletePage (off);
+ _audio_panel = 0;
+ }
+
+ if (have_audio) {
+ ++off;
+ }
+
+ for (int i = 0; i < static_cast<int>(TextType::COUNT); ++i) {
+ if (have_text[i] && !_text_panel[i]) {
+ _text_panel[i] = new TextPanel (this, static_cast<TextType>(i));
+ _notebook->InsertPage (off, _text_panel[i], _text_panel[i]->name());
+ _text_panel[i]->create ();
+ } else if (!have_text[i] && _text_panel[i]) {
+ _notebook->DeletePage (off);
+ _text_panel[i] = nullptr;
+ }
+ if (have_text[i]) {
+ ++off;
+ }
+ }
+
+ /* Set up the tab selection */
+
+ auto 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->GetPageCount() > 0) {
+ _notebook->SetSelection (0);