Simplify and fix up selection code for the content list (#2428).
[dcpomatic.git] / src / wx / text_panel.cc
index 8e7d4434e7958604b10d040d91e939c36336e503..ba6c07e76ca15d556a57a7c96e1445402390398b 100644 (file)
@@ -32,6 +32,7 @@
 #include "subtitle_appearance_dialog.h"
 #include "text_panel.h"
 #include "text_view.h"
+#include "wx_ptr.h"
 #include "wx_util.h"
 #include "lib/analyse_subtitles_job.h"
 #include "lib/dcp_content.h"
@@ -370,8 +371,7 @@ TextPanel::dcp_track_changed ()
        optional<DCPTextTrack> track;
 
        if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
-               auto d = new DCPTextTrackDialog (this);
-               ScopeGuard sg = [d]() { d->Destroy(); };
+               auto d = make_wx<DCPTextTrackDialog>(this);
                if (d->ShowModal() == wxID_OK) {
                        track = d->get();
                }
@@ -735,18 +735,13 @@ TextPanel::content_selection_changed ()
 void
 TextPanel::text_view_clicked ()
 {
-       if (_text_view) {
-               _text_view->Destroy ();
-               _text_view = nullptr;
-       }
-
        auto c = _parent->selected_text ();
        DCPOMATIC_ASSERT (c.size() == 1);
 
        auto decoder = decoder_factory (_parent->film(), c.front(), false, false, shared_ptr<Decoder>());
 
        if (decoder) {
-               _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
+               _text_view.reset(this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
                _text_view->Show ();
        }
 }
@@ -755,15 +750,10 @@ TextPanel::text_view_clicked ()
 void
 TextPanel::fonts_dialog_clicked ()
 {
-       if (_fonts_dialog) {
-               _fonts_dialog->Destroy ();
-               _fonts_dialog = nullptr;
-       }
-
        auto c = _parent->selected_text ();
        DCPOMATIC_ASSERT (c.size() == 1);
 
-       _fonts_dialog = new FontsDialog (this, c.front(), c.front()->text_of_original_type(_original_type));
+       _fonts_dialog.reset(this, c.front(), c.front()->text_of_original_type(_original_type));
        _fonts_dialog->Show ();
 }