Remember the path used for "add files" (#2049).
authorCarl Hetherington <cth@carlh.net>
Mon, 21 Jun 2021 21:56:13 +0000 (23:56 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 21 Jun 2021 21:56:13 +0000 (23:56 +0200)
Also default to the home directory rather than where DoM was run from,
or something equally unhelpful.

src/lib/config.cc
src/lib/config.h
src/wx/content_panel.cc

index ce02b046e4e91635857ec0a2daee5df1535097dc..a8653a10c891a2dd766fc89b140498443a63c03e 100644 (file)
@@ -176,6 +176,7 @@ Config::set_defaults ()
        _player_kdm_directory = boost::none;
        _audio_mapping = boost::none;
        _custom_languages.clear ();
+       _add_files_path = boost::none;
 
        _allowed_dcp_frame_rates.clear ();
        _allowed_dcp_frame_rates.push_back (24);
@@ -553,6 +554,8 @@ try
                } catch (std::runtime_error& e) {}
        }
 
+       _add_files_path = f.optional_string_child("AddFilesPath");
+
        if (boost::filesystem::exists (_cinemas_file)) {
                cxml::Document f ("Cinemas");
                f.read_file (_cinemas_file);
@@ -976,6 +979,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] 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());
+       }
 
        try {
                auto const s = doc.write_to_string_formatted ();
index 1662671249209ec4abc60ce070351de6bdcb8da3..5b64922e61ab3c65a1b7ddcc19af39aebbc569f8 100644 (file)
@@ -539,6 +539,10 @@ public:
                return _custom_languages;
        }
 
+       boost::optional<boost::filesystem::path> add_files_path () const {
+               return _add_files_path;
+       }
+
        /* SET (mostly) */
 
        void set_master_encoding_threads (int n) {
@@ -1048,6 +1052,11 @@ public:
 
        void add_custom_language (dcp::LanguageTag tag);
 
+       void set_add_files_path (boost::filesystem::path p) {
+               _add_files_path = p;
+               changed ();
+       }
+
        void changed (Property p = OTHER);
        boost::signals2::signal<void (Property)> Changed;
        /** Emitted if read() failed on an existing Config file.  There is nothing
@@ -1260,6 +1269,7 @@ private:
        boost::optional<boost::filesystem::path> _player_kdm_directory;
        boost::optional<AudioMapping> _audio_mapping;
        std::vector<dcp::LanguageTag> _custom_languages;
+       boost::optional<boost::filesystem::path> _add_files_path;
 
        static int const _current_version;
 
index 68f6f1b9479686ff88460147cef27229d806a258..bcc6999139f248255b1ad2f61ca3697ddc1e87ef 100644 (file)
@@ -34,6 +34,7 @@
 #include "lib/compose.hpp"
 #include "lib/config.h"
 #include "lib/content_factory.h"
+#include "lib/cross.h"
 #include "lib/dcp_content.h"
 #include "lib/dcpomatic_log.h"
 #include "lib/ffmpeg_content.h"
@@ -420,13 +421,15 @@ 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 (
                _splitter,
                _("Choose a file or files"),
-               wxT (""),
+               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
@@ -447,6 +450,10 @@ ContentPanel::add_file_clicked ()
        }
        add_files (path_list);
 
+       if (!path_list.empty()) {
+               Config::instance()->set_add_files_path(path_list[0].parent_path());
+       }
+
        d->Destroy ();
 }