Clean up Automation4::ScriptManager

Originally committed to SVN as r5642.
This commit is contained in:
Thomas Goyne 2011-09-28 19:48:58 +00:00
parent eec3d64221
commit 8ba559b7f7
2 changed files with 28 additions and 92 deletions

View File

@ -355,76 +355,31 @@ namespace Automation4 {
}
// ScriptManager
/// @brief DOCME
///
ScriptManager::ScriptManager()
{
// do nothing...?
}
/// @brief DOCME
///
ScriptManager::~ScriptManager()
{
RemoveAll();
}
/// @brief DOCME
/// @param script
/// @return
///
void ScriptManager::Add(Script *script)
{
for (std::vector<Script*>::iterator i = scripts.begin(); i != scripts.end(); ++i) {
if (script == *i) return;
}
scripts.push_back(script);
if (find(scripts.begin(), scripts.end(), script) == scripts.end())
scripts.push_back(script);
}
/// @brief DOCME
/// @param script
/// @return
///
void ScriptManager::Remove(Script *script)
{
for (std::vector<Script*>::iterator i = scripts.begin(); i != scripts.end(); ++i) {
if (script == *i) {
delete *i;
scripts.erase(i);
return;
}
std::vector<Script*>::iterator i = find(scripts.begin(), scripts.end(), script);
if (i != scripts.end()) {
delete *i;
scripts.erase(i);
}
}
/// @brief DOCME
///
void ScriptManager::RemoveAll()
{
for (std::vector<Script*>::iterator i = scripts.begin(); i != scripts.end(); ++i) {
delete *i;
}
scripts.clear();
delete_clear(scripts);
}
/// @brief DOCME
/// @return
///
const std::vector<Script*>& ScriptManager::GetScripts() const
{
return scripts;
}
/// @brief DOCME
/// @return
///
const std::vector<cmd::Command*>& ScriptManager::GetMacros()
{
macros.clear();
@ -437,20 +392,12 @@ namespace Automation4 {
// AutoloadScriptManager
/// @brief DOCME
/// @param _path
///
AutoloadScriptManager::AutoloadScriptManager(const wxString &_path)
: path(_path)
AutoloadScriptManager::AutoloadScriptManager(wxString const& path)
: path(path)
{
Reload();
}
/// @brief DOCME
///
void AutoloadScriptManager::Reload()
{
RemoveAll();
@ -496,7 +443,8 @@ namespace Automation4 {
slots.push_back(c->ass->AddFileOpenListener(&LocalScriptManager::Reload, this));
}
void LocalScriptManager::Reload() {
void LocalScriptManager::Reload()
{
RemoveAll();
wxString local_scripts = context->ass->GetScriptInfo("Automation Scripts");
@ -525,7 +473,6 @@ namespace Automation4 {
wxFileName sfname(trimmed);
sfname.MakeAbsolute(basepath);
if (sfname.FileExists()) {
wxString err;
Add(Automation4::ScriptFactory::CreateFromFile(sfname.GetFullPath(), true));
} else {
wxLogWarning("Automation Script referenced could not be found.\nFilename specified: %c%s\nSearched relative to: %s\nResolved filename: %s",
@ -534,7 +481,8 @@ namespace Automation4 {
}
}
void LocalScriptManager::OnSubtitlesSave() {
void LocalScriptManager::OnSubtitlesSave()
{
// Store Automation script data
// Algorithm:
// 1. If script filename has Automation Base Path as a prefix, the path is relative to that (ie. "$")
@ -614,6 +562,7 @@ namespace Automation4 {
if (log_errors)
wxLogError(_("The file was not recognised as an Automation script: %s"), filename);
return new UnknownScript(filename);
}
@ -661,7 +610,6 @@ namespace Automation4 {
return fnfilter;
}
// UnknownScript
UnknownScript::UnknownScript(wxString const& filename)
: Script(filename)

View File

@ -217,30 +217,25 @@ namespace Automation4 {
virtual std::vector<SubtitleFormat*> GetFormats() const=0;
};
/// DOCME
/// @class ScriptManager
/// @brief DOCME
///
/// DOCME
/// A manager of loaded automation scripts
class ScriptManager {
private:
/// DOCME
std::vector<Script*> scripts;
/// DOCME
std::vector<cmd::Command*> macros;
public:
ScriptManager();
virtual ~ScriptManager(); // Deletes all scripts managed
void Add(Script *script); // Add a script to the manager. The ScriptManager takes owvership of the script and will automatically delete it.
void Remove(Script *script); // Remove a script from the manager, and delete the Script object.
void RemoveAll(); // Deletes all scripts managed
/// Deletes all scripts managed
virtual ~ScriptManager();
/// Add a script to the manager. The ScriptManager takes ownership of the script and will automatically delete it.
void Add(Script *script);
/// Remove a script from the manager, and delete the Script object.
void Remove(Script *script);
/// Deletes all scripts managed
void RemoveAll();
/// Reload all scripts mananaged
virtual void Reload() = 0;
const std::vector<Script*>& GetScripts() const;
/// Get all managed scripts (both loaded and invalid)
const std::vector<Script*>& GetScripts() const { return scripts; }
const std::vector<cmd::Command*>& GetMacros();
// No need to have getters for the other kinds of features, I think.
@ -258,18 +253,11 @@ namespace Automation4 {
void Reload();
};
/// DOCME
/// @class AutoloadScriptManager
/// @brief DOCME
///
/// DOCME
/// Manager for scripts in the autoload directory
class AutoloadScriptManager : public ScriptManager {
private:
/// DOCME
wxString path;
public:
AutoloadScriptManager(const wxString &_path);
AutoloadScriptManager(wxString const& path);
void Reload();
};