CHANGED AUTO4 API: Removed the option for selecting which menu to put a macro in, since it wasn't used.

Originally committed to SVN as r691.
This commit is contained in:
Niels Martin Hansen 2007-01-03 04:31:17 +00:00
parent ab9e184009
commit 576f43249a
14 changed files with 27 additions and 71 deletions

View file

@ -211,10 +211,9 @@ namespace Automation4 {
// FeatureMacro
FeatureMacro::FeatureMacro(const wxString &_name, const wxString &_description, MacroMenu _menu)
FeatureMacro::FeatureMacro(const wxString &_name, const wxString &_description)
: Feature(SCRIPTFEATURE_MACRO, _name)
, description(_description)
, menu(_menu)
{
// nothing to do
}
@ -224,11 +223,6 @@ namespace Automation4 {
return description;
}
MacroMenu FeatureMacro::GetMenu() const
{
return menu;
}
// FeatureFilter
@ -580,19 +574,18 @@ namespace Automation4 {
return scripts;
}
const std::vector<FeatureMacro*>& ScriptManager::GetMacros(MacroMenu menu)
const std::vector<FeatureMacro*>& ScriptManager::GetMacros()
{
macros[menu].clear();
macros.clear();
for (std::vector<Script*>::iterator i = scripts.begin(); i != scripts.end(); ++i) {
std::vector<Feature*> &sfs = (*i)->GetFeatures();
for (std::vector<Feature*>::iterator j = sfs.begin(); j != sfs.end(); ++j) {
FeatureMacro *m = dynamic_cast<FeatureMacro*>(*j);
if (!m) continue;
if (menu == MACROMENU_ALL || m->GetMenu() == menu)
macros[menu].push_back(m);
macros.push_back(m);
}
}
return macros[menu];
return macros;
}

View file

@ -61,18 +61,6 @@ namespace Automation4 {
bool CalculateTextExtents(AssStyle *style, wxString &text, int &width, int &height, int &descent, int &extlead);
// The top-level menus a macro can appear in
enum MacroMenu {
MACROMENU_NONE = 0, // pseudo-index, dunno if this has any real meaning
MACROMENU_ALL = 0, // pseudo-index, used to retrieve information about all macros loaded
MACROMENU_EDIT,
MACROMENU_VIDEO,
MACROMENU_AUDIO,
MACROMENU_TOOLS,
MACROMENU_RIGHT, // right-click menu
MACROMENU_MAX // must be last, one higher than the last, used for array sizing
};
// The class of a Feature...
enum ScriptFeatureClass {
SCRIPTFEATURE_MACRO = 0,
@ -112,16 +100,14 @@ namespace Automation4 {
class FeatureMacro : public virtual Feature {
private:
wxString description;
MacroMenu menu;
protected:
FeatureMacro(const wxString &_name, const wxString &_description, MacroMenu _menu);
FeatureMacro(const wxString &_name, const wxString &_description);
public:
virtual ~FeatureMacro() { }
const wxString& GetDescription() const;
MacroMenu GetMenu() const;
virtual bool Validate(AssFile *subs, std::vector<int> &selected, int active) = 0;
virtual void Process(AssFile *subs, std::vector<int> &selected, int active, wxWindow *progress_parent) = 0;
@ -304,7 +290,7 @@ namespace Automation4 {
private:
std::vector<Script*> scripts;
std::vector<FeatureMacro*> macros[MACROMENU_MAX]; // array of vectors...
std::vector<FeatureMacro*> macros;
public:
ScriptManager();
@ -315,7 +301,7 @@ namespace Automation4 {
const std::vector<Script*>& GetScripts() const;
const std::vector<FeatureMacro*>& GetMacros(MacroMenu menu);
const std::vector<FeatureMacro*>& GetMacros();
// No need to have getters for the other kinds of features, I think.
// They automatically register themselves in the relevant places.
};

View file

@ -503,41 +503,28 @@ namespace Automation4 {
{
wxString _name(lua_tostring(L, 1), wxConvUTF8);
wxString _description(lua_tostring(L, 2), wxConvUTF8);
const char *_menustring = lua_tostring(L, 3);
MacroMenu _menu = MACROMENU_NONE;
if (strcmp(_menustring, "edit") == 0) _menu = MACROMENU_EDIT;
else if (strcmp(_menustring, "video") == 0) _menu = MACROMENU_VIDEO;
else if (strcmp(_menustring, "audio") == 0) _menu = MACROMENU_AUDIO;
else if (strcmp(_menustring, "tools") == 0) _menu = MACROMENU_TOOLS;
else if (strcmp(_menustring, "right") == 0) _menu = MACROMENU_RIGHT;
if (_menu == MACROMENU_NONE) {
lua_pushstring(L, "Error registering macro: Invalid menu name.");
lua_error(L);
}
LuaFeatureMacro *macro = new LuaFeatureMacro(_name, _description, _menu, L);
LuaFeatureMacro *macro = new LuaFeatureMacro(_name, _description, L);
return 0;
}
LuaFeatureMacro::LuaFeatureMacro(const wxString &_name, const wxString &_description, MacroMenu _menu, lua_State *_L)
LuaFeatureMacro::LuaFeatureMacro(const wxString &_name, const wxString &_description, lua_State *_L)
: LuaFeature(_L, SCRIPTFEATURE_MACRO, _name)
, FeatureMacro(_name, _description, _menu)
, FeatureMacro(_name, _description)
, Feature(SCRIPTFEATURE_MACRO, _name)
{
// new table for containing the functions for this feature
lua_newtable(L);
// store processing function
if (!lua_isfunction(L, 4)) {
if (!lua_isfunction(L, 3)) {
lua_pushstring(L, "The macro processing function must be a function");
lua_error(L);
}
lua_pushvalue(L, 4);
lua_pushvalue(L, 3);
lua_rawseti(L, -2, 1);
// and validation function
lua_pushvalue(L, 5);
lua_pushvalue(L, 4);
no_validate = !lua_isfunction(L, -1);
lua_rawseti(L, -2, 2);
// make the feature known

View file

@ -208,7 +208,7 @@ namespace Automation4 {
private:
bool no_validate;
protected:
LuaFeatureMacro(const wxString &_name, const wxString &_description, MacroMenu _menu, lua_State *_L);
LuaFeatureMacro(const wxString &_name, const wxString &_description, lua_State *_L);
public:
static int LuaRegister(lua_State *L);
virtual ~LuaFeatureMacro() { }

View file

@ -490,8 +490,8 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
// Automation menu
else if (curMenu == automationMenu) {
AddMacroMenuItems(automationMenu, wxGetApp().global_scripts->GetMacros(Automation4::MACROMENU_ALL));
AddMacroMenuItems(automationMenu, local_scripts->GetMacros(Automation4::MACROMENU_ALL));
AddMacroMenuItems(automationMenu, wxGetApp().global_scripts->GetMacros());
AddMacroMenuItems(automationMenu, local_scripts->GetMacros());
}
//Thaw();

View file

@ -2,7 +2,7 @@
-- Macro that adds \be1 tags in front of every selected line
script_name = "Add edgeblur macro"
script_description = "A testmacro showing how to do simple line modification in Automation 4"
script_description = "A demo macro showing how to do simple line modification in Automation 4"
script_author = "Niels Martin Hansen"
script_version = "1"
@ -16,4 +16,4 @@ function add_edgeblur(subtitles, selected_lines, active_line)
aegisub.set_undo_point("Add edgeblur")
end
aegisub.register_macro("Add edgeblur", "Adds \be1 tags to all selected lines", "edit", add_edgeblur)
aegisub.register_macro("Add edgeblur", "Adds \be1 tags to all selected lines", add_edgeblur)

View file

@ -12,4 +12,4 @@ function macro_test1(subtitles, selected_lines, active_line)
aegisub.debug.out("Hello Automation 4 World!")
end
aegisub.register_macro("Hello", "Shows a message", "tools", macro_test1)
aegisub.register_macro("Hello", "Shows a message", macro_test1)

View file

@ -43,8 +43,8 @@ function inserttest(subtitles, selected_lines, active_line)
end
aegisub.register_macro("File line count", "Count the number of lines in the ASS file", "tools", macro_test2, nil)
aegisub.register_macro("File line count", "Count the number of lines in the ASS file", macro_test2, nil)
aegisub.register_macro("Dump", "Dumps info on every line in the file", "tools", dumper, nil)
aegisub.register_macro("Dump", "Dumps info on every line in the file", dumper, nil)
aegisub.register_macro("Insert stuff", "Inserts some lines near the active line", "edit", inserttest, nil)
aegisub.register_macro("Insert stuff", "Inserts some lines near the active line", inserttest, nil)

View file

@ -30,4 +30,4 @@ function karatest(subtitles, selected_lines, active_line)
end
aegisub.register_macro("Karaoke fun", "Makes karaoke-like stuff", "edit", karatest, nil)
aegisub.register_macro("Karaoke fun", "Makes karaoke-like stuff", karatest, nil)

View file

@ -37,4 +37,4 @@ function progression(subtitles, selected_lines, active_line)
end
aegisub.register_macro("Progress fun", "Does absolutely nothing", "video", progression, nil)
aegisub.register_macro("Progress fun", "Does absolutely nothing", progression, nil)

View file

@ -37,4 +37,4 @@ function test5(subtitles, selected_lines, active_line)
end
aegisub.register_macro("More karaoke fun", "Makes some more karaoke-like stuff", "tools", test5, nil)
aegisub.register_macro("More karaoke fun", "Makes some more karaoke-like stuff", test5, nil)

View file

@ -88,5 +88,5 @@ function export_config_dialog(subs, store)
end
aegisub.register_macro("Config Dialog 1", "Show a stupid config dialog", "video", test7, nil)
aegisub.register_macro("Config Dialog 1", "Show a stupid config dialog", test7, nil)
aegisub.register_filter("Export Config", "Test export filter config dialog stuff", 500, exporter, export_config_dialog)

View file

@ -14,7 +14,6 @@ a new Macro Feature.
function aegisub.register_macro(
name,
description,
menu,
processing_function,
validation_function)
@ -25,15 +24,6 @@ function aegisub.register_macro(
A longer description of the function of this macro. This will appear
on the status bar when hovering over the menu item.
@menu (string)
The menu this macro will appear in. Must be one of:
o "edit"
o "video"
o "audio"
o "tools"
o "right" (the subtitles grid right-click menu)
The menu chosen should be relevant to the function of the macro.
@processing_function (function)
The actual function called for the macro execution.
This function must be an instance of the Macro Processing Function