From 98a10c9874d28e2e52f7495549b80528372ffbfb Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 3 Jan 2023 20:34:01 +0100 Subject: [PATCH] Generalise add_files_path to initial_paths(). --- src/lib/config.cc | 33 ++++++++++++++++++++++++++++----- src/lib/config.h | 11 +++-------- src/wx/content_panel.cc | 8 ++++---- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/lib/config.cc b/src/lib/config.cc index e3be484e2..21e670306 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -185,7 +185,8 @@ Config::set_defaults () _player_kdm_directory = boost::none; _audio_mapping = boost::none; _custom_languages.clear (); - _add_files_path = boost::none; + _initial_paths.clear(); + _initial_paths["AddFilesPath"] = boost::none; _use_isdcf_name_by_default = true; _write_kdms_to_disk = true; _email_kdms = false; @@ -599,7 +600,9 @@ try } catch (std::runtime_error& e) {} } - _add_files_path = f.optional_string_child("AddFilesPath"); + for (auto& initial: _initial_paths) { + initial.second = f.optional_string_child(initial.first); + } _use_isdcf_name_by_default = f.optional_bool_child("UseISDCFNameByDefault").get_value_or(true); _write_kdms_to_disk = f.optional_bool_child("WriteKDMsToDisk").get_value_or(true); _email_kdms = f.optional_bool_child("EmailKDMs").get_value_or(false); @@ -1071,9 +1074,10 @@ Config::write_config () const for (auto const& i: _custom_languages) { root->add_child("CustomLanguage")->add_child_text(i.to_string()); } - if (_add_files_path) { - /* [XML] AddFilesPath The default path that will be offered in the picker when adding files to a film. */ - root->add_child("AddFilesPath")->add_child_text(_add_files_path->string()); + for (auto const& initial: _initial_paths) { + if (initial.second) { + root->add_child(initial.first)->add_child_text(initial.second->string()); + } } root->add_child("UseISDCFNameByDefault")->add_child_text(_use_isdcf_name_by_default ? "1" : "0"); root->add_child("WriteKDMsToDisk")->add_child_text(_write_kdms_to_disk ? "1" : "0"); @@ -1591,3 +1595,22 @@ save_all_config_as_zip (boost::filesystem::path zip_file) zipper.close (); } + +void +Config::set_initial_path(string id, boost::filesystem::path path) +{ + auto iter = _initial_paths.find(id); + DCPOMATIC_ASSERT(iter != _initial_paths.end()); + iter->second = path; + changed(); +} + + +optional +Config::initial_path(string id) const +{ + auto iter = _initial_paths.find(id); + DCPOMATIC_ASSERT(iter != _initial_paths.end()); + return iter->second; +} + diff --git a/src/lib/config.h b/src/lib/config.h index 2535bd82a..b6a1a535d 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -565,9 +565,7 @@ public: return _custom_languages; } - boost::optional add_files_path () const { - return _add_files_path; - } + boost::optional initial_path(std::string id) const; bool use_isdcf_name_by_default () const { return _use_isdcf_name_by_default; @@ -1128,10 +1126,7 @@ public: void add_custom_language (dcp::LanguageTag tag); - void set_add_files_path (boost::filesystem::path p) { - _add_files_path = p; - changed (); - } + void set_initial_path(std::string id, boost::filesystem::path path); void set_use_isdcf_name_by_default (bool use) { maybe_set (_use_isdcf_name_by_default, use); @@ -1403,7 +1398,7 @@ private: boost::optional _player_kdm_directory; boost::optional _audio_mapping; std::vector _custom_languages; - boost::optional _add_files_path; + std::map> _initial_paths; bool _use_isdcf_name_by_default; bool _write_kdms_to_disk; bool _email_kdms; diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index 9de22e844..e035d1795 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -579,7 +579,7 @@ ContentPanel::add_file_clicked () return; } - auto path = Config::instance()->add_files_path(); + auto path = Config::instance()->initial_path("AddFilesPath"); /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using non-Latin filenames or paths. @@ -609,7 +609,7 @@ ContentPanel::add_file_clicked () add_files (path_list); if (!path_list.empty()) { - Config::instance()->set_add_files_path(path_list[0].parent_path()); + Config::instance()->set_initial_path("AddFilesPath", path_list[0].parent_path()); } d->Destroy (); @@ -619,7 +619,7 @@ ContentPanel::add_file_clicked () void ContentPanel::add_folder_clicked () { - auto const initial_path = Config::instance()->add_files_path(); + auto const initial_path = Config::instance()->initial_path("AddFilesPath"); auto d = new wxDirDialog(_splitter, _("Choose a folder"), std_to_wx(initial_path ? initial_path->string() : home_directory().string()), wxDD_DIR_MUST_EXIST); ScopeGuard sg = [d]() { d->Destroy(); }; @@ -673,7 +673,7 @@ ContentPanel::add_folder(boost::filesystem::path folder) void ContentPanel::add_dcp_clicked () { - auto const initial_path = Config::instance()->add_files_path(); + auto const initial_path = Config::instance()->initial_path("AddFilesPath"); auto d = new wxDirDialog(_splitter, _("Choose a DCP folder"), std_to_wx(initial_path ? initial_path->string() : home_directory().string()), wxDD_DIR_MUST_EXIST); ScopeGuard sg = [d]() { d->Destroy(); }; -- 2.30.2