Struct gtk::FileChooserNative [−][src]
pub struct FileChooserNative(_);
Expand description
FileChooserNative
is an abstraction of a dialog box suitable
for use with “File/Open” or “File/Save as” commands. By default, this
just uses a FileChooserDialog
to implement the actual dialog.
However, on certain platforms, such as Windows and macOS, the native platform
file chooser is used instead. When the application is running in a
sandboxed environment without direct filesystem access (such as Flatpak),
FileChooserNative
may call the proper APIs (portals) to let the user
choose a file and make it available to the application.
While the API of FileChooserNative
closely mirrors FileChooserDialog
, the main
difference is that there is no access to any Window
or Widget
for the dialog.
This is required, as there may not be one in the case of a platform native dialog.
Showing, hiding and running the dialog is handled by the NativeDialog
functions.
Typical usage ## {gtkfilechoosernative
-typical-usage}
In the simplest of cases, you can the following code to use
FileChooserDialog
to select a file for opening:
GtkFileChooserNative *native;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
gint res;
native = gtk_file_chooser_native_new ("Open File",
parent_window,
action,
"_Open",
"_Cancel");
res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native));
if (res == GTK_RESPONSE_ACCEPT)
{
char *filename;
GtkFileChooser *chooser = GTK_FILE_CHOOSER (native);
filename = gtk_file_chooser_get_filename (chooser);
open_file (filename);
g_free (filename);
}
g_object_unref (native);
To use a dialog for saving, you can use this:
GtkFileChooserNative *native;
GtkFileChooser *chooser;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
gint res;
native = gtk_file_chooser_native_new ("Save File",
parent_window,
action,
"_Save",
"_Cancel");
chooser = GTK_FILE_CHOOSER (native);
gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
if (user_edited_a_new_document)
gtk_file_chooser_set_current_name (chooser,
_("Untitled document"));
else
gtk_file_chooser_set_filename (chooser,
existing_filename);
res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native));
if (res == GTK_RESPONSE_ACCEPT)
{
char *filename;
filename = gtk_file_chooser_get_filename (chooser);
save_to_file (filename);
g_free (filename);
}
g_object_unref (native);
For more information on how to best set up a file dialog, see FileChooserDialog
.
Response Codes ## {gtkfilechooserdialognative
-responses}
FileChooserNative
inherits from NativeDialog
, which means it
will return ResponseType::Accept
if the user accepted, and
ResponseType::Cancel
if he pressed cancel. It can also return
ResponseType::DeleteEvent
if the window was unexpectedly closed.
Differences from FileChooserDialog
## {gtkfilechooserdialognative
-differences}
There are a few things in the GtkFileChooser API that are not
possible to use with FileChooserNative
, as such use would
prohibit the use of a native dialog.
There is no support for the signals that are emitted when the user navigates in the dialog, including:
signal::FileChooser::current-folder-changed
signal::FileChooser::selection-changed
signal::FileChooser::file-activated
signal::FileChooser::confirm-overwrite
You can also not use the methods that directly control user navigation:
If you need any of the above you will have to use FileChooserDialog
directly.
No operations that change the the dialog work while the dialog is visible. Set all the properties that are required before showing the dialog.
Win32 details ## {gtkfilechooserdialognative
-win32}
On windows the IFileDialog implementation (added in Windows Vista) is
used. It supports many of the features that FileChooserDialog
does, but there are some things it does not handle:
-
Extra widgets added with
FileChooserExt::set_extra_widget()
. -
Use of custom previews by connecting to
signal::FileChooser::update-preview
. -
Any
FileFilter
added using a mimetype or custom filter.
If any of these features are used the regular FileChooserDialog
will be used in place of the native one.
Portal details ## {gtkfilechooserdialognative
-portal}
When the org.freedesktop.portal.FileChooser portal is available on the session bus, it is used to bring up an out-of-process file chooser. Depending on the kind of session the application is running in, this may or may not be a GTK+ file chooser. In this situation, the following things are not supported and will be silently ignored:
-
Extra widgets added with
FileChooserExt::set_extra_widget()
. -
Use of custom previews by connecting to
signal::FileChooser::update-preview
. -
Any
FileFilter
added with a custom filter.
macOS details ## {gtkfilechooserdialognative
-macos}
On macOS the NSSavePanel and NSOpenPanel classes are used to provide native
file chooser dialogs. Some features provided by FileChooserDialog
are
not supported:
-
Extra widgets added with
FileChooserExt::set_extra_widget()
, unless the widget is an instance of GtkLabel, in which case the label text will be used to set the NSSavePanel message instance property. -
Use of custom previews by connecting to
signal::FileChooser::update-preview
. -
Any
FileFilter
added with a custom filter. -
Shortcut folders.
Implements
NativeDialogExt
, glib::ObjectExt
, FileChooserExt
, NativeDialogExtManual
Implementations
pub fn new<P: IsA<Window>>(
title: Option<&str>,
parent: Option<&P>,
action: FileChooserAction,
accept_label: Option<&str>,
cancel_label: Option<&str>
) -> FileChooserNative
This is supported on crate feature v3_20
only.
pub fn new<P: IsA<Window>>(
title: Option<&str>,
parent: Option<&P>,
action: FileChooserAction,
accept_label: Option<&str>,
cancel_label: Option<&str>
) -> FileChooserNative
v3_20
only.Creates a new FileChooserNative
.
title
Title of the native, or None
parent
Transient parent of the native, or None
action
Open or save mode for the dialog
accept_label
text to go in the accept button, or None
for the default
cancel_label
text to go in the cancel button, or None
for the default
Returns
a new FileChooserNative
This is supported on crate feature v3_20
only.
v3_20
only.Creates a new builder-pattern struct instance to construct FileChooserNative
objects.
This method returns an instance of FileChooserNativeBuilder
which can be used to create FileChooserNative
objects.
This is supported on crate feature v3_20
only.
v3_20
only.This is supported on crate feature v3_20
only.
v3_20
only.This is supported on crate feature v3_20
only.
v3_20
only.Sets the custom label text for the accept button.
If characters in label
are preceded by an underscore, they are underlined.
If you need a literal underscore character in a label, use “__” (two
underscores). The first underlined character represents a keyboard
accelerator called a mnemonic.
Pressing Alt and that key activates the button.
accept_label
custom label or None
for the default
This is supported on crate feature v3_20
only.
v3_20
only.Sets the custom label text for the cancel button.
If characters in label
are preceded by an underscore, they are underlined.
If you need a literal underscore character in a label, use “__” (two
underscores). The first underlined character represents a keyboard
accelerator called a mnemonic.
Pressing Alt and that key activates the button.
cancel_label
custom label or None
for the default
This is supported on crate feature v3_20
only.
v3_20
only.The text used for the label on the accept button in the dialog, or
None
to use the default text.
This is supported on crate feature v3_20
only.
v3_20
only.The text used for the label on the accept button in the dialog, or
None
to use the default text.
This is supported on crate feature v3_20
only.
v3_20
only.The text used for the label on the cancel button in the dialog, or
None
to use the default text.
This is supported on crate feature v3_20
only.
v3_20
only.The text used for the label on the cancel button in the dialog, or
None
to use the default text.
v3_20
only.v3_20
only.Trait Implementations
type Parent = NativeDialog
impl<T: ObjectType> PartialEq<T> for FileChooserNative
This is supported on crate feature v3_20
only.
impl<T: ObjectType> PartialEq<T> for FileChooserNative
v3_20
only.impl<T: ObjectType> PartialOrd<T> for FileChooserNative
This is supported on crate feature v3_20
only.
impl<T: ObjectType> PartialOrd<T> for FileChooserNative
v3_20
only.This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Returns the type identifier of Self
.
Auto Trait Implementations
impl RefUnwindSafe for FileChooserNative
impl !Send for FileChooserNative
impl !Sync for FileChooserNative
impl Unpin for FileChooserNative
impl UnwindSafe for FileChooserNative
Blanket Implementations
Mutably borrows from an owned value. Read more
Upcasts an object to a superclass or interface T
. Read more
Upcasts an object to a reference of its superclass or interface T
. Read more
Tries to downcast to a subclass or interface implementor T
. Read more
Tries to downcast to a reference of its subclass or interface implementor T
. Read more
Tries to cast to an object of type T
. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast
and upcast
will do many checks at compile-time already. Read more
Tries to cast to reference to an object of type T
. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast
and upcast
will do many checks at compile-time already. Read more
Casts to T
unconditionally. Read more
Casts to &T
unconditionally. Read more
Returns true
if the object is an instance of (can be cast to) T
.
pub fn set_properties_from_value(
&self,
property_values: &[(&str, Value)]
) -> Result<(), BoolError>
pub fn set_property<'a, N, V>(
&self,
property_name: N,
value: V
) -> Result<(), BoolError> where
V: ToValue,
N: Into<&'a str>,
pub fn set_property_from_value<'a, N>(
&self,
property_name: N,
value: &Value
) -> Result<(), BoolError> where
N: Into<&'a str>,
Safety Read more
Safety Read more
Safety Read more
Safety Read more
pub fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec) + Send + Sync,
pub fn connect_notify_local<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec),
pub unsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: Fn(&T, &ParamSpec),
pub fn has_property<'a, N>(&self, property_name: N, type_: Option<Type>) -> bool where
N: Into<&'a str>,
pub fn find_property<'a, N>(&self, property_name: N) -> Option<ParamSpec> where
N: Into<&'a str>,
pub fn connect<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
F: Fn(&[Value]) -> Option<Value> + Send + Sync + 'static,
N: Into<&'a str>,
Same as connect
but takes a SignalId
instead of a signal name.
pub fn connect_local<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
F: Fn(&[Value]) -> Option<Value> + 'static,
N: Into<&'a str>,
Same as connect_local
but takes a SignalId
instead of a signal name.
pub unsafe fn connect_unsafe<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
F: Fn(&[Value]) -> Option<Value>,
N: Into<&'a str>,
Same as connect_unsafe
but takes a SignalId
instead of a signal name.
Emit signal by signal id.
Emit signal with details by signal id.
Emit signal by it’s name.
pub fn bind_property<'a, O, N, M>(
&'a self,
source_property: N,
target: &'a O,
target_property: M
) -> BindingBuilder<'a> where
O: ObjectType,
N: Into<&'a str>,
M: Into<&'a str>,
Same as emit
but takes Value
for the arguments.
Same as emit_by_name
but takes Value
for the arguments.
Returns a SendValue
clone of self
.
impl<'a, T, C> FromValueOptional<'a> for T where
C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError>,
T: FromValue<'a, Checker = C>,