Hi and sorry, its me again.
Im struggeling with deselecting all items and then selecting another one from a script.
The following code gets called from a button in a row. The problem is that when the script is executed the deselect command does not work (i tested it successfully in the adhoc). Thus two files in different groups are selected and the GetNextGroup fails when going "forward" (actually giving the first selected file which will remain the same).
Am I missing a detail ?
function GroupNavigation(func, direction, collapseOthers)
{
var tab = func.sourcetab;
tab.Update();
var groups = tab.filegroups;
if(groups.count > 0)
{
var focusedItem = tab.GetFocusItem();
var containinigGroup = focusedItem.filegroup;
if(containinigGroup != null)
{
var groupIndex = GetGroupIndex(containinigGroup, groups);
if(groupIndex > -1)
{
var nextGroup = GetNextGroup(groups, groupIndex, direction);
var firstGroupItem = nextGroup.members(0); //GetNextGroup assures the group contains elements
Log("Navigating from group '" + containinigGroup + "' (" + groupIndex + ") to '" + nextGroup);// + "' (" + nextIndex + ")");
Log("focusing " +firstGroupItem);
var cmd = func.command;
cmd.RunCommand("SELECT FROMSCRIPT DESELECT");
cmd.Clear();
tab.Update();
cmd.AddFile(firstGroupItem);
//cmd.SetModifier("nodeselect");
cmd.RunCommand("Select FROMSCRIPT EXACT MAKEVISIBLE SETFOCUS");
//cmd.RunCommand("Select " + firstGroupItem + " EXACT MAKEVISIBLE SETFOCUS");
if(collapseOthers)
{
cmd.Clear();
cmd.ClearFailed();
cmd.ClearFiles();
cmd.AddLine("Go GROUPCOLLAPSE *");
cmd.AddLine("Go GROUPEXPAND " + nextGroup);
cmd.Run();
}
tab.Update();
}
}
}
}
function GetGroupIndex(group, groups)
{
var index = 0;
for (var groupEnum = new Enumerator(groups); !groupEnum.atEnd(); groupEnum.moveNext())
{
var groupItem = groupEnum.item();
if(groupItem.id === group.id)
return index;
index++;
}
return -1; // not found
}
function GetNextGroup(groups, currentIndex, navigationDirection)
{
var index = mod((currentIndex + navigationDirection), groups.count);
Log(index + " / " + groups.count);
var group = groups(index);
while(group.count == 0)
{
index = mod((index + navigationDirection), groups.count);
group = groups(index);
}
return group;
}