pub trait DialogExt: 'static {
Show 14 methods
fn add_action_widget(
&self,
child: &impl IsA<Widget>,
response_id: ResponseType
);
fn add_button(&self, button_text: &str, response_id: ResponseType) -> Widget;
fn content_area(&self) -> Box;
fn header_bar(&self) -> Option<HeaderBar>;
fn response_for_widget(&self, widget: &impl IsA<Widget>) -> ResponseType;
fn widget_for_response(&self, response_id: ResponseType) -> Option<Widget>;
fn response(&self, response_id: ResponseType);
fn run(&self) -> ResponseType;
fn set_default_response(&self, response_id: ResponseType);
fn set_response_sensitive(&self, response_id: ResponseType, setting: bool);
fn use_header_bar(&self) -> i32;
fn connect_close<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn emit_close(&self);
fn connect_response<F: Fn(&Self, ResponseType) + 'static>(
&self,
f: F
) -> SignalHandlerId;
}
Expand description
Trait containing all Dialog
methods.
Implementors
AboutDialog
, AppChooserDialog
, ColorChooserDialog
, Dialog
, FileChooserDialog
, FontChooserDialog
, MessageDialog
, RecentChooserDialog
Required Methods
fn add_action_widget(&self, child: &impl IsA<Widget>, response_id: ResponseType)
fn add_action_widget(&self, child: &impl IsA<Widget>, response_id: ResponseType)
Adds an activatable widget to the action area of a Dialog
,
connecting a signal handler that will emit the signal::Dialog::response
signal on the dialog when the widget is activated. The widget is
appended to the end of the dialog’s action area. If you want to add a
non-activatable widget, simply pack it into the action_area
field
of the Dialog
struct.
child
an activatable widget
response_id
response ID for child
Adds a button with the given text and sets things up so that
clicking the button will emit the signal::Dialog::response
signal with
the given response_id
. The button is appended to the end of the
dialog’s action area. The button widget is returned, but usually
you don’t need it.
button_text
text of button
response_id
response ID for the button
Returns
the Button
widget that was added
fn content_area(&self) -> Box
fn content_area(&self) -> Box
fn header_bar(&self) -> Option<HeaderBar>
fn header_bar(&self) -> Option<HeaderBar>
fn response_for_widget(&self, widget: &impl IsA<Widget>) -> ResponseType
fn response_for_widget(&self, widget: &impl IsA<Widget>) -> ResponseType
Gets the response id of a widget in the action area of a dialog.
widget
a widget in the action area of self
Returns
the response id of widget
, or ResponseType::None
if widget
doesn’t have a response id set.
fn widget_for_response(&self, response_id: ResponseType) -> Option<Widget>
fn widget_for_response(&self, response_id: ResponseType) -> Option<Widget>
Gets the widget button that uses the given response ID in the action area of a dialog.
response_id
the response ID used by the self
widget
Returns
the widget
button that uses the given
response_id
, or None
.
fn response(&self, response_id: ResponseType)
fn response(&self, response_id: ResponseType)
Emits the signal::Dialog::response
signal with the given response ID.
Used to indicate that the user has responded to the dialog in some way;
typically either you or run()
will be monitoring the
::response signal and take appropriate action.
response_id
response ID
fn run(&self) -> ResponseType
fn run(&self) -> ResponseType
Blocks in a recursive main loop until the self
either emits the
signal::Dialog::response
signal, or is destroyed. If the dialog is
destroyed during the call to run()
, run()
returns
ResponseType::None
. Otherwise, it returns the response ID from the
::response signal emission.
Before entering the recursive main loop, run()
calls
WidgetExt::show()
on the dialog for you. Note that you still
need to show any children of the dialog yourself.
During run()
, the default behavior of signal::Widget::delete-event
is disabled; if the dialog receives ::delete_event, it will not be
destroyed as windows usually are, and run()
will return
ResponseType::DeleteEvent
. Also, during run()
the dialog
will be modal. You can force run()
to return at any time by
calling response()
to emit the ::response signal. Destroying
the dialog during run()
is a very bad idea, because your
post-run code won’t know whether the dialog was destroyed or not.
After run()
returns, you are responsible for hiding or
destroying the dialog if you wish to do so.
Typical usage of this function might be:
⚠️ The following code is in C ⚠️
GtkWidget *dialog = gtk_dialog_new ();
// Set up dialog...
int result = gtk_dialog_run (GTK_DIALOG (dialog));
switch (result)
{
case GTK_RESPONSE_ACCEPT:
// do_application_specific_something ();
break;
default:
// do_nothing_since_dialog_was_cancelled ();
break;
}
gtk_widget_destroy (dialog);
Note that even though the recursive main loop gives the effect of a
modal dialog (it prevents the user from interacting with other
windows in the same window group while the dialog is run), callbacks
such as timeouts, IO channel watches, DND drops, etc, will
be triggered during a run()
call.
Returns
response ID
fn set_default_response(&self, response_id: ResponseType)
fn set_default_response(&self, response_id: ResponseType)
Sets the last widget in the dialog’s action area with the given response_id
as the default widget for the dialog. Pressing “Enter” normally activates
the default widget.
response_id
a response ID
fn set_response_sensitive(&self, response_id: ResponseType, setting: bool)
fn set_response_sensitive(&self, response_id: ResponseType, setting: bool)
Calls gtk_widget_set_sensitive (widget,
setting)
for each widget in the dialog’s action area with the given response_id
.
A convenient way to sensitize/desensitize dialog buttons.
response_id
a response ID
setting
true
for sensitive
fn use_header_bar(&self) -> i32
fn use_header_bar(&self) -> i32
fn connect_close<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId
fn connect_close<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId
The ::close signal is a [keybinding signal][GtkBindingSignal] which gets emitted when the user uses a keybinding to close the dialog.
The default binding for this signal is the Escape key.
fn emit_close(&self)
fn connect_response<F: Fn(&Self, ResponseType) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_response<F: Fn(&Self, ResponseType) + 'static>(
&self,
f: F
) -> SignalHandlerId
Emitted when an action widget is clicked, the dialog receives a
delete event, or the application programmer calls response()
.
On a delete event, the response ID is ResponseType::DeleteEvent
.
Otherwise, it depends on which action widget was clicked.
response_id
the response ID