Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/NSWorkSpace Notifications
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS MacOSX Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSWorkSpace Notifications
This example is the version from Sun, 17th Mar 2012.
Project "NSWorkSpace Notifications.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() // get notification center w = new NSWorkspaceMBS c = w.notificationCenter n = new NSWorkSpaceNotifications // register all events c.addObserver n, NSWorkspaceMBS.NSWorkspaceActiveSpaceDidChangeNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceDidActivateApplicationNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceDidChangeFileLabelsNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceDidDeactivateApplicationNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceDidHideApplicationNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceDidLaunchApplicationNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceDidMountNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceDidPerformFileOperationNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceDidRenameVolumeNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceDidTerminateApplicationNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceDidUnhideApplicationNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceDidUnmountNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceDidWakeNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceScreensDidSleepNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceScreensDidWakeNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceSessionDidBecomeActiveNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceSessionDidResignActiveNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceWillLaunchApplicationNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceWillPowerOffNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceWillSleepNotification c.addObserver n, NSWorkspaceMBS.NSWorkspaceWillUnmountNotification End EventHandler
Property c As NSNotificationCenterMBS
Property n As NSWorkSpaceNotifications
Property w As NSWorkspaceMBS
End Class
Class Window1 Inherits Window
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub ExpandRow(row As Integer) dim v as Variant = me.RowTag(row) if v isa Dictionary then dim d as Dictionary = v for each key as Variant in d.keys dim value as Variant = d.Value(key) dim keyString as string = AsString(key) dim valString as string = AsString(value) me.AddRow keyString me.Cell(me.LastIndex,1) = valString next end if End EventHandler
End Control
EventHandler Function CancelClose(appQuitting as Boolean) As Boolean // block quitting if needed Return not CheckBox1.Value End EventHandler
Function AsString(v as Variant) As string // try to get a text for everything #pragma BreakOnExceptions false if v isa FolderItem then dim f as FolderItem = v Return f.UnixpathMBS elseif v isa NSRunningApplicationMBS then dim n as NSRunningApplicationMBS = v Return n.localizedName end if Return v.StringValue Exception t as TypeMismatchException // ignore End Function
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 NSWorkSpaceNotifications Inherits NSNotificationObserverMBS
EventHandler Sub GotNotification(notification as NSNotificationMBS) // got event, so add it to listbox dim l as listbox = window1.List l.InsertFolder 0, Notification.name l.RowTag(l.LastIndex) = Notification.userInfo End EventHandler
End Class
End Project

See also:

Feedback, Comments & Corrections

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




Links
MBS Xojo Chart Plugins