# :stopdoc: # This file is automatically generated by the WXRuby3 documentation # generator. Do not alter this file. # :startdoc: module Wx # FD_DEFAULT_STYLE = 1 # # FD_OPEN = 1 # # FD_SAVE = 2 # # FD_OVERWRITE_PROMPT = 4 # # FD_NO_FOLLOW = 8 # # FD_FILE_MUST_EXIST = 16 # # FD_CHANGE_DIR = 128 # # FD_PREVIEW = 256 # # FD_MULTIPLE = 512 # # FD_SHOW_HIDDEN = 1024 # Default wildcard string used in {Wx::FileDialog} corresponding to all files. # FILE_SELECTOR_DEFAULT_WILDCARD_STR = "*.*" # This class represents the file chooser dialog. # # The path and filename are distinct elements of a full file pathname. If path is {Wx::EmptyString}, the current directory will be used. If filename is {Wx::EmptyString}, no default filename will be supplied. The wildcard determines what files are displayed in the file selector, and file extension supplies a type extension for the required filename. # The typical usage for the open file dialog is: # ```ruby # class MyFrame # ... # def on_open(event) # if (...current content has not been saved...) # if Wx.message_box('Current content has not been saved! Proceed?', 'Please confirm', # Wx::ICON_QUESTION | Wx::YES_NO, self) == Wx::NO # return # #else: proceed asking to the user the new file to open # end # end # # Wx::FileDialog(self, "Open XYZ file", "", "", # "XYZ files (*.xyz)|*.xyz", Wx::FD_OPEN|Wx::FD_FILE_MUST_EXIST) do |dlg| # return if dlg.show_modal == Wx::ID_CANCEL # the user changed idea...? # # # proceed loading the file chosen by the user # file = File.open(dlg.path, 'r') rescue nil # unless file # Wx.log_error("Cannot open file '#{dlg.path}'.") # return # end # ... # end # end # # end # ``` # # The typical usage for the save file dialog is instead somewhat simpler: # ```ruby # class MyFrame # ... # def on_save_as(event) # Wx::FileDialog(self, "Save XYZ file", "", "", # "XYZ files (*.xyz)|*.xyz", Wx::FD_SAVE|Wx::FD_OVERWRITE_PROMPT) do |dlg| # return if dlg.show_modal == Wx::ID_CANCEL # the user changed idea...? # # # save the current contents in the file # begin # File.open(dlg.path, 'w+') do |f| # # save to file # end # rescue # Wx.log_error("Cannot save current contents in file '#{dlg.path}'.") # return # end # end # ... # end # # end # ``` # # ## Wildcard Filters # # All implementations of the {Wx::FileDialog} provide a wildcard filter. Typing a filename containing wildcards (*, ?) in the filename text item, and clicking on Ok, will result in only those files matching the pattern being displayed. The wildcard may be a specification for multiple types of file with a description for each, such as: # ``` # "BMP and GIF files (*.bmp;*.gif)|*.bmp;*.gif|PNG files (*.png)|*.png" # ``` # # On Mac macOS in the open file dialog the filter choice box is not shown by default. Instead all given wildcards are applied at the same time: So in the above example all bmp, gif and png files are displayed. To enforce the display of the filter choice set the corresponding {Wx::SystemOptions} before calling the file open dialog: # ```ruby # Wx::SystemOptions.set_option(Wx::OSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1) # ``` # But in contrast to Windows and Unix, where the file type choice filters only the selected files, on Mac macOS even in this case the dialog shows all files matching all file types. The files which does not match the currently selected file type are greyed out and are not selectable. # # ## Dialog Customization # # Uniquely among the other standard dialogs, {Wx::FileDialog} can be customized by adding extra controls to it. Moreover, there are two ways to do it: the first one is to define a callback function and use {Wx::FileDialog#set_extra_control_creator} to tell the dialog to call it, while the second one requires defining a class inheriting from {Wx::FileDialogCustomizeHook} and implementing its virtual functions, notably {Wx::FileDialogCustomizeHook#add_custom_controls} where the extra controls have to be created, and finally calling {Wx::FileDialog#set_customize_hook} with this custom hook object. # The first approach is somewhat simpler and more flexible, as it allows to create any kind of custom controls, but is not supported by the "new style" (where "new" means used since Windows Vista, i.e. circa 2007) file dialogs under MSW. Because of this, calling {Wx::FileDialog#set_extra_control_creator} in WXMSW forces the use of old style (Windows XP) dialogs, that may look out of place. The second approach is implemented by the MSW dialogs natively and doesn't suffer from this limitation, so its use is recommended, especially if the few simple control types supported by it (see {Wx::FileDialogCustomize} for more information about the supported controls) are sufficient for your needs. # Both of the approaches to the dialog customization are demonstrated in the Dialogs Sample, please check it for more details. # #
# Note: #

New style file dialogs can only be used in WXMSW when the apartment, COM threading model is used. This is the case by default, but if the application initializes COM on its own using multi-threaded model, old style dialogs are used, at least when they must have a parent, as the new style dialog doesn't support this threading model. #

#
# # ### Styles # # This class supports the following styles: # # - {Wx::FD_DEFAULT_STYLE}: Equivalent to {Wx::FD_OPEN}. # # - {Wx::FD_OPEN}: This is an open dialog; usually this means that the default button's label of the dialog is "Open". Cannot be combined with {Wx::FD_SAVE}. # # - {Wx::FD_SAVE}: This is a save dialog; usually this means that the default button's label of the dialog is "Save". Cannot be combined with {Wx::FD_OPEN}. # # - {Wx::FD_OVERWRITE_PROMPT}: For save dialog only: prompt for a confirmation if a file will be overwritten. This style is always enabled on WXOSX and cannot be disabled. # # - {Wx::FD_NO_FOLLOW}: Directs the dialog to return the path and file name of the selected shortcut file, not its target as it does by default. Currently this flag is only implemented in WXMSW and WXOSX (where it prevents aliases from being resolved). The non-dereferenced link path is always returned, even without this flag, under Unix and so using it there doesn't do anything. This flag was added in wxWidgets 3.1.0. # # - {Wx::FD_FILE_MUST_EXIST}: For open dialog only: the user may only select files that actually exist. Notice that under macOS the file dialog with {Wx::FD_OPEN} style always behaves as if this style was specified, because it is impossible to choose a file that doesn't exist from a standard macOS file dialog. # # - {Wx::FD_MULTIPLE}: For open dialog only: allows selecting multiple files. # # - {Wx::FD_CHANGE_DIR}: Change the current working directory (when the dialog is dismissed) to the directory where the file(s) chosen by the user are. # # - {Wx::FD_PREVIEW}: Show the preview of the selected files (currently only supported by WXGTK). # # - {Wx::FD_SHOW_HIDDEN}: Show hidden files. This flag was added in wxWidgets 3.1.3 # # Category: Common Dialogs # @see wxFileDialog Overview # @see file_selector # # # @wxrb_require USE_FILEDLG class FileDialog < Dialog # Constructor. # # Use {Wx::FileDialog#show_modal} to show the dialog. # @param parent [Wx::Window] Parent window. # @param message [String] Message to show on the dialog. # @param defaultDir [String] The default directory, or the empty string. # @param defaultFile [String] The default filename, or the empty string. # @param wildcard [String] A wildcard, such as "*.*" or "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif". Note that the native Motif dialog has some limitations with respect to wildcards; see the Remarks section above. # @param style [Integer] A dialog style. See wxFD_* styles for more info. # @param pos [Array(Integer, Integer), Wx::Point] Dialog position. Not implemented. # @param size [Array(Integer, Integer), Wx::Size] Dialog size. Not implemented. # @param name [String] Dialog name. Not implemented. # @return [Wx::FileDialog] def initialize(parent, message=Wx::FILE_SELECTOR_PROMPT_STR, defaultDir=(''), defaultFile=(''), wildcard=Wx::FILE_SELECTOR_DEFAULT_WILDCARD_STR, style=Wx::FD_DEFAULT_STYLE, pos=Wx::DEFAULT_POSITION, size=Wx::DEFAULT_SIZE, name=Wx::FILE_DIALOG_NAME_STR) end # Returns the path of the file currently selected in dialog. # # Notice that this file is not necessarily going to be accepted by the user, so calling this function mostly makes sense from an update UI event handler of a custom file dialog extra control to update its state depending on the currently selected file. # Currently this function is fully implemented under GTK and MSW and always returns an empty string elsewhere. # # The path of the currently selected file or an empty string if nothing is selected. # @see Wx::FileDialog#set_extra_control_creator # @return [String] def get_currently_selected_filename; end alias_method :currently_selected_filename, :get_currently_selected_filename # Returns the file type filter index currently selected in dialog. # # Notice that this file type filter is not necessarily going to be the one finally accepted by the user, so calling this function mostly makes sense from an update UI event handler of a custom file dialog extra control to update its state depending on the currently selected file type filter. # Currently this function is fully implemented under macOS and MSW and always returns {Wx::NOT_FOUND} elsewhere. # # The 0-based index of the currently selected file type filter or {Wx::NOT_FOUND} if nothing is selected. # @see Wx::FileDialog#set_extra_control_creator # # @see Wx::FileDialog#get_filter_index # # @see Wx::FileDialog#set_filter_index # @return [Integer] def get_currently_selected_filter_index; end alias_method :currently_selected_filter_index, :get_currently_selected_filter_index # Returns the default directory. # @return [String] def get_directory; end alias_method :directory, :get_directory # If functions {Wx::FileDialog#set_extra_control_creator} and {Wx::FileDialog#show_modal} were called, returns the extra window. # # Otherwise returns NULL. # @return [Wx::Window] def get_extra_control; end alias_method :extra_control, :get_extra_control # Returns the default filename. # #
# Note: #

This function can't be used with dialogs which have the {Wx::FD_MULTIPLE} style, use {Wx::FileDialog#get_filenames} instead. #

#
# @return [String] def get_filename; end alias_method :filename, :get_filename # Fills the array filenames with the names of the files chosen. # # This function should only be used with the dialogs which have {Wx::FD_MULTIPLE} style, use {Wx::FileDialog#get_filename} for the others. # Note that under Windows, if the user selects shortcuts, the filenames include paths, since the application cannot determine the full path of each referenced file by appending the directory containing the shortcuts to the filename. # @return [Array] def get_filenames; end alias_method :filenames, :get_filenames # Returns the index into the list of filters supplied, optionally, in the wildcard parameter. # # Before the dialog is shown, this is the index which will be used when the dialog is first displayed. # After the dialog is shown, this is the index selected by the user. # @return [Integer] def get_filter_index; end alias_method :filter_index, :get_filter_index # Returns the message that will be displayed on the dialog. # @return [String] def get_message; end alias_method :message, :get_message # Returns the full path (directory and filename) of the selected file. # #
# Note: #

This function can't be used with dialogs which have the {Wx::FD_MULTIPLE} style, use {Wx::FileDialog#get_paths} instead. #

#
# @return [String] def get_path; end alias_method :path, :get_path # Fills the array paths with the full paths of the files chosen. # # This function should only be used with the dialogs which have {Wx::FD_MULTIPLE} style, use {Wx::FileDialog#get_path} for the others. # @return [Array] def get_paths; end alias_method :paths, :get_paths # Returns the file dialog wildcard. # @return [String] def get_wildcard; end alias_method :wildcard, :get_wildcard # Set the hook to be used for customizing the dialog contents. # # This function can be called before calling {Wx::FileDialog#show_modal} to specify that the dialog contents should be customized using the provided hook. See {Wx::FileDialogCustomizeHook} documentation and Dialogs Sample for the examples of using it. # #
# Note: #

In order to define a custom hook object, Wx::/filedlgcustomize.h must be included in addition to the usual Wx::/filedlg.h header. #

#
# # true if the hook was successfully set or false if customizing the file dialog is not supported by the current platform. # @param customizeHook [Wx::FileDialogCustomizeHook] The hook object that will be used by the dialog. This object must remain valid at least until {Wx::FileDialog#show_modal} returns. # @return [Boolean] def set_customize_hook(customizeHook) end alias_method :customize_hook=, :set_customize_hook # Sets the default directory. # @param directory [String] # @return [void] def set_directory(directory) end alias_method :directory=, :set_directory # Sets the default filename. # # In WXGTK this will have little effect unless a default directory has previously been set. # @param setfilename [String] # @return [void] def set_filename(setfilename) end alias_method :filename=, :set_filename # Sets the default filter index, starting from zero. # @param filterIndex [Integer] # @return [void] def set_filter_index(filterIndex) end alias_method :filter_index=, :set_filter_index # Sets the message that will be displayed on the dialog. # @param message [String] # @return [void] def set_message(message) end alias_method :message=, :set_message # Sets the path (the combined directory and filename that will be returned when the dialog is dismissed). # @param path [String] # @return [void] def set_path(path) end alias_method :path=, :set_path # Sets the wildcard, which can contain multiple file types, for example: "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif". # # Note that the native Motif dialog has some limitations with respect to wildcards; see the Remarks section above. # @param wildCard [String] # @return [void] def set_wildcard(wildCard) end alias_method :wildcard=, :set_wildcard # Shows the dialog, returning {Wx::StandardID::ID_OK} if the user pressed OK, and {Wx::StandardID::ID_CANCEL} otherwise. # @return [Integer] def show_modal; end end # FileDialog end