Platforms to show: All Mac Windows Linux Cross-Platform

/Mac64bit/TouchBar Test


Required plugins for this example: MBS MacBase Plugin, MBS MacControls Plugin, MBS MacCocoa Plugin, MBS Mac64bit Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Mac64bit/TouchBar Test

This example is the version from Fri, 3rd Mar 2022.

Project "TouchBar Test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() #if mbs.BuildNumber < 19170 then MsgBox "Please update plugins. quit #elseif not TargetCocoa then MsgBox "Please build for Mac OS X." quit #else if NSTouchBarMBS.Available then // ok // let the system add a menu for us NSTouchBarMBS.automaticCustomizeTouchBarMenuItemEnabled = true BuildAppTouchBar else MsgBox "Sorry, TouchBar is not supported on this Mac." quit end if #endif End EventHandler
Sub BuildAppTouchBar() System.DebugLog CurrentMethodName dim t as new MyNSTouchBarMBS t.customizationIdentifier = "test.myapp.TouchBar.app" t.principalItemIdentifier = "test" dim DefaultItems() as string DefaultItems.Append "test" DefaultItems.Append "print" DefaultItems.Append NSTouchBarItemMBS.NSTouchBarItemIdentifierFixedSpaceSmall DefaultItems.Append NSTouchBarItemMBS.NSTouchBarItemIdentifierOtherItemsProxy t.setDefaultItemIdentifiers DefaultItems // test item must be there, print can be removed t.setCustomizationRequiredItemIdentifiers array("test") t.setCustomizationAllowedItemIdentifiers array("print") t.AssignToApp self.myTouchBar = t System.DebugLog CurrentMethodName+" done" End Sub
Note "Plugins Needed"
MBS MacBase Plugin MBS Mac64bit Plugin MBS MacControls Plugin MBS Main Plugin MBS MacCocoa Plugin MBS MacCloud Plugin MBS MacCG Plugin MBS MacCF Plugin
Property myTouchBar As MyNSTouchBarMBS
End Class
Class MainWindow Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() NSTouchBarMBS.toggleTouchBarCustomizationPalette End EventHandler
End Control
EventHandler Sub Open() BuildWindowTouchBar End EventHandler
Sub BuildWindowTouchBar() System.DebugLog CurrentMethodName dim t as new MyNSTouchBarMBS t.customizationIdentifier = "test.myapp.TouchBar.window" t.principalItemIdentifier = "TestWindow" dim DefaultItems() as string DefaultItems.Append "TestWindow" DefaultItems.Append NSTouchBarItemMBS.NSTouchBarItemIdentifierOtherItemsProxy t.setDefaultItemIdentifiers DefaultItems // TestWindow can be removed t.setCustomizationAllowedItemIdentifiers array("TestWindow") // install and keep alive t.AssignToWindow self self.myTouchBar = t System.DebugLog CurrentMethodName+" done" End Sub
Property myTouchBar As MyNSTouchBarMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class MyNSTouchBarMBS Inherits NSTouchBarMBS
EventHandler Sub Hidden() System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub Shown() System.DebugLog CurrentMethodName End EventHandler
EventHandler Function makeItemForIdentifier(identifier as string) As NSTouchBarItemMBS System.DebugLog CurrentMethodName+": "+identifier // we build items on the fly Select case identifier case "test" dim b as new MyNSButtonMBS("test") dim m as new MyNSCustomTouchBarItemMBS(identifier) m.Button = b m.customizationLabel = "Test Item" m.view = b m.visibilityPriority = m.PriorityHigh items.Append m Return m case "print" dim b as new MyNSButtonMBS("Print") dim m as new MyNSCustomTouchBarItemMBS(identifier) m.Button = b m.customizationLabel = "Print Report" m.view = b m.visibilityPriority = m.PriorityNormal items.Append m Return m case "testWindow" // for window dim b as new MyNSButtonMBS("Click") b.bezelColor = NSColorMBS.colorWithDeviceRGB(0.35, 0.61, 0.35, 1.00) dim m as new MyNSCustomTouchBarItemMBS(identifier) m.Button = b m.customizationLabel = "Click me" m.view = b m.visibilityPriority = m.PriorityNormal items.Append m Return m end Select End EventHandler
Property Items() As NSTouchBarItemMBS
End Class
Class MyNSCustomTouchBarItemMBS Inherits NSCustomTouchBarItemMBS
EventHandler Sub Hidden() System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub Shown() System.DebugLog CurrentMethodName End EventHandler
Property Button As MyNSButtonMBS
End Class
Class MyNSButtonMBS Inherits NSButtonMBS
EventHandler Sub Action() MsgBox "Button "+me.title+" clicked" End EventHandler
End Class
End Project

The items on this page are in the following plugins: MBS Mac64bit Plugin.


The biggest plugin in space...