summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-01-14 01:23:06 +0100
committerCarl Hetherington <cth@carlh.net>2023-01-14 01:23:06 +0100
commit5800e1f2abecb709cbdc1408d1328f29cdbcb370 (patch)
treec31c5a9bdb559855e22973ff8ccfb8b68db37891 /src
parentabcd6c9182507e6336a1839661dac856d5bea553 (diff)
Use ScopeGuard more.
Diffstat (limited to 'src')
-rw-r--r--src/wx/fonts_dialog.cc13
-rw-r--r--src/wx/timing_panel.cc3
-rw-r--r--src/wx/wx_util.cc10
3 files changed, 12 insertions, 14 deletions
diff --git a/src/wx/fonts_dialog.cc b/src/wx/fonts_dialog.cc
index 14fb368d3..b21bb8498 100644
--- a/src/wx/fonts_dialog.cc
+++ b/src/wx/fonts_dialog.cc
@@ -25,6 +25,7 @@
#include "wx_util.h"
#include "lib/content.h"
#include "lib/font.h"
+#include "lib/scope_guard.h"
#include "lib/text_content.h"
#include <dcp/warnings.h>
LIBDCP_DISABLE_WARNINGS
@@ -184,16 +185,13 @@ FontsDialog::set_from_file_clicked ()
#endif
auto d = new wxFileDialog (this, _("Choose a font file"), default_dir, wxT(""), wxT("*.ttf;*.otf;*.ttc"), wxFD_CHANGE_DIR);
- int const r = d->ShowModal ();
+ ScopeGuard sg = [d]() { d->Destroy(); };
- if (r != wxID_OK) {
- d->Destroy ();
+ if (d->ShowModal() != wxID_OK) {
return;
}
font->set_file (wx_to_std(d->GetPath()));
- d->Destroy ();
-
setup ();
}
@@ -207,14 +205,13 @@ FontsDialog::set_from_system_font_clicked()
}
auto dialog = new SystemFontDialog(this);
- auto const r = dialog->ShowModal();
- if (r == wxID_OK) {
+ ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+ if (dialog->ShowModal() == wxID_OK) {
auto font_file = dialog->get_font();
if (font_file) {
font->set_file(*font_file);
}
}
- dialog->Destroy();
setup ();
}
diff --git a/src/wx/timing_panel.cc b/src/wx/timing_panel.cc
index 5b8adc495..732cd07d5 100644
--- a/src/wx/timing_panel.cc
+++ b/src/wx/timing_panel.cc
@@ -33,6 +33,7 @@
#include "lib/dcp_subtitle_content.h"
#include "lib/ffmpeg_content.h"
#include "lib/image_content.h"
+#include "lib/scope_guard.h"
#include "lib/string_text_file_content.h"
#include "lib/text_content.h"
#include "lib/video_content.h"
@@ -507,11 +508,11 @@ TimingPanel::move_to_start_of_reel_clicked ()
}
auto d = new MoveToDialog(this, position, _parent->film());
+ ScopeGuard sg = [d]() { d->Destroy(); };
if (d->ShowModal() == wxID_OK) {
for (auto i: _parent->selected()) {
i->set_position (_parent->film(), d->position());
}
}
- d->Destroy ();
}
diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc
index 933d303d1..1f2afb4f5 100644
--- a/src/wx/wx_util.cc
+++ b/src/wx/wx_util.cc
@@ -34,6 +34,7 @@
#include "lib/cross.h"
#include "lib/job.h"
#include "lib/job_manager.h"
+#include "lib/scope_guard.h"
#include "lib/util.h"
#include "lib/version.h"
#include <dcp/locale_convert.h>
@@ -161,13 +162,13 @@ void
error_dialog (wxWindow* parent, wxString m, optional<wxString> e)
{
auto d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxOK | wxICON_ERROR);
+ ScopeGuard sg = [d]() { d->Destroy(); };
if (e) {
wxString em = *e;
em[0] = wxToupper (em[0]);
d->SetExtendedMessage (em);
}
d->ShowModal ();
- d->Destroy ();
}
@@ -179,8 +180,8 @@ void
message_dialog (wxWindow* parent, wxString m)
{
auto d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxOK | wxICON_INFORMATION);
+ ScopeGuard sg = [d]() { d->Destroy(); };
d->ShowModal ();
- d->Destroy ();
}
@@ -189,9 +190,8 @@ bool
confirm_dialog (wxWindow* parent, wxString m)
{
auto d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxYES_NO | wxICON_QUESTION);
- int const r = d->ShowModal ();
- d->Destroy ();
- return r == wxID_YES;
+ ScopeGuard sg = [d]() { d->Destroy(); };
+ return d->ShowModal() == wxID_YES;
}