Platforms to show: All Mac Windows Linux Cross-Platform

/MacFrameworks/User Notification/UserNotification example


Required plugins for this example: MBS MacFrameworks Plugin, 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: /MacFrameworks/User Notification/UserNotification example

This example is the version from Sat, 11th Sep 2015.

Project "UserNotification example.xojo_binary_project"
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 a = new MyNSApplicationDelegateMBS End Sub
Property a As MyNSApplicationDelegateMBS
End Class
Class MainWindow Inherits Window
Control iTitle Inherits TextField
ControlInstance iTitle Inherits TextField
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control isubtitle Inherits TextField
ControlInstance isubtitle Inherits TextField
End Control
Control iinformativeText Inherits TextField
ControlInstance iinformativeText Inherits TextField
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control iactionButtonTitle Inherits TextField
ControlInstance iactionButtonTitle Inherits TextField
End Control
Control Label4 Inherits Label
ControlInstance Label4 Inherits Label
End Control
Control iotherButtonTitle Inherits TextField
ControlInstance iotherButtonTitle Inherits TextField
End Control
Control Label5 Inherits Label
ControlInstance Label5 Inherits Label
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() dim n as NSUserNotificationMBS = Create m.deliverNotification n End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() dim n as NSUserNotificationMBS = Create dim d as new date d.Second = d.Second + 10 n.deliveryDate = d m.scheduleNotification n End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() list m.scheduledNotifications End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action() list m.deliveredNotifications End EventHandler
End Control
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
End Control
Control Label6 Inherits Label
ControlInstance Label6 Inherits Label
End Control
EventHandler Sub Open() if NSUserNotificationMBS.Available = false then MsgBox "NSUserNotification is not available." quit end if m = new NSUserNotificationCenterMBS d = new MyNSUserNotificationCenterDelegateMBS End EventHandler
Function Create() As NSUserNotificationMBS dim n as new NSUserNotificationMBS n.Title = iTitle.text n.informativeText = iinformativeText.text if iactionButtonTitle.text.len>0 then n.actionButtonTitle = iactionButtonTitle.text n.hasActionButton = true end if n.otherButtonTitle = iotherButtonTitle.Text n.subtitle = isubtitle.Text Return n End Function
Sub list(d() as NSUserNotificationMBS) if UBound(d) = -1 then MsgBox "no notifications." Return end if dim lines() as string for each n as NSUserNotificationMBS in d lines.Append n.description next MsgBox Join(lines,EndOfLine) End Sub
Property d As MyNSUserNotificationCenterDelegateMBS
Property m As NSUserNotificationCenterMBS
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 MyNSUserNotificationCenterDelegateMBS Inherits NSUserNotificationCenterDelegateMBS
EventHandler Sub didActivateNotification(center as NSUserNotificationCenterMBS, notification as NSUserNotificationMBS) dim a as integer = notification.activationType dim m as string Select case a case notification.NSUserNotificationActivationTypeNone case notification.NSUserNotificationActivationTypeContentsClicked m = " with click on contents" case notification.NSUserNotificationActivationTypeActionButtonClicked m = " with click on action button" end Select MainWindow.listbox1.AddRow "Activate: "+notification.Title+m End EventHandler
EventHandler Sub didDeliverNotification(center as NSUserNotificationCenterMBS, notification as NSUserNotificationMBS) MainWindow.listbox1.AddRow "Deliver: "+notification.Title End EventHandler
EventHandler Function shouldPresentNotification(center as NSUserNotificationCenterMBS, notification as NSUserNotificationMBS) As boolean MainWindow.listbox1.AddRow "Should present: "+notification.Title Return true End EventHandler
End Class
Class MyNSApplicationDelegateMBS Inherits NSApplicationDelegateMBS
EventHandler Sub applicationDidFinishLaunching(Notification as NSNotificationMBS) System.DebugLog CurrentMethodName Notification.Print dim userInfo as Dictionary = Notification.userInfo dim key as string = NSApplicationMBS.NSApplicationLaunchUserNotificationKey if userInfo.HasKey(key) then dim UserNotification as NSUserNotificationMBS = userInfo.Lookup(key, nil) if UserNotification <> nil then MsgBox "Notification clicked with title: "+UserNotification.title+" and text: "+UserNotification.informativeText else MsgBox "no notification?" end if end if End EventHandler
End Class
End Project

See also:

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


The biggest plugin in space...