When doing jump-to-selected jump to the first subtitle in TextSubtitleContent (#1160).
authorCarl Hetherington <cth@carlh.net>
Mon, 8 Jan 2018 23:54:10 +0000 (23:54 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 8 Jan 2018 23:54:10 +0000 (23:54 +0000)
ChangeLog
src/lib/text_subtitle.cc
src/lib/text_subtitle.h
src/wx/content_panel.cc

index 3c7e25e910b7fba18d245f60ad672b858632f3ff..486d70c575e447197766bd89d1e216cba8c4c06d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-01-08  Carl Hetherington  <cth@carlh.net>
+
+       * When doing jump-to-selected, jump to the first subtitle
+       in any text subtitle content (#1160).
+
 2018-01-07  Carl Hetherington  <cth@carlh.net>
 
        * Updated nl_NL translation from Rob van Nieuwkerk.
index 0f5e055cfc781180069506e8c05fe0ecdf8e3e37..2de815459b8ae1f35550f9eaf2053ec460de3f9b 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -36,6 +36,7 @@ using std::cout;
 using std::string;
 using boost::shared_ptr;
 using boost::scoped_array;
+using boost::optional;
 using dcp::Data;
 
 TextSubtitle::TextSubtitle (shared_ptr<const TextSubtitleContent> content)
@@ -85,6 +86,17 @@ TextSubtitle::TextSubtitle (shared_ptr<const TextSubtitleContent> content)
        delete reader;
 }
 
+/** @return time of first subtitle, if there is one */
+optional<ContentTime>
+TextSubtitle::first () const
+{
+       if (_subtitles.empty()) {
+               return optional<ContentTime>();
+       }
+
+       return ContentTime::from_seconds(_subtitles[0].from.all_as_seconds());
+}
+
 ContentTime
 TextSubtitle::length () const
 {
index c02f7a14b50fbc6215985c3da7c31d5aa434930c..94adb5cc58e9400b0d3b03b4dd144fa929a49d60 100644 (file)
@@ -37,6 +37,7 @@ class TextSubtitle
 public:
        TextSubtitle (boost::shared_ptr<const TextSubtitleContent>);
 
+       boost::optional<ContentTime> first () const;
        ContentTime length () const;
 
 protected:
index 8620fa3e0a410664368e1e54a30bb0c448b375c1..fa3754dd67381c7547641c7338c95d2634b181e0 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.
 
@@ -39,6 +39,8 @@
 #include "lib/config.h"
 #include "lib/log.h"
 #include "lib/compose.hpp"
+#include "lib/text_subtitle_content.h"
+#include "lib/text_subtitle.h"
 #include <wx/wx.h>
 #include <wx/notebook.h>
 #include <wx/listctrl.h>
@@ -254,8 +256,19 @@ 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<TextSubtitleContent>(i)) {
+                       /* Rather special case; if we select a text subtitle file jump to its
+                          first subtitle.
+                       */
+                       TextSubtitle ts (dynamic_pointer_cast<TextSubtitleContent>(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;
                }
        }