Skip to main content

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::{SignalHandlerId, connect_raw},
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    ///
73    /// The strings are returned in an undefined order.
74    /// ## `initial_text`
75    /// text to be completed.
76    ///
77    /// # Returns
78    ///
79    /// array of strings with
80    ///   possible completions for @initial_text
81    #[doc(alias = "g_filename_completer_get_completions")]
82    #[doc(alias = "get_completions")]
83    pub fn completions(&self, initial_text: &str) -> Vec<glib::GString> {
84        unsafe {
85            FromGlibPtrContainer::from_glib_full(ffi::g_filename_completer_get_completions(
86                self.to_glib_none().0,
87                initial_text.to_glib_none().0,
88            ))
89        }
90    }
91
92    /// If @dirs_only is [`true`], @self will only
93    /// complete directory names, and not file names.
94    ///
95    /// This function needs to be called before waiting for results from the
96    /// completer to be populated.
97    /// ## `dirs_only`
98    /// a #gboolean.
99    #[doc(alias = "g_filename_completer_set_dirs_only")]
100    pub fn set_dirs_only(&self, dirs_only: bool) {
101        unsafe {
102            ffi::g_filename_completer_set_dirs_only(self.to_glib_none().0, dirs_only.into_glib());
103        }
104    }
105
106    /// Emitted when the file name completion information comes available.
107    #[doc(alias = "got-completion-data")]
108    pub fn connect_got_completion_data<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
109        unsafe extern "C" fn got_completion_data_trampoline<F: Fn(&FilenameCompleter) + 'static>(
110            this: *mut ffi::GFilenameCompleter,
111            f: glib::ffi::gpointer,
112        ) {
113            unsafe {
114                let f: &F = &*(f as *const F);
115                f(&from_glib_borrow(this))
116            }
117        }
118        unsafe {
119            let f: Box_<F> = Box_::new(f);
120            connect_raw(
121                self.as_ptr() as *mut _,
122                c"got-completion-data".as_ptr(),
123                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
124                    got_completion_data_trampoline::<F> as *const (),
125                )),
126                Box_::into_raw(f),
127            )
128        }
129    }
130}
131
132impl Default for FilenameCompleter {
133    fn default() -> Self {
134        Self::new()
135    }
136}