Skip to main content

gtk/
app_chooser.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::Widget;
4use gio::AppInfo;
5use glib::object::IsA;
6use glib::translate::*;
7
8glib::wrapper! {
9    /// [`AppChooser`][crate::AppChooser] is an interface that can be implemented by widgets which
10    /// allow the user to choose an application (typically for the purpose of
11    /// opening a file). The main objects that implement this interface are
12    /// [`AppChooserWidget`][crate::AppChooserWidget], [`AppChooserDialog`][crate::AppChooserDialog] and [`AppChooserButton`][crate::AppChooserButton].
13    ///
14    /// Applications are represented by GIO [`gio::AppInfo`][crate::gio::AppInfo] objects here.
15    /// GIO has a concept of recommended and fallback applications for a
16    /// given content type. Recommended applications are those that claim
17    /// to handle the content type itself, while fallback also includes
18    /// applications that handle a more generic content type. GIO also
19    /// knows the default and last-used application for a given content
20    /// type. The [`AppChooserWidget`][crate::AppChooserWidget] provides detailed control over
21    /// whether the shown list of applications should include default,
22    /// recommended or fallback applications.
23    ///
24    /// To obtain the application that has been selected in a [`AppChooser`][crate::AppChooser],
25    /// use [`AppChooserExtManual::app_info()`][crate::prelude::AppChooserExtManual::app_info()].
26    ///
27    /// ## Properties
28    ///
29    ///
30    /// #### `content-type`
31    ///  The content type of the [`AppChooser`][crate::AppChooser] object.
32    ///
33    /// See [GContentType][gio-GContentType]
34    /// for more information about content types.
35    ///
36    /// Readable | Writeable | Construct Only
37    /// <details><summary><h4>Widget</h4></summary>
38    ///
39    ///
40    /// #### `app-paintable`
41    ///  Readable | Writeable
42    ///
43    ///
44    /// #### `can-default`
45    ///  Readable | Writeable
46    ///
47    ///
48    /// #### `can-focus`
49    ///  Readable | Writeable
50    ///
51    ///
52    /// #### `composite-child`
53    ///  Readable
54    ///
55    ///
56    /// #### `double-buffered`
57    ///  Whether the widget is double buffered.
58    ///
59    /// Readable | Writeable
60    ///
61    ///
62    /// #### `events`
63    ///  Readable | Writeable
64    ///
65    ///
66    /// #### `expand`
67    ///  Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
68    ///
69    /// Readable | Writeable
70    ///
71    ///
72    /// #### `focus-on-click`
73    ///  Whether the widget should grab focus when it is clicked with the mouse.
74    ///
75    /// This property is only relevant for widgets that can take focus.
76    ///
77    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
78    /// GtkComboBox) implemented this property individually.
79    ///
80    /// Readable | Writeable
81    ///
82    ///
83    /// #### `halign`
84    ///  How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
85    ///
86    /// Readable | Writeable
87    ///
88    ///
89    /// #### `has-default`
90    ///  Readable | Writeable
91    ///
92    ///
93    /// #### `has-focus`
94    ///  Readable | Writeable
95    ///
96    ///
97    /// #### `has-tooltip`
98    ///  Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
99    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
100    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
101    /// whether it will provide a tooltip or not.
102    ///
103    /// Note that setting this property to [`true`] for the first time will change
104    /// the event masks of the GdkWindows of this widget to include leave-notify
105    /// and motion-notify events. This cannot and will not be undone when the
106    /// property is set to [`false`] again.
107    ///
108    /// Readable | Writeable
109    ///
110    ///
111    /// #### `height-request`
112    ///  Readable | Writeable
113    ///
114    ///
115    /// #### `hexpand`
116    ///  Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
117    ///
118    /// Readable | Writeable
119    ///
120    ///
121    /// #### `hexpand-set`
122    ///  Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
123    ///
124    /// Readable | Writeable
125    ///
126    ///
127    /// #### `is-focus`
128    ///  Readable | Writeable
129    ///
130    ///
131    /// #### `margin`
132    ///  Sets all four sides' margin at once. If read, returns max
133    /// margin on any side.
134    ///
135    /// Readable | Writeable
136    ///
137    ///
138    /// #### `margin-bottom`
139    ///  Margin on bottom side of widget.
140    ///
141    /// This property adds margin outside of the widget's normal size
142    /// request, the margin will be added in addition to the size from
143    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
144    ///
145    /// Readable | Writeable
146    ///
147    ///
148    /// #### `margin-end`
149    ///  Margin on end of widget, horizontally. This property supports
150    /// left-to-right and right-to-left text directions.
151    ///
152    /// This property adds margin outside of the widget's normal size
153    /// request, the margin will be added in addition to the size from
154    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
155    ///
156    /// Readable | Writeable
157    ///
158    ///
159    /// #### `margin-left`
160    ///  Margin on left side of widget.
161    ///
162    /// This property adds margin outside of the widget's normal size
163    /// request, the margin will be added in addition to the size from
164    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
165    ///
166    /// Readable | Writeable
167    ///
168    ///
169    /// #### `margin-right`
170    ///  Margin on right side of widget.
171    ///
172    /// This property adds margin outside of the widget's normal size
173    /// request, the margin will be added in addition to the size from
174    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
175    ///
176    /// Readable | Writeable
177    ///
178    ///
179    /// #### `margin-start`
180    ///  Margin on start of widget, horizontally. This property supports
181    /// left-to-right and right-to-left text directions.
182    ///
183    /// This property adds margin outside of the widget's normal size
184    /// request, the margin will be added in addition to the size from
185    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
186    ///
187    /// Readable | Writeable
188    ///
189    ///
190    /// #### `margin-top`
191    ///  Margin on top side of widget.
192    ///
193    /// This property adds margin outside of the widget's normal size
194    /// request, the margin will be added in addition to the size from
195    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
196    ///
197    /// Readable | Writeable
198    ///
199    ///
200    /// #### `name`
201    ///  Readable | Writeable
202    ///
203    ///
204    /// #### `no-show-all`
205    ///  Readable | Writeable
206    ///
207    ///
208    /// #### `opacity`
209    ///  The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
210    /// more details about window opacity.
211    ///
212    /// Before 3.8 this was only available in GtkWindow
213    ///
214    /// Readable | Writeable
215    ///
216    ///
217    /// #### `parent`
218    ///  Readable | Writeable
219    ///
220    ///
221    /// #### `receives-default`
222    ///  Readable | Writeable
223    ///
224    ///
225    /// #### `scale-factor`
226    ///  The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
227    /// more details about widget scaling.
228    ///
229    /// Readable
230    ///
231    ///
232    /// #### `sensitive`
233    ///  Readable | Writeable
234    ///
235    ///
236    /// #### `style`
237    ///  The style of the widget, which contains information about how it will look (colors, etc).
238    ///
239    /// Readable | Writeable
240    ///
241    ///
242    /// #### `tooltip-markup`
243    ///  Sets the text of tooltip to be the given string, which is marked up
244    /// with the [Pango text markup language][PangoMarkupFormat].
245    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
246    ///
247    /// This is a convenience property which will take care of getting the
248    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
249    /// will automatically be set to [`true`] and there will be taken care of
250    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
251    ///
252    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
253    /// are set, the last one wins.
254    ///
255    /// Readable | Writeable
256    ///
257    ///
258    /// #### `tooltip-text`
259    ///  Sets the text of tooltip to be the given string.
260    ///
261    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
262    ///
263    /// This is a convenience property which will take care of getting the
264    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
265    /// will automatically be set to [`true`] and there will be taken care of
266    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
267    ///
268    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
269    /// are set, the last one wins.
270    ///
271    /// Readable | Writeable
272    ///
273    ///
274    /// #### `valign`
275    ///  How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
276    ///
277    /// Readable | Writeable
278    ///
279    ///
280    /// #### `vexpand`
281    ///  Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
282    ///
283    /// Readable | Writeable
284    ///
285    ///
286    /// #### `vexpand-set`
287    ///  Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
288    ///
289    /// Readable | Writeable
290    ///
291    ///
292    /// #### `visible`
293    ///  Readable | Writeable
294    ///
295    ///
296    /// #### `width-request`
297    ///  Readable | Writeable
298    ///
299    ///
300    /// #### `window`
301    ///  The widget's window if it is realized, [`None`] otherwise.
302    ///
303    /// Readable
304    /// </details>
305    ///
306    /// # Implements
307    ///
308    /// [`AppChooserExt`][trait@crate::prelude::AppChooserExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
309    pub struct AppChooser(Interface<ffi::GtkAppChooser>) @requires Widget;
310
311    match fn {
312        type_ => || ffi::gtk_app_chooser_get_type(),
313    }
314}
315
316mod sealed {
317    pub trait Sealed {}
318    impl<T: glib::IsA<crate::AppChooser>> Sealed for T {}
319}
320
321/// Trait containing all [`struct@AppChooser`] methods.
322///
323/// # Implementors
324///
325/// [`AppChooserButton`][struct@crate::AppChooserButton], [`AppChooserDialog`][struct@crate::AppChooserDialog], [`AppChooserWidget`][struct@crate::AppChooserWidget], [`AppChooser`][struct@crate::AppChooser]
326pub trait AppChooserExt: IsA<AppChooser> + sealed::Sealed + 'static {
327    /// Returns the currently selected application.
328    ///
329    /// # Returns
330    ///
331    /// a [`gio::AppInfo`][crate::gio::AppInfo] for the currently selected
332    ///  application, or [`None`] if none is selected. Free with `g_object_unref()`
333    #[doc(alias = "gtk_app_chooser_get_app_info")]
334    #[doc(alias = "get_app_info")]
335    fn app_info(&self) -> Option<AppInfo> {
336        unsafe {
337            from_glib_full(ffi::gtk_app_chooser_get_app_info(
338                self.as_ref().to_glib_none().0,
339            ))
340        }
341    }
342
343    /// Returns the current value of the [`content-type`][struct@crate::AppChooser#content-type] property.
344    ///
345    /// # Returns
346    ///
347    /// the content type of `self`. Free with `g_free()`
348    #[doc(alias = "gtk_app_chooser_get_content_type")]
349    #[doc(alias = "get_content_type")]
350    fn content_type(&self) -> Option<String> {
351        unsafe {
352            from_glib_full(ffi::gtk_app_chooser_get_content_type(
353                self.as_ref().to_glib_none().0,
354            ))
355        }
356    }
357
358    /// Reloads the list of applications.
359    #[doc(alias = "gtk_app_chooser_refresh")]
360    fn refresh(&self) {
361        unsafe { ffi::gtk_app_chooser_refresh(self.as_ref().to_glib_none().0) }
362    }
363}
364
365impl<O: IsA<AppChooser>> AppChooserExt for O {}