+ SubtitleAppearanceDialog dialog(this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
+ if (dialog.ShowModal() == wxID_OK) {
+ dialog.apply();
+ }
+}
+
+
+/** The user has clicked on the outline subtitles check box */
+void
+TextPanel::outline_subtitles_changed ()
+{
+ if (_outline_subtitles->GetValue()) {
+ _analysis_content = _parent->selected_text().front();
+ try_to_load_analysis ();
+ } else {
+ clear_outline_subtitles ();
+ }
+}
+
+
+void
+TextPanel::try_to_load_analysis ()
+{
+ if (_loading_analysis) {
+ return;
+ }
+
+ _loading_analysis = true;
+ ScopeGuard sg = [this]() {
+ _loading_analysis = false;
+ setup_sensitivity();
+ };
+
+ setup_sensitivity ();
+ _analysis.reset ();
+
+ auto content = _analysis_content.lock ();
+ if (!content) {
+ return;
+ }
+
+ auto const path = _parent->film()->subtitle_analysis_path(content);
+
+ if (!boost::filesystem::exists(path)) {
+ for (auto i: JobManager::instance()->get()) {
+ if (dynamic_pointer_cast<AnalyseSubtitlesJob>(i) && !i->finished()) {
+ i->cancel ();
+ }
+ }
+
+ JobManager::instance()->analyse_subtitles (
+ _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this, _1)
+ );
+ return;
+ }
+
+ try {
+ _analysis.reset (new SubtitleAnalysis(path));
+ } catch (OldFormatError& e) {
+ /* An old analysis file: recreate it */
+ JobManager::instance()->analyse_subtitles (
+ _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this, _1)
+ );
+ return;
+ }
+
+ update_outline_subtitles_in_viewer ();
+}
+
+
+void
+TextPanel::update_outline_subtitles_in_viewer ()
+{
+ auto& fv = _parent->film_viewer();
+
+ if (_analysis) {
+ auto rect = _analysis->bounding_box ();
+ if (rect) {
+ auto content = _analysis_content.lock ();
+ DCPOMATIC_ASSERT (content);
+ rect->x += content->text.front()->x_offset() - _analysis->analysis_x_offset();
+ rect->y += content->text.front()->y_offset() - _analysis->analysis_y_offset();
+ }
+ fv.set_outline_subtitles(rect);
+ } else {
+ fv.set_outline_subtitles({});
+ }
+}
+
+
+/** Remove any current subtitle outline display */
+void
+TextPanel::clear_outline_subtitles ()
+{
+ _analysis.reset ();
+ update_outline_subtitles_in_viewer ();
+ if (_outline_subtitles) {
+ _outline_subtitles->SetValue (false);
+ }
+}
+
+
+void
+TextPanel::analysis_finished(Job::Result result)
+{
+ _loading_analysis = false;
+
+ auto content = _analysis_content.lock ();
+ if (!content || result == Job::Result::RESULT_CANCELLED) {
+ clear_outline_subtitles();
+ setup_sensitivity();
+ return;
+ }
+
+ if (!boost::filesystem::exists(_parent->film()->subtitle_analysis_path(content))) {
+ /* We analysed and still nothing showed up, so maybe it failed. Give up. */
+ error_dialog (_parent->window(), _("Could not analyse subtitles."));
+ clear_outline_subtitles ();
+ setup_sensitivity ();
+ return;
+ }
+
+ try_to_load_analysis ();
+}
+
+
+void
+TextPanel::language_changed ()
+{
+ for (auto i: _parent->selected_text()) {
+ auto t = i->text_of_original_type(_original_type);
+ if (t) {
+ t->set_language (_language->get());
+ }