github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/internal/go-common-file-dialog/cfd/CommonFileDialog.go (about) 1 // Cross-platform. 2 3 // Common File Dialogs 4 package cfd 5 6 type Dialog interface { 7 // Show the dialog to the user. 8 // Blocks until the user has closed the dialog. 9 Show() error 10 // Sets the dialog's parent window. Use 0 to set the dialog to have no parent window. 11 SetParentWindowHandle(hwnd uintptr) 12 // Show the dialog to the user. 13 // Blocks until the user has closed the dialog and returns their selection. 14 // Returns an error if the user cancelled the dialog. 15 // Do not use for the Open Multiple Files dialog. Use ShowAndGetResults instead. 16 ShowAndGetResult() (string, error) 17 // Sets the title of the dialog window. 18 SetTitle(title string) error 19 // Sets the "role" of the dialog. This is used to derive the dialog's GUID, which the 20 // OS will use to differentiate it from dialogs that are intended for other purposes. 21 // This means that, for example, a dialog with role "Import" will have a different 22 // previous location that it will open to than a dialog with role "Open". Can be any string. 23 SetRole(role string) error 24 // Sets the folder used as a default if there is not a recently used folder value available 25 SetDefaultFolder(defaultFolder string) error 26 // Sets the folder that the dialog always opens to. 27 // If this is set, it will override the "default folder" behaviour and the dialog will always open to this folder. 28 SetFolder(folder string) error 29 // Gets the selected file or folder path, as an absolute path eg. "C:\Folder\file.txt" 30 // Do not use for the Open Multiple Files dialog. Use GetResults instead. 31 GetResult() (string, error) 32 // Sets the file name, I.E. the contents of the file name text box. 33 // For Select Folder Dialog, sets folder name. 34 SetFileName(fileName string) error 35 // Release the resources allocated to this Dialog. 36 // Should be called when the dialog is finished with. 37 Release() error 38 } 39 40 type FileDialog interface { 41 Dialog 42 // Set the list of file filters that the user can select. 43 SetFileFilters(fileFilter []FileFilter) error 44 // Set the selected item from the list of file filters (set using SetFileFilters) by its index. Defaults to 0 (the first item in the list) if not called. 45 SetSelectedFileFilterIndex(index uint) error 46 // Sets the default extension applied when a user does not provide one as part of the file name. 47 // If the user selects a different file filter, the default extension will be automatically updated to match the new file filter. 48 // For Open / Open Multiple File Dialog, this only has an effect when the user specifies a file name with no extension and a file with the default extension exists. 49 // For Save File Dialog, this extension will be used whenever a user does not specify an extension. 50 SetDefaultExtension(defaultExtension string) error 51 } 52 53 type OpenFileDialog interface { 54 FileDialog 55 } 56 57 type OpenMultipleFilesDialog interface { 58 FileDialog 59 // Show the dialog to the user. 60 // Blocks until the user has closed the dialog and returns the selected files. 61 ShowAndGetResults() ([]string, error) 62 // Gets the selected file paths, as absolute paths eg. "C:\Folder\file.txt" 63 GetResults() ([]string, error) 64 } 65 66 type SelectFolderDialog interface { 67 Dialog 68 } 69 70 type SaveFileDialog interface { // TODO Properties 71 FileDialog 72 }