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.
This commit is contained in:
Niels Martin Hansen 2007-01-19 11:47:37 +00:00
parent 329821ed7c
commit 91f0533a67
6 changed files with 33 additions and 8 deletions

View file

@ -198,6 +198,8 @@ namespace Automation4 {
lua_pushcfunction(L, luaopen_string); lua_call(L, 0, 0); lua_pushcfunction(L, luaopen_string); lua_call(L, 0, 0);
lua_pushcfunction(L, luaopen_table); 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_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); _stackcheck.check(0);
// dofile and loadfile are replaced with include // dofile and loadfile are replaced with include
lua_pushnil(L); lua_pushnil(L);

View file

@ -186,7 +186,7 @@ void DialogAutomation::OnAdd(wxCommandEvent &evt)
catchall.RemoveLast(); catchall.RemoveLast();
} }
if (factories.size() > 1) { 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); 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) { 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->GetName().c_str(),
ei->script->GetDescription().c_str(), ei->script->GetDescription().c_str(),
ei->script->GetAuthor().c_str(), ei->script->GetAuthor().c_str(),
ei->script->GetVersion().c_str(), ei->script->GetVersion().c_str(),
ei->script->GetFilename().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")); wxMessageBox(info, _("Automation Script Info"));

View file

@ -564,6 +564,11 @@ DialogOptions::DialogOptions(wxWindow *parent)
control = new wxComboBox(autoPage,-1,_T(""),wxDefaultPosition,wxDefaultSize,3,prio_choices,wxCB_READONLY|wxCB_DROPDOWN); control = new wxComboBox(autoPage,-1,_T(""),wxDefaultPosition,wxDefaultSize,3,prio_choices,wxCB_READONLY|wxCB_DROPDOWN);
Bind(control, _T("Automation Thread Priority")); Bind(control, _T("Automation Thread Priority"));
autoSizer2->Add(control, 1, wxEXPAND); 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 // Sizers
autoSizer1->Add(autoSizer2,1,wxEXPAND | wxALL,5); autoSizer1->Add(autoSizer2,1,wxEXPAND | wxALL,5);

View file

@ -972,7 +972,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) {
scripts_string += scriptfn; scripts_string += scriptfn;
} }
subs->SetScriptInfo(_T("Automation 4 Scripts"), scripts_string); subs->SetScriptInfo(_T("Automation Scripts"), scripts_string);
} }
} }

View file

@ -730,10 +730,27 @@ void FrameMain::OnNewSubtitles(wxCommandEvent& WXUNUSED(event)) {
//////////////////// ////////////////////
// Export subtitles // Export subtitles
void FrameMain::OnExportSubtitles(wxCommandEvent & WXUNUSED(event)) { 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); int autoreload = Options.AsInt(_T("Automation Autoreload Mode"));
//if (!filename.empty()) { if (autoreload & 1) {
// AssFile::top->Export(filename); // Local scripts
//} const std::vector<Automation4::Script*> 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); DialogExport exporter(this);
exporter.ShowModal(); exporter.ShowModal();
} }

View file

@ -176,6 +176,7 @@ void OptionsManager::LoadDefaults() {
SetText(_T("Automation Autoload Path"), AegisubApp::folderName + _T("automation/autoload/")); SetText(_T("Automation Autoload Path"), AegisubApp::folderName + _T("automation/autoload/"));
SetInt(_T("Automation Trace Level"), 3); SetInt(_T("Automation Trace Level"), 3);
SetInt(_T("Automation Thread Priority"), 1); // "below normal" SetInt(_T("Automation Thread Priority"), 1); // "below normal"
SetInt(_T("Automation Autoreload Mode"), 0); // never
// Generate colors // Generate colors
wxColour tempCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); wxColour tempCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);