@@ -65,8 +65,10 @@ pub enum DocumentMessage {
65
65
#[ child]
66
66
Movement ( MovementMessage ) ,
67
67
DispatchOperation ( Box < DocumentOperation > ) ,
68
- SelectLayers ( Vec < Vec < LayerId > > ) ,
68
+ SetSelectedLayers ( Vec < Vec < LayerId > > ) ,
69
+ AddSelectedLayers ( Vec < Vec < LayerId > > ) ,
69
70
SelectAllLayers ,
71
+ SelectionChanged ,
70
72
DeselectAllLayers ,
71
73
DeleteLayer ( Vec < LayerId > ) ,
72
74
DeleteSelectedLayers ,
@@ -125,9 +127,17 @@ impl DocumentMessageHandler {
125
127
self . layer_data . values_mut ( ) . for_each ( |layer_data| layer_data. selected = false ) ;
126
128
}
127
129
fn select_layer ( & mut self , path : & [ LayerId ] ) -> Option < Message > {
130
+ if self . document . layer ( path) . ok ( ) ?. overlay {
131
+ return None ;
132
+ }
128
133
self . layer_data ( path) . selected = true ;
134
+ let data = self . layer_panel_entry ( path. to_vec ( ) ) . ok ( ) ?;
129
135
// TODO: Add deduplication
130
- ( !path. is_empty ( ) ) . then ( || self . handle_folder_changed ( path[ ..path. len ( ) - 1 ] . to_vec ( ) ) ) . flatten ( )
136
+ ( !path. is_empty ( ) ) . then ( || FrontendMessage :: UpdateLayer { path : path. to_vec ( ) . into ( ) , data } . into ( ) )
137
+ }
138
+ pub fn selected_layers_bounding_box ( & self ) -> Option < [ DVec2 ; 2 ] > {
139
+ let paths = self . selected_layers ( ) . map ( |vec| & vec[ ..] ) ;
140
+ self . document . combined_viewport_bounding_box ( paths)
131
141
}
132
142
pub fn layerdata ( & self , path : & [ LayerId ] ) -> & LayerData {
133
143
self . layer_data . get ( path) . expect ( "Layerdata does not exist" )
@@ -247,6 +257,7 @@ impl DocumentMessageHandler {
247
257
. iter ( )
248
258
. zip ( paths. iter ( ) . zip ( data) )
249
259
. rev ( )
260
+ . filter ( |( layer, _) | !layer. overlay )
250
261
. map ( |( layer, ( path, data) ) | {
251
262
layer_panel_entry (
252
263
& data,
@@ -345,35 +356,40 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
345
356
self . layer_data ( & path) . expanded ^= true ;
346
357
responses. extend ( self . handle_folder_changed ( path) ) ;
347
358
}
359
+ SelectionChanged => responses. push_back ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) ) ,
348
360
DeleteSelectedLayers => {
349
361
for path in self . selected_layers ( ) . cloned ( ) {
350
362
responses. push_back ( DocumentOperation :: DeleteLayer { path } . into ( ) )
351
363
}
364
+ responses. push_back ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) ) ;
352
365
}
353
366
DuplicateSelectedLayers => {
354
367
for path in self . selected_layers_sorted ( ) {
355
368
responses. push_back ( DocumentOperation :: DuplicateLayer { path } . into ( ) )
356
369
}
357
370
}
358
- SelectLayers ( paths) => {
371
+ SetSelectedLayers ( paths) => {
359
372
self . clear_selection ( ) ;
373
+ responses. push_front ( AddSelectedLayers ( paths) . into ( ) ) ;
374
+ }
375
+ AddSelectedLayers ( paths) => {
360
376
for path in paths {
361
377
responses. extend ( self . select_layer ( & path) ) ;
362
378
}
363
379
// TODO: Correctly update layer panel in clear_selection instead of here
364
380
responses. extend ( self . handle_folder_changed ( Vec :: new ( ) ) ) ;
381
+ responses. push_back ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) ) ;
365
382
}
366
383
SelectAllLayers => {
367
- let all_layer_paths = self . layer_data . keys ( ) . filter ( |path| !path. is_empty ( ) ) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
368
- for path in all_layer_paths {
369
- responses. extend ( self . select_layer ( & path) ) ;
370
- }
371
- }
372
- DeselectAllLayers => {
373
- self . clear_selection ( ) ;
374
- let children = self . layer_panel ( & [ ] ) . expect ( "The provided Path was not valid" ) ;
375
- responses. push_back ( FrontendMessage :: ExpandFolder { path : vec ! [ ] . into ( ) , children } . into ( ) ) ;
384
+ let all_layer_paths = self
385
+ . layer_data
386
+ . keys ( )
387
+ . filter ( |path| !path. is_empty ( ) && !self . document . layer ( path) . unwrap ( ) . overlay )
388
+ . cloned ( )
389
+ . collect :: < Vec < _ > > ( ) ;
390
+ responses. push_back ( SetSelectedLayers ( all_layer_paths) . into ( ) ) ;
376
391
}
392
+ DeselectAllLayers => responses. push_back ( SetSelectedLayers ( vec ! [ ] ) . into ( ) ) ,
377
393
Undo => {
378
394
// this is a temporary fix and will be addressed by #123
379
395
if let Some ( id) = self . document . root . as_folder ( ) . unwrap ( ) . list_layers ( ) . last ( ) {
@@ -391,10 +407,11 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
391
407
DocumentResponse :: FolderChanged { path } => self . handle_folder_changed ( path) ,
392
408
DocumentResponse :: DeletedLayer { path } => {
393
409
self . layer_data . remove ( & path) ;
394
- None
410
+
411
+ Some ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) )
395
412
}
396
413
DocumentResponse :: LayerChanged { path } => self . layer_panel_entry ( path. clone ( ) ) . ok ( ) . map ( |data| FrontendMessage :: UpdateLayer { path : path. into ( ) , data } . into ( ) ) ,
397
- DocumentResponse :: CreatedLayer { path } => self . select_layer ( & path) ,
414
+ DocumentResponse :: CreatedLayer { path } => ( ! self . document . layer ( & path) . unwrap ( ) . overlay ) . then ( || SetSelectedLayers ( vec ! [ path ] ) . into ( ) ) ,
398
415
DocumentResponse :: DocumentChanged => unreachable ! ( ) ,
399
416
} )
400
417
. flatten ( ) ,
@@ -441,6 +458,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
441
458
} ;
442
459
responses. push_back ( operation. into ( ) ) ;
443
460
}
461
+ responses. push_back ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) ) ;
444
462
}
445
463
MoveSelectedLayersTo { path, insert_index } => {
446
464
responses. push_back ( DocumentsMessage :: CopySelectedLayers . into ( ) ) ;
@@ -496,6 +514,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
496
514
. into ( ) ,
497
515
) ;
498
516
}
517
+ responses. push_back ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) ) ;
499
518
}
500
519
}
501
520
AlignSelectedLayers ( axis, aggregate) => {
@@ -528,6 +547,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
528
547
. into ( ) ,
529
548
) ;
530
549
}
550
+ responses. push_back ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) ) ;
531
551
}
532
552
}
533
553
RenameLayer ( path, name) => responses. push_back ( DocumentOperation :: RenameLayer { path, name } . into ( ) ) ,
0 commit comments