]> gitweb.factorcode.org Git - factor.git/blob - basis/cocoa/touchbar/touchbar.factor
factor: Add newlines to every line.
[factor.git] / basis / cocoa / touchbar / touchbar.factor
1 ! Copyright (C) 2017 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.enums alien.syntax cocoa cocoa.classes
4 cocoa.messages combinators core-foundation.strings kernel locals
5 namespaces sequences words ;
6 IN: cocoa.touchbar
7
8 ! ui.backend.cocoa.views creates buttons for each of these actions
9 ENUM: default-touchbar refresh-all-action auto-use-action ;
10
11 : enum>CFStringArray ( seq -- alien )
12     enum>keys
13     NSArray -> alloc
14         swap <CFStringArray> -> initWithArray: ;
15
16 : make-touchbar ( enum self -- touchbar )
17     [ NSTouchBar -> alloc -> init dup ] dip -> setDelegate: {
18         [ swap enum>CFStringArray -> setDefaultItemIdentifiers: ]
19         [ swap enum>CFStringArray -> setCustomizationAllowedItemIdentifiers: ]
20         [ nip ]
21     } 2cleave ;
22
23 :: make-NSTouchBar-button ( self identifier label-string action-string -- button )
24     NSCustomTouchBarItem -> alloc
25         identifier <CFString> -> initWithIdentifier: :> item
26         NSButton
27             label-string <CFString>
28             self
29             action-string lookup-selector -> buttonWithTitle:target:action: :> button
30         item button -> setView:
31         item ;