@@ -155,8 +155,8 @@ impl GpuPage {
155
155
156
156
// Load list of Views
157
157
let loaded_views_data: Vec < String > = settings_obj. get :: < Vec < String > > ( "viewconfigs" ) ;
158
- println ! ( "views saved:`{}`" , loaded_views_data. len( ) ) ; //TEST
159
- println ! ( "views saved:`{:?}`" , loaded_views_data) ; //TEST
158
+ // println!("views saved:`{}`", loaded_views_data.len()); //TEST
159
+ // println!("views saved:`{:?}`", loaded_views_data); //TEST
160
160
161
161
// Remove old content grid
162
162
match self . child_at ( 0 , 0 ) {
@@ -181,54 +181,39 @@ impl GpuPage {
181
181
let new_grid: Grid = Grid :: builder ( )
182
182
. name ( & new_grid_name)
183
183
. orientation ( Orientation :: Horizontal )
184
- //.margin_start(12)
185
- //.margin_end(12)
186
- //.margin_top(12)
187
- //.margin_bottom(12)
188
- //.halign(Align::Center)
189
- //.valign(Align::Center)
190
- //.hexpand(true)
191
- //.vexpand(true)
192
184
. build ( ) ;
193
185
content_grid. attach ( & new_grid, 0 , 0 as i32 , 100 , 12 ) ;
194
186
195
- // Set layout properties of grid
196
- //let child_manager: LayoutChild = grid_manager.layout_child(&new_grid);
197
- //child_manager.set_property("row-span", 1);
198
- //child_manager.set_property("column-span", 1);
199
-
200
187
// Build title label & add to grid
201
188
let label_value: String =
202
- String :: from ( "Please edit the list of Views using 'Edit Views ' button" ) ;
189
+ String :: from ( "Please add a View using 'Add View ' button" ) ;
203
190
let new_title_label: Label = Label :: builder ( )
204
191
. label ( & label_value)
205
192
. name ( "default" )
206
193
. hexpand ( true )
207
194
. hexpand_set ( true )
208
195
. halign ( Align :: Center )
209
- //.valign(Align::Center)
210
196
. margin_top ( 40 )
211
197
. margin_bottom ( 40 )
212
- //.width_chars(space)
213
198
. build ( ) ;
214
199
new_grid. attach ( & new_title_label, 1 , 1 , 1 , 1 ) ;
215
200
216
201
// Add edit button for current view
217
202
// Fetch grid's layout manager
218
203
match new_grid. layout_manager ( ) {
219
204
Some ( grid_manager) => {
220
- // Create edit button
221
- let edit_button : Button = Button :: builder ( )
222
- . name ( "edit_button " )
223
- . label ( "Edit View" )
205
+ // Create add_view_button
206
+ let add_view_button : Button = Button :: builder ( )
207
+ . name ( "add_view_button " )
208
+ . label ( "Add View" )
224
209
. margin_start ( 12 )
225
210
. margin_end ( 12 )
226
211
. margin_top ( 12 )
227
212
. margin_bottom ( 12 )
228
213
. halign ( Align :: Center )
229
214
. build ( ) ;
230
- new_grid. attach ( & edit_button , 0 , 80 , 1 , 1 ) ;
231
- edit_button . connect_clicked ( clone ! ( @weak self as gpage => move |_| {
215
+ new_grid. attach ( & add_view_button , 0 , 80 as i32 , 1 , 1 ) ;
216
+ add_view_button . connect_clicked ( clone ! ( @weak self as gpage => move |_| {
232
217
// Create modification window
233
218
// Borrow (mutable) the window's container
234
219
let mut modification_window_container: RefMut <ModificationWindowContainer > = gpage. imp( ) . modification_window. borrow_mut( ) ;
@@ -239,18 +224,18 @@ impl GpuPage {
239
224
// Check if an object is stored
240
225
match & modification_window_container. window {
241
226
Some ( _window) => {
242
- println!( "..window exists" ) ; //DEBUG
227
+ // println!("..window exists");//DEBUG
243
228
244
229
// Check if the window is already open
245
230
match modification_window_container. open {
246
231
false => {
247
- println!( "....opening window" ) ; //DEBUG
232
+ // println!("....opening window");//DEBUG
248
233
249
234
// Create an app object
250
235
let app: Application = Application :: builder( ) . application_id( APP_ID ) . build( ) ;
251
236
252
237
// Create new modification window
253
- let new_modification_window: ModificationWindow = ModificationWindow :: new( & app, 0 , & gpage. property:: <String >( "uuid" ) , & gpage) ;
238
+ let new_modification_window: ModificationWindow = ModificationWindow :: new( & app, - 1 , & gpage. property:: <String >( "uuid" ) , & gpage) ;
254
239
255
240
// Show new modification window
256
241
new_modification_window. show( ) ;
@@ -265,14 +250,14 @@ impl GpuPage {
265
250
}
266
251
} ,
267
252
None => {
268
- println!( "..window does not exist" ) ; //DEBUG
269
- println!( "....opening window" ) ; //DEBUG
253
+ // println!("..window does not exist");//DEBUG
254
+ // println!("....opening window");//DEBUG
270
255
271
256
// Create an app object
272
257
let app: Application = Application :: builder( ) . application_id( APP_ID ) . build( ) ;
273
258
274
259
// Create modification window
275
- let new_modification_window: ModificationWindow = ModificationWindow :: new( & app, 0 , & gpage. property:: <String >( "uuid" ) , & gpage) ;
260
+ let new_modification_window: ModificationWindow = ModificationWindow :: new( & app, - 1 , & gpage. property:: <String >( "uuid" ) , & gpage) ;
276
261
277
262
// Show new modification window
278
263
new_modification_window. show( ) ;
@@ -288,7 +273,7 @@ impl GpuPage {
288
273
} ) ) ;
289
274
290
275
// Set layout properties of button
291
- let child_manager: LayoutChild = grid_manager. layout_child ( & edit_button ) ;
276
+ let child_manager: LayoutChild = grid_manager. layout_child ( & add_view_button ) ;
292
277
child_manager. set_property ( "row-span" , 2 ) ;
293
278
child_manager. set_property ( "column-span" , 2 ) ;
294
279
}
@@ -316,7 +301,7 @@ impl GpuPage {
316
301
317
302
// For each loaded view
318
303
for index in 0 ..loaded_views_data. len ( ) {
319
- println ! ( "item: `{}`" , loaded_views_data[ index] ) ; //TEST
304
+ // println!("item: `{}`", loaded_views_data[index]); //TEST
320
305
321
306
// Split current item into the 4 parts
322
307
let parts: Vec < & str > = loaded_views_data[ index] . split ( ':' ) . collect :: < Vec < & str > > ( ) ;
@@ -354,13 +339,13 @@ impl GpuPage {
354
339
// Grab all saved properties
355
340
let properties: Vec < String > = self . check_properties_for_view ( & loaded_views[ index] ) ;
356
341
342
+ // println!("GOT {} PROPERTIES FOR VIEW {}", properties.len(), index);
343
+
357
344
// Add property items to the final list
358
345
for prop in & properties {
359
346
props. push ( prop. as_str ( ) . clone ( ) . to_owned ( ) ) ;
360
347
}
361
348
362
- // println!("GOT {} PROPERTIES FOR VIEW {}", properties.len(), index);
363
-
364
349
// Create new view
365
350
let new_grid_name: String = index. to_string ( ) + "_grid" ;
366
351
let new_grid: Grid = Grid :: builder ( )
@@ -383,6 +368,23 @@ impl GpuPage {
383
368
let new_view_grid: Grid = output. 0 ;
384
369
labels = output. 1 ;
385
370
371
+ // If no labels (from no properties)
372
+ if labels. len ( ) == 0 {
373
+ // Build title label & add to grid
374
+ let label_value: String =
375
+ String :: from ( "Please edit this View using 'Edit View' button" ) ;
376
+ let new_title_label: Label = Label :: builder ( )
377
+ . label ( & label_value)
378
+ . name ( "default" )
379
+ . hexpand ( true )
380
+ . hexpand_set ( true )
381
+ . halign ( Align :: Center )
382
+ . margin_top ( 40 )
383
+ . margin_bottom ( 40 )
384
+ . build ( ) ;
385
+ new_view_grid. attach ( & new_title_label, 1 , 1 , 1 , 1 ) ;
386
+ }
387
+
386
388
// Add edit button for current view
387
389
// Fetch grid's layout manager
388
390
match new_view_grid. layout_manager ( ) {
@@ -409,12 +411,12 @@ impl GpuPage {
409
411
// Check if an object is stored
410
412
match & modification_window_container. window {
411
413
Some ( _window) => {
412
- println!( "..window exists" ) ; //DEBUG
414
+ // println!("..window exists");//DEBUG
413
415
414
416
// Check if the window is already open
415
417
match modification_window_container. open {
416
418
false => {
417
- println!( "....opening window" ) ; //DEBUG
419
+ // println!("....opening window");//DEBUG
418
420
419
421
// Create an app object
420
422
let app: Application = Application :: builder( ) . application_id( APP_ID ) . build( ) ;
@@ -435,8 +437,8 @@ impl GpuPage {
435
437
}
436
438
} ,
437
439
None => {
438
- println!( "..window does not exist" ) ; //DEBUG
439
- println!( "....opening window" ) ; //DEBUG
440
+ // println!("..window does not exist");//DEBUG
441
+ // println!("....opening window");//DEBUG
440
442
441
443
// Create an app object
442
444
let app: Application = Application :: builder( ) . application_id( APP_ID ) . build( ) ;
@@ -461,6 +463,82 @@ impl GpuPage {
461
463
let child_manager: LayoutChild = grid_manager. layout_child ( & edit_button) ;
462
464
child_manager. set_property ( "row-span" , 2 ) ;
463
465
child_manager. set_property ( "column-span" , 2 ) ;
466
+
467
+
468
+ // Create add_view_button
469
+ let add_view_button: Button = Button :: builder ( )
470
+ . name ( "add_view_button" )
471
+ . label ( "Add View" )
472
+ . margin_start ( 12 )
473
+ . margin_end ( 12 )
474
+ . margin_top ( 12 )
475
+ . margin_bottom ( 12 )
476
+ . halign ( Align :: Center )
477
+ . build ( ) ;
478
+ new_view_grid. attach ( & add_view_button, 0 , 82 as i32 , 1 , 1 ) ;
479
+ add_view_button. connect_clicked ( clone ! ( @weak self as gpage => move |_| {
480
+ // Create modification window
481
+ // Borrow (mutable) the window's container
482
+ let mut modification_window_container: RefMut <ModificationWindowContainer > = gpage. imp( ) . modification_window. borrow_mut( ) ;
483
+
484
+ // Get state from settings
485
+ modification_window_container. open = gpage. imp( ) . get_setting:: <bool >( "modification-open" ) ;
486
+
487
+ // Check if an object is stored
488
+ match & modification_window_container. window {
489
+ Some ( _window) => {
490
+ // println!("..window exists");//DEBUG
491
+
492
+ // Check if the window is already open
493
+ match modification_window_container. open {
494
+ false => {
495
+ // println!("....opening window");//DEBUG
496
+
497
+ // Create an app object
498
+ let app: Application = Application :: builder( ) . application_id( APP_ID ) . build( ) ;
499
+
500
+ // Create new modification window
501
+ let new_modification_window: ModificationWindow = ModificationWindow :: new( & app, -1 , & gpage. property:: <String >( "uuid" ) , & gpage) ;
502
+
503
+ // Show new modification window
504
+ new_modification_window. show( ) ;
505
+
506
+ // Store object and state back in container
507
+ modification_window_container. open = true ;
508
+ modification_window_container. window = Some ( new_modification_window) ;
509
+ } ,
510
+ true => {
511
+ println!( "....window already open" ) ; //DEBUG
512
+ } ,
513
+ }
514
+ } ,
515
+ None => {
516
+ // println!("..window does not exist");//DEBUG
517
+ // println!("....opening window");//DEBUG
518
+
519
+ // Create an app object
520
+ let app: Application = Application :: builder( ) . application_id( APP_ID ) . build( ) ;
521
+
522
+ // Create modification window
523
+ let new_modification_window: ModificationWindow = ModificationWindow :: new( & app, -1 , & gpage. property:: <String >( "uuid" ) , & gpage) ;
524
+
525
+ // Show new modification window
526
+ new_modification_window. show( ) ;
527
+
528
+ // Store object and state back in container
529
+ modification_window_container. open = true ;
530
+ modification_window_container. window = Some ( new_modification_window) ;
531
+ } ,
532
+ }
533
+
534
+ // Set new state in settings
535
+ gpage. imp( ) . update_setting:: <bool >( "modification-open" , modification_window_container. open) ;
536
+ } ) ) ;
537
+
538
+ // Set layout properties of button
539
+ let child_manager: LayoutChild = grid_manager. layout_child ( & add_view_button) ;
540
+ child_manager. set_property ( "row-span" , 2 ) ;
541
+ child_manager. set_property ( "column-span" , 2 ) ;
464
542
}
465
543
None => panic ! ( "Cannot fetch layout manager of grid.." ) ,
466
544
}
@@ -481,7 +559,12 @@ impl GpuPage {
481
559
new_item. set_icon_name ( Some ( "package-x-generic-symbolic" ) ) ;
482
560
}
483
561
484
- self . create_updater ( labels, props) ;
562
+ // if properties exist, call create_updater() function to add time-delayed callback to update appropriate labels
563
+ if props. len ( ) > 0 {
564
+ self . create_updater ( labels, props) ;
565
+ } // else {
566
+ // println!("No properties, no callbacks!");
567
+ // }
485
568
486
569
// Replace current view stack
487
570
self . imp ( ) . replace_stack ( Some ( & new_stack) ) ;
@@ -511,17 +594,14 @@ impl GpuPage {
511
594
// Load list of Properties for current Page
512
595
let loaded_properties_data: Vec < String > =
513
596
settings_obj. get :: < Vec < String > > ( "viewcomponentconfigs" ) ;
514
- // println!("items saved:`{}`", loaded_properties_data.len()); //TEST
597
+ // println!("items saved #: `{}`", loaded_properties_data.len()); //TEST
598
+ // println!("items saved: `{:?}`", loaded_properties_data); //TEST
515
599
516
600
// If present in saved settings, use! otherwise follow below defaults
517
601
if let 0 = loaded_properties_data. len ( ) {
518
- match self
519
- . property :: < Provider > ( "provider" )
520
- . property :: < i32 > ( "provider-type" )
521
- {
522
- -1 => vec ! [ String :: from( "choose_provider" ) ] ,
523
- _ => vec ! [ String :: from( "choose_properties" ) ] ,
524
- }
602
+ // println!("no properties.."); //TEST
603
+
604
+ vec ! [ ]
525
605
} else {
526
606
// Create temporary structure for sorting loaded data
527
607
let mut loaded_properties: Vec < String > =
@@ -552,8 +632,7 @@ impl GpuPage {
552
632
match parts[ 2 ] . parse :: < usize > ( ) {
553
633
Ok ( position) => {
554
634
if position <= loaded_properties_data. len ( ) {
555
- // println!("VALID POSITION INDEX: `{}`", position); //TEST
556
-
635
+ // println!("VALID POSITION INDEX: `{}`", offset_position); //TEST
557
636
// println!("VALID PROPERTY: `{}`", parts[3]); //TEST
558
637
559
638
// Add to final list
@@ -596,6 +675,7 @@ impl GpuPage {
596
675
properties : Vec < String > ,
597
676
mut labels : Vec < Label > ,
598
677
) -> ( Grid , Vec < Label > ) {
678
+
599
679
// Load properties from struct
600
680
let properties_store: Arc < Mutex < Vec < String > > > = Arc :: new ( Mutex :: new ( properties) ) ;
601
681
0 commit comments