Platforms to show: All Mac Windows Linux Cross-Platform

/Win/Windows File Dialog
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/Windows File Dialog
This example is the version from Sun, 9th May 2020.
Project "Windows File Dialog.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() End EventHandler
EventHandler Function UnhandledException(error As RuntimeException) As Boolean MsgBox Introspection.GetType(error).fullname+EndOfLine+Str(error.ErrorNumber)+": "+error.Message+_ EndOfLine+Join(error.Stack, EndOfLine) Return True End EventHandler
End Class
Class MainWindow Inherits Window
Control OpenButton Inherits PushButton
ControlInstance OpenButton Inherits PushButton
EventHandler Sub Action() list.DeleteAllRows Dim s As New MyWinFileOpenDialogMBS s.list = list fileDialog = s SetOptions s Dim r As Boolean = s.show(Self) If r Then Dim items As WinShellItemArrayMBS = s.Results Dim c As Integer = items.Count Log Str(c)+" files" For i As Integer = 0 To c-1 Dim item As WinShellItemMBS = items.Item(i) Log item.NativePath Next else log "Cancelled." End If End EventHandler
End Control
Control SaveButton Inherits PushButton
ControlInstance SaveButton Inherits PushButton
EventHandler Sub Action() list.DeleteAllRows Dim s As New MyWinFileSaveDialogMBS s.list = list fileDialog = s SetOptions s Dim r As Boolean = s.show(Self) If r Then Dim item As WinShellItemMBS = s.Result Log "Result: "+item.DisplayName Log item.NativePath End If End EventHandler
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control TitleTextField Inherits TextField
ControlInstance TitleTextField Inherits TextField
End Control
Control CheckTitle Inherits CheckBox
ControlInstance CheckTitle Inherits CheckBox
End Control
Control FilenameLabelTextField Inherits TextField
ControlInstance FilenameLabelTextField Inherits TextField
End Control
Control CheckFilenameLabel Inherits CheckBox
ControlInstance CheckFilenameLabel Inherits CheckBox
End Control
Control OKButtonTextField Inherits TextField
ControlInstance OKButtonTextField Inherits TextField
End Control
Control CheckOKButton Inherits CheckBox
ControlInstance CheckOKButton Inherits CheckBox
End Control
Control FilenameTextField Inherits TextField
ControlInstance FilenameTextField Inherits TextField
End Control
Control CheckFileName Inherits CheckBox
ControlInstance CheckFileName Inherits CheckBox
End Control
Control DefaultExtensionTextField Inherits TextField
ControlInstance DefaultExtensionTextField Inherits TextField
End Control
Control CheckDefaultExtension Inherits CheckBox
ControlInstance CheckDefaultExtension Inherits CheckBox
End Control
Control CheckDefaultFolder Inherits CheckBox
ControlInstance CheckDefaultFolder Inherits CheckBox
End Control
Control CheckFileTypes Inherits CheckBox
ControlInstance CheckFileTypes Inherits CheckBox
EventHandler Sub Action() CheckFileTypeIndex.Enabled = me.value End EventHandler
End Control
Control CheckFileTypeIndex Inherits CheckBox
ControlInstance CheckFileTypeIndex Inherits CheckBox
End Control
Control popupFileTypeIndex Inherits PopupMenu
ControlInstance popupFileTypeIndex Inherits PopupMenu
End Control
Control CheckOverwritePrompt Inherits CheckBox
ControlInstance CheckOverwritePrompt Inherits CheckBox
End Control
Control CheckStrictFileTypes Inherits CheckBox
ControlInstance CheckStrictFileTypes Inherits CheckBox
End Control
Control CheckNoChangeDir Inherits CheckBox
ControlInstance CheckNoChangeDir Inherits CheckBox
End Control
Control CheckPickFolders Inherits CheckBox
ControlInstance CheckPickFolders Inherits CheckBox
End Control
Control CheckForceFileSystem Inherits CheckBox
ControlInstance CheckForceFileSystem Inherits CheckBox
End Control
Control CheckAllowMultiSelect Inherits CheckBox
ControlInstance CheckAllowMultiSelect Inherits CheckBox
End Control
Control CheckPathMustExist Inherits CheckBox
ControlInstance CheckPathMustExist Inherits CheckBox
End Control
Control CheckFileMustExist Inherits CheckBox
ControlInstance CheckFileMustExist Inherits CheckBox
End Control
Control CheckHideMRUPlaces Inherits CheckBox
ControlInstance CheckHideMRUPlaces Inherits CheckBox
End Control
Control CheckForceShowHidden Inherits CheckBox
ControlInstance CheckForceShowHidden Inherits CheckBox
End Control
Control CheckCustom Inherits CheckBox
ControlInstance CheckCustom Inherits CheckBox
End Control
Control CustomValue Inherits TextField
ControlInstance CustomValue Inherits TextField
End Control
EventHandler Sub Open() End EventHandler
Sub CheckCustomControls(s as WinFileDialogMBS) // Must run while dialog is still open if CheckCustom.Value then dim a as string = s.EditBoxText(3) log "Author field: "+a CustomValue.text = a dim b as string = s.EditBoxText(5) log "Subject field: "+b dim k as Boolean = s.CheckButtonState(7) log "Custom color checkbox: "+str(k) if k then dim m as Integer = s.SelectedControlItem(8) dim n as string = s.ControlItemText(8,m) log "Color picked: "+str(m)+" "+n end if end if End Sub
Sub SetOptions(s as WinFileDialogMBS) // option flags s.OptionOverwritePrompt = CheckOverwritePrompt.Value s.OptionStrictFileTypes = CheckStrictFileTypes.Value s.OptionNoChangeDir = CheckNoChangeDir.value s.OptionPickFolders = CheckPickFolders.Value s.OptionForceFileSystem = CheckForceFileSystem.value s.OptionAllowMultiSelect = CheckAllowMultiSelect.value s.OptionPathMustExist = CheckPathMustExist.value s.OptionFileMustExist = CheckFileMustExist.Value s.OptionHideMRUPlaces = CheckHideMRUPlaces.Value s.OptionForceShowHidden = CheckForceShowHidden.Value // check file types if CheckFileTypes.Value then Dim FileTypes() As WinFileTypeMBS FileTypes.Append New WinFileTypeMBS("JPEG image", "*.jpg") FileTypes.Append New WinFileTypeMBS("PNG image", "*.png") FileTypes.Append New WinFileTypeMBS("Tiff image", "*.tif;*.tiff") s.SetFileTypes FileTypes if CheckFileTypeIndex.Value then s.FileTypeIndex = popupFileTypeIndex.listindex end if end if if CheckFileName.Value then s.FileName = FilenameTextField.Text end if if CheckDefaultExtension.Value then s.DefaultExtension = DefaultExtensionTextField.Text end if // if not last location is saved, go here: if CheckDefaultFolder.Value then s.DefaultFolder = New WinShellItemMBS(SpecialFolder.Desktop) end if // some labels if CheckFilenameLabel.Value then s.FileNameLabel = FilenameLabelTextField.Text end if if CheckOKButton.Value then s.OkButtonLabel = OKButtonTextField.text end if if CheckTitle.Value then s.Title = TitleTextField.Text end if if CheckCustom.Value then s.StartVisualGroup 1, "Metadata" s.AddText 2, "Author:" s.AddEditBox 3, CustomValue.Text s.AddText 4, "Subject:" s.AddEditBox 5, "Hello World" s.EndVisualGroup s.StartVisualGroup 6, "Color" s.AddCheckButton 7, "Custom color", false s.AddComboBox 8 s.AddControlItem 8, 1, "Red" s.AddControlItem 8, 2, "Green" s.AddControlItem 8, 3, "Blue" s.ControlState(8) = s.kControlStateVisible s.EndVisualGroup end if End Sub
Sub log(s as string) list.AddRow s End Sub
Property fileDialog As WinFileDialogMBS
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 MyWinFileOpenDialogMBS Inherits WinFileOpenDialogMBS
EventHandler Sub ButtonClicked(ControlID as Integer) Log CurrentMethodName+" "+Str(ControlID) End EventHandler
EventHandler Sub CheckButtonToggled(ControlID as Integer, Checked as Boolean) log CurrentMethodName+" "+Str(ControlID) if ControlID = 7 then if checked then me.ControlState(8) = me.kControlStateEnableVisible else me.ControlState(8) = me.kControlStateVisible end if end if End EventHandler
EventHandler Sub ControlActivating(ControlID as Integer) log CurrentMethodName+" "+Str(ControlID) End EventHandler
EventHandler Function FileOk() As Boolean Log CurrentMethodName MainWindow.CheckCustomControls(me) Return True End EventHandler
EventHandler Sub FileTypeChanged() log CurrentMethodName End EventHandler
EventHandler Sub FolderChanged() Log CurrentMethodName dim folder as WinShellItemMBS = self.Folder if folder <> nil then log folder.NativePath end if End EventHandler
EventHandler Function FolderChanging(Folder as WinShellItemMBS) As boolean Log CurrentMethodName Log Folder.NativePath Return True End EventHandler
EventHandler Sub ItemSelected(ControlID as Integer, ItemID as Integer) Log CurrentMethodName+" "+str(ControlID)+" "+str(ItemID) End EventHandler
EventHandler Function Overwrite(item as WinShellItemMBS) As Integer Log CurrentMethodName Return kOverwriteDefault End EventHandler
EventHandler Sub SelectionChange() log CurrentMethodName End EventHandler
EventHandler Function ShareViolation(item as WinShellItemMBS) As Integer Log CurrentMethodName Return kShareViolationDefault End EventHandler
Sub log(s as string) list.AddRow s End Sub
Property list As listbox
End Class
Class MyWinFileSaveDialogMBS Inherits WinFileSaveDialogMBS
EventHandler Sub ButtonClicked(ControlID as Integer) log CurrentMethodName+" "+str(ControlID) End EventHandler
EventHandler Sub CheckButtonToggled(ControlID as Integer, Checked as Boolean) log CurrentMethodName+" "+str(ControlID) if ControlID = 7 then if checked then me.ControlState(8) = me.kControlStateEnableVisible else me.ControlState(8) = me.kControlStateVisible end if end if End EventHandler
EventHandler Sub ControlActivating(ControlID as Integer) log CurrentMethodName+" "+str(ControlID) End EventHandler
EventHandler Function FileOk() As Boolean Log CurrentMethodName MainWindow.CheckCustomControls(me) Return True End EventHandler
EventHandler Sub FileTypeChanged() log CurrentMethodName End EventHandler
EventHandler Sub FolderChanged() log CurrentMethodName dim folder as WinShellItemMBS = self.Folder if folder <> nil then log folder.NativePath end if End EventHandler
EventHandler Function FolderChanging(Folder as WinShellItemMBS) As boolean Log CurrentMethodName Log Folder.NativePath Return True End EventHandler
EventHandler Sub ItemSelected(ControlID as Integer, ItemID as Integer) log CurrentMethodName+" "+str(ControlID)+" "+str(ItemID) End EventHandler
EventHandler Function Overwrite(item as WinShellItemMBS) As Integer Log CurrentMethodName Return kOverwriteDefault End EventHandler
EventHandler Sub SelectionChange() log CurrentMethodName End EventHandler
EventHandler Function ShareViolation(item as WinShellItemMBS) As Integer Log CurrentMethodName Return kShareViolationDefault End EventHandler
Sub log(s as string) list.AddRow s End Sub
Property list As listbox
End Class
End Project

See also:

Feedback, Comments & Corrections

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

The biggest plugin in space...




Links
MBS Xojo blog