Use wx_ptr some more.
[dcpomatic.git] / src / wx / text_panel.cc
index 7e6557ba9c88bd0d678887c12eef705b62e3417f..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"
@@ -41,6 +42,7 @@
 #include "lib/ffmpeg_content.h"
 #include "lib/ffmpeg_subtitle_stream.h"
 #include "lib/job_manager.h"
+#include "lib/scope_guard.h"
 #include "lib/string_text_file_content.h"
 #include "lib/string_text_file_decoder.h"
 #include "lib/subtitle_analysis.h"
@@ -369,11 +371,10 @@ TextPanel::dcp_track_changed ()
        optional<DCPTextTrack> track;
 
        if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
-               auto d = new DCPTextTrackDialog (this);
+               auto d = make_wx<DCPTextTrackDialog>(this);
                if (d->ShowModal() == wxID_OK) {
                        track = d->get();
                }
-               d->Destroy ();
        } else {
                /* Find the DCPTextTrack that was selected */
                for (auto i: _parent->film()->closed_caption_tracks()) {
@@ -734,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 ();
        }
 }
@@ -754,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 ();
 }