Back to Codeedit

``CodeEdit/ToolbarBranchPicker``

Documentation.docc/CodeEditUI/ToolbarBranchPicker.md

0.3.61.2 KB
Original Source

CodeEdit/ToolbarBranchPicker

Overview

When the current project is a git repository, this will show the currently checked-out branch as a subtitle. Once a tap is registered, a popup will appear displaying the currently checked-out branch and all other local branches.

This view should be set to the view property in a NSToolbarItem.

Usage

First make sure a WorkspaceDocument is accessible in the context.

swift
var workspace: WorkspaceDocument?

Then in toolbar(_:itemForItemIdentifier:willBeInsertedIntoToolbar:), create a new NSToolbarItem:

swift
let toolbarItem = NSToolbarItem(itemIdentifier: /* Identifier */)

// create a NSHostingView
let view = BranchPickerToolbarItem(workspace?.workspaceClient)
let hostingView = NSHostingView(rootView: view)

// set the view property of the toolbar item
toolbarItem.view = hostingView

// return the toolbar item
return toolbarItem

Preview