@@ -66,8 +66,10 @@ pub enum DocumentMessage {
6666 #[ child]
6767 Movement ( MovementMessage ) ,
6868 DispatchOperation ( Box < DocumentOperation > ) ,
69- SelectLayers ( Vec < Vec < LayerId > > ) ,
69+ SetSelectedLayers ( Vec < Vec < LayerId > > ) ,
70+ AddSelectedLayers ( Vec < Vec < LayerId > > ) ,
7071 SelectAllLayers ,
72+ SelectionChanged ,
7173 DeselectAllLayers ,
7274 DeleteLayer ( Vec < LayerId > ) ,
7375 DeleteSelectedLayers ,
@@ -125,9 +127,17 @@ impl DocumentMessageHandler {
125127 self . layer_data . values_mut ( ) . for_each ( |layer_data| layer_data. selected = false ) ;
126128 }
127129 fn select_layer ( & mut self , path : & [ LayerId ] ) -> Option < Message > {
130+ if self . document . layer ( path) . ok ( ) ?. overlay {
131+ return None ;
132+ }
128133 self . layer_data ( path) . selected = true ;
134+ let data = self . layer_panel_entry ( path. to_vec ( ) ) . ok ( ) ?;
129135 // 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 ( ) , 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)
131141 }
132142 pub fn layerdata ( & self , path : & [ LayerId ] ) -> & LayerData {
133143 self . layer_data . get ( path) . expect ( "Layerdata does not exist" )
@@ -247,6 +257,7 @@ impl DocumentMessageHandler {
247257 . iter ( )
248258 . zip ( paths. iter ( ) . zip ( data) )
249259 . rev ( )
260+ . filter ( |( layer, _) | !layer. overlay )
250261 . map ( |( layer, ( path, data) ) | {
251262 layer_panel_entry (
252263 & data,
@@ -332,34 +343,41 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
332343 self . layer_data ( & path) . expanded ^= true ;
333344 responses. extend ( self . handle_folder_changed ( path) ) ;
334345 }
346+ SelectionChanged => responses. push_back ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) ) ,
335347 DeleteSelectedLayers => {
336348 for path in self . selected_layers ( ) . cloned ( ) {
337349 responses. push_back ( DocumentOperation :: DeleteLayer { path } . into ( ) )
338350 }
351+ responses. push_back ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) ) ;
339352 }
340353 DuplicateSelectedLayers => {
341354 for path in self . selected_layers_sorted ( ) {
342355 responses. push_back ( DocumentOperation :: DuplicateLayer { path } . into ( ) )
343356 }
344357 }
345- SelectLayers ( paths) => {
358+ SetSelectedLayers ( paths) => {
346359 self . clear_selection ( ) ;
360+ responses. push_front ( AddSelectedLayers ( paths) . into ( ) ) ;
361+ }
362+ AddSelectedLayers ( paths) => {
347363 for path in paths {
348364 responses. extend ( self . select_layer ( & path) ) ;
349365 }
350366 // TODO: Correctly update layer panel in clear_selection instead of here
351367 responses. extend ( self . handle_folder_changed ( Vec :: new ( ) ) ) ;
368+ responses. push_back ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) ) ;
352369 }
353370 SelectAllLayers => {
354- let all_layer_paths = self . layer_data . keys ( ) . filter ( |path| !path. is_empty ( ) ) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
355- for path in all_layer_paths {
356- responses. extend ( self . select_layer ( & path) ) ;
357- }
371+ let all_layer_paths = self
372+ . layer_data
373+ . keys ( )
374+ . filter ( |path| !path. is_empty ( ) && !self . document . layer ( path) . unwrap ( ) . overlay )
375+ . cloned ( )
376+ . collect :: < Vec < _ > > ( ) ;
377+ responses. push_back ( SetSelectedLayers ( all_layer_paths) . into ( ) ) ;
358378 }
359379 DeselectAllLayers => {
360- self . clear_selection ( ) ;
361- let children = self . layer_panel ( & [ ] ) . expect ( "The provided Path was not valid" ) ;
362- responses. push_back ( FrontendMessage :: ExpandFolder { path : vec ! [ ] , children } . into ( ) ) ;
380+ responses. push_back ( SetSelectedLayers ( vec ! [ ] ) . into ( ) ) ;
363381 }
364382 Undo => {
365383 // this is a temporary fix and will be addressed by #123
@@ -378,7 +396,8 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
378396 DocumentResponse :: FolderChanged { path } => self . handle_folder_changed ( path) ,
379397 DocumentResponse :: DeletedLayer { path } => {
380398 self . layer_data . remove ( & path) ;
381- None
399+
400+ Some ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) )
382401 }
383402 DocumentResponse :: LayerChanged { path } => Some (
384403 FrontendMessage :: UpdateLayer {
@@ -387,7 +406,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
387406 }
388407 . into ( ) ,
389408 ) ,
390- DocumentResponse :: CreatedLayer { path } => self . select_layer ( & path) ,
409+ DocumentResponse :: CreatedLayer { path } => ( ! self . document . layer ( & path) . unwrap ( ) . overlay ) . then ( || SetSelectedLayers ( vec ! [ path ] ) . into ( ) ) ,
391410 DocumentResponse :: DocumentChanged => unreachable ! ( ) ,
392411 } )
393412 . flatten ( ) ,
@@ -434,6 +453,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
434453 } ;
435454 responses. push_back ( operation. into ( ) ) ;
436455 }
456+ responses. push_back ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) ) ;
437457 }
438458 MoveSelectedLayersTo { path, insert_index } => {
439459 responses. push_back ( DocumentsMessage :: CopySelectedLayers . into ( ) ) ;
@@ -488,6 +508,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
488508 . into ( ) ,
489509 ) ;
490510 }
511+ responses. push_back ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) ) ;
491512 }
492513 }
493514 AlignSelectedLayers ( axis, aggregate) => {
@@ -520,6 +541,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
520541 . into ( ) ,
521542 ) ;
522543 }
544+ responses. push_back ( SelectMessage :: UpdateSelectionBoundingBox . into ( ) ) ;
523545 }
524546 }
525547 RenameLayer ( path, name) => responses. push_back ( DocumentOperation :: RenameLayer { path, name } . into ( ) ) ,
0 commit comments