From 127bdaa2d8a869112fd6ec908cf115f391dbba24 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 16 Jan 2024 01:44:49 +0100 Subject: [PATCH] Remember some more paths when selecting files (#2728). * export subtitles * export video * debug log * cinema database * config file --- src/lib/config.cc | 5 ++++ src/wx/content_panel.cc | 1 + src/wx/export_subtitles_dialog.cc | 10 ++++--- src/wx/export_video_file_dialog.cc | 8 +++--- src/wx/file_dialog.cc | 22 +++++++++++---- src/wx/file_dialog.h | 1 + src/wx/file_picker_ctrl.cc | 45 +++++++++++++++++++++++------- src/wx/file_picker_ctrl.h | 24 ++++++++++++---- src/wx/full_config_dialog.cc | 18 ++++++------ src/wx/player_config_dialog.cc | 6 ++-- 10 files changed, 102 insertions(+), 38 deletions(-) diff --git a/src/lib/config.cc b/src/lib/config.cc index 1bb2f3c6a..1126d0bbd 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -191,6 +191,11 @@ Config::set_defaults () _initial_paths["AddDKDMPath"] = boost::none; _initial_paths["SelectCertificatePath"] = boost::none; _initial_paths["AddCombinerInputPath"] = boost::none; + _initial_paths["ExportSubtitlesPath"] = boost::none; + _initial_paths["ExportVideoPath"] = boost::none; + _initial_paths["DebugLogPath"] = boost::none; + _initial_paths["CinemaDatabasePath"] = boost::none; + _initial_paths["ConfigFilePath"] = boost::none; _use_isdcf_name_by_default = true; _write_kdms_to_disk = true; _email_kdms = false; diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index 1f54ae0cf..9e73900fc 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -602,6 +602,7 @@ ContentPanel::add_file_clicked () wxT("All files|*.*|Subtitle files|*.srt;*.xml|Audio files|*.wav;*.w64;*.flac;*.aif;*.aiff"), wxFD_MULTIPLE | wxFD_CHANGE_DIR, "AddFilesPath", + {}, add_files_override_path(_film) ); diff --git a/src/wx/export_subtitles_dialog.cc b/src/wx/export_subtitles_dialog.cc index ade58b3fb..9baa1396e 100644 --- a/src/wx/export_subtitles_dialog.cc +++ b/src/wx/export_subtitles_dialog.cc @@ -58,7 +58,7 @@ ExportSubtitlesDialog::ExportSubtitlesDialog (wxWindow* parent, int reels, bool wxString const wildcard = _interop ? _("Subtitle files (.xml)|*.xml") : _("Subtitle files (.mxf)|*.mxf"); _file_label = add (_("Output file"), true); - _file = new FilePickerCtrl (this, _("Select output file"), wildcard, false, true); + _file = new FilePickerCtrl(this, _("Select output file"), wildcard, false, true, "ExportSubtitlesPath"); add (_file); _dir_label = add (_("Output folder"), true); @@ -97,9 +97,11 @@ boost::filesystem::path ExportSubtitlesDialog::path () const { if (_file->IsEnabled()) { - wxFileName fn(std_to_wx(_file->path().string())); - fn.SetExt (_interop ? "xml" : "mxf"); - return wx_to_std (fn.GetFullPath()); + if (auto path = _file->path()) { + wxFileName fn(std_to_wx(path->string())); + fn.SetExt(_interop ? "xml" : "mxf"); + return wx_to_std(fn.GetFullPath()); + } } return wx_to_std (_dir->GetPath()); diff --git a/src/wx/export_video_file_dialog.cc b/src/wx/export_video_file_dialog.cc index 8b01282b6..611985602 100644 --- a/src/wx/export_video_file_dialog.cc +++ b/src/wx/export_video_file_dialog.cc @@ -96,8 +96,7 @@ ExportVideoFileDialog::ExportVideoFileDialog (wxWindow* parent, string name) need to check if foo.mov (or similar) exists. I can't find a way to make wxWidgets do this, so disable its check and the caller will have to do it themselves. */ - _file = new FilePickerCtrl (this, _("Select output file"), format_filters[0], false, false); - _file->set_path(_initial_name); + _file = new FilePickerCtrl(this, _("Select output file"), format_filters[0], false, false, "ExportVideoPath", _initial_name); add (_file); for (int i = 0; i < FORMATS; ++i) { @@ -168,7 +167,6 @@ ExportVideoFileDialog::format_changed () auto const selection = _format->GetSelection(); DCPOMATIC_ASSERT (selection >= 0 && selection < FORMATS); _file->set_wildcard(format_filters[selection]); - _file->set_path(_initial_name); _x264_crf->Enable (formats[selection] == ExportFormat::H264_AAC); for (int i = 0; i < 2; ++i) { _x264_crf_label[i]->Enable(formats[selection] == ExportFormat::H264_AAC); @@ -180,7 +178,9 @@ ExportVideoFileDialog::format_changed () boost::filesystem::path ExportVideoFileDialog::path () const { - wxFileName fn(std_to_wx(_file->path().string())); + auto path = _file->path(); + DCPOMATIC_ASSERT(path); + wxFileName fn(std_to_wx(path->string())); fn.SetExt (format_extensions[_format->GetSelection()]); return wx_to_std (fn.GetFullPath()); } diff --git a/src/wx/file_dialog.cc b/src/wx/file_dialog.cc index bed8b4e0d..5a530359c 100644 --- a/src/wx/file_dialog.cc +++ b/src/wx/file_dialog.cc @@ -27,26 +27,38 @@ #include +using std::string; using std::vector; using boost::optional; +wxString initial_path( + std::string initial_path_key, + optional override_path + ) +{ + if (override_path) { + return std_to_wx(override_path->string()); + } + + return std_to_wx(Config::instance()->initial_path(initial_path_key).get_value_or(home_directory()).string()); +} + + FileDialog::FileDialog( wxWindow* parent, wxString title, wxString allowed, long style, std::string initial_path_key, + boost::optional initial_filename, optional override_path ) : wxFileDialog( parent, title, - std_to_wx( - override_path.get_value_or( - Config::instance()->initial_path(initial_path_key).get_value_or(home_directory()) - ).string()), - wxEmptyString, + initial_path(initial_path_key, override_path), + std_to_wx(initial_filename.get_value_or("")), allowed, style ) diff --git a/src/wx/file_dialog.h b/src/wx/file_dialog.h index ae55abf97..ad8f68aa1 100644 --- a/src/wx/file_dialog.h +++ b/src/wx/file_dialog.h @@ -40,6 +40,7 @@ public: wxString allowed, long style, std::string initial_path_key, + boost::optional initial_filename = boost::optional(), boost::optional override_path = boost::optional() ); diff --git a/src/wx/file_picker_ctrl.cc b/src/wx/file_picker_ctrl.cc index 07424e74c..7aa0bfb40 100644 --- a/src/wx/file_picker_ctrl.cc +++ b/src/wx/file_picker_ctrl.cc @@ -20,6 +20,7 @@ #include "dcpomatic_button.h" +#include "file_dialog.h" #include "file_picker_ctrl.h" #include "wx_util.h" #include @@ -35,12 +36,24 @@ using namespace std; using namespace boost; -FilePickerCtrl::FilePickerCtrl (wxWindow* parent, wxString prompt, wxString wildcard, bool open, bool warn_overwrite) +FilePickerCtrl::FilePickerCtrl( + wxWindow* parent, + wxString prompt, + wxString wildcard, + bool open, + bool warn_overwrite, + std::string initial_path_key, + optional initial_filename, + optional override_path + ) : wxPanel (parent) , _prompt (prompt) , _wildcard (wildcard) , _open (open) , _warn_overwrite (warn_overwrite) + , _initial_path_key(initial_path_key) + , _initial_filename(initial_filename) + , _override_path(override_path) { _sizer = new wxBoxSizer (wxHORIZONTAL); @@ -53,18 +66,31 @@ FilePickerCtrl::FilePickerCtrl (wxWindow* parent, wxString prompt, wxString wild SetSizerAndFit (_sizer); _file->Bind (wxEVT_BUTTON, boost::bind (&FilePickerCtrl::browse_clicked, this)); + + set_filename(_initial_filename); +} + + +void +FilePickerCtrl::set_filename(optional filename) +{ + if (filename) { + _file->SetLabel(std_to_wx(*filename)); + } else { + _file->SetLabel(_("None")); + } } void -FilePickerCtrl::set_path(boost::filesystem::path path) +FilePickerCtrl::set_path(optional path) { _path = path; - if (!_path.empty()) { - _file->SetLabel(std_to_wx(_path.filename().string())); + if (_path) { + set_filename(_path->filename().string()); } else { - _file->SetLabel (_("(None)")); + set_filename({}); } wxCommandEvent ev (wxEVT_FILEPICKER_CHANGED, wxID_ANY); @@ -72,7 +98,7 @@ FilePickerCtrl::set_path(boost::filesystem::path path) } -boost::filesystem::path +boost::optional FilePickerCtrl::path() const { return _path; @@ -86,10 +112,9 @@ FilePickerCtrl::browse_clicked () if (_warn_overwrite) { style |= wxFD_OVERWRITE_PROMPT; } - wxFileDialog dialog(this, _prompt, wxEmptyString, wxEmptyString, _wildcard, style); - dialog.SetPath(std_to_wx(_path.string())); - if (dialog.ShowModal() == wxID_OK) { - set_path(boost::filesystem::path(wx_to_std(dialog.GetPath()))); + FileDialog dialog(this, _prompt, _wildcard, style, _initial_path_key, _initial_filename, _path); + if (dialog.show()) { + set_path(dialog.path()); } } diff --git a/src/wx/file_picker_ctrl.h b/src/wx/file_picker_ctrl.h index 2411254fa..57363b0c7 100644 --- a/src/wx/file_picker_ctrl.h +++ b/src/wx/file_picker_ctrl.h @@ -24,25 +24,39 @@ LIBDCP_DISABLE_WARNINGS #include LIBDCP_ENABLE_WARNINGS #include +#include class FilePickerCtrl : public wxPanel { public: - FilePickerCtrl (wxWindow* parent, wxString prompt, wxString wildcard, bool open, bool warn_overwrite); - - boost::filesystem::path path() const; - void set_path(boost::filesystem::path path); + FilePickerCtrl( + wxWindow* parent, + wxString prompt, + wxString wildcard, + bool open, + bool warn_overwrite, + std::string initial_path_key, + boost::optional initial_filename = boost::optional(), + boost::optional override_path = boost::optional() + ); + + boost::optional path() const; + void set_path(boost::optional path); void set_wildcard(wxString); private: void browse_clicked (); + void set_filename(boost::optional filename); wxButton* _file; - boost::filesystem::path _path; + boost::optional _path; wxSizer* _sizer; wxString _prompt; wxString _wildcard; bool _open; bool _warn_overwrite; + std::string _initial_path_key; + boost::optional _initial_filename; + boost::optional _override_path; }; diff --git a/src/wx/full_config_dialog.cc b/src/wx/full_config_dialog.cc index f7945a44a..77f173d7c 100644 --- a/src/wx/full_config_dialog.cc +++ b/src/wx/full_config_dialog.cc @@ -115,12 +115,12 @@ private: ++r; add_label_to_sizer (table, _panel, _("Configuration file"), true, wxGBPosition (r, 0)); - _config_file = new FilePickerCtrl (_panel, _("Select configuration file"), "*.xml", true, false); + _config_file = new FilePickerCtrl(_panel, _("Select configuration file"), "*.xml", true, false, "ConfigFilePath"); table->Add (_config_file, wxGBPosition (r, 1)); ++r; add_label_to_sizer (table, _panel, _("Cinema and screen database file"), true, wxGBPosition (r, 0)); - _cinemas_file = new FilePickerCtrl (_panel, _("Select cinema and screen database file"), "*.xml", true, false); + _cinemas_file = new FilePickerCtrl(_panel, _("Select cinema and screen database file"), "*.xml", true, false, "CinemaDatabasePath"); table->Add (_cinemas_file, wxGBPosition (r, 1)); auto export_cinemas = new Button (_panel, _("Export...")); table->Add (export_cinemas, wxGBPosition (r, 2)); @@ -217,12 +217,12 @@ private: { auto config = Config::instance(); auto const new_file = _config_file->path(); - if (new_file == config->config_read_file()) { + if (!new_file || *new_file == config->config_read_file()) { return; } bool copy_and_link = true; - if (dcp::filesystem::exists(new_file)) { - ConfigMoveDialog dialog(_panel, new_file); + if (dcp::filesystem::exists(*new_file)) { + ConfigMoveDialog dialog(_panel, *new_file); if (dialog.ShowModal() == wxID_OK) { copy_and_link = false; } @@ -231,16 +231,18 @@ private: if (copy_and_link) { config->write (); if (new_file != config->config_read_file()) { - config->copy_and_link (new_file); + config->copy_and_link(*new_file); } } else { - config->link (new_file); + config->link(*new_file); } } void cinemas_file_changed () { - Config::instance()->set_cinemas_file(_cinemas_file->path()); + if (auto path = _cinemas_file->path()) { + Config::instance()->set_cinemas_file(*path); + } } void default_add_file_location_changed() diff --git a/src/wx/player_config_dialog.cc b/src/wx/player_config_dialog.cc index 512c64c91..58874e50b 100644 --- a/src/wx/player_config_dialog.cc +++ b/src/wx/player_config_dialog.cc @@ -126,7 +126,7 @@ private: ++r; add_label_to_sizer (table, _panel, _("Debug log file"), true, wxGBPosition (r, 0)); - _debug_log_file = new FilePickerCtrl (_panel, _("Select debug log file"), "*", false, true); + _debug_log_file = new FilePickerCtrl(_panel, _("Select debug log file"), "*", false, true, "DebugLogPath"); table->Add (_debug_log_file, wxGBPosition(r, 1)); ++r; @@ -208,7 +208,9 @@ private: void debug_log_file_changed () { - Config::instance()->set_player_debug_log_file(_debug_log_file->path()); + if (auto path = _debug_log_file->path()) { + Config::instance()->set_player_debug_log_file(*path); + } } wxChoice* _player_mode; -- 2.30.2