0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Catalystでprimary paneのツールバーにアイテムを表示する

Last updated at Posted at 2021-01-09

NSToolbarDelegateで、WWDC20で追加されたばかりの新規APIを利用します。

以下のようにprimarySidebarTrackingSeparatorItemIdentifierを配置してください。そうすると、システムがそこをprimaryとsupplementary(もしくはsecondary)の境界線だと認識するので、適切にアイテムを配置してくれます。

この時、上記のidentifierに対してtoolbar(_:itemForItemIdentifier:willBeInsertedIntoToolbar:)では追加の記述は必要ありません。

extension ToolbarDelegate: NSToolbarDelegate {

    func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
        let identifiers: [NSToolbarItem.Identifier] = [
            .flexibleSpace,
            .itemPlacedInPrimary,
            .primarySidebarTrackingSeparatorItemIdentifier,
            .toggleSidebar,
            .flexibleSpace
        ]
        return identifiers
    }

    func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
        return toolbarDefaultItemIdentifiers(toolbar)
    }

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?