Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/Dock Menu/Dock menu with submenu with ApplicationDelegate
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/Dock Menu/Dock menu with submenu with ApplicationDelegate
This example is the version from Wed, 2nd Sep 2014.
Project "Dock menu with submenu with ApplicationDelegate.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() System.DebugLog CurrentMethodName End EventHandler
Sub Constructor() System.DebugLog CurrentMethodName if not TargetCocoa then MsgBox "Please run this example on Cocoa target." end if m = new MyApplicationDelegate End Sub
Property Protected m As MyApplicationDelegate
End Class
Class Window1 Inherits Window
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 MyApplicationDelegate Inherits NSApplicationDelegateMBS
EventHandler Function applicationDockMenu() As NSMenuMBS redim items(-1) // clear last menuitems // we do keep menu item objects in an array, so the Real Studio object with the event handler stays alive. m=new NSMenuMBS dim a as new MyCocoaMenuItemMBS a.CreateMenuItem "Top menu entry" a.Enabled=true a.Tag=1 items.Append a // so RB doesn't free the object. m.AddItem a dim b as new MyCocoaMenuItemMBS b.CreateSeparator items.Append b m.AddItem b dim c as new MyCocoaMenuItemMBS c.CreateMenuItem "Middle menu entry" c.Enabled=true c.Tag=2 c.state=1 items.Append c m.AddItem c dim d as new MyCocoaMenuItemMBS d.CreateMenuItem "Bottom menu entry" d.Enabled=false d.tag=3 items.Append d m.AddItem d dim e as new MyCocoaMenuItemMBS e.CreateMenuItem "Greetings from Real Studio" e.Enabled=true e.tag=3 items.Append e m.AddItem e sm = new nsMenuMBS dim g as new MyCocoaMenuItemMBS g.CreateMenuItem "inside submenu" g.Enabled=true g.tag=5 items.Append g sm.AddItem g dim f as new MyCocoaMenuItemMBS f.CreateMenuItem "submenu" f.Enabled=true f.tag=4 f.submenu = sm items.Append f m.AddItem f return m End EventHandler
Property Protected items() As NSMenuItemMBS
Property Protected m As NSMenuMBS
Property sm As nsmenuMBS
End Class
Class MyCocoaMenuItemMBS Inherits NSMenuItemMBS
EventHandler Sub Action() MsgBox "You chose menu item number "+str(tag) End EventHandler
End Class
End Project

See also:

Feedback, Comments & Corrections

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

MBS Xojo Plugins