Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/Lion Persistence


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/Lion Persistence

This example is the version from Sat, 24th May 2013.

Project "Lion Persistence.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Function CancelClose() As Boolean ///////////////////////////////////////////////////////////////////////////////////////////// // It's important that you force the application to terminate, otherwise RS winds things down // and informs the OS that you don't want WindowRestoration to work!!!! // // However please note that this will BREAK your application as no Cancel Close or Close events // will be sent to any windows! // // So if you wish to do anything before the application terminates, now is the time. // Realisitically you should do some verification before you terminate the application to make // sure that your app is behaving the way the user expects... But I'll leave that all up to you // to figure out. ///////////////////////////////////////////////////////////////////////////////////////////// Dim nsa as NSApplicationMBS = app.NSApplicationMBS nsa.terminate End EventHandler
Sub constructor() ///////////////////////////////////////////////////////////////////////////////////////////// // It's important that the delegate is initiated here or else you don't get half the events. ///////////////////////////////////////////////////////////////////////////////////////////// system.DebugLog currentMEthodName+" ///////////////////////////////// INITATED" mag = new appDelegate End Sub
Property Protected mag As appDelegate
End Class
Class Window1 Inherits Window
Control TextArea1 Inherits TextArea
ControlInstance TextArea1 Inherits TextArea
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control Separator1 Inherits Separator
ControlInstance Separator1 Inherits Separator
End Control
EventHandler Sub DropObject(obj As DragItem, action As Integer) if obj.folderItemAvailable then setFile( obj.FolderItem ) end if End EventHandler
EventHandler Sub Open() me.acceptFileDrop( "????" ) End EventHandler
Sub Constructor() // Calling the overridden superclass constructor. Super.Constructor // Here we set an identifier so that we can get the OS to restore the location of the window for us. Dim w as NSWindowMBS = me.NSWindowMBS w.identifier = "mainWindow" End Sub
Sub setFile(infile as folderitem) file = infile self.title = infile.displayName TextArea1.text = file.URLPath if file.exists = false then label1.Text = "Doesn't Exist" elseif file.isReadable and file.isWriteable then label1.Text = "Readable && Writeable" elseif file.isReadable then label1.text = "Readable" elseif file.isWriteable then label1.text = "Writable" else label1.text = "No Access" end if End Sub
Property file As folderitem
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class appDelegate Inherits NSApplicationDelegateMBS
EventHandler Sub applicationDidDecodeRestorableState(coder as NSCoderMBS) if coder.containsValueForKey( "myFile" ) then window1.setFile coder.decodeNSURLFile( "myFile" ) end if End EventHandler
EventHandler Sub applicationWillEncodeRestorableState(coder as NSCoderMBS) if window1.file <> nil then coder.encodeNSURLFile( window1.file, "myFile" ) end if End EventHandler
EventHandler Function restoreWindowWithIdentifier(identifier as string, state as NSCoderMBS, byref resultWindow as variant, byref error as NSErrorMBS) As boolean System.DebugLog currentMethodName+" identifier:"+identifier if identifier = "mainWindow" then resultWindow = window1 end if Return True End EventHandler
End Class
End Project

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


The biggest plugin in space...