Class FileDialog

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class FileDialog extends GObject

Asynchronous API to present a file chooser dialog.

GtkFileDialog collects the arguments that are needed to present the dialog to the user, such as a title for the dialog and whether it should be modal.

The dialog is shown with open(Window, Cancellable, AsyncReadyCallback), save(Window, Cancellable, AsyncReadyCallback), etc.

Since:
4.10
  • Constructor Details

    • FileDialog

      public FileDialog(MemorySegment address)
      Create a FileDialog instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • FileDialog

      public FileDialog()
      Create a new FileDialog.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the FileDialog class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected FileDialog asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • getAcceptLabel

      public @Nullable String getAcceptLabel()
      Retrieves the text used by the dialog on its accept button.
      Returns:
      the label shown on the file chooser's accept button
      Since:
      4.10
    • getDefaultFilter

      public @Nullable FileFilter getDefaultFilter()
      Gets the filter that will be selected by default in the file chooser dialog.
      Returns:
      the default filter
      Since:
      4.10
    • getFilters

      public @Nullable ListModel getFilters()
      Gets the filters that will be offered to the user in the file chooser dialog.
      Returns:
      the filters, as a list model of FileFilter
      Since:
      4.10
    • getInitialFile

      public @Nullable File getInitialFile()
      Gets the file that will be initially selected in the file chooser dialog.
      Returns:
      the file
      Since:
      4.10
    • getInitialFolder

      public @Nullable File getInitialFolder()
      Gets the folder that will be set as the initial folder in the file chooser dialog.
      Returns:
      the folder
      Since:
      4.10
    • getInitialName

      public @Nullable String getInitialName()
      Gets the filename that will be initially selected.
      Returns:
      the name
      Since:
      4.10
    • getModal

      public boolean getModal()
      Returns whether the file chooser dialog blocks interaction with the parent window while it is presented.
      Returns:
      true if the file chooser dialog is modal
      Since:
      4.10
    • getTitle

      public String getTitle()
      Returns the title that will be shown on the file chooser dialog.
      Returns:
      the title
      Since:
      4.10
    • open

      public void open(@Nullable Window parent, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Presents a file chooser dialog to the user.

      The file chooser dialog will be set up to select a single file.

      The callback will be called when the dialog is closed.

      Parameters:
      parent - the parent window
      cancellable - a cancellable to cancel the operation
      callback - a callback to call when the operation is complete
      Since:
      4.10
    • openFinish

      public File openFinish(AsyncResult result) throws GErrorException

      Finishes the open(Window, Cancellable, AsyncReadyCallback) call.

      Note that this function returns a Gtk.DialogError.DISMISSED error if the user cancels the dialog.

      Parameters:
      result - the result
      Returns:
      the file that was selected
      Throws:
      GErrorException - see GError
      Since:
      4.10
    • openMultiple

      public void openMultiple(@Nullable Window parent, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Presents a file chooser dialog to the user.

      The file chooser dialog will be set up to select multiple files.

      The file chooser dialog will initially be opened in the directory Gtk.FileDialog:initial-folder.

      The callback will be called when the dialog is closed.

      Parameters:
      parent - the parent window
      cancellable - a cancellable to cancel the operation
      callback - a callback to call when the operation is complete
      Since:
      4.10
    • openMultipleFinish

      public ListModel openMultipleFinish(AsyncResult result) throws GErrorException

      Finishes the open(Window, Cancellable, AsyncReadyCallback) call.

      Note that this function returns a Gtk.DialogError.DISMISSED error if the user cancels the dialog.

      Parameters:
      result - the result
      Returns:
      the files that were selected, as a list model of File
      Throws:
      GErrorException - see GError
      Since:
      4.10
    • openMultipleTextFiles

      public void openMultipleTextFiles(@Nullable Window parent, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Presents a file chooser dialog to the user.

      The file chooser dialog will be set up to select multiple files.

      The file chooser dialog will initially be opened in the directory Gtk.FileDialog:initial-folder.

      In contrast to open(Window, Cancellable, AsyncReadyCallback), this function lets the user select the text encoding for the files, if possible.

      The callback will be called when the dialog is closed.

      Parameters:
      parent - the parent window
      cancellable - a cancellable to cancel the operation
      callback - a callback to call when the operation is complete
      Since:
      4.18
    • openMultipleTextFilesFinish

      public ListModel openMultipleTextFilesFinish(AsyncResult result, Out<String> encoding) throws GErrorException

      Finishes the open(Window, Cancellable, AsyncReadyCallback) call.

      Note that this function returns a Gtk.DialogError.DISMISSED error if the user cancels the dialog.

      Parameters:
      result - the result
      encoding - return location for the text encoding to use
      Returns:
      the files that were selected, as a list model of File
      Throws:
      GErrorException - see GError
      Since:
      4.18
    • openTextFile

      public void openTextFile(@Nullable Window parent, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Initiates a file selection operation by presenting a file chooser dialog to the user.

      In contrast to open(Window, Cancellable, AsyncReadyCallback), this function lets the user select the text encoding for the file, if possible.

      The callback will be called when the dialog is closed.

      Parameters:
      parent - the parent GtkWindow
      cancellable - a GCancellable to cancel the operation
      callback - a callback to call when the operation is complete
      Since:
      4.18
    • openTextFileFinish

      public File openTextFileFinish(AsyncResult result, Out<String> encoding) throws GErrorException

      Finishes the openTextFile(Window, Cancellable, AsyncReadyCallback) call and returns the resulting file and text encoding.

      If the user has explicitly selected a text encoding to use for the file, then encoding will be set to a codeset name that is suitable for passing to iconv_open(). Otherwise, it will be NULL.

      Note that this function returns a Gtk.DialogError.DISMISSED error if the user cancels the dialog.

      Parameters:
      result - a GAsyncResult
      encoding - return location for the text encoding to use
      Returns:
      the file that was selected
      Throws:
      GErrorException - see GError
      Since:
      4.18
    • save

      public void save(@Nullable Window parent, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Presents a file chooser dialog to the user.

      The file chooser dialog will be save mode.

      The callback will be called when the dialog is closed.

      Parameters:
      parent - the parent window
      cancellable - a cancellable to cancel the operation
      callback - a callback to call when the operation is complete
      Since:
      4.10
    • saveFinish

      public File saveFinish(AsyncResult result) throws GErrorException

      Finishes the save(Window, Cancellable, AsyncReadyCallback) call.

      Note that this function returns a Gtk.DialogError.DISMISSED error if the user cancels the dialog.

      Parameters:
      result - the result
      Returns:
      the file that was selected
      Throws:
      GErrorException - see GError
      Since:
      4.10
    • saveTextFile

      public void saveTextFile(@Nullable Window parent, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Initiates a file save operation by presenting a file chooser dialog to the user.

      In contrast to save(Window, Cancellable, AsyncReadyCallback), this function lets the user select the text encoding and line endings for the text file, if possible.

      The callback will be called when the dialog is closed.

      Parameters:
      parent - the parent GtkWindow
      cancellable - a GCancellable to cancel the operation
      callback - a callback to call when the operation is complete
      Since:
      4.18
    • saveTextFileFinish

      public File saveTextFileFinish(AsyncResult result, Out<String> encoding, Out<String> lineEnding) throws GErrorException

      Finishes the saveTextFile(Window, Cancellable, AsyncReadyCallback) call and returns the resulting file, text encoding and line endings.

      If the user has explicitly selected a text encoding to use for the file, then encoding will be set to a codeset name that is suitable for passing to iconv_open(). Otherwise, it will be NULL.

      The lineEnding will be set to one of "\n", "\r\n", "\r" or "", where the latter means to preserve existing line endings.

      Note that this function returns a Gtk.DialogError.DISMISSED error if the user cancels the dialog.

      Parameters:
      result - a GAsyncResult
      encoding - return location for the text encoding to use
      lineEnding - return location for the line endings to use
      Returns:
      the file that was selected.
      Throws:
      GErrorException - see GError
      Since:
      4.18
    • selectFolder

      public void selectFolder(@Nullable Window parent, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Presents a file chooser dialog to the user.

      The file chooser dialog will be set up to select a single folder.

      If you pass initialFolder, the file chooser dialog will initially be opened in the parent directory of that folder, otherwise, it will be in the directory Gtk.FileDialog:initial-folder.

      The callback will be called when the dialog is closed.

      Parameters:
      parent - the parent window
      cancellable - a cancellable to cancel the operation
      callback - a callback to call when the operation is complete
      Since:
      4.10
    • selectFolderFinish

      public File selectFolderFinish(AsyncResult result) throws GErrorException

      Finishes the selectFolder(Window, Cancellable, AsyncReadyCallback) call.

      Note that this function returns a Gtk.DialogError.DISMISSED error if the user cancels the dialog.

      Parameters:
      result - the result
      Returns:
      the folder that was selected
      Throws:
      GErrorException - see GError
      Since:
      4.10
    • selectMultipleFolders

      public void selectMultipleFolders(@Nullable Window parent, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Presents a file chooser dialog to the user.

      The file chooser dialog will be set up to allow selecting multiple folders.

      The file chooser dialog will initially be opened in the directory Gtk.FileDialog:initial-folder.

      The callback will be called when the dialog is closed.

      Parameters:
      parent - the parent window
      cancellable - a cancellable to cancel the operation
      callback - a callback to call when the operation is complete
      Since:
      4.10
    • selectMultipleFoldersFinish

      public ListModel selectMultipleFoldersFinish(AsyncResult result) throws GErrorException

      Finishes the selectMultipleFolders(Window, Cancellable, AsyncReadyCallback) call.

      Note that this function returns a Gtk.DialogError.DISMISSED error if the user cancels the dialog.

      Parameters:
      result - the result
      Returns:
      the folders that were selected, as a list model of File
      Throws:
      GErrorException - see GError
      Since:
      4.10
    • setAcceptLabel

      public void setAcceptLabel(@Nullable String acceptLabel)

      Sets the label shown on the file chooser's accept button.

      Leaving the accept label unset or setting it as NULL will fall back to a default label, depending on what API is used to launch the file dialog.

      Parameters:
      acceptLabel - the new accept label
      Since:
      4.10
    • setDefaultFilter

      public void setDefaultFilter(@Nullable FileFilter filter)

      Sets the filter that will be selected by default in the file chooser dialog.

      If set to NULL, the first item in Gtk.FileDialog:filters will be used as the default filter. If that list is empty, the dialog will be unfiltered.

      Parameters:
      filter - the file filter
      Since:
      4.10
    • setFilters

      public void setFilters(@Nullable ListModel filters)
      Sets the filters that will be offered to the user in the file chooser dialog.
      Parameters:
      filters - a list model of FileFilter
      Since:
      4.10
    • setInitialFile

      public void setInitialFile(@Nullable File file)

      Sets the file that will be initially selected in the file chooser dialog.

      This function is a shortcut for calling both setInitialFolder(File) and setInitialName(String) with the directory and name of file, respectively.

      Parameters:
      file - a file
      Since:
      4.10
    • setInitialFolder

      public void setInitialFolder(@Nullable File folder)
      Sets the folder that will be set as the initial folder in the file chooser dialog.
      Parameters:
      folder - a file
      Since:
      4.10
    • setInitialName

      public void setInitialName(@Nullable String name)

      Sets the filename that will be initially selected.

      For save dialogs, name will usually be pre-entered into the name field.

      If a file with this name already exists in the directory set via Gtk.FileDialog:initial-folder, the dialog will preselect it.

      Parameters:
      name - a string
      Since:
      4.10
    • setModal

      public void setModal(boolean modal)
      Sets whether the file chooser dialog blocks interaction with the parent window while it is presented.
      Parameters:
      modal - the new value
      Since:
      4.10
    • setTitle

      public void setTitle(String title)
      Sets the title that will be shown on the file chooser dialog.
      Parameters:
      title - the new title
      Since:
      4.10
    • builder

      public static FileDialog.Builder<? extends FileDialog.Builder> builder()
      A FileDialog.Builder object constructs a FileDialog with the specified properties. Use the various set...() methods to set properties, and finish construction with FileDialog.Builder.build().
      Returns:
      the builder object