From 91f0533a67f0ecd1318c548f93559db92c7a3576 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Fri, 19 Jan 2007 11:47:37 +0000 Subject: [PATCH] Auto4: Autoreload scripts on export, correctly save loaded scripts to subs file, make io and os libs available to scripts Originally committed to SVN as r842. --- aegisub/auto4_lua.cpp | 2 ++ aegisub/dialog_automation.cpp | 6 +++--- aegisub/dialog_options.cpp | 5 +++++ aegisub/frame_main.cpp | 2 +- aegisub/frame_main_events.cpp | 25 +++++++++++++++++++++---- aegisub/options.cpp | 1 + 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/aegisub/auto4_lua.cpp b/aegisub/auto4_lua.cpp index cd3049bcb..488fb665c 100644 --- a/aegisub/auto4_lua.cpp +++ b/aegisub/auto4_lua.cpp @@ -198,6 +198,8 @@ namespace Automation4 { lua_pushcfunction(L, luaopen_string); lua_call(L, 0, 0); lua_pushcfunction(L, luaopen_table); lua_call(L, 0, 0); lua_pushcfunction(L, luaopen_math); lua_call(L, 0, 0); + lua_pushcfunction(L, luaopen_io); lua_call(L, 0, 0); + lua_pushcfunction(L, luaopen_os); lua_call(L, 0, 0); _stackcheck.check(0); // dofile and loadfile are replaced with include lua_pushnil(L); diff --git a/aegisub/dialog_automation.cpp b/aegisub/dialog_automation.cpp index 9c3e8cf28..f0fc84374 100644 --- a/aegisub/dialog_automation.cpp +++ b/aegisub/dialog_automation.cpp @@ -186,7 +186,7 @@ void DialogAutomation::OnAdd(wxCommandEvent &evt) catchall.RemoveLast(); } if (factories.size() > 1) { - fnfilter = _T("All script formats|") + catchall + _T("|") + fnfilter; + fnfilter = _T("All supported scripts|") + catchall + _T("|") + fnfilter; } wxString fname = wxFileSelector(_("Add Automation script"), Options.AsText(_T("Last open automation path")), wxEmptyString, wxEmptyString, fnfilter, wxOPEN|wxFILE_MUST_EXIST, this); @@ -272,13 +272,13 @@ void DialogAutomation::OnInfo(wxCommandEvent &evt) } if (ei) { - info += wxString::Format(_("\nScript info:\nName: %s\nDescription: %s\nAuthor: %s\nVersion: %s\nFull path: %s\nCorrectly initialised: %s"), + info += wxString::Format(_("\nScript info:\nName: %s\nDescription: %s\nAuthor: %s\nVersion: %s\nFull path: %s\nState: %s"), ei->script->GetName().c_str(), ei->script->GetDescription().c_str(), ei->script->GetAuthor().c_str(), ei->script->GetVersion().c_str(), ei->script->GetFilename().c_str(), - ei->script->GetLoadedState() ? _("Yes") : _("No")); + ei->script->GetLoadedState() ? _("Correctly loaded") : _("Failed to load")); } wxMessageBox(info, _("Automation Script Info")); diff --git a/aegisub/dialog_options.cpp b/aegisub/dialog_options.cpp index e5c6611b3..405f28138 100644 --- a/aegisub/dialog_options.cpp +++ b/aegisub/dialog_options.cpp @@ -564,6 +564,11 @@ DialogOptions::DialogOptions(wxWindow *parent) control = new wxComboBox(autoPage,-1,_T(""),wxDefaultPosition,wxDefaultSize,3,prio_choices,wxCB_READONLY|wxCB_DROPDOWN); Bind(control, _T("Automation Thread Priority")); autoSizer2->Add(control, 1, wxEXPAND); + autoSizer2->Add(new wxStaticText(autoPage,-1,_("Autoreload on Export: ")),0,wxALIGN_CENTER_VERTICAL | wxRIGHT,10); + wxString reload_choices[4] = { _("No scripts"), _("Subtitle-local scripts"), _("Global autoload scripts"), _("All scripts") }; + control = new wxComboBox(autoPage,-1,_T(""),wxDefaultPosition,wxDefaultSize,4,reload_choices,wxCB_READONLY|wxCB_DROPDOWN); + Bind(control, _T("Automation Autoreload Mode")); + autoSizer2->Add(control, 1, wxEXPAND); // Sizers autoSizer1->Add(autoSizer2,1,wxEXPAND | wxALL,5); diff --git a/aegisub/frame_main.cpp b/aegisub/frame_main.cpp index 9ab017bf1..05ca842a6 100644 --- a/aegisub/frame_main.cpp +++ b/aegisub/frame_main.cpp @@ -972,7 +972,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) { scripts_string += scriptfn; } - subs->SetScriptInfo(_T("Automation 4 Scripts"), scripts_string); + subs->SetScriptInfo(_T("Automation Scripts"), scripts_string); } } diff --git a/aegisub/frame_main_events.cpp b/aegisub/frame_main_events.cpp index 5ac6d1afb..9833f9c47 100644 --- a/aegisub/frame_main_events.cpp +++ b/aegisub/frame_main_events.cpp @@ -730,10 +730,27 @@ void FrameMain::OnNewSubtitles(wxCommandEvent& WXUNUSED(event)) { //////////////////// // Export subtitles void FrameMain::OnExportSubtitles(wxCommandEvent & WXUNUSED(event)) { - //wxString filename = wxFileSelector(_T("Export subtitles file"),_T(""),_T(""),_T(""),_T("Advanced Substation Alpha (*.ass)|*.ass"),wxSAVE | wxOVERWRITE_PROMPT); - //if (!filename.empty()) { - // AssFile::top->Export(filename); - //} + int autoreload = Options.AsInt(_T("Automation Autoreload Mode")); + if (autoreload & 1) { + // Local scripts + const std::vector scripts = local_scripts->GetScripts(); + for (size_t i = 0; i < scripts.size(); ++i) { + try { + scripts[i]->Reload(); + } + catch (const wchar_t *e) { + wxLogError(e); + } + catch (...) { + wxLogError(_T("An unknown error occurred reloading Automation script '%s'."), scripts[i]->GetName().c_str()); + } + } + } + if (autoreload & 1) { + // Global scripts + wxGetApp().global_scripts->Reload(); + } + DialogExport exporter(this); exporter.ShowModal(); } diff --git a/aegisub/options.cpp b/aegisub/options.cpp index 87c94f8ca..3f615ba6b 100644 --- a/aegisub/options.cpp +++ b/aegisub/options.cpp @@ -176,6 +176,7 @@ void OptionsManager::LoadDefaults() { SetText(_T("Automation Autoload Path"), AegisubApp::folderName + _T("automation/autoload/")); SetInt(_T("Automation Trace Level"), 3); SetInt(_T("Automation Thread Priority"), 1); // "below normal" + SetInt(_T("Automation Autoreload Mode"), 0); // never // Generate colors wxColour tempCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);