Use more ScopeGuards.
[dcpomatic.git] / src / wx / controls.cc
index 61c671788cacb2f328b31775e434b664c15f6d6e..804b59daec390173e28931f9e65fb6c2f8397f8e 100644 (file)
@@ -36,6 +36,7 @@
 #include "lib/job.h"
 #include "lib/job_manager.h"
 #include "lib/player_video.h"
+#include "lib/scope_guard.h"
 #include <dcp/cpl.h>
 #include <dcp/dcp.h>
 #include <dcp/reel.h>
@@ -137,7 +138,7 @@ Controls::Controls(wxWindow* parent, FilmViewer& viewer, bool editor_controls)
                _eye->Bind (wxEVT_CHOICE, boost::bind (&Controls::eye_changed, this));
        }
        if (_outline_content) {
-               _outline_content->Bind (wxEVT_CHECKBOX, boost::bind (&Controls::outline_content_changed, this));
+               _outline_content->bind(&Controls::outline_content_changed, this);
        }
 
        _slider->Bind           (wxEVT_SCROLL_THUMBTRACK,    boost::bind(&Controls::slider_moved,    this, false));
@@ -150,7 +151,7 @@ Controls::Controls(wxWindow* parent, FilmViewer& viewer, bool editor_controls)
        _frame_number->Bind     (wxEVT_LEFT_DOWN,            boost::bind(&Controls::frame_number_clicked, this));
        _timecode->Bind         (wxEVT_LEFT_DOWN,            boost::bind(&Controls::timecode_clicked, this));
        if (_jump_to_selected) {
-               _jump_to_selected->Bind (wxEVT_CHECKBOX, boost::bind (&Controls::jump_to_selected_clicked, this));
+               _jump_to_selected->bind(&Controls::jump_to_selected_clicked, this);
                _jump_to_selected->SetValue (Config::instance()->jump_to_selected ());
        }
 
@@ -381,10 +382,11 @@ void
 Controls::timecode_clicked ()
 {
        auto dialog = new PlayheadToTimecodeDialog(this, _viewer.position(), _film->video_frame_rate());
+       ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+
        if (dialog->ShowModal() == wxID_OK) {
                _viewer.seek(dialog->get(), true);
        }
-       dialog->Destroy ();
 }
 
 
@@ -392,10 +394,11 @@ void
 Controls::frame_number_clicked ()
 {
        auto dialog = new PlayheadToFrameDialog(this, _viewer.position(), _film->video_frame_rate());
+       ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+
        if (dialog->ShowModal() == wxID_OK) {
                _viewer.seek(dialog->get(), true);
        }
-       dialog->Destroy ();
 }