Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS MacBase Plugin, MBS Main Plugin, MBS MacCocoa Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSSavePanelObserver
This example is the version from Sat, 4th Sep 2020.
Project "NSSavePanelObserver.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control CheckEnable Inherits CheckBox
ControlInstance CheckEnable Inherits CheckBox
EventHandler Sub Action()
MyNSSavePanelObserverMBS.Enabled = Me.Value
End EventHandler
End Control
Control OpenButton Inherits PushButton
ControlInstance OpenButton Inherits PushButton
EventHandler Sub Action()
Dim dlg As New OpenDialog
Dim f As FolderItem
#If Not TargetLinux Then
dlg.InitialDirectory = SpecialFolder.Documents
#Else //open Home directory on linux
dlg.InitialDirectory = SpecialFolder.Home
#EndIf
dlg.Title = "Select a Text file"
Log "ShowModal..."
f = dlg.ShowModal
Log "ShowModal done"
If f <> Nil Then
//proceed normally
Log "file: "+f.NativePath
Else
//User Cancelled
Log "cancelled."
End If
End EventHandler
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control SaveButton Inherits PushButton
ControlInstance SaveButton Inherits PushButton
EventHandler Sub Action()
Dim dlg As New SaveAsDialog
Dim f As FolderItem
dlg.InitialDirectory = SpecialFolder.Documents
dlg.PromptText = "Prompt Text"
dlg.SuggestedFileName = "Suggested Filename"
dlg.Title = "Title Property"
Log "ShowModal..."
f = dlg.ShowModal
Log "ShowModal done"
If f <> Nil Then
// file saved
Log "file: "+f.NativePath
Else
// user canceled
Log "cancelled."
End If
End EventHandler
End Control
EventHandler Sub Open()
Observer = New MyNSSavePanelObserverMBS
End EventHandler
Sub Log(s as string)
List.AddRow s
List.ScrollPosition = list.ListCount
End Sub
Property Observer As MyNSSavePanelObserverMBS
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 MyNSSavePanelObserverMBS Inherits NSSavePanelObserverMBS
EventHandler Sub DidShowPanel(panel as NSSavePanelMBS, Result as Integer)
MainWindow.Log CurrentMethodName
MainWindow.Log "Result: "+Str(result)
End EventHandler
EventHandler Sub WillShowPanel(panel as NSSavePanelMBS)
MainWindow.Log CurrentMethodName
panel.Title = "Observer called"
panel.showsHiddenFiles = True
// change suggested file name for save dialog
panel.nameFieldStringValue = "test file"
End EventHandler
End Class
End Project
The items on this page are in the following plugins: MBS MacCocoa Plugin.