_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;
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)
);
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);
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());
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) {
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);
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());
}
#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
)
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>()
);
#include "dcpomatic_button.h"
+#include "file_dialog.h"
#include "file_picker_ctrl.h"
#include "wx_util.h"
#include <dcp/warnings.h>
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);
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);
}
-boost::filesystem::path
+boost::optional<boost::filesystem::path>
FilePickerCtrl::path() const
{
return _path;
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());
}
}
#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;
};
++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));
{
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;
}
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()
++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;
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;