+
+ /* 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_text[TEXT_COUNT] = { false, false };
+ BOOST_FOREACH (shared_ptr<Content> i, selected()) {
+ if (i->video) {
+ have_video = true;
+ }
+ if (i->audio) {
+ have_audio = true;
+ }
+ BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
+ have_text[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());
+ } 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());
+ } else if (!have_audio && _audio_panel) {
+ _notebook->DeletePage (off);
+ _audio_panel = 0;
+ }
+
+ if (have_audio) {
+ ++off;
+ }
+
+ for (int i = 0; i < TEXT_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());
+ } else if (!have_text[i] && _text_panel[i]) {
+ _notebook->DeletePage (off);
+ _text_panel[i] = 0;
+ }
+ if (have_text[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->GetPageCount() > 0) {
+ _notebook->SetSelection (0);
+ }
+
+ setup_sensitivity ();
+ SelectionChanged ();