1
- use gtk:: { gdk, gio, glib, prelude:: * , subclass:: prelude:: * } ;
1
+ use gtk:: { gdk, gio, glib, prelude:: * , subclass:: prelude:: * , StateFlags } ;
2
2
3
3
use crate :: {
4
4
application:: { selection:: * , Application } ,
@@ -70,6 +70,14 @@ impl ModuleList {
70
70
pub fn show_search ( & self ) {
71
71
self . imp ( ) . search_bar . set_search_mode ( true ) ;
72
72
}
73
+
74
+ pub fn unselect_items ( & self ) {
75
+ self . imp ( ) . lists ( ) . iter ( ) . for_each ( |( list, _) |
76
+ list. selected_rows ( ) . iter ( ) . for_each ( |item|
77
+ item. unset_state_flags ( StateFlags :: SELECTED )
78
+ )
79
+ ) ;
80
+ }
73
81
}
74
82
75
83
#[ gtk:: template_callbacks]
@@ -103,24 +111,38 @@ pub struct ModuleListTemplate {
103
111
104
112
#[ template_child]
105
113
basic_list_box : TemplateChild < gtk:: ListBox > ,
114
+ #[ template_child]
115
+ basic_list_label : TemplateChild < gtk:: Label > ,
106
116
107
117
#[ template_child]
108
118
input_output_list_box : TemplateChild < gtk:: ListBox > ,
119
+ #[ template_child]
120
+ input_output_list_label : TemplateChild < gtk:: Label > ,
109
121
110
122
#[ template_child]
111
123
gate_list_box : TemplateChild < gtk:: ListBox > ,
124
+ #[ template_child]
125
+ gate_list_label : TemplateChild < gtk:: Label > ,
112
126
113
127
#[ template_child]
114
128
combinational_list_box : TemplateChild < gtk:: ListBox > ,
129
+ #[ template_child]
130
+ combinational_list_label : TemplateChild < gtk:: Label > ,
115
131
116
132
#[ template_child]
117
133
latch_list_box : TemplateChild < gtk:: ListBox > ,
134
+ #[ template_child]
135
+ latch_list_label : TemplateChild < gtk:: Label > ,
118
136
119
137
#[ template_child]
120
138
flip_flop_list_box : TemplateChild < gtk:: ListBox > ,
139
+ #[ template_child]
140
+ flip_flop_list_label : TemplateChild < gtk:: Label > ,
121
141
122
142
#[ template_child]
123
143
custom_list_box : TemplateChild < gtk:: ListBox > ,
144
+ #[ template_child]
145
+ custom_list_label : TemplateChild < gtk:: Label > ,
124
146
125
147
#[ template_child]
126
148
search_bar : TemplateChild < gtk:: SearchBar > ,
@@ -143,14 +165,15 @@ impl ModuleListTemplate {
143
165
}
144
166
}
145
167
146
- fn lists ( & self ) -> [ & gtk:: ListBox ; 6 ] {
168
+ fn lists ( & self ) -> [ ( & gtk:: ListBox , & gtk :: Label ) ; 7 ] {
147
169
[
148
- & self . basic_list_box ,
149
- & self . input_output_list_box ,
150
- & self . gate_list_box ,
151
- & self . latch_list_box ,
152
- & self . flip_flop_list_box ,
153
- & self . custom_list_box ,
170
+ ( & self . basic_list_box , & self . basic_list_label ) ,
171
+ ( & self . input_output_list_box , & self . input_output_list_label ) ,
172
+ ( & self . gate_list_box , & self . gate_list_label ) ,
173
+ ( & self . combinational_list_box , & self . combinational_list_label ) ,
174
+ ( & self . latch_list_box , & self . latch_list_label ) ,
175
+ ( & self . flip_flop_list_box , & self . flip_flop_list_label ) ,
176
+ ( & self . custom_list_box , & self . custom_list_label )
154
177
]
155
178
}
156
179
@@ -207,6 +230,9 @@ impl ModuleListTemplate {
207
230
. button ( gdk:: ffi:: GDK_BUTTON_SECONDARY as u32 )
208
231
. build ( ) ;
209
232
item. add_controller ( & right_click_gesture) ;
233
+ // item.connect_state_flags_changed(|item, flags| {
234
+ // item.unset_state_flags(StateFlags::SELECTED);
235
+ // });
210
236
211
237
let name = module. name ( ) . to_owned ( ) ;
212
238
let is_builtin = module. builtin ( ) ;
@@ -239,7 +265,7 @@ impl ModuleListTemplate {
239
265
}
240
266
241
267
fn clear_list ( & self ) {
242
- self . lists ( ) . iter ( ) . for_each ( |list| {
268
+ self . lists ( ) . iter ( ) . for_each ( |( list, _ ) | {
243
269
while let Some ( row) = list. row_at_index ( 0 ) {
244
270
list. remove ( & row) ;
245
271
}
@@ -263,19 +289,23 @@ impl ModuleListTemplate {
263
289
}
264
290
265
291
fn n_visible ( & self ) -> u32 {
266
- self . lists ( ) . iter ( ) . map ( |list| list. n_visible ( ) ) . sum ( )
292
+ self . lists ( ) . iter ( ) . map ( |( list, _ ) | list. n_visible ( ) ) . sum ( )
267
293
}
268
294
269
295
fn filter ( & self , search_text : Option < String > ) {
270
296
if let Some ( search_text) = search_text {
271
- self . lists ( ) . iter ( ) . for_each ( move |list| {
297
+ self . lists ( ) . iter ( ) . for_each ( move |( list, label ) | {
272
298
let search_text = search_text. clone ( ) ;
273
299
list. set_filter_func ( move |item| Self :: filter_func ( item, & search_text) ) ;
300
+ label. set_visible ( list. n_visible ( ) != 0 ) ;
274
301
} ) ;
275
302
} else {
276
303
self . lists ( )
277
304
. iter ( )
278
- . for_each ( |list| list. unset_filter_func ( ) ) ;
305
+ . for_each ( |( list, label) | {
306
+ list. unset_filter_func ( ) ;
307
+ label. set_visible ( true ) ;
308
+ } ) ;
279
309
}
280
310
281
311
self . stack . set_visible_child_name ( if self . n_visible ( ) == 0 {
@@ -333,7 +363,7 @@ impl ObjectImpl for ModuleListTemplate {
333
363
} ;
334
364
self . lists ( )
335
365
. iter ( )
336
- . for_each ( |list| list. set_sort_func ( order_alphabetically) ) ;
366
+ . for_each ( |( list, _ ) | list. set_sort_func ( order_alphabetically) ) ;
337
367
}
338
368
}
339
369
0 commit comments