Skip to content

Latest commit

 

History

History
39 lines (26 loc) · 1.17 KB

File metadata and controls

39 lines (26 loc) · 1.17 KB

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.

var workspace: WorkspaceDocument?

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

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

BranchPicker