Remember some more paths when selecting files (#2728).
authorCarl Hetherington <cth@carlh.net>
Tue, 16 Jan 2024 00:44:49 +0000 (01:44 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 16 Jan 2024 20:33:29 +0000 (21:33 +0100)
* export subtitles
* export video
* debug log
* cinema database
* config file

src/lib/config.cc
src/wx/content_panel.cc
src/wx/export_subtitles_dialog.cc
src/wx/export_video_file_dialog.cc
src/wx/file_dialog.cc
src/wx/file_dialog.h
src/wx/file_picker_ctrl.cc
src/wx/file_picker_ctrl.h
src/wx/full_config_dialog.cc
src/wx/player_config_dialog.cc

index 1bb2f3c6a53e45fcd74b81f80b45883bb15f8eef..1126d0bbd2fc7a64225c986eccb4385149413d39 100644 (file)
@@ -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;
index 1f54ae0cf8a17ccbfcb7044472edb2bf38c0e68a..9e73900fcf012efd41e30502e27509553aae74ae 100644 (file)
@@ -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)
                );
 
index ade58b3fb06c871a7df18b1b12406ed9dccb7261..9baa1396e8be5ed7f4180bdc70acfa15efb5ef2e 100644 (file)
@@ -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());
index 8b01282b659cdbd848b6efa0b8ead841dc18b54b..61198560294d792975cbcff0b665ba0ce970e0ec 100644 (file)
@@ -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());
 }
index bed8b4e0d2c32e1c8776026cc47c7f6c17fd2d7f..5a530359c25bbcfe35880d2bbd59589e6b26ac69 100644 (file)
 #include <vector>
 
 
+using std::string;
 using std::vector;
 using boost::optional;
 
 
+wxString initial_path(
+       std::string initial_path_key,
+       optional<boost::filesystem::path> 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<std::string> initial_filename,
        optional<boost::filesystem::path> 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
                )
index ae55abf9730bdaec61052ecd1593412821e00a2c..ad8f68aa11a514c037510926e5d975f2e2106ed7 100644 (file)
@@ -40,6 +40,7 @@ public:
                wxString allowed,
                long style,
                std::string initial_path_key,
+               boost::optional<std::string> initial_filename = boost::optional<std::string>(),
                boost::optional<boost::filesystem::path> override_path = boost::optional<boost::filesystem::path>()
                );
 
index 07424e74cd82182cc9670c411eea98dbb7a6a0f8..7aa0bfb40cc9d9031a238c7e3f39f2980773a34d 100644 (file)
@@ -20,6 +20,7 @@
 
 
 #include "dcpomatic_button.h"
+#include "file_dialog.h"
 #include "file_picker_ctrl.h"
 #include "wx_util.h"
 #include <dcp/warnings.h>
@@ -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<std::string> initial_filename,
+       optional<filesystem::path> 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<string> 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<boost::filesystem::path> 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<boost::filesystem::path>
 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());
        }
 }
 
index 2411254faa53c0c385164ad3f0eeb168f364e692..57363b0c737e4d2db61783a7b8f24d4ba622a8f2 100644 (file)
@@ -24,25 +24,39 @@ LIBDCP_DISABLE_WARNINGS
 #include <wx/wx.h>
 LIBDCP_ENABLE_WARNINGS
 #include <boost/filesystem.hpp>
+#include <boost/optional.hpp>
 
 
 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<std::string> initial_filename = boost::optional<std::string>(),
+               boost::optional<boost::filesystem::path> override_path = boost::optional<boost::filesystem::path>()
+               );
+
+       boost::optional<boost::filesystem::path> path() const;
+       void set_path(boost::optional<boost::filesystem::path> path);
        void set_wildcard(wxString);
 
 private:
        void browse_clicked ();
+       void set_filename(boost::optional<std::string> filename);
 
        wxButton* _file;
-       boost::filesystem::path _path;
+       boost::optional<boost::filesystem::path> _path;
        wxSizer* _sizer;
        wxString _prompt;
        wxString _wildcard;
        bool _open;
        bool _warn_overwrite;
+       std::string _initial_path_key;
+       boost::optional<std::string> _initial_filename;
+       boost::optional<boost::filesystem::path> _override_path;
 };
index f7945a44a4404f1076e2f9f3334d0068ebe2e238..77f173d7cd67cebad5c34ef7418d726a211ffe57 100644 (file)
@@ -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()
index 512c64c91314157093116fa9c0a0d045f7f2e010..58874e50b59ac63cb589ebd32bce6a28135823a7 100644 (file)
@@ -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;