]> gitweb.factorcode.org Git - factor.git/commitdiff
cocoa: Add basic support for TouchBar.
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 30 May 2017 17:09:02 +0000 (12:09 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 30 May 2017 20:33:48 +0000 (15:33 -0500)
basis/alien/enums/enums.factor
basis/cocoa/cocoa.factor
basis/cocoa/touchbar/touchbar.factor [new file with mode: 0644]
basis/ui/backend/cocoa/views/views.factor

index 10ca2ba07008a0a209590b8a46609aa12d036880..6b7b66ce5b16397f148d091b2458afbd65d05436 100644 (file)
@@ -55,3 +55,9 @@ PRIVATE>
 
 PREDICATE: enum-c-type-word < c-type-word
     "c-type" word-prop enum-c-type? ;
+
+: enum>values ( enum -- seq )
+    "c-type" word-prop members>> values ;
+
+: enum>keys ( enum -- seq )
+    "c-type" word-prop members>> keys [ name>> ] map ;
\ No newline at end of file
index 222301e5ffebe65123ea0f2daaff7a49fe66bac3..9fa68ff900c4dfc713e1d2c19bae8db24622f084 100644 (file)
@@ -51,6 +51,7 @@ SYNTAX: IMPORT: scan-token [ ] import-objc-class ;
         "NSBundle"
         "NSButton"
         "NSColorSpace"
+        "NSCustomTouchBarItem"
         "NSData"
         "NSDictionary"
         "NSError"
diff --git a/basis/cocoa/touchbar/touchbar.factor b/basis/cocoa/touchbar/touchbar.factor
new file mode 100644 (file)
index 0000000..a5d5be2
--- /dev/null
@@ -0,0 +1,31 @@
+! Copyright (C) 2017 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors alien.enums alien.syntax cocoa cocoa.classes
+cocoa.messages combinators core-foundation.strings kernel locals
+namespaces sequences words ;
+IN: cocoa.touchbar
+
+! ui.backend.cocoa.views creates buttons for each of these actions
+ENUM: default-touchbar refresh-all-action auto-use-action ;
+
+: enum>CFStringArray ( seq -- alien )
+    enum>keys
+    NSArray -> alloc
+        swap <CFStringArray> -> initWithArray: ;
+
+: make-touchbar ( enum self -- touchbar )
+    [ NSTouchBar -> alloc -> init dup ] dip -> setDelegate: {
+        [ swap enum>CFStringArray -> setDefaultItemIdentifiers: ]
+        [ swap enum>CFStringArray -> setCustomizationAllowedItemIdentifiers: ]
+        [ nip ]
+    } 2cleave ;
+
+:: make-NSTouchBar-button ( self identifier label-string action-string -- button )
+    NSCustomTouchBarItem -> alloc
+        identifier <CFString> -> initWithIdentifier: :> item
+        NSButton
+            label-string <CFString>
+            self
+            action-string lookup-selector -> buttonWithTitle:target:action: :> button
+        item button -> setView:
+        item ;
\ No newline at end of file
index b4c594f7fc0b7a677069efd2fc7c012c36e4a27a..a854e3fe57a53a8be96bdf1558c67ca0978c7d7f 100644 (file)
@@ -2,12 +2,13 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.c-types alien.data alien.strings
 arrays assocs cocoa cocoa.application cocoa.classes
-cocoa.pasteboard cocoa.runtime cocoa.subclassing cocoa.types
-cocoa.views combinators core-foundation.strings core-graphics
-core-graphics.types core-text io.encodings.utf8 kernel literals
-locals math math.rectangles namespaces opengl sequences threads
-ui.gadgets ui.gadgets.private ui.gadgets.worlds ui.gestures
-ui.private unicode ;
+cocoa.pasteboard cocoa.runtime cocoa.subclassing cocoa.touchbar
+cocoa.types cocoa.views combinators core-foundation.strings
+core-graphics core-graphics.types core-text io.encodings.utf8
+kernel literals locals math math.rectangles namespaces opengl
+sequences threads ui.gadgets ui.gadgets.private
+ui.gadgets.worlds ui.gestures ui.private ui.tools.listener
+vocabs.refresh ;
 IN: ui.backend.cocoa.views
 
 : send-mouse-moved ( view event -- )
@@ -183,6 +184,29 @@ CLASS: FactorView < NSOpenGLView
         ] when
     ] ;
 
+    METHOD: void refreshAllAction [
+        [ refresh-all ] \ refresh-all call-listener
+    ] ;
+
+    METHOD: void autoUseAction [
+        [ com-auto-use ] \ com-auto-use call-listener
+    ] ;
+
+    METHOD: Class makeTouchBar [ default-touchbar self make-touchbar ] ;
+
+    METHOD: Class touchBar: Class touchbar makeItemForIdentifier: Class string [
+        string CF>string
+        {
+            { "refresh-all-action" [
+                self "refresh-all-action" "refresh-all" "refreshAllAction" make-NSTouchBar-button
+            ] }
+            { "auto-use-action" [
+                self "auto-use-action" "auto-use" "autoUseAction" make-NSTouchBar-button
+            ] }
+            [ drop f ]
+        } case
+    ] ;
+
     ! Rendering
     METHOD: void drawRect: NSRect rect [ self window [ draw-world ] when* ] ;