Level Styles

Donec ullamcorper nulla non metus auctor fringilla. Nullam quis risus eget urna mollis ornare vel eu leo. Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit sit amet non magna. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

The levelStyles Property

The value of the levelStyles property of the Outline class is an array of the styles used by default for Items at different nesting levels in the document. The length of this array will be the larger of the currently defined number of level styles or the maximum nesting level of Items in the Outline.

document.outline.levelStyles.length
DO THIS ►

Enter and run the example script in the Console window.

console-level-styles-01

Because our outline currently has two levels of data (planets and moons), the result of the script execution will be the integer: 2

Note that since no level styles have yet been defined, the style attributes base style are in effect.

DO THIS ►

Reveal the Inspector sidebar by pressing the Inspector button in the toolbar. Press the Document > Edit Styles tabs, and all of the document styles, including the two level styles, will be listed.

level-styles-sidebar

Editing a Level Style

To edit a level style, use the levelStyle(…) method which returns a reference to the level style for the specified nesting level, possibly extending the levelStyles array.

Let’s use this method to change some of the style attributes of the top-level level style. Note that since JavaScript indexes arrays beginning with zero (0), the first level style will be: levelStyle(0)

style0 = document.outline.levelStyle(0) style0.set(Style.Attribute.FontSize,24) style0.set(Style.Attribute.FontFamily,'Chalkboard SE')
omnioutliner:///omnijs-run?script=style0%20%3D%20document%2Eoutline%2ElevelStyle%280%29%0Astyle0%2Eset%28Style%2EAttribute%2EFontSize%2C24%29%0Astyle0%2Eset%28Style%2EAttribute%2EFontFamily%2C%27Chalkboard%20SE%27%29
DO THIS ►

Enter and run the example script in the Console window.

Set Level 1 Style

The indicated styling will be applied to the top-level rows. Reveal the sidebar and inspector panels, and select the Level 1 style to see the applied results:

console-level-styles-02

As we just did, let’s use the levelStyle() method to change some of the style attributes of the second-level level style. Note that since JavaScript indexes arrays beginning with zero (0), the second level style will be: levelStyle(1)

style1 = document.outline.levelStyle(1) style1.set(Style.Attribute.FontSize,18) style1.set(Style.Attribute.FontFamily,'Times New Roman')
omnioutliner:///omnijs-run?script=style1%20%3D%20document%2Eoutline%2ElevelStyle%281%29%0Astyle1%2Eset%28Style%2EAttribute%2EFontSize%2C18%29%0Astyle1%2Eset%28Style%2EAttribute%2EFontFamily%2C%27Times%20New%20Roman%27%29
DO THIS ►

Enter and run the example script in the Console window.

console-level-styles-03

The indicated styling will be applied to the second-level rows.

Expand and Focus

Let’s optimize the display of the outline to fully show the items we specify.

DO THIS ►

Starting with Mercury, check every other planet in the outline.

document-with-sidebars
DO THIS ►

Execute the following script to expand all rows.

nodes = document.editors[0].rootNode.children nodes.forEach(function(node){ if(node.canExpand){node.expand(true)} })
omnioutliner:///omnijs-run?script=nodes%20%3D%20document%2Eeditors%5B0%5D%2ErootNode%2Echildren%0Anodes%2EforEach%28function%28node%29%7B%0A%09if%28node%2EcanExpand%29%7Bnode%2Eexpand%28true%29%7D%0A%7D%29
Expand all rows
DO THIS ►

To consolidate item display, execute the following script to focus only the checked rows.

editor = document.editors[0] checkColumn = document.outline.statusColumn checkedItems = new Array() editor.rootNode.children.forEach( function(node){ state = node.valueForColumn(checkColumn) if (state === State.Checked){ checkedItems.push(node.object) } } ) editor.focusedItems = checkedItems
omnioutliner:///omnijs-run?script=editor%20%3D%20document%2Eeditors%5B0%5D%0AcheckColumn%20%3D%20document%2Eoutline%2EstatusColumn%0AcheckedItems%20%3D%20new%20Array%28%29%0Aeditor%2ErootNode%2Echildren%2EforEach%28%0A%09function%28node%29%7B%0A%09%09state%20%3D%20node%2EvalueForColumn%28checkColumn%29%0A%09%09if%20%28state%20%3D%3D%3D%20State%2EChecked%29%7B%0A%09%09%09checkedItems%2Epush%28node%2Eobject%29%0A%09%09%7D%0A%09%7D%0A%29%0Aeditor%2EfocusedItems%20%3D%20checkedItems

The result is a focused list of the checked items, with specific styling applied to both the top and secondary levels:

final-document-window

What’s Next?

In the next section we’ll review what you’ve learned in this tutorial.

UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.

DISCLAIMER