Editors
To change how an outline looks or is organized, scripts address an Editor.
An element of the Document class, an instance of the Editor class is the entity that controls the display of the outline and its items. By addressing an editor, a script can select, expand, and collapse rows, as well as control the display of columns.
The current editor object is referenced as editor zero (0), meaning it is the first editor in the array of editors currently in use by open document windows. (see below)
Set Visibility of Columns | ||
01 | var editor = document.editors[0] | |
02 | var tree = document.outline | |
03 | editor.setVisibilityOfColumn(tree.outlineColumn,true) | |
04 | editor.setVisibilityOfColumn(tree.statusColumn,false) | |
05 | editor.setVisibilityOfColumn(tree.noteColumn,false) |
Editor Properties
Here are the properties of an instance of the Editor class:
focusedItems (Array of Items) • An array of references to the currently focused items.
foldingEnabled (boolean) • When set, cells with text that would layout over multiple lines only show their first line, followed by an ellipsis. Editing a cell that is folded, will temporarily expand it.
noteDisplay (NoteDisplay) • How the notes for each row are displayed, either together with their row when Inline is selected, or in a separate pane with Pane.
rootNode (TreeNode) • Returns a reference to the invisible root node of the Editor.
selectedNodes (Array of TreeNodes r/o) • Returns the list of selected TreeNodes, in the order they appear in the tree. This property is read-only. To select nodes, uses the select method of the Editor instance.
selection (Selection r/o) • Returns the current selection in the editor
Row Text Folding
An example script of setting the property of the current Editor for truncating the text of outline rows:
Row Text Folding | ||
01 | document.editors[0].foldingEnabled = true |
Nodes
In terms of an Editor, the individual items of the outline column are called nodes, and references to them are used with commands like the select() command that accepts an array of node references as the objects to select.
Select First Top-Level Item | ||
01 | var editor = document.editors[0] | |
02 | var node = editor.rootNode.children[0] | |
03 | editor.select([node]) |
Here’s how to leave active editing and deselect all rows:
Deselect the Editor | ||
01 | var editor = document.editors[0] | |
02 | editor.select([]) |
In the following example, the top-level items of the outline (children) are examined to determine the state of their corresponding status checkboxes. If selected, the item is expanded to reveal its descendants, otherwise the item is collapsed.
Expand|Collapse Rows based upon Status | ||
01 | var editor = document.editors[0] | |
02 | editor.rootNode.children.forEach(function(node){ | |
03 | var nodeState = node.valueForColumn(document.outline.statusColumn) | |
04 | if (nodeState === State.Checked){ | |
05 | node.expand() | |
06 | } else { | |
07 | node.collapse() | |
08 | } | |
09 | }) |
A useful feature of OmniOutliner is the ability to focus the outline display to only show specific items, temporarily hiding the other elements of the outline. Omni Automation scripts have the ability to focus and unfocuse the outline display.
As shown in the following example (line 4), a reference to a node’s corresponding item is the value of the node’s object property.
Focus Selected Items | ||
01 | function focusSelectedItems(){ | |
02 | var editor = document.editors[0] | |
03 | var nodes = editor.selectedNodes | |
04 | var items = nodes.map(function(node){return node.object}) | |
05 | editor.focusedItems = items | |
06 | } |
Unfocus | ||
01 | function unfocus(){ | |
02 | if (document.editors[0].focusedItems != []){ | |
03 | document.editors[0].focusedItems = [] | |
04 | } | |
05 | } |
And here is an example for focusing only the checked items:
Focus Checked Items | ||
01 | var editor = document.editors[0] | |
02 | var itemsToFocus = new Array() | |
03 | rootItem.descendants.forEach(function(item){ | |
04 | if(editor.nodeForItem(item).state === State.Checked){ | |
05 | itemsToFocus.push(item) | |
06 | } | |
07 | }) | |
08 | if(itemsToFocus.length > 0){editor.focusedItems = itemsToFocus} |
Editor Functions
Here are the methods used with an instance of the Editor class:
visibilityOfColumn(Column) (--> boolean) • Returns true if the specified Column is visible.
setVisibilityOfColumn(Column, boolean) • Sets the visibility of the specified Column within the Editor.
widthForColumn(Column) (--> Number) • Returns the width in points used to display the Column, assuming a zoom factor of 1.0.
setWidthForColumn(Column, Number) • Sets the width in points used to display the Column, assuming a zoom factor of 1.0.
sortOrderingForColumn(Column) (--> SortOrdering or nil) • Returns the current sort ordering in this editor for the specified Column, or null if no ordering is set.
setSortOrderingForColumn(Column, SortOrdering or nil) • Changes the sort ordering for the specified Column in this editor.
withoutSorting(Function) (--> Object or nil) • Temporarily disables any automatic sorting while running the passed in Function (which is invoked with zero arguments). The result of the function is returned.
summaryForColumn(Column) (--> Column.Summary or nil) • Returns the current Summary used to calculate cells value for parent items in the specified Column, or null if the values are directly editable.
setSummaryForColumn(Column, Column.Summary or nil) • Sets or clears the Summary used to calculate cells value for parent items.
beforeColumn(Column or nil) (--> EditorColumnPosition) • Returns an EditorColumnPosition that indicates the slot before the specified column, or before all columns if null is given.
afterColumn(Column or nil) (--> EditorColumnPosition) • Returns an EditorColumnPosition that indicates the slot after the specified column, or after all columns if null is given.
nodeForItem(Item) (--> TreeNode or nil) • Deprecated: Please use nodeForObject() instead. Returns the TreeNode that represents the item in this Editor, or null if it cannot be found (possibly filtered out, or not contained in the focusedItems).
nodesForItems(Items) (--> TreeNodes) • Deprecated: Please use nodeForObjects() instead. Returns an array of TreeNodes for the Items that are currently in the Editor’s filtered and focused view. The size of the resulting node array may be smaller (even empty) than the passed in items array.
nodeForObject(object:Object) (TreeNode or null) • Returns the TreeNode that represents the object in this Tree, or null if it cannot be found (possibly filtered out).
nodesForObjects(object:Array of Object) (Array of TreeNode) • Returns an array of TreeNodes for the objects that are currently in the Tree, according to the same filters as nodeForObject(). The size of the resulting node array may be smaller (even empty) than the passed in objects array.
reveal(TreeNodes) • Ensures the ancestor nodes of all the specified nodes are expanded.
select(TreeNodes, extendingBoolean or nil) • Selects the specified TreeNodes that are visible (nodes with collapsed ancestors cannot be selected). If extending is true, the existing selection is not cleared.
scrollToNode(TreeNode) • Attempts to scroll the view so that the specified TreeNode is visible. If the node is not revealed due to a collapsed ancestor, this may not be possible and no scrolling will be performed.
indentNodes(TreeNodes) • Indents the specified nodes one level, or throws an error if that isn’t possible.
outdentNodes(TreeNodes) • Outdents the specified nodes one level, or throws an error if that isn’t possible.
copyNodes(TreeNodes, Pasteboard) • Copies the listed nodes to the indicated pasteboard.
paste(Pasteboard, TreeNode, childIndex) • Inserts the nodes on the pasteboard into the outline.
Here’s how to convert an item (row) reference into a node reference:
Node for Item | ||
01 | var row = rootItem.children[0] | |
02 | var editor = document.editors[0] | |
03 | var node = editor.nodeForObject(row) |
Here’s an example script using the scrollToNode() method to scroll the outline document to the top:
Scroll to the Top | ||
01 | var editor = document.editors[0] | |
02 | editor.scrollToNode(editor.rootNode.children[0]) |
Here’s an example script using the outdentNodes() method to move the selected row to the top-level in the outline:
Move Selected Row to Top Level | ||
01 | var editor = document.editors[0] | |
02 | var node = editor.selectedNodes[0] | |
03 | while (node.level != 1){ | |
04 | editor.outdentNodes([node]) | |
05 | node = editor.selectedNodes[0] | |
06 | } |
Here’s a script that uses the visibilityOfColumn() method to derive references to the visible columns:
Get the Visible Columns | ||
01 | var editor = document.editors[0] | |
02 | var visibleColumns = columns.map(column => { | |
03 | if (editor.visibilityOfColumn(column)){return column} | |
04 | }) |
EditorColumnPosition
Instances of the EditorColumnPosition class are generated by using one of the following methods with an instance of the Editor class:
beforeColumn(Column or nil) (--> EditorColumnPosition) • Returns an instance of the EditorColumnPosition class that indicates the slot before the specified column, or before all columns if null is given.
afterColumn(Column or nil) (--> EditorColumnPosition) • Returns an instance of the EditorColumnPosition class that indicates the slot after the specified column, or after all columns if null is given.
Editor Column Position | ||
01 | pos = document.editors[0].afterColumn(document.outline.outlineColumn) |
The following example script uses the addColumn(…) function of the Column class to append a numeric column to the end of the outline. Also note that since a null value is entered rather than an instance of the EditorColumnPosition class for the parameter of the afterColumn(…) method, the new column is created after the last column.
Add Numeric Column to Outline | ||
01 | var tree = document.outline | |
02 | var editor = document.editors[0] | |
03 | var newCol = tree.addColumn( | |
04 | Column.Type.Number, | |
05 | editor.afterColumn(null), | |
06 | null | |
07 | ) | |
08 | newCol.title = 'Q2' | |
09 | editor.setSummaryForColumn(newCol, Column.Summary.Total) |
SortOrdering Properties
The properties of the SortOrdering class are used as the value for the sorting methods sortOrderingForColumn and setSortOrderingForColumn of the Editor class:
Ascending • Sort smaller numerical or lexigraphically preceding values first.
Descending • Sort larger numerical or lexigraphically later values first.
Sort Outline Column as Descending | ||
01 | var editor = document.editors[0] | |
02 | var column = document.outline.outlineColumn | |
03 | var sortStatus = editor.sortOrderingForColumn(column) | |
04 | if (sortStatus != SortOrdering.Descending){ | |
05 | editor.setSortOrderingForColumn(column, SortOrdering.Descending) | |
06 | } |
NoteDisplay Properties
The properties of the NoteDisplay class are used for the value of the noteDisplay property (note lowercase n) of the Editor class:
Inline • Display notes inline with the row.
Pane • Display notes in a separate pane.
Editors can be used to control the manner in which notes are displayed:
Set Note Display | ||
01 | var alert = new Alert("NOTES DISPLAY", "Display item notes inline or at the bottom of the pane?") | |
02 | alert.addOption("Inline") | |
03 | alert.addOption("Pane") | |
04 | alert.show(function(result){ | |
05 | if (result == 0){ | |
06 | document.editors[0].noteDisplay = NoteDisplay.Inline | |
07 | } else { | |
08 | document.editors[0].noteDisplay = NoteDisplay.Pane | |
09 | } | |
10 | }) |
Value for Column
Here’s a plug-in example that uses the valueForColumn(…) function to display the sum of the numeric columns of the selected row:
Display Sum of Numeric Columns of Selected Row | ||
01 | /*{ | |
02 | "type": "action", | |
03 | "targets": ["omnioutliner"], | |
04 | "author": "Otto Automator", | |
05 | "identifier": "com.omni-automation.oo.numeric-row-sum", | |
06 | "description": "Display the sum of the numeric values of the numeric columns of the selected row.", | |
07 | "label": "Sum of Selected Row", | |
08 | "shortLabel": "Row Sum" | |
09 | }*/ | |
10 | (() => { | |
11 | var action = new PlugIn.Action(function(selection, sender){ | |
12 | // action code | |
13 | // selection options: columns, document, editor, items, nodes, outline, styles | |
14 | ||
15 | var item = selection.items[0] | |
16 | var numericColumns = new Array() | |
17 | columns.forEach(col => { | |
18 | if (col.type === Column.Type.Number){numericColumns.push(col)} | |
19 | }) | |
20 | if (numericColumns.length != 0){ | |
21 | var total = Decimal.zero | |
22 | numericColumns.forEach(col => { | |
23 | total = total.add(item.valueForColumn(col)) | |
24 | }) | |
25 | new Alert("SUM: ", total.toString()).show() | |
26 | } else { | |
27 | message = "The selected row contains no numeric columns." | |
28 | new Alert("Missing Columns", message).show() | |
29 | } | |
30 | ||
31 | }); | |
32 | ||
33 | action.validate = function(selection, sender){ | |
34 | // validation code | |
35 | // selection options: columns, document, editor, items, nodes, outline, styles | |
36 | return (selection.items.length === 1) | |
37 | }; | |
38 | ||
39 | return action; | |
40 | })(); |
This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.