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 completion for @initial_text from @self.
50    /// ## `initial_text`
51    /// text to be completed.
52    ///
53    /// # Returns
54    ///
55    /// a completed string, or [`None`] if no
56    ///     completion exists. This string is not owned by GIO, so remember to g_free()
57    ///     it when finished.
58    #[doc(alias = "g_filename_completer_get_completion_suffix")]
59    #[doc(alias = "get_completion_suffix")]
60    pub fn completion_suffix(&self, initial_text: &str) -> Option<glib::GString> {
61        unsafe {
62            from_glib_full(ffi::g_filename_completer_get_completion_suffix(
63                self.to_glib_none().0,
64                initial_text.to_glib_none().0,
65            ))
66        }
67    }
68
69    /// Gets an array of completion strings for a given initial text.
70    /// ## `initial_text`
71    /// text to be completed.
72    ///
73    /// # Returns
74    ///
75    /// array of strings with possible completions for @initial_text.
76    /// This array must be freed by g_strfreev() when finished.
77    #[doc(alias = "g_filename_completer_get_completions")]
78    #[doc(alias = "get_completions")]
79    pub fn completions(&self, initial_text: &str) -> Vec<glib::GString> {
80        unsafe {
81            FromGlibPtrContainer::from_glib_full(ffi::g_filename_completer_get_completions(
82                self.to_glib_none().0,
83                initial_text.to_glib_none().0,
84            ))
85        }
86    }
87
88    /// If @dirs_only is [`true`], @self will only
89    /// complete directory names, and not file names.
90    /// ## `dirs_only`
91    /// a #gboolean.
92    #[doc(alias = "g_filename_completer_set_dirs_only")]
93    pub fn set_dirs_only(&self, dirs_only: bool) {
94        unsafe {
95            ffi::g_filename_completer_set_dirs_only(self.to_glib_none().0, dirs_only.into_glib());
96        }
97    }
98
99    /// Emitted when the file name completion information comes available.
100    #[doc(alias = "got-completion-data")]
101    pub fn connect_got_completion_data<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
102        unsafe extern "C" fn got_completion_data_trampoline<F: Fn(&FilenameCompleter) + 'static>(
103            this: *mut ffi::GFilenameCompleter,
104            f: glib::ffi::gpointer,
105        ) {
106            let f: &F = &*(f as *const F);
107            f(&from_glib_borrow(this))
108        }
109        unsafe {
110            let f: Box_<F> = Box_::new(f);
111            connect_raw(
112                self.as_ptr() as *mut _,
113                b"got-completion-data\0".as_ptr() as *const _,
114                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
115                    got_completion_data_trampoline::<F> as *const (),
116                )),
117                Box_::into_raw(f),
118            )
119        }
120    }
121}
122
123impl Default for FilenameCompleter {
124    fn default() -> Self {
125        Self::new()
126    }
127}