# Formatting
Class
## About
`Formatting` holds the editor's text-formatting commands, for menus and other application controls. Each `Editor` creates one when it is constructed; read it from the editor's read-only `Formatting` property. The commands follow the same rules as the toolbar and keyboard shortcuts: they act on the selected text while a node is being edited, on the selected nodes otherwise, and on the typing style when no text is selected.
```xojo
Function FormatBold() As Boolean Handles FormatBold.MenuItemSelected
Editor.Formatting.Toggle(GraffitiProEditor.Formatting.Styles.Bold)
Return True
End Function
Sub MenuBarSelected()
FormatBold.Enabled = Editor.Formatting.CanApply(GraffitiProEditor.Formatting.Styles.Bold)
FormatBold.HasCheckMark = Editor.Formatting.IsApplied(GraffitiProEditor.Formatting.Styles.Bold)
End Sub
```
- `Toggle`, `IsApplied`, and `CanApply` take a `Styles` value: bold, italic, underline, strikethrough, inline code, highlight, keyboard key, superscript, or subscript.
- `ClearFormatting` removes character formatting, and `EditLink` shows the link dialog.
- `Align` and `Alignment` set and read alignment the way the toolbar's Alignment menu does.
- Each command has a `Can` member that reports whether it would act. Nothing changes while the editor is `ReadOnly`, and `FontOptions` that disallow a style make `CanApply` False.
Each change is one undo step, through `Editor.History`. The editor does not handle menu-bar items itself; the demo project's `windowProEditor` connects its Format menu to these commands.
## Enumerations
| Name | Value | Description |
| --- | :---: | --- |
| Commands | Toggle = 0 <br > IsApplied = 1 <br > Clear = 2 <br > EditLink = 3 <br > Align = 4 <br > CurrentAlignment = 5 | (None) |
| Styles | Bold = 0 <br > Italic = 1 <br > Underline = 2 <br > Strikethrough = 3 <br > Code = 4 <br > Highlight = 5 <br > Keyboard = 6 <br > Superscript = 7 <br > Subscript = 8 | (None) |
## Delegates
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| CommandHandler | command As GraffitiProEditor . Formatting . Commands <br> argument As Integer <br> perform As Boolean) As Integer | command As GraffitiProEditor . Formatting . Commands, argument As Integer, perform As Boolean) As Integer | (None) |
## Methods
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| Align | value As GraffitiProEditor.Alignments | (None) | Aligns the selected nodes' text, or the nodes themselves where they draw no aligned text, or the document when nothing is selected, as the toolbar's Alignment menu does. Does nothing while the editor is read-only. |
| CanApply | style As GraffitiProEditor.Formatting.Styles | Boolean | Returns True when Toggle would change the supplied style: text that supports formatting is selected or being edited, the editor is not read-only, and FontOptions allow the style. |
| ClearFormatting | (None) | (None) | Removes character formatting from the selected text, or from the selected nodes. Does nothing while the editor is read-only. |
| EditLink | (None) | (None) | Shows the editor's link dialog for the selected text, as Command-K (Control-K elsewhere) does. Does nothing while the editor is read-only. |
| IsApplied | style As GraffitiProEditor.Formatting.Styles | Boolean | Returns whether the supplied style is on for the selected text, or for the typing style when no text is selected, as the toolbar's toggle buttons show it. |
| Toggle | style As GraffitiProEditor.Formatting.Styles | (None) | Turns the supplied style on or off for the selected text or nodes, or for the next typed text when no text is selected, as the keyboard shortcuts and toolbar buttons do. Superscript and subscript exclude each other. |
## Properties
| Name | Type | Default Value | Description |
| --- | :---: | :---: | --- |
| Alignment | GraffitiProEditor.Alignments | (None) | Returns the alignment Align would change: the selected node's text alignment, or its block alignment, or the document's alignment when nothing is selected. |
| CanAlign | Boolean | (None) | Returns True when Align would act: the editor is not read-only, and nothing is selected or a selected node can be aligned. |
| CanClearFormatting | Boolean | (None) | Returns True when ClearFormatting would act: text or nodes with formatting are selected and the editor is not read-only. |
| CanEditLink | Boolean | (None) | Returns True when EditLink would act: a node whose text supports formatting is selected and the editor is not read-only. |
| Owner | GraffitiProEditor.Editor | (None) | Returns the editor these commands belong to. |