OO-PG0018
Plug-In: Expand Rows to Level
Expands rows up to and including the level chosen by the user.
Return to: OmniOutliner Plug-In Collection
Expand Rows to Level
/*{"type": "action","targets": ["omnioutliner"],"author": "Otto Automator","identifier": "com.omni-automation.oo.expand-rows-to-level","version": "1.0","description": "Expands rows up to and including the level chosen by the user.","label": "Expand Rows to Level","shortLabel": "Expand to Level","paletteLabel": "Expand to Level","image": "square.3.layers.3d"}*/(() => {const action = new PlugIn.Action(async function(selection, sender){try {editor = document.editors[0]tree = document.outlinelvlStyles = document.outline.levelStyleslevelIndexes = Array(lvlStyles.length).fill().map((element, index) => index + 1)levelTitles = levelIndexes.map(String)levelsMenu = new Form.Field.Option("levelIndex",null,levelIndexes,levelTitles,1)inputForm = new Form()inputForm.addField(levelsMenu)formPrompt = "Expand rows up to and including level:"buttonTitle = "Continue"formObject = await inputForm.show(formPrompt, buttonTitle)levelIndex = formObject.values["levelIndex"]rootItem.apply(item => {itemLevel = item.levelconsole.log("ITEM LEVEL:", itemLevel)if(itemLevel !== 0){node = editor.nodeForObject(item)if (itemLevel >= levelIndex){if(node.canCollapse){node.collapse()}}if (itemLevel < levelIndex){if(node.canExpand){node.expand()}}}})}catch(err){if(!causedByUserCancelling){new Alert(err.name, err.message).show()}}});action.validate = function(selection, sender){return true};return action;})();