mirror of https://github.com/odrling/Aegisub
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:
parent
ab9e184009
commit
576f43249a
|
@ -211,10 +211,9 @@ namespace Automation4 {
|
||||||
|
|
||||||
// FeatureMacro
|
// FeatureMacro
|
||||||
|
|
||||||
FeatureMacro::FeatureMacro(const wxString &_name, const wxString &_description, MacroMenu _menu)
|
FeatureMacro::FeatureMacro(const wxString &_name, const wxString &_description)
|
||||||
: Feature(SCRIPTFEATURE_MACRO, _name)
|
: Feature(SCRIPTFEATURE_MACRO, _name)
|
||||||
, description(_description)
|
, description(_description)
|
||||||
, menu(_menu)
|
|
||||||
{
|
{
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
@ -224,11 +223,6 @@ namespace Automation4 {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
MacroMenu FeatureMacro::GetMenu() const
|
|
||||||
{
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// FeatureFilter
|
// FeatureFilter
|
||||||
|
|
||||||
|
@ -580,19 +574,18 @@ namespace Automation4 {
|
||||||
return scripts;
|
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) {
|
for (std::vector<Script*>::iterator i = scripts.begin(); i != scripts.end(); ++i) {
|
||||||
std::vector<Feature*> &sfs = (*i)->GetFeatures();
|
std::vector<Feature*> &sfs = (*i)->GetFeatures();
|
||||||
for (std::vector<Feature*>::iterator j = sfs.begin(); j != sfs.end(); ++j) {
|
for (std::vector<Feature*>::iterator j = sfs.begin(); j != sfs.end(); ++j) {
|
||||||
FeatureMacro *m = dynamic_cast<FeatureMacro*>(*j);
|
FeatureMacro *m = dynamic_cast<FeatureMacro*>(*j);
|
||||||
if (!m) continue;
|
if (!m) continue;
|
||||||
if (menu == MACROMENU_ALL || m->GetMenu() == menu)
|
macros.push_back(m);
|
||||||
macros[menu].push_back(m);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return macros[menu];
|
return macros;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -61,18 +61,6 @@ namespace Automation4 {
|
||||||
bool CalculateTextExtents(AssStyle *style, wxString &text, int &width, int &height, int &descent, int &extlead);
|
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...
|
// The class of a Feature...
|
||||||
enum ScriptFeatureClass {
|
enum ScriptFeatureClass {
|
||||||
SCRIPTFEATURE_MACRO = 0,
|
SCRIPTFEATURE_MACRO = 0,
|
||||||
|
@ -112,16 +100,14 @@ namespace Automation4 {
|
||||||
class FeatureMacro : public virtual Feature {
|
class FeatureMacro : public virtual Feature {
|
||||||
private:
|
private:
|
||||||
wxString description;
|
wxString description;
|
||||||
MacroMenu menu;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FeatureMacro(const wxString &_name, const wxString &_description, MacroMenu _menu);
|
FeatureMacro(const wxString &_name, const wxString &_description);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~FeatureMacro() { }
|
virtual ~FeatureMacro() { }
|
||||||
|
|
||||||
const wxString& GetDescription() const;
|
const wxString& GetDescription() const;
|
||||||
MacroMenu GetMenu() const;
|
|
||||||
|
|
||||||
virtual bool Validate(AssFile *subs, std::vector<int> &selected, int active) = 0;
|
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;
|
virtual void Process(AssFile *subs, std::vector<int> &selected, int active, wxWindow *progress_parent) = 0;
|
||||||
|
@ -304,7 +290,7 @@ namespace Automation4 {
|
||||||
private:
|
private:
|
||||||
std::vector<Script*> scripts;
|
std::vector<Script*> scripts;
|
||||||
|
|
||||||
std::vector<FeatureMacro*> macros[MACROMENU_MAX]; // array of vectors...
|
std::vector<FeatureMacro*> macros;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ScriptManager();
|
ScriptManager();
|
||||||
|
@ -315,7 +301,7 @@ namespace Automation4 {
|
||||||
|
|
||||||
const std::vector<Script*>& GetScripts() const;
|
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.
|
// No need to have getters for the other kinds of features, I think.
|
||||||
// They automatically register themselves in the relevant places.
|
// They automatically register themselves in the relevant places.
|
||||||
};
|
};
|
||||||
|
|
|
@ -503,41 +503,28 @@ namespace Automation4 {
|
||||||
{
|
{
|
||||||
wxString _name(lua_tostring(L, 1), wxConvUTF8);
|
wxString _name(lua_tostring(L, 1), wxConvUTF8);
|
||||||
wxString _description(lua_tostring(L, 2), 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;
|
LuaFeatureMacro *macro = new LuaFeatureMacro(_name, _description, L);
|
||||||
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);
|
|
||||||
|
|
||||||
return 0;
|
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)
|
: LuaFeature(_L, SCRIPTFEATURE_MACRO, _name)
|
||||||
, FeatureMacro(_name, _description, _menu)
|
, FeatureMacro(_name, _description)
|
||||||
, Feature(SCRIPTFEATURE_MACRO, _name)
|
, Feature(SCRIPTFEATURE_MACRO, _name)
|
||||||
{
|
{
|
||||||
// new table for containing the functions for this feature
|
// new table for containing the functions for this feature
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
// store processing function
|
// 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_pushstring(L, "The macro processing function must be a function");
|
||||||
lua_error(L);
|
lua_error(L);
|
||||||
}
|
}
|
||||||
lua_pushvalue(L, 4);
|
lua_pushvalue(L, 3);
|
||||||
lua_rawseti(L, -2, 1);
|
lua_rawseti(L, -2, 1);
|
||||||
// and validation function
|
// and validation function
|
||||||
lua_pushvalue(L, 5);
|
lua_pushvalue(L, 4);
|
||||||
no_validate = !lua_isfunction(L, -1);
|
no_validate = !lua_isfunction(L, -1);
|
||||||
lua_rawseti(L, -2, 2);
|
lua_rawseti(L, -2, 2);
|
||||||
// make the feature known
|
// make the feature known
|
||||||
|
|
|
@ -208,7 +208,7 @@ namespace Automation4 {
|
||||||
private:
|
private:
|
||||||
bool no_validate;
|
bool no_validate;
|
||||||
protected:
|
protected:
|
||||||
LuaFeatureMacro(const wxString &_name, const wxString &_description, MacroMenu _menu, lua_State *_L);
|
LuaFeatureMacro(const wxString &_name, const wxString &_description, lua_State *_L);
|
||||||
public:
|
public:
|
||||||
static int LuaRegister(lua_State *L);
|
static int LuaRegister(lua_State *L);
|
||||||
virtual ~LuaFeatureMacro() { }
|
virtual ~LuaFeatureMacro() { }
|
||||||
|
|
|
@ -490,8 +490,8 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
|
||||||
|
|
||||||
// Automation menu
|
// Automation menu
|
||||||
else if (curMenu == automationMenu) {
|
else if (curMenu == automationMenu) {
|
||||||
AddMacroMenuItems(automationMenu, wxGetApp().global_scripts->GetMacros(Automation4::MACROMENU_ALL));
|
AddMacroMenuItems(automationMenu, wxGetApp().global_scripts->GetMacros());
|
||||||
AddMacroMenuItems(automationMenu, local_scripts->GetMacros(Automation4::MACROMENU_ALL));
|
AddMacroMenuItems(automationMenu, local_scripts->GetMacros());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Thaw();
|
//Thaw();
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
-- Macro that adds \be1 tags in front of every selected line
|
-- Macro that adds \be1 tags in front of every selected line
|
||||||
|
|
||||||
script_name = "Add edgeblur macro"
|
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_author = "Niels Martin Hansen"
|
||||||
script_version = "1"
|
script_version = "1"
|
||||||
|
|
||||||
|
@ -16,4 +16,4 @@ function add_edgeblur(subtitles, selected_lines, active_line)
|
||||||
aegisub.set_undo_point("Add edgeblur")
|
aegisub.set_undo_point("Add edgeblur")
|
||||||
end
|
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)
|
||||||
|
|
|
@ -12,4 +12,4 @@ function macro_test1(subtitles, selected_lines, active_line)
|
||||||
aegisub.debug.out("Hello Automation 4 World!")
|
aegisub.debug.out("Hello Automation 4 World!")
|
||||||
end
|
end
|
||||||
|
|
||||||
aegisub.register_macro("Hello", "Shows a message", "tools", macro_test1)
|
aegisub.register_macro("Hello", "Shows a message", macro_test1)
|
|
@ -43,8 +43,8 @@ function inserttest(subtitles, selected_lines, active_line)
|
||||||
end
|
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)
|
|
@ -30,4 +30,4 @@ function karatest(subtitles, selected_lines, active_line)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
aegisub.register_macro("Karaoke fun", "Makes karaoke-like stuff", "edit", karatest, nil)
|
aegisub.register_macro("Karaoke fun", "Makes karaoke-like stuff", karatest, nil)
|
|
@ -37,4 +37,4 @@ function progression(subtitles, selected_lines, active_line)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
aegisub.register_macro("Progress fun", "Does absolutely nothing", "video", progression, nil)
|
aegisub.register_macro("Progress fun", "Does absolutely nothing", progression, nil)
|
|
@ -37,4 +37,4 @@ function test5(subtitles, selected_lines, active_line)
|
||||||
end
|
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)
|
|
@ -88,5 +88,5 @@ function export_config_dialog(subs, store)
|
||||||
end
|
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)
|
aegisub.register_filter("Export Config", "Test export filter config dialog stuff", 500, exporter, export_config_dialog)
|
|
@ -14,7 +14,6 @@ a new Macro Feature.
|
||||||
function aegisub.register_macro(
|
function aegisub.register_macro(
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
menu,
|
|
||||||
processing_function,
|
processing_function,
|
||||||
validation_function)
|
validation_function)
|
||||||
|
|
||||||
|
@ -25,15 +24,6 @@ function aegisub.register_macro(
|
||||||
A longer description of the function of this macro. This will appear
|
A longer description of the function of this macro. This will appear
|
||||||
on the status bar when hovering over the menu item.
|
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)
|
@processing_function (function)
|
||||||
The actual function called for the macro execution.
|
The actual function called for the macro execution.
|
||||||
This function must be an instance of the Macro Processing Function
|
This function must be an instance of the Macro Processing Function
|
||||||
|
|
Loading…
Reference in New Issue