function OnInit(initData) { initData.name = 'SelectNext'; initData.version = '2023-03-02'; initData.url = 'https://resource.dopus.com/t/selectnext-select-the-next-n-items/43827'; initData.desc = 'SelectNext'; initData.default_enable = true; initData.min_version = '12.0'; } function OnAddCommands(addCmdData) { var cmd = addCmdData.AddCommand(); cmd.name = 'SelectNext'; cmd.method = 'OnSelectNext'; cmd.desc = 'Select the next n items in the source'; cmd.label = 'SelectNext'; cmd.template = 'numitems/n,nodeselect/s'; cmd.icon = 'script'; cmd.hide = false; } function OnSelectNext(scriptCmdData) { var cmd = scriptCmdData.func.command; var tab = scriptCmdData.func.sourcetab; var args = scriptCmdData.func.args; cmd.deselect = false; if (tab.all.count == 0) return; var k = args.numitems; if (typeof k != 'number' || k == 0) k = 15; // argument is missing, not a number, or zero? use default! var i = 0; cmd.ClearFiles(); if (k > 0) { if (tab.selected.count > 0) { var last = tab.selected(tab.selected.count - 1); i = tab.all.count - 1; while (last.name != tab.all(i).name) i--; i++; } if (i == tab.all.count) i = 0; while (i < tab.all.count && k > 0) { cmd.AddFile(tab.all(i)); i++; k--; } } else { if (tab.selected.count > 0) { var first = tab.selected(0); while (first.name != tab.all(i).name) i++; i--; } if (i < 0) i = tab.all.count - 1; while (i >= 0 && k < 0) { cmd.AddFile(tab.all(i)); i--; k++; } } if (!args.nodeselect) cmd.RunCommand('Select NONE'); cmd.RunCommand('Select FROMSCRIPT SETFOCUS'); cmd.RunCommand('Select SHOWFOCUS'); }