diff --git a/aegisub/src/auto4_base.cpp b/aegisub/src/auto4_base.cpp index 1308d9044..24da038d3 100644 --- a/aegisub/src/auto4_base.cpp +++ b/aegisub/src/auto4_base.cpp @@ -456,7 +456,10 @@ namespace Automation4 { delete_clear(scripts); wxString local_scripts = context->ass->GetScriptInfo("Automation Scripts"); - if (local_scripts.empty()) return; + if (local_scripts.empty()) { + ScriptsChanged(); + return; + } wxStringTokenizer tok(local_scripts, "|", wxTOKEN_STRTOK); wxFileName assfn(context->ass->filename); diff --git a/aegisub/src/auto4_base.h b/aegisub/src/auto4_base.h index bce181e27..fb74a035c 100644 --- a/aegisub/src/auto4_base.h +++ b/aegisub/src/auto4_base.h @@ -219,7 +219,7 @@ namespace Automation4 { void Remove(Script *script); /// Deletes all scripts managed void RemoveAll(); - /// Reload all scripts mananaged + /// Reload all scripts managed virtual void Reload() = 0; /// Reload a single managed script virtual void Reload(Script *script); diff --git a/aegisub/src/command/automation.cpp b/aegisub/src/command/automation.cpp index 97164dbcb..3b8644eb9 100644 --- a/aegisub/src/command/automation.cpp +++ b/aegisub/src/command/automation.cpp @@ -87,20 +87,13 @@ struct open_manager : public Command { STR_HELP("Open automation manager") void operator()(agi::Context *c) { - if (wxGetMouseState().CmdDown()) { - wxGetApp().global_scripts->Reload(); - - if (wxGetMouseState().ShiftDown()) { - c->local_scripts->Reload(); - wxGetApp().frame->StatusTimeout(_("Reloaded all Automation scripts")); - } - else { - wxGetApp().frame->StatusTimeout(_("Reloaded autoload Automation scripts")); - } + if (c->automationManager) { + c->automationManager->Show(); + c->automationManager->SetFocus(); } else { - c->videoController->Stop(); - DialogAutomation(c).ShowModal(); + c->automationManager = new DialogAutomation(c); + c->automationManager->Show(); } } }; diff --git a/aegisub/src/dialog_automation.cpp b/aegisub/src/dialog_automation.cpp index 434e4c17a..16fc9d880 100644 --- a/aegisub/src/dialog_automation.cpp +++ b/aegisub/src/dialog_automation.cpp @@ -64,7 +64,9 @@ DialogAutomation::DialogAutomation(agi::Context *c) : wxDialog(c->parent, -1, _("Automation Manager"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) , context(c) , local_manager(c->local_scripts) +, local_scripts_changed(local_manager->AddScriptChangeListener(&DialogAutomation::RebuildList, this)) , global_manager(wxGetApp().global_scripts) +, global_scripts_changed(global_manager->AddScriptChangeListener(&DialogAutomation::RebuildList, this)) { SetIcon(BitmapToIcon(GETIMAGE(automation_toolbutton_24))); @@ -77,8 +79,8 @@ DialogAutomation::DialogAutomation(agi::Context *c) wxButton *reload_autoload_button = new wxButton(this, -1, _("Re&scan Autoload Dir")); wxButton *close_button = new wxButton(this, wxID_CANCEL, _("&Close")); - list->Bind(wxEVT_COMMAND_LIST_ITEM_SELECTED, &DialogAutomation::OnSelectionChange, this); - list->Bind(wxEVT_COMMAND_LIST_ITEM_DESELECTED, &DialogAutomation::OnSelectionChange, this); + list->Bind(wxEVT_COMMAND_LIST_ITEM_SELECTED, std::tr1::bind(&DialogAutomation::UpdateDisplay, this)); + list->Bind(wxEVT_COMMAND_LIST_ITEM_DESELECTED, std::tr1::bind(&DialogAutomation::UpdateDisplay, this)); add_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogAutomation::OnAdd, this); remove_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogAutomation::OnRemove, this); reload_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogAutomation::OnReload, this); @@ -120,7 +122,6 @@ DialogAutomation::DialogAutomation(agi::Context *c) close_button->SetDefault(); RebuildList(); - UpdateDisplay(); } template @@ -142,6 +143,8 @@ void DialogAutomation::RebuildList() for_each(local_manager->GetScripts(), bind(&DialogAutomation::AddScript, this, _1, false)); for_each(global_manager->GetScripts(), bind(&DialogAutomation::AddScript, this, _1, true)); + + UpdateDisplay(); } void DialogAutomation::SetScriptInfo(int i, Automation4::Script *script) @@ -206,9 +209,7 @@ void DialogAutomation::OnAdd(wxCommandEvent &) continue; } - Automation4::Script *script = Automation4::ScriptFactory::CreateFromFile(fnames[i], true); - local_manager->Add(script); - AddScript(script, false); + local_manager->Add(Automation4::ScriptFactory::CreateFromFile(fnames[i], true)); } } @@ -218,10 +219,8 @@ void DialogAutomation::OnRemove(wxCommandEvent &) if (i < 0) return; const ExtraScriptInfo &ei = script_info[list->GetItemData(i)]; if (ei.is_global) return; - list->DeleteItem(i); + local_manager->Remove(ei.script); - // don't bother doing anything in script_info, it's relatively short-lived, and having any indexes change would break stuff - list->Select(i); } void DialogAutomation::OnReload(wxCommandEvent &) @@ -234,8 +233,6 @@ void DialogAutomation::OnReload(wxCommandEvent &) global_manager->Reload(ei.script); else local_manager->Reload(ei.script); - - SetScriptInfo(i, ei.script); } static wxString fac_to_str(const Automation4::ScriptFactory* f) { @@ -291,11 +288,4 @@ void DialogAutomation::OnInfo(wxCommandEvent &) void DialogAutomation::OnReloadAutoload(wxCommandEvent &) { global_manager->Reload(); - RebuildList(); - UpdateDisplay(); -} - -void DialogAutomation::OnSelectionChange(wxListEvent &) -{ - UpdateDisplay(); } diff --git a/aegisub/src/dialog_automation.h b/aegisub/src/dialog_automation.h index 08287a2f2..607045aa7 100644 --- a/aegisub/src/dialog_automation.h +++ b/aegisub/src/dialog_automation.h @@ -34,15 +34,13 @@ /// @ingroup secondary_ui /// - - - #ifndef AGI_PRE #include #include #endif +#include namespace Automation4 { class ScriptManager; @@ -76,9 +74,15 @@ class DialogAutomation : public wxDialog { /// File-local script manager Automation4::ScriptManager *local_manager; + /// Listener for external changes to the local scripts + agi::signal::Connection local_scripts_changed; + /// Global script manager Automation4::ScriptManager *global_manager; + /// Listener for external changes to the global scripts + agi::signal::Connection global_scripts_changed; + /// List of loaded scripts wxListView *list; @@ -100,7 +104,6 @@ class DialogAutomation : public wxDialog { void OnInfo(wxCommandEvent &); void OnReloadAutoload(wxCommandEvent &); - void OnSelectionChange(wxListEvent &); public: DialogAutomation(agi::Context *context); diff --git a/aegisub/src/frame_main.cpp b/aegisub/src/frame_main.cpp index a4b898122..bba763a0e 100644 --- a/aegisub/src/frame_main.cpp +++ b/aegisub/src/frame_main.cpp @@ -125,6 +125,7 @@ FrameMain::FrameMain (wxArrayString args) #endif StartupLog("Initializing context models"); + memset(context.get(), 0, sizeof(*context)); AssFile::top = context->ass = new AssFile; context->ass->AddCommitListener(&FrameMain::UpdateTitle, this); context->ass->AddFileOpenListener(&FrameMain::OnSubtitlesOpen, this); @@ -180,9 +181,6 @@ FrameMain::FrameMain (wxArrayString args) #endif StartupLog("Create views and inner main window controls"); - context->detachedVideo = 0; - context->stylingAssistant = 0; - context->stylesManager = 0; InitContents(); OPT_SUB("Video/Detached/Enabled", &FrameMain::OnVideoDetach, this, agi::signal::_1); diff --git a/aegisub/src/include/aegisub/context.h b/aegisub/src/include/aegisub/context.h index 16a871b2f..0bcce122f 100644 --- a/aegisub/src/include/aegisub/context.h +++ b/aegisub/src/include/aegisub/context.h @@ -3,6 +3,7 @@ class AudioBox; class AudioController; class AssDialogue; class AudioKaraoke; +class DialogAutomation; class DialogDetachedVideo; class DialogStyling; class DialogStyleManager; @@ -35,6 +36,7 @@ struct Context { // Views (i.e. things that should eventually not be here at all) AudioBox *audioBox; AudioKaraoke *karaoke; + DialogAutomation *automationManager; DialogDetachedVideo *detachedVideo; DialogStyling *stylingAssistant; DialogStyleManager *stylesManager;