@@ -39,29 +39,6 @@ use super::{Driver, MODEL_IDENT};
3939
4040use self :: WidgetType :: * ;
4141
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-
6542macro_rules! set_container {
6643 ( $_self: expr, $widget: expr, $widget_name: expr, $widget_type: expr) => {
6744 if let Some ( ref container_type) = $widget. container_type {
@@ -299,6 +276,26 @@ impl<'a> Generator<'a> {
299276 }
300277 }
301278
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+
302299 fn gtk_widget ( & mut self , widget : & Widget , gtk_widget : & GtkWidget , parent : Option < & Ident > ,
303300 parent_widget_type : WidgetType ) -> Tokens
304301 {
@@ -320,7 +317,7 @@ impl<'a> Generator<'a> {
320317
321318 let add_child_or_show_all = self . add_child_or_show_all ( widget, parent, parent_widget_type) ;
322319 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) ;
324321 let child_properties = gen_set_child_prop_calls ( widget, parent, parent_widget_type, IsGtk ) ;
325322
326323 quote ! {
@@ -350,21 +347,38 @@ impl<'a> Generator<'a> {
350347 . map ( |child| self . widget ( child, Some ( widget_name) , IsRelm ) )
351348 . collect ( ) ;
352349 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) ;
354351 self . properties . append ( & mut properties) ;
355352 self . properties . append ( & mut visible_properties) ;
356353
357354 let add_or_create_widget = self . add_or_create_widget (
358355 parent, parent_widget_type, widget_name, widget_type_ident, & widget. init_parameters , widget. is_container ) ;
359356 let child_properties = gen_set_child_prop_calls ( widget, parent, parent_widget_type, IsRelm ) ;
357+ let messages = self . messages ( widget, relm_widget) ;
360358
361359 quote ! {
362360 #add_or_create_widget
361+ #messages
363362 #( #children) *
364363 #( #child_properties) *
365364 }
366365 }
367366
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+
368382 fn widget ( & mut self , widget : & Widget , parent : Option < & Ident > , parent_widget_type : WidgetType ) -> Tokens {
369383 match widget. widget {
370384 Gtk ( ref gtk_widget) => self . gtk_widget ( widget, gtk_widget, parent, parent_widget_type) ,
0 commit comments