@@ -39,29 +39,6 @@ use super::{Driver, MODEL_IDENT};
39
39
40
40
use self :: WidgetType :: * ;
41
41
42
- macro_rules! gen_set_prop_calls {
43
- ( $widget: expr, $ident: expr, $model_ident: expr) => { {
44
- let ident = $ident;
45
- let mut properties = vec![ ] ;
46
- let mut visible_properties = vec![ ] ;
47
- for ( key, value) in & $widget. properties {
48
- let mut remover = Transformer :: new( $model_ident) ;
49
- let new_value = remover. fold_expr( value. clone( ) ) ;
50
- let property_func = Ident :: new( format!( "set_{}" , key) ) ;
51
- let property = quote! {
52
- #ident. #property_func( #new_value) ;
53
- } ;
54
- if key == "visible" {
55
- visible_properties. push( property) ;
56
- }
57
- else {
58
- properties. push( property) ;
59
- }
60
- }
61
- ( properties, visible_properties)
62
- } } ;
63
- }
64
-
65
42
macro_rules! set_container {
66
43
( $_self: expr, $widget: expr, $widget_name: expr, $widget_type: expr) => {
67
44
if let Some ( ref container_type) = $widget. container_type {
@@ -299,6 +276,26 @@ impl<'a> Generator<'a> {
299
276
}
300
277
}
301
278
279
+ fn gtk_set_prop_calls ( & self , widget : & Widget , ident : Tokens ) -> ( Vec < Tokens > , Vec < Tokens > ) {
280
+ let mut properties = vec ! [ ] ;
281
+ let mut visible_properties = vec ! [ ] ;
282
+ for ( key, value) in & widget. properties {
283
+ let mut remover = Transformer :: new ( MODEL_IDENT ) ;
284
+ let new_value = remover. fold_expr ( value. clone ( ) ) ;
285
+ let property_func = Ident :: new ( format ! ( "set_{}" , key) ) ;
286
+ let property = quote ! {
287
+ #ident. #property_func( #new_value) ;
288
+ } ;
289
+ if key == "visible" {
290
+ visible_properties. push ( property) ;
291
+ }
292
+ else {
293
+ properties. push ( property) ;
294
+ }
295
+ }
296
+ ( properties, visible_properties)
297
+ }
298
+
302
299
fn gtk_widget ( & mut self , widget : & Widget , gtk_widget : & GtkWidget , parent : Option < & Ident > ,
303
300
parent_widget_type : WidgetType ) -> Tokens
304
301
{
@@ -320,7 +317,7 @@ impl<'a> Generator<'a> {
320
317
321
318
let add_child_or_show_all = self . add_child_or_show_all ( widget, parent, parent_widget_type) ;
322
319
let ident = quote ! { #widget_name } ;
323
- let ( properties, visible_properties) = gen_set_prop_calls ! ( widget, ident, MODEL_IDENT ) ;
320
+ let ( properties, visible_properties) = self . gtk_set_prop_calls ( widget, ident) ;
324
321
let child_properties = gen_set_child_prop_calls ( widget, parent, parent_widget_type, IsGtk ) ;
325
322
326
323
quote ! {
@@ -350,21 +347,38 @@ impl<'a> Generator<'a> {
350
347
. map ( |child| self . widget ( child, Some ( widget_name) , IsRelm ) )
351
348
. collect ( ) ;
352
349
let ident = quote ! { #widget_name. widget( ) } ;
353
- let ( mut properties, mut visible_properties) = gen_set_prop_calls ! ( widget, ident, MODEL_IDENT ) ;
350
+ let ( mut properties, mut visible_properties) = self . gtk_set_prop_calls ( widget, ident) ;
354
351
self . properties . append ( & mut properties) ;
355
352
self . properties . append ( & mut visible_properties) ;
356
353
357
354
let add_or_create_widget = self . add_or_create_widget (
358
355
parent, parent_widget_type, widget_name, widget_type_ident, & widget. init_parameters , widget. is_container ) ;
359
356
let child_properties = gen_set_child_prop_calls ( widget, parent, parent_widget_type, IsRelm ) ;
357
+ let messages = self . messages ( widget, relm_widget) ;
360
358
361
359
quote ! {
362
360
#add_or_create_widget
361
+ #messages
363
362
#( #children) *
364
363
#( #child_properties) *
365
364
}
366
365
}
367
366
367
+ fn messages ( & self , widget : & Widget , relm_widget : & RelmWidget ) -> Tokens {
368
+ let mut tokens = quote ! { } ;
369
+ let name = & widget. name ;
370
+ for ( variant, value) in & relm_widget. messages {
371
+ let mut remover = Transformer :: new ( MODEL_IDENT ) ;
372
+ let value = remover. fold_expr ( value. clone ( ) ) ;
373
+ let variant = Ident :: new ( variant. as_str ( ) ) ;
374
+ tokens = quote ! {
375
+ #tokens
376
+ #name. stream( ) . emit( #variant( #value) ) ;
377
+ } ;
378
+ }
379
+ tokens
380
+ }
381
+
368
382
fn widget ( & mut self , widget : & Widget , parent : Option < & Ident > , parent_widget_type : WidgetType ) -> Tokens {
369
383
match widget. widget {
370
384
Gtk ( ref gtk_widget) => self . gtk_widget ( widget, gtk_widget, parent, parent_widget_type) ,
0 commit comments