/////////////////////////////////////////////////////////////////////////////// function OnInit(data){ data.name = "Command.GUI: ScrollSelectionIntoView"; data.desc = "Automatically scroll to selected items."; data.version = "1.1"; data.default_enable = true; data.copyright = "tbone in 2o14/o6"; var cmd = data.AddCommand(); cmd.name = "ScrollSelectionIntoView"; cmd.method = "ScrollSelectionIntoView"; cmd.desc = data.desc; cmd.label = "ScrollSelectionIntoView"; data.config.DebugOutput = false; data.config.PriorizeCheckboxSelection = false; } /////////////////////////////////////////////////////////////////////////////// function ScrollSelectionIntoView(data) { Debug("ScrollSelectionIntoView():"); var cmd = data.func.command; cmd.ClearFiles(); var wasCheckboxMode = (data.func.sourcetab.selstats.checkbox_mode==true); var isCheckboxMode = wasCheckboxMode; var priorizeCheckboxSelection = GetParameter(data, "PRIOCHECKBOXSELECTION", "PriorizeCheckboxSelection", false); if (wasCheckboxMode && (priorizeCheckboxSelection==false)){ //checkboxes active, regular selection has priority, Debug(" CheckboxMode detected, tmp. turning it off, to test for regular selection (has prio)"); isCheckboxMode = SwitchCheckboxMode( false, data.func); } var selectionFound = true; if (data.func.sourcetab.selected.count == 0){ Debug(" Nothing selected in "+(isCheckboxMode ? "CheckboxMode" : "RegularMode")); if (wasCheckboxMode){ Debug(" Turning checkboxes back on, to scroll for checkbox selections"); isCheckboxMode = SwitchCheckboxMode( true, data.func); if (data.func.sourcetab.selected.count == 0){ Debug(" Nothing selected in "+(isCheckboxMode ? "CheckboxMode" : "RegularMode")); selectionFound = false; } } else selectionFound = false; } else { Debug(" Selection found in "+(isCheckboxMode ? "CheckboxMode" : "RegularMode")); } if (!selectionFound){ Debug(" Aborting, nothing selected"); return true; } Debug(" Scrolling selected items into view for "+(isCheckboxMode ? "CheckboxMode" : "RegularMode")); var selectedItems = data.func.sourcetab.selected; cmd.AddLine('Select DESELECT *'); cmd.AddFiles(selectedItems); cmd.AddLine('Select MAKEVISIBLE EXACT FROMSCRIPT'); cmd.Run(); if (wasCheckboxMode && !isCheckboxMode){ Debug(" Turning checkboxes back on (because they were on)"); isCheckboxMode = SwitchCheckboxMode( true, data.func); } return true; } /////////////////////////////////////////////////////////////////////////////// function SwitchCheckboxMode( truefalse, func){ var targetState = "off"; if (truefalse) targetState = "on"; func.command.RunCommand('Set CheckboxMode='+targetState); func.command.Clear(); func.sourcetab.Update(); return func.sourcetab.selstats.checkbox_mode; } /////////////////////////////////////////////////////////////////////////////// function Debug(text){ if (Script.config.DebugOutput) DOpus.Output(text); } /////////////////////////////////////////////////////////////////////////////// function GetParameter( data, templateName, configName, defaultValue){ if (templateName && data.func.args.got_arg[templateName]) return data.func.args[templateName] if (configName && Script.config[configName]!=undefined){ switch(typeof(Script.config[configName])){ case "string": if(Script.config[configName]!=="") return Script.config[configName]; break; case "boolean": return Script.config[configName]; } } return defaultValue; }