forked from mia/Aegisub
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.
This commit is contained in:
parent
dad803e956
commit
725820efc0
1 changed files with 18 additions and 1 deletions
|
@ -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<AssDialogue*> 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&) {
|
||||
|
|
Loading…
Reference in a new issue