1
1
// Take a look at the license at the top of the repository in the LICENSE file.
2
2
3
- use glib:: { prelude:: * , Variant } ;
3
+ use glib:: { prelude:: * , Variant , VariantTy , VariantType } ;
4
4
5
5
use crate :: { ActionMap , SimpleAction } ;
6
6
10
10
O : IsA < ActionMap > ,
11
11
{
12
12
name : String ,
13
- parameter_type : Option < String > ,
14
- state : Option < String > ,
13
+ parameter_type : Option < VariantType > ,
14
+ state : Option < Variant > ,
15
15
pub ( crate ) activate : Option < Box < dyn Fn ( & O , & SimpleAction , Option < & Variant > ) + ' static > > ,
16
16
pub ( crate ) change_state : Option < Box < dyn Fn ( & O , & SimpleAction , Option < & Variant > ) + ' static > > ,
17
17
}
@@ -24,12 +24,12 @@ where
24
24
& self . name
25
25
}
26
26
27
- pub fn parameter_type ( & self ) -> Option < & str > {
27
+ pub fn parameter_type ( & self ) -> Option < & VariantTy > {
28
28
self . parameter_type . as_deref ( )
29
29
}
30
30
31
- pub fn state ( & self ) -> Option < & str > {
32
- self . state . as_deref ( )
31
+ pub fn state ( & self ) -> Option < & Variant > {
32
+ self . state . as_ref ( )
33
33
}
34
34
35
35
pub fn builder ( name : & str ) -> ActionEntryBuilder < O > {
@@ -69,13 +69,13 @@ where
69
69
} )
70
70
}
71
71
72
- pub fn parameter_type ( mut self , parameter_type : & str ) -> Self {
73
- self . 0 . parameter_type = Some ( parameter_type. to_owned ( ) ) ;
72
+ pub fn parameter_type ( mut self , parameter_type : Option < & VariantTy > ) -> Self {
73
+ self . 0 . parameter_type = parameter_type. map ( |vt| vt . to_owned ( ) ) ;
74
74
self
75
75
}
76
76
77
- pub fn state ( mut self , state : & str ) -> Self {
78
- self . 0 . state = Some ( state. to_owned ( ) ) ;
77
+ pub fn state ( mut self , state : Variant ) -> Self {
78
+ self . 0 . state = Some ( state) ;
79
79
self
80
80
}
81
81
@@ -109,12 +109,20 @@ mod tests {
109
109
fn action_entry ( ) {
110
110
let app = crate :: Application :: new ( None , Default :: default ( ) ) ;
111
111
112
- let close = ActionEntry :: builder ( "close" )
113
- . activate ( move |_app, _, _| {
114
- //Do something
115
- } )
116
- . build ( ) ;
117
- app. add_action_entries ( vec ! [ close] ) . unwrap ( ) ;
112
+ app. add_action_entries ( vec ! [
113
+ ActionEntry :: builder( "close" )
114
+ . activate( move |_app, _, _| {
115
+ //Do something
116
+ } )
117
+ . build( ) ,
118
+ ActionEntry :: builder( "enable" )
119
+ . state( true . to_variant( ) )
120
+ . change_state( move |_app, _, _| {
121
+ //Do something
122
+ } )
123
+ . build( ) ,
124
+ ] ) ;
118
125
assert ! ( app. lookup_action( "close" ) . is_some( ) ) ;
126
+ assert ! ( app. lookup_action( "enable" ) . is_some( ) ) ;
119
127
}
120
128
}
0 commit comments