stevengharris / MarkupEditor

WYSIWYG editing for SwiftUI and UIKit apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

toolbar customization

FahadAloraini opened this issue · comments

you should be able to customize the toolbar by being able to remove any of the toolbars (ex. if you want to remove the InsertToolbar )
and if you want to remove some of the features in a toolbar (ex.remove the underline in the FormatToolbar)

Yes, you are right. I will see if I can take care of this before the Beta.

I added a section to the README discussing it:

Customizing Toolbar Contents

You can customize toolbars by eliminating them and/or subsetting their contents. Here is an example that eliminates the CorrectionToolbar (that holds the Undo and Redo buttons) and only includes Bold, Italic, and Underline as formats in the FormatToolbar. As discussed below the default for allowLocalImages is false for several reasons. If you use customized ToolbarContents, then you need to specify allowLocalImages directly in ImageContents to override the default.

let myToolbarContents = ToolbarContents(
    correction: false,
    formatContents: FormatContents(code: false, strike: false, subSuper: false),
    imageContents: ImageContents(allowLocalImages: true)
)
markupEnv.toolbarPreference.contents = myToolbarContents

You would typically be doing this kind of customization in your SceneDelegate, which is where you can find a commented-out example of how to do it in the demos.

FYI, in doing the work to sync menu item enable/disable properly using ToolbarContents, I needed to change the suggested way to customize ToolbarContents just a bit. Specifically, it needs to be done earlier in the lifecycle because the menu is set up early. So, I updated the README and the demos accordingly:

Customizing Toolbar Contents

You can customize toolbars by eliminating them and/or subsetting their contents. You do this by creating a new instance of ToolbarContents and assigning it to ToolbarContents.custom. The MarkupMenu also uses the ToolbarContents to customize what it holds, so it's important to have set ToolbarContents.custom before creating the MarkupMenu. An easy way to do that is to set it up in your AppDelegate by overriding init(). Here is an example that eliminates the CorrectionToolbar (that holds the Undo and Redo buttons) and InsertToolbar, and only includes Bold, Italic, and Underline as formats in the FormatToolbar.

override init() {
    let myToolbarContents = ToolbarContents(
        correction: false,  // No undo/redo buttons, but will still show up in Edit menu
        insert: false,      // Eliminate the entire InsertToolbar
        // Remove code, strikethrough, subscript, and superscript as formatting options
        formatContents: FormatContents(code: false, strike: false, subSuper: false)
    )
    ToolbarContents.custom = myToolbarContents
}