sourceview5 0.11.0

Rust bindings for GtkSourceView 5
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{CompressionType, Encoding, NewlineType, ffi};
use glib::{
    prelude::*,
    signal::{SignalHandlerId, connect_raw},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "GtkSourceFile")]
    pub struct File(Object<ffi::GtkSourceFile, ffi::GtkSourceFileClass>);

    match fn {
        type_ => || ffi::gtk_source_file_get_type(),
    }
}

impl File {
    pub const NONE: Option<&'static File> = None;

    #[doc(alias = "gtk_source_file_new")]
    pub fn new() -> File {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gtk_source_file_new()) }
    }

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`File`] objects.
    ///
    /// This method returns an instance of [`FileBuilder`](crate::builders::FileBuilder) which can be used to create [`File`] objects.
    pub fn builder() -> FileBuilder {
        FileBuilder::new()
    }
}

impl Default for File {
    fn default() -> Self {
        Self::new()
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`File`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct FileBuilder {
    builder: glib::object::ObjectBuilder<'static, File>,
}

impl FileBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    pub fn location(self, location: &impl IsA<gio::File>) -> Self {
        Self {
            builder: self.builder.property("location", location.clone().upcast()),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`File`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> File {
        assert_initialized_main_thread!();
        self.builder.build()
    }
}

pub trait SourceFileExt: IsA<File> + 'static {
    #[doc(alias = "gtk_source_file_check_file_on_disk")]
    fn check_file_on_disk(&self) {
        unsafe {
            ffi::gtk_source_file_check_file_on_disk(self.as_ref().to_glib_none().0);
        }
    }

    #[doc(alias = "gtk_source_file_get_compression_type")]
    #[doc(alias = "get_compression_type")]
    #[doc(alias = "compression-type")]
    fn compression_type(&self) -> CompressionType {
        unsafe {
            from_glib(ffi::gtk_source_file_get_compression_type(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_file_get_encoding")]
    #[doc(alias = "get_encoding")]
    fn encoding(&self) -> Encoding {
        unsafe {
            from_glib_none(ffi::gtk_source_file_get_encoding(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_file_get_location")]
    #[doc(alias = "get_location")]
    fn location(&self) -> gio::File {
        unsafe {
            from_glib_none(ffi::gtk_source_file_get_location(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_file_get_newline_type")]
    #[doc(alias = "get_newline_type")]
    #[doc(alias = "newline-type")]
    fn newline_type(&self) -> NewlineType {
        unsafe {
            from_glib(ffi::gtk_source_file_get_newline_type(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_file_is_deleted")]
    fn is_deleted(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_source_file_is_deleted(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_file_is_externally_modified")]
    fn is_externally_modified(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_source_file_is_externally_modified(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_file_is_local")]
    fn is_local(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_source_file_is_local(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_file_is_readonly")]
    fn is_readonly(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_source_file_is_readonly(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_file_set_location")]
    #[doc(alias = "location")]
    fn set_location(&self, location: Option<&impl IsA<gio::File>>) {
        unsafe {
            ffi::gtk_source_file_set_location(
                self.as_ref().to_glib_none().0,
                location.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    #[doc(alias = "gtk_source_file_set_mount_operation_factory")]
    fn set_mount_operation_factory<P: Fn(&File) -> gio::MountOperation + 'static>(
        &self,
        callback: P,
    ) {
        let callback_data: Box_<P> = Box_::new(callback);
        unsafe extern "C" fn callback_func<P: Fn(&File) -> gio::MountOperation + 'static>(
            file: *mut ffi::GtkSourceFile,
            userdata: glib::ffi::gpointer,
        ) -> *mut gio::ffi::GMountOperation {
            unsafe {
                let file = from_glib_borrow(file);
                let callback = &*(userdata as *mut P);
                (*callback)(&file)
                    /*Not checked*/
                    .to_glib_none()
                    .0
            }
        }
        let callback = Some(callback_func::<P> as _);
        unsafe extern "C" fn notify_func<P: Fn(&File) -> gio::MountOperation + 'static>(
            data: glib::ffi::gpointer,
        ) {
            unsafe {
                let _callback = Box_::from_raw(data as *mut P);
            }
        }
        let destroy_call3 = Some(notify_func::<P> as _);
        let super_callback0: Box_<P> = callback_data;
        unsafe {
            ffi::gtk_source_file_set_mount_operation_factory(
                self.as_ref().to_glib_none().0,
                callback,
                Box_::into_raw(super_callback0) as *mut _,
                destroy_call3,
            );
        }
    }

    #[doc(alias = "read-only")]
    fn is_read_only(&self) -> bool {
        ObjectExt::property(self.as_ref(), "read-only")
    }

    #[doc(alias = "compression-type")]
    fn connect_compression_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_compression_type_trampoline<
            P: IsA<File>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkSourceFile,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(File::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::compression-type".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_compression_type_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "encoding")]
    fn connect_encoding_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_encoding_trampoline<P: IsA<File>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkSourceFile,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(File::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::encoding".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_encoding_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "location")]
    fn connect_location_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_location_trampoline<P: IsA<File>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkSourceFile,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(File::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::location".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_location_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "newline-type")]
    fn connect_newline_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_newline_type_trampoline<P: IsA<File>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkSourceFile,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(File::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::newline-type".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_newline_type_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "read-only")]
    fn connect_read_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_read_only_trampoline<P: IsA<File>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkSourceFile,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(File::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::read-only".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_read_only_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<File>> SourceFileExt for O {}