Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/Save and restore State 2
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS Main Plugin, MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/Save and restore State 2
This example is the version from Tue, 13th May 2013.
Project "Save and restore State 2.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Activate() System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub Close() System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub Deactivate() System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub Open() System.DebugLog CurrentMethodName // register plugins here if SystemInformationMBS.isLion and TargetCocoa then // ok else MsgBox "Please run this example with Mac OS X 10.7 and Cocoa target." end if NSWindowRestoreHandler = new MyNSWindowRestoreHandlerMBS del = new MyNSApplicationDelegateMBS End EventHandler
Sub Constructor() System.DebugLog CurrentMethodName End Sub
Property NSWindowRestoreHandler As myNSWindowRestoreHandlerMBS
Property del As MyNSApplicationDelegateMBS
Property lastrun As string
End Class
Class MainWindow Inherits Window
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
EventHandler Sub Close() del = nil End EventHandler
EventHandler Sub Open() del = new MyNSWindowDelegateMBS(Self) del.InstallRestoreEvents dim w as new NSWindowMBS(Self) w.identifier = "MainWindow" // tell the plugin to set its setRestorationClass 'w.setRestorationClass End EventHandler
Property del As MyNSWindowDelegateMBS
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 MyNSApplicationDelegateMBS Inherits NSApplicationDelegateMBS
EventHandler Sub applicationDidBecomeActive(Notification as NSNotificationMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub applicationDidDecodeRestorableState(coder as NSCoderMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub applicationDidFinishLaunching(Notification as NSNotificationMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub applicationDidHide(Notification as NSNotificationMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub applicationDidUnhide(Notification as NSNotificationMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub applicationWillBecomeActive(Notification as NSNotificationMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub applicationWillEncodeRestorableState(coder as NSCoderMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub applicationWillTerminate(Notification as NSNotificationMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub applicationWillUnhide(Notification as NSNotificationMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Function restoreWindowWithIdentifier(identifier as string, state as NSCoderMBS, byref resultWindow as variant, byref error as NSErrorMBS) As boolean System.DebugLog CurrentMethodName System.DebugLog identifier Return false End EventHandler
End Class
Class MyNSWindowRestoreHandlerMBS Inherits NSWindowRestoreHandlerMBS
EventHandler Sub RestoreWindow(identifier as string, state as NSCoderMBS) System.DebugLog CurrentMethodName System.DebugLog identifier dim s as string = state.decodeString("lastrun") System.DebugLog "Got text: "+s app.lastrun = s MainWindow.Listbox1.AddRow "Got State with Lastrun="+s // pass back details self.SetRestoredWindow MainWindow self.SetError nil End EventHandler
End Class
Class MyNSWindowDelegateMBS Inherits NSWindowDelegateMBS
EventHandler Sub encodeRestorableStateWithCoder(win as NSWindowMBS, coder as NSCoderMBS) System.DebugLog CurrentMethodName dim d as new date dim s as string = "Hello World "+ d.LongTime coder.encodeString(s, "title") MainWindow.Listbox1.AddRow "Encoded state." Exception n as NSExceptionMBS System.DebugLog "Exception: "+n.message End EventHandler
EventHandler Sub restoreStateWithCoder(win as NSWindowMBS, coder as NSCoderMBS) System.DebugLog CurrentMethodName dim s as string = coder.decodeString("title") System.DebugLog "Title: "+s MainWindow.Title = s End EventHandler
End Class
End Project

Feedback, Comments & Corrections

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




Links
MBS FileMaker Plugins