Class: Wx::FileDialogCustomizeHook
- Inherits:
-
Object
- Object
- Wx::FileDialogCustomizeHook
- Defined in:
- lib/wx/doc/gen/file_dialog_customize_hook.rb
Overview
Base class for customization hooks used with FileDialog.
FileDialogCustomizeHook is an abstract base class, i.e. in order to use a concrete class inheriting from it and implementing its pure virtual #add_custom_controls function must be defined. Then an object of this class should be passed to Wx::FileDialog#set_customize_hook, which will result in its #add_custom_controls being called before the dialog is shown, #update_custom_controls being called whenever something changes in the dialog while it is shown and, finally, #transfer_data_from_custom_controls being called when the user accepts their choice in the dialog. Putting all this together, here is an example of customizing the file dialog using this class:
class EncryptHook < Wx::FileDialogCustomizeHook
attr_reader :encrypt
# Override to add custom controls using the provided customizer object.
def add_custom_controls(customizer)
# Suppose we can encrypt files when saving them.
@checkbox = customizer.add_check_box('Encrypt')
# While @checkbox is not a Wx::CheckBox, it looks almost like one
# and, in particular, we can bind to custom control events as usual.
@checkbox.evt_checkbox(Wx::ID_ANY) do |event|
# We can also call Wx::Window-like functions on them.
@button.enable(event.checked?)
end
# The encryption parameters can be edited in a dedicated dialog.
@button = customizer.add_button('Parameters...')
@button.evt_button(Wx::ID_ANY) do |event|
# ... show the encryption parameters dialog here ...
end
end
# Override to save the values of the custom controls.
def transfer_data_from_custom_controls
# Save the checkbox value, as we won't be able to use it any more
# once this function returns.
@encrypt = @checkbox.get_value
end
end
# ...
def some_method
Wx.FileDialog(nil, 'Save document', '', 'file.my',
'My files (*.my)|*.my',
Wx::FD_SAVE | Wx::FD_OVERWRITE_PROMPT) do |dialog|
# This object may be destroyed before the dialog, but must remain
# alive until #show_modal returns.
customize_hook = EncryptHook.new
dialog.set_customize_hook(custom_hook)
if dialog.show_modal == Wx::ID_OK
if customize_hook.encrypt
# ... save with encryption ...
else
# ... save without encryption ...
end
end
end
Category: Common Dialogs
Instance Method Summary collapse
-
#add_custom_controls(customizer) ⇒ void
Must be overridden to add custom controls to the dialog using the provided customizer object.
-
#transfer_data_from_custom_controls ⇒ void
Should typically be overridden to save the values of the custom controls when the dialog is accepted.
-
#update_custom_controls ⇒ void
May be overridden to update the custom controls whenever something changes in the dialog.
Instance Method Details
#add_custom_controls(customizer) ⇒ void
This method returns an undefined value.
Must be overridden to add custom controls to the dialog using the provided customizer object.
Call Wx::FileDialogCustomize functions to add controls and possibly bind to their events. Note that there is no possibility to define the custom controls layout, they will appear more or less consecutively, but the exact layout is determined by the current platform.
81 |
# File 'lib/wx/doc/gen/file_dialog_customize_hook.rb', line 81 def add_custom_controls(customizer) end |
#transfer_data_from_custom_controls ⇒ void
This method returns an undefined value.
Should typically be overridden to save the values of the custom controls when the dialog is accepted.
Custom controls are destroyed and cannot be used any longer once Wx::FileDialog#show_modal returns, so their values must be retrieved in this function, which is called just before this happens. This function is not called if the user cancels the dialog. Base class version does nothing.
97 |
# File 'lib/wx/doc/gen/file_dialog_customize_hook.rb', line 97 def transfer_data_from_custom_controls; end |
#update_custom_controls ⇒ void
This method returns an undefined value.
May be overridden to update the custom controls whenever something changes in the dialog.
This function is called when the user selects a file, changes the directory or changes the current filter in the dialog, for example. It can be used to update the custom controls state depending on the currently selected file, for example. Note that it is not necessarily called when the value of a custom control changes. Base class version does nothing.
89 |
# File 'lib/wx/doc/gen/file_dialog_customize_hook.rb', line 89 def update_custom_controls; end |