FileDialog

package
v0.0.0-...-357ca8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

FileDialog is a preset dialog used to choose files and directories in the filesystem. It supports filter masks. FileDialog automatically sets its window title according to the FileMode. If you want to use a custom title, disable this by setting ModeOverridesTitle to false.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Access

type Access int //gd:FileDialog.Access
const (
	// The dialog only allows accessing files under the [Resource] path (res://).
	//
	// [Resource]: https://pkg.go.dev/graphics.gd/classdb/Resource
	AccessResources Access = 0
	// The dialog only allows accessing files under user data path (user://).
	AccessUserdata Access = 1
	// The dialog allows accessing files on the whole file system.
	AccessFilesystem Access = 2
)

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsFileDialog() Instance
}

type Customization

type Customization int //gd:FileDialog.Customization
const (
	// Toggles visibility of the favorite button, and the favorite list on the left side of the dialog.
	//
	// Equivalent to [HiddenFilesToggleEnabled].
	//
	// [HiddenFilesToggleEnabled]: https://pkg.go.dev/graphics.gd/classdb/#Instance.HiddenFilesToggleEnabled
	CustomizationHiddenFiles Customization = 0
	// If enabled, shows the button for creating new directories (when using [FileModeOpenDir], [FileModeOpenAny], or [FileModeSaveFile]).
	//
	// Equivalent to [FolderCreationEnabled].
	//
	// [FolderCreationEnabled]: https://pkg.go.dev/graphics.gd/classdb/#Instance.FolderCreationEnabled
	CustomizationCreateFolder Customization = 1
	// If enabled, shows the toggle file filter button.
	//
	// Equivalent to [FileFilterToggleEnabled].
	//
	// [FileFilterToggleEnabled]: https://pkg.go.dev/graphics.gd/classdb/#Instance.FileFilterToggleEnabled
	CustomizationFileFilter Customization = 2
	// If enabled, shows the file sorting options button.
	//
	// Equivalent to [FileSortOptionsEnabled].
	//
	// [FileSortOptionsEnabled]: https://pkg.go.dev/graphics.gd/classdb/#Instance.FileSortOptionsEnabled
	CustomizationFileSort Customization = 3
	// If enabled, shows the toggle favorite button and favorite list on the left side of the dialog.
	//
	// Equivalent to [FavoritesEnabled].
	//
	// [FavoritesEnabled]: https://pkg.go.dev/graphics.gd/classdb/#Instance.FavoritesEnabled
	CustomizationFavorites Customization = 4
	// If enabled, shows the recent directories list on the left side of the dialog.
	//
	// Equivalent to [RecentListEnabled].
	//
	// [RecentListEnabled]: https://pkg.go.dev/graphics.gd/classdb/#Instance.RecentListEnabled
	CustomizationRecent Customization = 5
	// If enabled, shows the layout switch buttons (list/thumbnails).
	//
	// Equivalent to [LayoutToggleEnabled].
	//
	// [LayoutToggleEnabled]: https://pkg.go.dev/graphics.gd/classdb/#Instance.LayoutToggleEnabled
	CustomizationLayout Customization = 6
)

type DisplayMode

type DisplayMode int //gd:FileDialog.DisplayMode
const (
	// The dialog displays files as a grid of thumbnails. Use theme's 'thumbnail_size' to adjust their size.
	DisplayThumbnails DisplayMode = 0
	// The dialog displays files as a list of filenames.
	DisplayList DisplayMode = 1
)

type Expanded

type Expanded = MoreArgs

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsAcceptDialog

func (self *Extension[T]) AsAcceptDialog() AcceptDialog.Instance

func (*Extension[T]) AsConfirmationDialog

func (self *Extension[T]) AsConfirmationDialog() ConfirmationDialog.Instance

func (*Extension[T]) AsFileDialog

func (self *Extension[T]) AsFileDialog() Instance

func (*Extension[T]) AsNode

func (self *Extension[T]) AsNode() Node.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsViewport

func (self *Extension[T]) AsViewport() Viewport.Instance

func (*Extension[T]) AsWindow

func (self *Extension[T]) AsWindow() Window.Instance

type FileMode

type FileMode int //gd:FileDialog.FileMode
const (
	// The dialog allows selecting one, and only one file.
	FileModeOpenFile FileMode = 0
	// The dialog allows selecting multiple files.
	FileModeOpenFiles FileMode = 1
	// The dialog only allows selecting a directory, disallowing the selection of any file.
	FileModeOpenDir FileMode = 2
	// The dialog allows selecting one file or directory.
	FileModeOpenAny FileMode = 3
	// The dialog will warn when a file exists.
	FileModeSaveFile FileMode = 4
)

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.FileDialog

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) Access

func (self Instance) Access() Access

The file system access scope.

Warning: In Web builds, FileDialog cannot access the host file system. In sandboxed Linux and macOS environments, UseNativeDialog is automatically used to allow limited access to host file system.

func (Instance) AddFilter

func (self Instance) AddFilter(filter string)

Adds a comma-separated file name 'filter' option to the FileDialog with an optional 'description', which restricts what files can be picked.

A 'filter' should be of the form "filename.extension", where filename and extension can be * to match any string. Filters starting with . (i.e. empty filenames) are not allowed.

For example, a 'filter' of "*.png, *.jpg" and a 'description' of "Images" results in filter text "Images (*.png, *.jpg)".

func (Instance) AddOption

func (self Instance) AddOption(name string, values []string, default_value_index int)

Adds an additional OptionButton to the file dialog. If 'values' is empty, a CheckBox is added instead.

'default_value_index' should be an index of the value in the 'values'. If 'values' is empty it should be either 1 (checked), or 0 (unchecked).

func (Instance) AsAcceptDialog

func (self Instance) AsAcceptDialog() AcceptDialog.Instance

func (Instance) AsConfirmationDialog

func (self Instance) AsConfirmationDialog() ConfirmationDialog.Instance

func (Instance) AsFileDialog

func (self Instance) AsFileDialog() Instance

func (Instance) AsNode

func (self Instance) AsNode() Node.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsViewport

func (self Instance) AsViewport() Viewport.Instance

func (Instance) AsWindow

func (self Instance) AsWindow() Window.Instance

func (Instance) ClearFilenameFilter

func (self Instance) ClearFilenameFilter()

Clear the filter for file names.

func (Instance) ClearFilters

func (self Instance) ClearFilters()

Clear all the added filters in the dialog.

func (Instance) CurrentDir

func (self Instance) CurrentDir() string

The current working directory of the file dialog.

Note: For native file dialogs, this property is only treated as a hint and may not be respected by specific OS implementations.

func (Instance) CurrentFile

func (self Instance) CurrentFile() string

The currently selected file of the file dialog.

func (Instance) CurrentPath

func (self Instance) CurrentPath() string

The currently selected file path of the file dialog.

func (Instance) DeselectAll

func (self Instance) DeselectAll()

Clear all currently selected items in the dialog.

func (Instance) DisplayMode

func (self Instance) DisplayMode() DisplayMode

Display mode of the dialog's file list.

func (Instance) FavoritesEnabled

func (self Instance) FavoritesEnabled() bool

If true, shows the toggle favorite button and favorite list on the left side of the dialog.

func (Instance) FileFilterToggleEnabled

func (self Instance) FileFilterToggleEnabled() bool

If true, shows the toggle file filter button.

func (Instance) FileMode

func (self Instance) FileMode() FileMode

The dialog's open or save mode, which affects the selection behavior.

func (Instance) FileSortOptionsEnabled

func (self Instance) FileSortOptionsEnabled() bool

If true, shows the file sorting options button.

func (Instance) FilenameFilter

func (self Instance) FilenameFilter() string

The filter for file names (case-insensitive). When set to a non-empty string, only files that contains the substring will be shown. FilenameFilter can be edited by the user with the filter button at the top of the file dialog.

See also Filters, which should be used to restrict the file types that can be selected instead of FilenameFilter which is meant to be set by the user.

func (Instance) Filters

func (self Instance) Filters() []string

The available file type filters. Each filter string in the array should be formatted like this: *.png,*.jpg,*.jpeg;Image Files;image/png,image/jpeg. The description text of the filter is optional and can be omitted. Both file extensions and MIME type should be always set.

Note: Embedded file dialog and Windows file dialog support only file extensions, while Android, Linux, and macOS file dialogs also support MIME types.

func (Instance) FolderCreationEnabled

func (self Instance) FolderCreationEnabled() bool

If true, shows the button for creating new directories (when using FileModeOpenDir, FileModeOpenAny, or FileModeSaveFile).

func (Instance) GetLineEdit

func (self Instance) GetLineEdit() LineEdit.Instance

Returns the LineEdit for the selected file.

Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their CanvasItem.Visible property.

func (Instance) GetOptionDefault

func (self Instance) GetOptionDefault(option int) int

Returns the default value index of the OptionButton or CheckBox with index 'option'.

func (Instance) GetOptionName

func (self Instance) GetOptionName(option int) string

Returns the name of the OptionButton or CheckBox with index 'option'.

func (Instance) GetOptionValues

func (self Instance) GetOptionValues(option int) []string

Returns an array of values of the OptionButton with index 'option'.

func (Instance) GetSelectedOptions

func (self Instance) GetSelectedOptions() map[string]int

Returns a data structure with the selected values of the additional OptionButtons and/or CheckBoxes. data structure keys are names and values are selected value indices.

func (Instance) GetVbox

func (self Instance) GetVbox() VBoxContainer.Instance

Returns the vertical box container of the dialog, custom controls can be added to it.

Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their CanvasItem.Visible property.

Note: Changes to this node are ignored by native file dialogs, use AddOption to add custom elements to the dialog instead.

func (Instance) HiddenFilesToggleEnabled

func (self Instance) HiddenFilesToggleEnabled() bool

If true, shows the toggle hidden files button.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) Invalidate

func (self Instance) Invalidate()

Invalidate and update the current dialog content list.

Note: This method does nothing on native file dialogs.

func (Instance) LayoutToggleEnabled

func (self Instance) LayoutToggleEnabled() bool

If true, shows the layout switch buttons (list/thumbnails).

func (Instance) ModeOverridesTitle

func (self Instance) ModeOverridesTitle() bool

If true, changing the FileMode property will set the window title accordingly (e.g. setting FileMode to FileModeOpenFile will change the window title to "Open a File").

func (Instance) MoreArgs

func (self Instance) MoreArgs() MoreArgs

MoreArgs enables certain functions to be called with additional 'optional' arguments.

func (Instance) OnDirSelected

func (self Instance) OnDirSelected(cb func(dir string), flags ...Signal.Flags)

Emitted when the user selects a directory.

func (Instance) OnFileSelected

func (self Instance) OnFileSelected(cb func(path string), flags ...Signal.Flags)

Emitted when the user selects a file by double-clicking it or pressing the OK button.

func (Instance) OnFilenameFilterChanged

func (self Instance) OnFilenameFilterChanged(cb func(filter string), flags ...Signal.Flags)

Emitted when the filter for file names changes.

func (Instance) OnFilesSelected

func (self Instance) OnFilesSelected(cb func(paths []string), flags ...Signal.Flags)

Emitted when the user selects multiple files.

func (Instance) OptionCount

func (self Instance) OptionCount() int

The number of additional OptionButtons and CheckBoxes in the dialog.

func (Instance) RecentListEnabled

func (self Instance) RecentListEnabled() bool

If true, shows the recent directories list on the left side of the dialog.

func (Instance) RootSubfolder

func (self Instance) RootSubfolder() string

If non-empty, the given sub-folder will be "root" of this FileDialog, i.e. user won't be able to go to its parent directory.

Note: This property is ignored by native file dialogs.

func (Instance) SetAccess

func (self Instance) SetAccess(value Access)

SetAccess sets the property returned by [GetAccess].

func (Instance) SetCurrentDir

func (self Instance) SetCurrentDir(value string)

SetCurrentDir sets the property returned by [GetCurrentDir].

func (Instance) SetCurrentFile

func (self Instance) SetCurrentFile(value string)

SetCurrentFile sets the property returned by [GetCurrentFile].

func (Instance) SetCurrentPath

func (self Instance) SetCurrentPath(value string)

SetCurrentPath sets the property returned by [GetCurrentPath].

func (Instance) SetDisplayMode

func (self Instance) SetDisplayMode(value DisplayMode)

SetDisplayMode sets the property returned by [GetDisplayMode].

func (Instance) SetFavoritesEnabled

func (self Instance) SetFavoritesEnabled(value bool)

SetFavoritesEnabled sets the property returned by [IsCustomizationFlagEnabled].

func (Instance) SetFileFilterToggleEnabled

func (self Instance) SetFileFilterToggleEnabled(value bool)

SetFileFilterToggleEnabled sets the property returned by [IsCustomizationFlagEnabled].

func (Instance) SetFileMode

func (self Instance) SetFileMode(value FileMode)

SetFileMode sets the property returned by [GetFileMode].

func (Instance) SetFileSortOptionsEnabled

func (self Instance) SetFileSortOptionsEnabled(value bool)

SetFileSortOptionsEnabled sets the property returned by [IsCustomizationFlagEnabled].

func (Instance) SetFilenameFilter

func (self Instance) SetFilenameFilter(value string)

SetFilenameFilter sets the property returned by [GetFilenameFilter].

func (Instance) SetFilters

func (self Instance) SetFilters(value []string)

SetFilters sets the property returned by [GetFilters].

func (Instance) SetFolderCreationEnabled

func (self Instance) SetFolderCreationEnabled(value bool)

SetFolderCreationEnabled sets the property returned by [IsCustomizationFlagEnabled].

func (Instance) SetHiddenFilesToggleEnabled

func (self Instance) SetHiddenFilesToggleEnabled(value bool)

SetHiddenFilesToggleEnabled sets the property returned by [IsCustomizationFlagEnabled].

func (Instance) SetLayoutToggleEnabled

func (self Instance) SetLayoutToggleEnabled(value bool)

SetLayoutToggleEnabled sets the property returned by [IsCustomizationFlagEnabled].

func (Instance) SetModeOverridesTitle

func (self Instance) SetModeOverridesTitle(value bool)

SetModeOverridesTitle sets the property returned by [IsModeOverridingTitle].

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetOptionCount

func (self Instance) SetOptionCount(value int)

SetOptionCount sets the property returned by [GetOptionCount].

func (Instance) SetOptionDefault

func (self Instance) SetOptionDefault(option int, default_value_index int)

Sets the default value index of the OptionButton or CheckBox with index 'option'.

func (Instance) SetOptionName

func (self Instance) SetOptionName(option int, name string)

Sets the name of the OptionButton or CheckBox with index 'option'.

func (Instance) SetOptionValues

func (self Instance) SetOptionValues(option int, values []string)

Sets the option values of the OptionButton with index 'option'.

func (Instance) SetRecentListEnabled

func (self Instance) SetRecentListEnabled(value bool)

SetRecentListEnabled sets the property returned by [IsCustomizationFlagEnabled].

func (Instance) SetRootSubfolder

func (self Instance) SetRootSubfolder(value string)

SetRootSubfolder sets the property returned by [GetRootSubfolder].

func (Instance) SetShowHiddenFiles

func (self Instance) SetShowHiddenFiles(value bool)

SetShowHiddenFiles sets the property returned by [IsShowingHiddenFiles].

func (Instance) SetUseNativeDialog

func (self Instance) SetUseNativeDialog(value bool)

SetUseNativeDialog sets the property returned by [GetUseNativeDialog].

func (Instance) ShowHiddenFiles

func (self Instance) ShowHiddenFiles() bool

If true, the dialog will show hidden files.

Note: This property is ignored by native file dialogs on Android and Linux.

func (Instance) UseNativeDialog

func (self Instance) UseNativeDialog() bool

If true, and if supported by the current DisplayServer, OS native dialog will be used instead of custom one.

Note: On Android, it is only supported for Android 10+ devices and when using AccessFilesystem. For access mode AccessResources and AccessUserdata, the system will fall back to custom FileDialog.

Note: On Linux and macOS, sandboxed apps always use native dialogs to access the host file system.

Note: On macOS, sandboxed apps will save security-scoped bookmarks to retain access to the opened folders across multiple sessions. Use OS.GetGrantedPermissions to get a list of saved bookmarks.

Note: Native dialogs are isolated from the base process, file dialog properties can't be modified once the dialog is shown.

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type MoreArgs

type MoreArgs [1]gdclass.FileDialog

MoreArgs is a container for Instance functions with additional 'optional' arguments.

func (MoreArgs) AddFilter

func (self MoreArgs) AddFilter(filter string, description string)

Adds a comma-separated file name 'filter' option to the FileDialog with an optional 'description', which restricts what files can be picked.

A 'filter' should be of the form "filename.extension", where filename and extension can be * to match any string. Filters starting with . (i.e. empty filenames) are not allowed.

For example, a 'filter' of "*.png, *.jpg" and a 'description' of "Images" results in filter text "Images (*.png, *.jpg)".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL