Add options for where the add files dialog starts (#2413).
authorCarl Hetherington <cth@carlh.net>
Fri, 13 Jan 2023 19:40:24 +0000 (20:40 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 13 Jan 2023 23:42:39 +0000 (00:42 +0100)
src/lib/config.cc
src/lib/config.h
src/wx/content_panel.cc
src/wx/content_panel.h
src/wx/full_config_dialog.cc
test/data

index e3325859f017d98b10a5b39f4e2f4cd40293e83c..2db50d687a26aa94f2890b739310d44b43460020 100644 (file)
@@ -153,6 +153,7 @@ Config::set_defaults ()
        _sound_output = optional<string> ();
        _last_kdm_write_type = KDM_WRITE_FLAT;
        _last_dkdm_write_type = DKDM_WRITE_INTERNAL;
+       _default_add_file_location = DefaultAddFileLocation::SAME_AS_LAST_TIME;
 
        /* I think the scaling factor here should be the ratio of the longest frame
           encode time to the shortest; if the thread count is T, longest time is L
@@ -620,6 +621,14 @@ try
        _main_divider_sash_position = f.optional_number_child<int>("MainDividerSashPosition");
        _main_content_divider_sash_position = f.optional_number_child<int>("MainContentDividerSashPosition");
 
+       if (auto loc = f.optional_string_child("DefaultAddFileLocation")) {
+               if (*loc == "last") {
+                       _default_add_file_location = DefaultAddFileLocation::SAME_AS_LAST_TIME;
+               } else if (*loc == "project") {
+                       _default_add_file_location = DefaultAddFileLocation::SAME_AS_PROJECT;
+               }
+       }
+
        _export.read(f.optional_node_child("Export"));
 }
 catch (...) {
@@ -1097,6 +1106,10 @@ Config::write_config () const
                root->add_child("MainContentDividerSashPosition")->add_child_text(raw_convert<string>(*_main_content_divider_sash_position));
        }
 
+       root->add_child("DefaultAddFileLocation")->add_child_text(
+               _default_add_file_location == DefaultAddFileLocation::SAME_AS_LAST_TIME ? "last" : "project"
+               );
+
        _export.write(root->add_child("Export"));
 
        auto target = config_write_file();
index b6a1a535d08e10f53db404d4e4b94bb4e28f8d08..a816cd89bc99a03f7e6e426cce93b43dd3823e65 100644 (file)
@@ -603,6 +603,15 @@ public:
                return _main_content_divider_sash_position;
        }
 
+       enum class DefaultAddFileLocation {
+               SAME_AS_LAST_TIME,
+               SAME_AS_PROJECT
+       };
+
+       DefaultAddFileLocation default_add_file_location() const {
+               return _default_add_file_location;
+       }
+
        /* SET (mostly) */
 
        void set_master_encoding_threads (int n) {
@@ -1172,6 +1181,10 @@ public:
                maybe_set(_main_content_divider_sash_position, position);
        }
 
+       void set_default_add_file_location(DefaultAddFileLocation location) {
+               maybe_set(_default_add_file_location, location);
+       }
+
        void changed (Property p = OTHER);
        boost::signals2::signal<void (Property)> Changed;
        /** Emitted if read() failed on an existing Config file.  There is nothing
@@ -1408,6 +1421,7 @@ private:
        boost::optional<std::string> _last_release_notes_version;
        boost::optional<int> _main_divider_sash_position;
        boost::optional<int> _main_content_divider_sash_position;
+       DefaultAddFileLocation _default_add_file_location;
 
        ExportConfig _export;
 
index 5bc006e12318a5fcc7af505633baa8907271aefa..a25e37a2ad1df70d774f76513d1d88f419cd4df4 100644 (file)
@@ -22,6 +22,7 @@
 #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"
@@ -570,6 +571,17 @@ ContentPanel::check_selection ()
 }
 
 
+optional<boost::filesystem::path>
+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<boost::filesystem::path>();
+
+}
+
+
 void
 ContentPanel::add_file_clicked ()
 {
@@ -588,7 +600,8 @@ ContentPanel::add_file_clicked ()
                _("Choose a file or files"),
                wxT("All files|*.*|Subtitle files|*.srt;*.xml|Audio files|*.wav;*.w64;*.flac;*.aif;*.aiff"),
                wxFD_MULTIPLE | wxFD_CHANGE_DIR,
-               "AddFilesPath"
+               "AddFilesPath",
+               add_files_override_path()
                );
 
        ScopeGuard sg = [dialog]() { dialog->Destroy(); };
@@ -602,17 +615,11 @@ ContentPanel::add_file_clicked ()
 void
 ContentPanel::add_folder_clicked ()
 {
-       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);
+       auto d = new DirDialog(_splitter, _("Choose a folder"), wxDD_DIR_MUST_EXIST, "AddFilesPath", add_files_override_path());
        ScopeGuard sg = [d]() { d->Destroy(); };
-       int r = d->ShowModal ();
-       if (r != wxID_OK) {
-               return;
+       if (d->show()) {
+               add_folder(d->path());
        }
-
-       boost::filesystem::path const path(wx_to_std(d->GetPath()));
-       add_folder(path);
 }
 
 
@@ -653,17 +660,11 @@ ContentPanel::add_folder(boost::filesystem::path folder)
 void
 ContentPanel::add_dcp_clicked ()
 {
-       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);
+       auto d = new DirDialog(_splitter, _("Choose a DCP folder"), wxDD_DIR_MUST_EXIST, "AddFilesPath", add_files_override_path());
        ScopeGuard sg = [d]() { d->Destroy(); };
-       int r = d->ShowModal ();
-       if (r != wxID_OK) {
-               return;
+       if (d->show()) {
+               add_dcp(d->path());
        }
-
-       boost::filesystem::path const path(wx_to_std(d->GetPath()));
-       add_dcp(path);
 }
 
 
index de1123ccebe78c4e31d207ceed64a288ef373533..8f25353b3c4167eec241dfa42d7f7a4979983d4b 100644 (file)
@@ -109,6 +109,7 @@ private:
        void later_clicked ();
        void right_click (wxListEvent &);
        void files_dropped (wxDropFilesEvent &);
+       boost::optional<boost::filesystem::path> add_files_override_path() const;
 
        void setup ();
        void setup_sensitivity ();
index 19fc2917160ea27a302d39a876c4eb396696e63f..f7ed2b5beef491fb6810a2b1bf043e4a584a023f 100644 (file)
@@ -28,6 +28,7 @@
 #include "config_dialog.h"
 #include "config_move_dialog.h"
 #include "dcpomatic_button.h"
+#include "dcpomatic_choice.h"
 #include "dir_picker_ctrl.h"
 #include "editable_list.h"
 #include "email_dialog.h"
@@ -124,6 +125,11 @@ private:
                table->Add (export_cinemas, wxGBPosition (r, 2));
                ++r;
 
+               add_label_to_sizer(table, _panel, _("Default \"add file\" location"), true, wxGBPosition(r, 0));
+               _default_add_file_location = new Choice(_panel);
+               table->Add(_default_add_file_location, wxGBPosition(r, 1));
+               ++r;
+
 #ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
                _analyse_ebur128 = new CheckBox (_panel, _("Find integrated loudness, true peak and loudness range when analysing audio"));
                table->Add (_analyse_ebur128, wxGBPosition (r, 0), wxGBSpan (1, 2));
@@ -136,6 +142,10 @@ private:
 
                add_update_controls (table, r);
 
+               _default_add_file_location->add(_("Same place as last time"));
+               _default_add_file_location->add(_("Same place as project"));
+               _default_add_file_location->bind(&FullGeneralPage::default_add_file_location_changed, this);
+
                _config_file->Bind  (wxEVT_FILEPICKER_CHANGED, boost::bind(&FullGeneralPage::config_file_changed,  this));
                _cinemas_file->Bind (wxEVT_FILEPICKER_CHANGED, boost::bind(&FullGeneralPage::cinemas_file_changed, this));
 
@@ -163,6 +173,7 @@ private:
                checked_set (_automatic_audio_analysis, config->automatic_audio_analysis ());
                checked_set (_config_file, config->config_read_file());
                checked_set (_cinemas_file, config->cinemas_file());
+               checked_set(_default_add_file_location, config->default_add_file_location() == Config::DefaultAddFileLocation::SAME_AS_LAST_TIME ? 0 : 1);
 
                GeneralPage::config_changed ();
        }
@@ -233,6 +244,14 @@ private:
                Config::instance()->set_cinemas_file (wx_to_std (_cinemas_file->GetPath ()));
        }
 
+       void default_add_file_location_changed()
+       {
+               Config::instance()->set_default_add_file_location(
+                       _default_add_file_location->get().get_value_or(0) == 0 ? Config::DefaultAddFileLocation::SAME_AS_LAST_TIME : Config::DefaultAddFileLocation::SAME_AS_PROJECT
+                       );
+       }
+
+       Choice* _default_add_file_location;
        wxSpinCtrl* _master_encoding_threads;
        wxSpinCtrl* _server_encoding_threads;
        FilePickerCtrl* _config_file;
index 4a9a6988520e62128562a0ccfb4fed84a7f1dd63..ff060de6bba8c07d1a63b0e059fd8d0c4e72c51e 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit 4a9a6988520e62128562a0ccfb4fed84a7f1dd63
+Subproject commit ff060de6bba8c07d1a63b0e059fd8d0c4e72c51e