From 4e1e68c88bd59339aceef73131ed939f72e353b5 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 24 Oct 2011 20:17:48 +0000 Subject: [PATCH] Allow adding multiple scripts at once in the automation dialog Originally committed to SVN as r5768. --- aegisub/src/dialog_automation.cpp | 32 +++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/aegisub/src/dialog_automation.cpp b/aegisub/src/dialog_automation.cpp index 8fd8bcf57..978dfc60b 100644 --- a/aegisub/src/dialog_automation.cpp +++ b/aegisub/src/dialog_automation.cpp @@ -181,27 +181,31 @@ static bool has_file(Container const& c, wxFileName const& fn) void DialogAutomation::OnAdd(wxCommandEvent &) { - wxString fname = wxFileSelector( + wxFileDialog diag(this, _("Add Automation script"), lagi_wxString(OPT_GET("Path/Last/Automation")->GetString()), - "", "", + "", Automation4::ScriptFactory::GetWildcardStr(), - wxFD_OPEN | wxFD_FILE_MUST_EXIST, - this); + wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE); - if (fname.empty()) return; + if (diag.ShowModal() == wxID_CANCEL) return; - wxFileName fnpath(fname); - OPT_SET("Path/Last/Automation")->SetString(STD_STR(fnpath.GetPath())); + wxArrayString fnames; + diag.GetPaths(fnames); - if (has_file(local_manager->GetScripts(), fnpath) || has_file(global_manager->GetScripts(), fnpath)) { - wxLogError("Script '%s' is already loaded", fname); - return; + for (size_t i = 0; i < fnames.size(); ++i) { + wxFileName fnpath(fnames[i]); + OPT_SET("Path/Last/Automation")->SetString(STD_STR(fnpath.GetPath())); + + if (has_file(local_manager->GetScripts(), fnpath) || has_file(global_manager->GetScripts(), fnpath)) { + wxLogError("Script '%s' is already loaded", fnames[i]); + continue; + } + + Automation4::Script *script = Automation4::ScriptFactory::CreateFromFile(fnames[i], true); + local_manager->Add(script); + AddScript(script, false); } - - Automation4::Script *script = Automation4::ScriptFactory::CreateFromFile(fname, true); - local_manager->Add(script); - AddScript(script, false); } void DialogAutomation::OnRemove(wxCommandEvent &)