Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toolbar customization #31

Closed
FahadAloraini opened this issue Jul 21, 2022 · 3 comments · Fixed by #36
Closed

toolbar customization #31

FahadAloraini opened this issue Jul 21, 2022 · 3 comments · Fixed by #36

Comments

@FahadAloraini
Copy link

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)

@stevengharris
Copy link
Owner

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

@stevengharris stevengharris linked a pull request Aug 3, 2022 that will close this issue
@stevengharris
Copy link
Owner

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.

@stevengharris
Copy link
Owner

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants