@@ -76,6 +76,7 @@ pub struct Driver {
76
76
model_type : Option < ImplItem > ,
77
77
model_param_type : Option < ImplItem > ,
78
78
msg_type : Option < ImplItem > ,
79
+ other_methods : Vec < ImplItem > ,
79
80
properties_model_map : Option < PropertyModelMap > ,
80
81
root_method : Option < ImplItem > ,
81
82
root_type : Option < ImplItem > ,
@@ -103,12 +104,13 @@ impl Driver {
103
104
Driver {
104
105
data_method : None ,
105
106
generic_types : None ,
106
- root_method : None ,
107
- root_type : None ,
108
107
model_type : None ,
109
108
model_param_type : None ,
110
109
msg_type : None ,
110
+ other_methods : vec ! [ ] ,
111
111
properties_model_map : None ,
112
+ root_method : None ,
113
+ root_type : None ,
112
114
root_widget : None ,
113
115
root_widget_expr : None ,
114
116
root_widget_type : None ,
@@ -121,6 +123,13 @@ impl Driver {
121
123
}
122
124
}
123
125
126
+ fn add_set_property_to_method ( & self , func : & mut ImplItem ) {
127
+ if let Method ( _, ref mut block) = func. node {
128
+ let mut adder = Adder :: new ( self . properties_model_map . as_ref ( ) . expect ( "update method" ) ) ;
129
+ * block = adder. fold_block ( block. clone ( ) ) ;
130
+ }
131
+ }
132
+
124
133
fn add_widgets ( & mut self , widget : & Widget , map : & PropertyModelMap ) {
125
134
// Only add widgets that are needed by the update() function.
126
135
let mut to_add = false ;
@@ -186,7 +195,7 @@ impl Driver {
186
195
self . widget_msg_type = Some ( get_second_param_type ( & sig) ) ;
187
196
self . update_method = Some ( i)
188
197
} ,
189
- method_name => panic ! ( "Unexpected method {}" , method_name ) ,
198
+ _ => self . other_methods . push ( i ) ,
190
199
}
191
200
} ,
192
201
Type ( _) => {
@@ -218,13 +227,16 @@ impl Driver {
218
227
}
219
228
new_items. push ( self . get_update ( ) ) ;
220
229
new_items. push ( self . get_root ( ) ) ;
230
+ let other_methods = self . get_other_methods ( & typ) ;
221
231
let item = Impl ( unsafety, polarity, generics, path, typ, new_items) ;
222
232
ast. node = item;
223
233
let container_impl = view. container_impl ;
224
234
quote ! {
225
235
#widget_struct
226
236
#ast
227
237
#container_impl
238
+
239
+ #other_methods
228
240
}
229
241
}
230
242
else {
@@ -273,6 +285,18 @@ impl Driver {
273
285
} )
274
286
}
275
287
288
+ fn get_other_methods ( & mut self , typ : & Ty ) -> Tokens {
289
+ let mut other_methods: Vec < _ > = self . other_methods . drain ( ..) . collect ( ) ;
290
+ for method in & mut other_methods {
291
+ self . add_set_property_to_method ( method) ;
292
+ }
293
+ quote ! {
294
+ impl #typ {
295
+ #( #other_methods) *
296
+ }
297
+ }
298
+ }
299
+
276
300
fn get_root ( & mut self ) -> ImplItem {
277
301
self . root_method . take ( ) . unwrap_or_else ( || {
278
302
let root_widget_expr = self . root_widget_expr . take ( ) . expect ( "root widget expr" ) ;
@@ -299,10 +323,7 @@ impl Driver {
299
323
*/
300
324
fn get_update ( & mut self ) -> ImplItem {
301
325
let mut func = self . update_method . take ( ) . expect ( "update method" ) ;
302
- if let Method ( _, ref mut block) = func. node {
303
- let mut adder = Adder :: new ( self . properties_model_map . as_ref ( ) . expect ( "update method" ) ) ;
304
- * block = adder. fold_block ( block. clone ( ) ) ;
305
- }
326
+ self . add_set_property_to_method ( & mut func) ;
306
327
// TODO: consider gtk::main_quit() as return.
307
328
func
308
329
}
0 commit comments