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 gio_sys;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::GString;
12use glib_sys;
13use std::boxed::Box as Box_;
14use std::fmt;
15use std::mem::transmute;
16
17glib_wrapper! {
18    pub struct FilenameCompleter(Object<gio_sys::GFilenameCompleter, gio_sys::GFilenameCompleterClass, FilenameCompleterClass>);
19
20    match fn {
21        get_type => || gio_sys::g_filename_completer_get_type(),
22    }
23}
24
25impl FilenameCompleter {
26    pub fn new() -> FilenameCompleter {
27        unsafe { from_glib_full(gio_sys::g_filename_completer_new()) }
28    }
29}
30
31impl Default for FilenameCompleter {
32    fn default() -> Self {
33        Self::new()
34    }
35}
36
37pub const NONE_FILENAME_COMPLETER: Option<&FilenameCompleter> = None;
38
39pub trait FilenameCompleterExt: 'static {
40    fn get_completion_suffix(&self, initial_text: &str) -> Option<GString>;
41
42    fn get_completions(&self, initial_text: &str) -> Vec<GString>;
43
44    fn set_dirs_only(&self, dirs_only: bool);
45
46    fn connect_got_completion_data<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
47}
48
49impl<O: IsA<FilenameCompleter>> FilenameCompleterExt for O {
50    fn get_completion_suffix(&self, initial_text: &str) -> Option<GString> {
51        unsafe {
52            from_glib_full(gio_sys::g_filename_completer_get_completion_suffix(
53                self.as_ref().to_glib_none().0,
54                initial_text.to_glib_none().0,
55            ))
56        }
57    }
58
59    fn get_completions(&self, initial_text: &str) -> Vec<GString> {
60        unsafe {
61            FromGlibPtrContainer::from_glib_full(gio_sys::g_filename_completer_get_completions(
62                self.as_ref().to_glib_none().0,
63                initial_text.to_glib_none().0,
64            ))
65        }
66    }
67
68    fn set_dirs_only(&self, dirs_only: bool) {
69        unsafe {
70            gio_sys::g_filename_completer_set_dirs_only(
71                self.as_ref().to_glib_none().0,
72                dirs_only.to_glib(),
73            );
74        }
75    }
76
77    fn connect_got_completion_data<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
78        unsafe extern "C" fn got_completion_data_trampoline<P, F: Fn(&P) + 'static>(
79            this: *mut gio_sys::GFilenameCompleter,
80            f: glib_sys::gpointer,
81        ) where
82            P: IsA<FilenameCompleter>,
83        {
84            let f: &F = &*(f as *const F);
85            f(&FilenameCompleter::from_glib_borrow(this).unsafe_cast())
86        }
87        unsafe {
88            let f: Box_<F> = Box_::new(f);
89            connect_raw(
90                self.as_ptr() as *mut _,
91                b"got-completion-data\0".as_ptr() as *const _,
92                Some(transmute(
93                    got_completion_data_trampoline::<Self, F> as usize,
94                )),
95                Box_::into_raw(f),
96            )
97        }
98    }
99}
100
101impl fmt::Display for FilenameCompleter {
102    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
103        write!(f, "FilenameCompleter")
104    }
105}