#include "wx_util.h"
#include "video_panel.h"
#include "audio_panel.h"
-#include "subtitle_panel.h"
+#include "text_panel.h"
#include "timing_panel.h"
#include "timeline_dialog.h"
#include "image_sequence_dialog.h"
#include "lib/config.h"
#include "lib/log.h"
#include "lib/compose.hpp"
-#include "lib/plain_text_content.h"
-#include "lib/plain_text.h"
+#include "lib/string_text_file_content.h"
+#include "lib/string_text_file.h"
#include <wx/wx.h>
#include <wx/notebook.h>
#include <wx/listctrl.h>
using std::string;
using std::cout;
using std::vector;
+using std::max;
using std::exception;
using boost::shared_ptr;
using boost::weak_ptr;
ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr<Film> film, FilmViewer* viewer)
: _timeline_dialog (0)
, _parent (n)
+ , _last_selected_tab (0)
, _film (film)
, _film_viewer (viewer)
, _generally_sensitive (true)
_panels.push_back (_video_panel);
_audio_panel = new AudioPanel (this);
_panels.push_back (_audio_panel);
- _subtitle_panel = new SubtitlePanel (this);
- _panels.push_back (_subtitle_panel);
+ for (int i = 0; i < TEXT_COUNT; ++i) {
+ _text_panel[i] = new TextPanel (this, static_cast<TextType>(i));
+ _panels.push_back (_text_panel[i]);
+ }
_timing_panel = new TimingPanel (this, _film_viewer);
_panels.push_back (_timing_panel);
+ _notebook->AddPage (_timing_panel, _("Timing"), false);
_content->Bind (wxEVT_LIST_ITEM_SELECTED, boost::bind (&ContentPanel::selection_changed, this));
_content->Bind (wxEVT_LIST_ITEM_DESELECTED, boost::bind (&ContentPanel::selection_changed, this));
}
ContentList
-ContentPanel::selected_subtitle ()
+ContentPanel::selected_text ()
{
ContentList sc;
BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
- if (i->subtitle) {
+ if (!i->text.empty()) {
sc.push_back (i);
}
}
}
optional<DCPTime> go_to;
- BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
+ BOOST_FOREACH (shared_ptr<Content> i, selected()) {
DCPTime p;
p = i->position();
- if (dynamic_pointer_cast<PlainText>(i) && i->paths_valid()) {
+ if (dynamic_pointer_cast<StringTextFileContent>(i) && i->paths_valid()) {
/* Rather special case; if we select a text subtitle file jump to its
first subtitle.
*/
- TextSubtitle ts (dynamic_pointer_cast<PlainText>(i));
+ StringTextFile ts (dynamic_pointer_cast<StringTextFileContent>(i));
if (ts.first()) {
p += DCPTime(ts.first().get(), _film->active_frame_rate_change(i->position()));
}
}
}
- if (go_to && Config::instance()->jump_to_selected ()) {
- _film_viewer->set_position (go_to.get().ceil(_film->video_frame_rate()));
+ if (go_to && Config::instance()->jump_to_selected() && signal_manager) {
+ signal_manager->when_idle(boost::bind(&FilmViewer::set_position, _film_viewer, go_to.get().ceil(_film->video_frame_rate())));
}
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_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;
+ }
+ }
+
+ bool video_panel = false;
+ bool audio_panel = false;
+ bool text_panel[TEXT_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 < TEXT_COUNT; ++j) {
+ if (_notebook->GetPage(i) == _text_panel[j]) {
+ text_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 < TEXT_COUNT; ++i) {
+ if (have_text[i] != text_panel[i]) {
+ if (text_panel[i]) {
+ _notebook->RemovePage (off);
+ }
+ if (have_text[i]) {
+ _notebook->InsertPage (off, _text_panel[i], _text_panel[i]->name());
+ }
+ }
+ 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);
}
SelectionChanged ();
_video_panel->Enable (_generally_sensitive && video_selection.size() > 0);
_audio_panel->Enable (_generally_sensitive && audio_selection.size() > 0);
- _subtitle_panel->Enable (_generally_sensitive && selection.size() == 1 && selection.front()->subtitle);
+ for (int i = 0; i < TEXT_COUNT; ++i) {
+ _text_panel[i]->Enable (_generally_sensitive && selection.size() == 1 && !selection.front()->text.empty());
+ }
_timing_panel->Enable (_generally_sensitive);
}