PlainText -> PlainTextFile.
[dcpomatic.git] / src / wx / content_panel.cc
index 843f392809d45e68f3aca113a7d3250f57f920e6..70364106cae7aabb22e8eb589569f3bec516d3a8 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -28,7 +28,7 @@
 #include "image_sequence_dialog.h"
 #include "film_viewer.h"
 #include "lib/audio_content.h"
-#include "lib/subtitle_content.h"
+#include "lib/text_content.h"
 #include "lib/video_content.h"
 #include "lib/ffmpeg_content.h"
 #include "lib/content_factory.h"
@@ -39,6 +39,8 @@
 #include "lib/config.h"
 #include "lib/log.h"
 #include "lib/compose.hpp"
+#include "lib/plain_text_file_content.h"
+#include "lib/plain_text_file.h"
 #include <wx/wx.h>
 #include <wx/notebook.h>
 #include <wx/listctrl.h>
@@ -254,18 +256,31 @@ ContentPanel::selection_changed ()
 
        optional<DCPTime> go_to;
        BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
-               if (!go_to || i->position() < go_to.get()) {
-                       go_to = i->position ();
+               DCPTime p;
+               p = i->position();
+               if (dynamic_pointer_cast<PlainTextFileContent>(i) && i->paths_valid()) {
+                       /* Rather special case; if we select a text subtitle file jump to its
+                          first subtitle.
+                       */
+                       PlainTextFile ts (dynamic_pointer_cast<PlainTextFileContent>(i));
+                       if (ts.first()) {
+                               p += DCPTime(ts.first().get(), _film->active_frame_rate_change(i->position()));
+                       }
+               }
+               if (!go_to || p < go_to.get()) {
+                       go_to = p;
                }
        }
 
        if (go_to && Config::instance()->jump_to_selected ()) {
-               _film_viewer->set_position (go_to.get ());
+               _film_viewer->set_position (go_to.get().ceil(_film->video_frame_rate()));
        }
 
        if (_timeline_dialog) {
                _timeline_dialog->set_selection (selected ());
        }
+
+       SelectionChanged ();
 }
 
 void
@@ -394,6 +409,10 @@ ContentPanel::remove_clicked (bool hotkey)
 void
 ContentPanel::timeline_clicked ()
 {
+       if (!_film) {
+               return;
+       }
+
        if (_timeline_dialog) {
                _timeline_dialog->Destroy ();
                _timeline_dialog = 0;