From 725820efc067581e79037b032a20cfeddaa77ba2 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 31 Jan 2012 00:44:16 +0000 Subject: [PATCH] Add support for setting the active line from automation macros The macro processing function can now return a second value, which is the index of the line to make active, which must be one of the lines in the selection. If it is not, or if the value is not present, then the active line is left unchanged if it is in the new selection, or set to the first line of the new selection if it is not. Closes #1435. Originally committed to SVN as r6398. --- aegisub/src/auto4_lua.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/aegisub/src/auto4_lua.cpp b/aegisub/src/auto4_lua.cpp index a738a6ba5..310ec0e47 100644 --- a/aegisub/src/auto4_lua.cpp +++ b/aegisub/src/auto4_lua.cpp @@ -707,10 +707,23 @@ namespace Automation4 { lua_pushinteger(L, transform_selection(L, c)); try { - LuaThreadedCall(L, 3, 1, StrDisplay(c), c->parent, true); + LuaThreadedCall(L, 3, 2, StrDisplay(c), c->parent, true); subsobj->ProcessingComplete(StrDisplay(c)); + AssDialogue *active_line = 0; + int active_idx = 0; + + // Check for a new active row + if (lua_isnumber(L, -1)) { + active_idx = lua_tointeger(L, -1); + if (active_idx < 1 || active_idx > (int)c->ass->Line.size()) { + wxLogError("Active row %d is out of bounds (must be 1-%u)", active_idx, c->ass->Line.size()); + active_idx = 0; + } + } + lua_pop(L, 1); + // top of stack will be selected lines array, if any was returned if (lua_istable(L, -1)) { std::set sel; @@ -735,11 +748,15 @@ namespace Automation4 { sel.insert(diag); last_idx = cur; + if (!active_line || active_idx == cur) + active_line = diag; } lua_pop(L, 1); } c->selectionController->SetSelectedSet(sel); + if (active_line && (active_idx > 0 || !sel.count(c->selectionController->GetActiveLine()))) + c->selectionController->SetActiveLine(active_line); } } catch (agi::UserCancelException const&) {