X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Fwx%2Fcontent_panel.cc;h=fd13157474a391c55e56e3a8d59ab5cf25ec56cd;hp=1a5dbdc51952b50e013bf40405954b0b214895e2;hb=6a4a63310445bd5554f0df1b290b0c1af3f73779;hpb=9c096947fee8eb296c4341fec6426d5b74fd3d36 diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index 1a5dbdc51..fd1315747 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -22,12 +22,15 @@ #include "audio_panel.h" #include "content_panel.h" #include "dcpomatic_button.h" +#include "dir_dialog.h" +#include "file_dialog.h" #include "film_viewer.h" #include "image_sequence_dialog.h" #include "text_panel.h" #include "timeline_dialog.h" #include "timing_panel.h" #include "video_panel.h" +#include "wx_ptr.h" #include "wx_util.h" #include "lib/audio_content.h" #include "lib/case_insensitive_sorter.h" @@ -43,7 +46,6 @@ #include "lib/image_content.h" #include "lib/log.h" #include "lib/playlist.h" -#include "lib/scope_guard.h" #include "lib/string_text_file.h" #include "lib/string_text_file_content.h" #include "lib/text_content.h" @@ -569,6 +571,17 @@ ContentPanel::check_selection () } +optional +ContentPanel::add_files_override_path() const +{ + DCPOMATIC_ASSERT(_film->directory()); + return Config::instance()->default_add_file_location() == Config::DefaultAddFileLocation::SAME_AS_PROJECT + ? _film->directory()->parent_path() + : boost::optional(); + +} + + void ContentPanel::add_file_clicked () { @@ -579,55 +592,31 @@ ContentPanel::add_file_clicked () return; } - auto path = Config::instance()->add_files_path(); - /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using non-Latin filenames or paths. */ - auto d = new wxFileDialog ( + FileDialog dialog( _splitter, _("Choose a file or files"), - std_to_wx(path ? path->string() : home_directory().string()), - wxT (""), - wxT ("All files|*.*|Subtitle files|*.srt;*.xml|Audio files|*.wav;*.w64;*.flac;*.aif;*.aiff"), - wxFD_MULTIPLE | wxFD_CHANGE_DIR + wxT("All files|*.*|Subtitle files|*.srt;*.xml|Audio files|*.wav;*.w64;*.flac;*.aif;*.aiff"), + wxFD_MULTIPLE | wxFD_CHANGE_DIR, + "AddFilesPath", + add_files_override_path() ); - int const r = d->ShowModal (); - - if (r != wxID_OK) { - d->Destroy (); - return; - } - - wxArrayString paths; - d->GetPaths (paths); - vector path_list; - for (unsigned int i = 0; i < paths.GetCount(); ++i) { - path_list.push_back (wx_to_std(paths[i])); + if (dialog.show()) { + add_files(dialog.paths()); } - add_files (path_list); - - if (!path_list.empty()) { - Config::instance()->set_add_files_path(path_list[0].parent_path()); - } - - d->Destroy (); } void ContentPanel::add_folder_clicked () { - auto d = new wxDirDialog (_splitter, _("Choose a folder"), wxT(""), wxDD_DIR_MUST_EXIST); - ScopeGuard sg = [d]() { d->Destroy(); }; - int r = d->ShowModal (); - if (r != wxID_OK) { - return; + DirDialog dialog(_splitter, _("Choose a folder"), wxDD_DIR_MUST_EXIST, "AddFilesPath", add_files_override_path()); + if (dialog.show()) { + add_folder(dialog.path()); } - - boost::filesystem::path const path(wx_to_std(d->GetPath())); - add_folder(path); } @@ -651,16 +640,12 @@ ContentPanel::add_folder(boost::filesystem::path folder) for (auto i: content) { auto ic = dynamic_pointer_cast (i); if (ic) { - auto e = new ImageSequenceDialog (_splitter); - int const r = e->ShowModal(); - auto const frame_rate = e->frame_rate (); - e->Destroy (); + ImageSequenceDialog dialog(_splitter); - if (r != wxID_OK) { + if (dialog.ShowModal() != wxID_OK) { return; } - - ic->set_video_frame_rate(_film, frame_rate); + ic->set_video_frame_rate(_film, dialog.frame_rate()); } _film->examine_and_add_content (i); @@ -671,16 +656,10 @@ ContentPanel::add_folder(boost::filesystem::path folder) void ContentPanel::add_dcp_clicked () { - auto d = new wxDirDialog (_splitter, _("Choose a DCP folder"), wxT(""), wxDD_DIR_MUST_EXIST); - int r = d->ShowModal (); - boost::filesystem::path const path (wx_to_std (d->GetPath ())); - d->Destroy (); - - if (r != wxID_OK) { - return; + DirDialog dialog(_splitter, _("Choose a DCP folder"), wxDD_DIR_MUST_EXIST, "AddFilesPath", add_files_override_path()); + if (dialog.show()) { + add_dcp(dialog.path()); } - - add_dcp(path); } @@ -730,12 +709,7 @@ ContentPanel::timeline_clicked () return; } - if (_timeline_dialog) { - _timeline_dialog->Destroy (); - _timeline_dialog = nullptr; - } - - _timeline_dialog = new TimelineDialog (this, _film, _film_viewer); + _timeline_dialog.reset(this, _film, _film_viewer); _timeline_dialog->set_selection (selected()); _timeline_dialog->Show (); }