Add aegisub.project_properties()

Returns a table with all of the project metadata junk that used to be in
the script info section of the file.

Closes #1747.
This commit is contained in:
Thomas Goyne 2014-05-22 07:08:22 -07:00
parent 6a8958f287
commit aa21b3d77d
2 changed files with 34 additions and 5 deletions

View file

@ -267,6 +267,33 @@ namespace {
return 4; return 4;
} }
int project_properties(lua_State *L)
{
const agi::Context *c = get_context(L);
if (!c)
lua_pushnil(L);
else {
lua_createtable(L, 0, 14);
#define PUSH_FIELD(name) set_field(L, #name, c->ass->Properties.name)
PUSH_FIELD(automation_scripts);
PUSH_FIELD(export_filters);
PUSH_FIELD(export_encoding);
PUSH_FIELD(style_storage);
PUSH_FIELD(audio_file);
PUSH_FIELD(video_file);
PUSH_FIELD(timecodes_file);
PUSH_FIELD(keyframes_file);
PUSH_FIELD(video_zoom);
PUSH_FIELD(ar_value);
PUSH_FIELD(scroll_position);
PUSH_FIELD(active_row);
PUSH_FIELD(ar_mode);
PUSH_FIELD(video_position);
#undef PUSH_FIELD
}
return 1;
}
class LuaFeature { class LuaFeature {
int myid = 0; int myid = 0;
protected: protected:
@ -422,7 +449,7 @@ namespace {
// make "aegisub" table // make "aegisub" table
lua_pushstring(L, "aegisub"); lua_pushstring(L, "aegisub");
lua_createtable(L, 0, 12); lua_createtable(L, 0, 13);
set_field<LuaCommand::LuaRegister>(L, "register_macro"); set_field<LuaCommand::LuaRegister>(L, "register_macro");
set_field<LuaExportFilter::LuaRegister>(L, "register_filter"); set_field<LuaExportFilter::LuaRegister>(L, "register_filter");
@ -437,6 +464,7 @@ namespace {
set_field<clipboard_init>(L, "__init_clipboard"); set_field<clipboard_init>(L, "__init_clipboard");
set_field<get_file_name>(L, "file_name"); set_field<get_file_name>(L, "file_name");
set_field<get_translation>(L, "gettext"); set_field<get_translation>(L, "gettext");
set_field<project_properties>(L, "project_properties");
// store aegisub table to globals // store aegisub table to globals
lua_settable(L, LUA_GLOBALSINDEX); lua_settable(L, LUA_GLOBALSINDEX);

View file

@ -54,10 +54,6 @@ class SubsController {
agi::signal::Signal<agi::fs::path> FileOpen; agi::signal::Signal<agi::fs::path> FileOpen;
/// The file has been saved /// The file has been saved
agi::signal::Signal<> FileSave; agi::signal::Signal<> FileSave;
/// The file is about to be saved
/// This signal is intended for adding metadata which is awkward or
/// expensive to always keep up to date
agi::signal::Signal<> UpdateProperties;
/// The filename of the currently open file, if any /// The filename of the currently open file, if any
agi::fs::path filename; agi::fs::path filename;
@ -111,6 +107,11 @@ public:
/// Can the file be saved in its current format? /// Can the file be saved in its current format?
bool CanSave() const; bool CanSave() const;
/// The file is about to be saved
/// This signal is intended for adding metadata which is awkward or
/// expensive to always keep up to date
agi::signal::Signal<> UpdateProperties;
DEFINE_SIGNAL_ADDERS(FileOpen, AddFileOpenListener) DEFINE_SIGNAL_ADDERS(FileOpen, AddFileOpenListener)
DEFINE_SIGNAL_ADDERS(FileSave, AddFileSaveListener) DEFINE_SIGNAL_ADDERS(FileSave, AddFileSaveListener)