1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{Buildable, Sorter};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    /// [`MultiSorter`][crate::MultiSorter] combines multiple sorters by trying them
    /// in turn.
    ///
    /// If the first sorter compares two items as equal,
    /// the second is tried next, and so on.
    ///
    /// ## Properties
    ///
    ///
    /// #### `item-type`
    ///  The type of items. See [`ListModelExtManual::item_type()`][crate::gio::prelude::ListModelExtManual::item_type()].
    ///
    /// Readable
    ///
    ///
    /// #### `n-items`
    ///  The number of items. See [`ListModelExtManual::n_items()`][crate::gio::prelude::ListModelExtManual::n_items()].
    ///
    /// Readable
    ///
    /// # Implements
    ///
    /// [`SorterExt`][trait@crate::prelude::SorterExt], [`trait@glib::ObjectExt`], [`trait@gio::prelude::ListModelExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt]
    #[doc(alias = "GtkMultiSorter")]
    pub struct MultiSorter(Object<ffi::GtkMultiSorter, ffi::GtkMultiSorterClass>) @extends Sorter, @implements gio::ListModel, Buildable;

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

impl MultiSorter {
    /// Creates a new multi sorter.
    ///
    /// This sorter compares items by trying each of the sorters
    /// in turn, until one returns non-zero. In particular, if
    /// no sorter has been added to it, it will always compare
    /// items as equal.
    ///
    /// # Returns
    ///
    /// a new [`MultiSorter`][crate::MultiSorter]
    #[doc(alias = "gtk_multi_sorter_new")]
    pub fn new() -> MultiSorter {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gtk_multi_sorter_new()) }
    }

    /// Add @sorter to @self to use for sorting at the end.
    ///
    /// @self will consult all existing sorters before it will
    /// sort with the given @sorter.
    /// ## `sorter`
    /// a sorter to add
    #[doc(alias = "gtk_multi_sorter_append")]
    pub fn append(&self, sorter: impl IsA<Sorter>) {
        unsafe {
            ffi::gtk_multi_sorter_append(self.to_glib_none().0, sorter.upcast().into_glib_ptr());
        }
    }

    /// Removes the sorter at the given @position from the list of sorter
    /// used by @self.
    ///
    /// If @position is larger than the number of sorters, nothing happens.
    /// ## `position`
    /// position of sorter to remove
    #[doc(alias = "gtk_multi_sorter_remove")]
    pub fn remove(&self, position: u32) {
        unsafe {
            ffi::gtk_multi_sorter_remove(self.to_glib_none().0, position);
        }
    }
}

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