-
-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathaction.rs
More file actions
89 lines (72 loc) · 2.5 KB
/
Copy pathaction.rs
File metadata and controls
89 lines (72 loc) · 2.5 KB
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
89
use gio::{prelude::*, subclass::prelude::*};
mod imp {
use super::*;
use std::cell::OnceCell;
#[derive(glib::Properties, Default)]
#[properties(wrapper_type = super::RenamedAction)]
pub struct RenamedAction {
#[property(get, construct_only)]
pub new_name: OnceCell<glib::GString>,
#[property(get, construct_only)]
pub action: OnceCell<gio::Action>,
}
#[glib::object_subclass]
impl ObjectSubclass for RenamedAction {
const NAME: &'static str = "ExampleRenamedAction";
type Type = super::RenamedAction;
type Interfaces = (gio::Action,);
}
#[glib::derived_properties]
impl ObjectImpl for RenamedAction {
fn properties() -> &'static [glib::ParamSpec] {
Self::derived_properties()
}
fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
if !self.delegate_set_property(id, value, pspec) {
self.derived_set_property(id, value, pspec);
}
}
fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
self.delegate_get_property(id, pspec)
.unwrap_or_else(|| self.derived_property(id, pspec))
}
}
impl ActionImpl for RenamedAction {
fn name(&self) -> glib::GString {
self.obj().new_name()
}
fn parameter_type(&self) -> Option<glib::VariantType> {
self.obj().action().parameter_type()
}
fn state_type(&self) -> Option<glib::VariantType> {
self.obj().action().state_type()
}
fn state_hint(&self) -> Option<glib::Variant> {
self.obj().action().state_hint()
}
fn is_enabled(&self) -> bool {
self.obj().action().is_enabled()
}
fn state(&self) -> Option<glib::Variant> {
self.obj().action().state()
}
fn change_state(&self, value: glib::Variant) {
self.obj().action().change_state(&value);
}
fn activate(&self, parameter: Option<glib::Variant>) {
self.obj().action().activate(parameter.as_ref());
}
}
}
glib::wrapper! {
pub struct RenamedAction(ObjectSubclass<imp::RenamedAction>)
@implements gio::Action;
}
impl RenamedAction {
pub fn new(name: &str, action: &impl IsA<gio::Action>) -> Self {
glib::Object::builder()
.property("new-name", name)
.property("action", action)
.build()
}
}