gio/auto/
filename_completer.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// Completes partial file and directory names given a partial string by
16    /// looking in the file system for clues. Can return a list of possible
17    /// completion strings for widget implementations.
18    ///
19    /// ## Signals
20    ///
21    ///
22    /// #### `got-completion-data`
23    ///  Emitted when the file name completion information comes available.
24    ///
25    ///
26    ///
27    /// # Implements
28    ///
29    /// [`trait@glib::ObjectExt`]
30    #[doc(alias = "GFilenameCompleter")]
31    pub struct FilenameCompleter(Object<ffi::GFilenameCompleter, ffi::GFilenameCompleterClass>);
32
33    match fn {
34        type_ => || ffi::g_filename_completer_get_type(),
35    }
36}
37
38impl FilenameCompleter {
39    /// Creates a new filename completer.
40    ///
41    /// # Returns
42    ///
43    /// a #GFilenameCompleter.
44    #[doc(alias = "g_filename_completer_new")]
45    pub fn new() -> FilenameCompleter {
46        unsafe { from_glib_full(ffi::g_filename_completer_new()) }
47    }
48
49    /// Obtains a suffix completion for @initial_text from @self.
50    ///
51    /// Suffix will be an empty string if there's no shared suffix among matching
52    /// completions. If there's no matching completions anyway, `NULL` is returned.
53    /// ## `initial_text`
54    /// text to be completed.
55    ///
56    /// # Returns
57    ///
58    /// a suffix completion string, or `NULL` if no
59    ///     completion exists.
60    #[doc(alias = "g_filename_completer_get_completion_suffix")]
61    #[doc(alias = "get_completion_suffix")]
62    pub fn completion_suffix(&self, initial_text: &str) -> Option<glib::GString> {
63        unsafe {
64            from_glib_full(ffi::g_filename_completer_get_completion_suffix(
65                self.to_glib_none().0,
66                initial_text.to_glib_none().0,
67            ))
68        }
69    }
70
71    /// Gets an array of completion strings for a given initial text.
72    /// ## `initial_text`
73    /// text to be completed.
74    ///
75    /// # Returns
76    ///
77    /// array of strings with possible completions for @initial_text.
78    /// This array must be freed by g_strfreev() when finished.
79    #[doc(alias = "g_filename_completer_get_completions")]
80    #[doc(alias = "get_completions")]
81    pub fn completions(&self, initial_text: &str) -> Vec<glib::GString> {
82        unsafe {
83            FromGlibPtrContainer::from_glib_full(ffi::g_filename_completer_get_completions(
84                self.to_glib_none().0,
85                initial_text.to_glib_none().0,
86            ))
87        }
88    }
89
90    /// If @dirs_only is [`true`], @self will only
91    /// complete directory names, and not file names.
92    ///
93    /// This function needs to be called before waiting for results from the
94    /// completer to be populated.
95    /// ## `dirs_only`
96    /// a #gboolean.
97    #[doc(alias = "g_filename_completer_set_dirs_only")]
98    pub fn set_dirs_only(&self, dirs_only: bool) {
99        unsafe {
100            ffi::g_filename_completer_set_dirs_only(self.to_glib_none().0, dirs_only.into_glib());
101        }
102    }
103
104    /// Emitted when the file name completion information comes available.
105    #[doc(alias = "got-completion-data")]
106    pub fn connect_got_completion_data<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
107        unsafe extern "C" fn got_completion_data_trampoline<F: Fn(&FilenameCompleter) + 'static>(
108            this: *mut ffi::GFilenameCompleter,
109            f: glib::ffi::gpointer,
110        ) {
111            let f: &F = &*(f as *const F);
112            f(&from_glib_borrow(this))
113        }
114        unsafe {
115            let f: Box_<F> = Box_::new(f);
116            connect_raw(
117                self.as_ptr() as *mut _,
118                c"got-completion-data".as_ptr() as *const _,
119                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
120                    got_completion_data_trampoline::<F> as *const (),
121                )),
122                Box_::into_raw(f),
123            )
124        }
125    }
126}
127
128impl Default for FilenameCompleter {
129    fn default() -> Self {
130        Self::new()
131    }
132}