1
1
use super :: clipboards:: Clipboard ;
2
2
use super :: layer_panel:: { layer_panel_entry, LayerDataTypeDiscriminant , LayerMetadata , LayerPanelEntry , RawBuffer } ;
3
3
use super :: utility_types:: { AlignAggregate , AlignAxis , DocumentSave , FlipAxis } ;
4
- use super :: vectorize_layer_metadata;
4
+ use super :: { vectorize_layer_metadata, PropertiesPanelMessageHandler } ;
5
5
use super :: { ArtboardMessageHandler , MovementMessageHandler , OverlaysMessageHandler , TransformLayerMessageHandler } ;
6
6
use crate :: consts:: {
7
7
ASYMPTOTIC_EFFECT , DEFAULT_DOCUMENT_NAME , FILE_EXPORT_SUFFIX , FILE_SAVE_SUFFIX , GRAPHITE_DOCUMENT_VERSION , SCALE_EFFECT , SCROLLBAR_SPACING , VIEWPORT_ZOOM_TO_FIT_PADDING_SCALE_FACTOR ,
@@ -16,7 +16,7 @@ use crate::viewport_tools::vector_editor::vector_shape::VectorShape;
16
16
use crate :: EditorError ;
17
17
18
18
use graphene:: document:: Document as GrapheneDocument ;
19
- use graphene:: layers:: folder :: Folder ;
19
+ use graphene:: layers:: folder_layer :: FolderLayer ;
20
20
use graphene:: layers:: layer_info:: LayerDataType ;
21
21
use graphene:: layers:: style:: ViewMode ;
22
22
use graphene:: { DocumentError , DocumentResponse , LayerId , Operation as DocumentOperation } ;
@@ -45,6 +45,7 @@ pub struct DocumentMessageHandler {
45
45
pub artboard_message_handler : ArtboardMessageHandler ,
46
46
#[ serde( skip) ]
47
47
transform_layer_handler : TransformLayerMessageHandler ,
48
+ properties_panel_message_handler : PropertiesPanelMessageHandler ,
48
49
pub overlays_visible : bool ,
49
50
pub snapping_enabled : bool ,
50
51
pub view_mode : ViewMode ,
@@ -65,6 +66,7 @@ impl Default for DocumentMessageHandler {
65
66
overlays_message_handler : OverlaysMessageHandler :: default ( ) ,
66
67
artboard_message_handler : ArtboardMessageHandler :: default ( ) ,
67
68
transform_layer_handler : TransformLayerMessageHandler :: default ( ) ,
69
+ properties_panel_message_handler : PropertiesPanelMessageHandler :: default ( ) ,
68
70
snapping_enabled : true ,
69
71
overlays_visible : true ,
70
72
view_mode : ViewMode :: default ( ) ,
@@ -221,7 +223,7 @@ impl DocumentMessageHandler {
221
223
)
222
224
}
223
225
224
- fn serialize_structure ( & self , folder : & Folder , structure : & mut Vec < u64 > , data : & mut Vec < LayerId > , path : & mut Vec < LayerId > ) {
226
+ fn serialize_structure ( & self , folder : & FolderLayer , structure : & mut Vec < u64 > , data : & mut Vec < LayerId > , path : & mut Vec < LayerId > ) {
225
227
let mut space = 0 ;
226
228
for ( id, layer) in folder. layer_ids . iter ( ) . zip ( folder. layers ( ) ) . rev ( ) {
227
229
data. push ( * id) ;
@@ -676,16 +678,28 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
676
678
self . transform_layer_handler
677
679
. process_action ( message, ( & mut self . layer_metadata , & mut self . graphene_document , ipp) , responses) ;
678
680
}
681
+ #[ remain:: unsorted]
682
+ PropertiesPanel ( message) => {
683
+ self . properties_panel_message_handler . process_action ( message, & self . graphene_document , responses) ;
684
+ }
679
685
680
686
// Messages
681
687
AbortTransaction => {
682
688
self . undo ( responses) . unwrap_or_else ( |e| log:: warn!( "{}" , e) ) ;
683
689
responses. extend ( [ RenderDocument . into ( ) , DocumentStructureChanged . into ( ) ] ) ;
684
690
}
685
691
AddSelectedLayers { additional_layers } => {
686
- for layer_path in additional_layers {
687
- responses. extend ( self . select_layer ( & layer_path) ) ;
692
+ for layer_path in & additional_layers {
693
+ responses. extend ( self . select_layer ( layer_path) ) ;
694
+ }
695
+
696
+ let selected_paths: Vec < Vec < u64 > > = self . selected_layers ( ) . map ( |path| path. to_vec ( ) ) . collect ( ) ;
697
+ if selected_paths. is_empty ( ) {
698
+ responses. push_back ( PropertiesPanelMessage :: ClearSelection . into ( ) )
699
+ } else {
700
+ responses. push_back ( PropertiesPanelMessage :: SetActiveLayers { paths : selected_paths } . into ( ) )
688
701
}
702
+
689
703
// TODO: Correctly update layer panel in clear_selection instead of here
690
704
responses. push_back ( FolderChanged { affected_folder_path : vec ! [ ] } . into ( ) ) ;
691
705
responses. push_back ( DocumentMessage :: SelectionChanged . into ( ) ) ;
@@ -727,6 +741,16 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
727
741
responses. push_back ( ToolMessage :: DocumentIsDirty . into ( ) ) ;
728
742
}
729
743
}
744
+ BooleanOperation ( op) => {
745
+ // convert Vec<&[LayerId]> to Vec<Vec<&LayerId>> because Vec<&[LayerId]> does not implement several traits (Debug, Serialize, Deserialize, ...) required by DocumentOperation enum
746
+ responses. push_back (
747
+ DocumentOperation :: BooleanOperation {
748
+ operation : op,
749
+ selected : self . selected_layers_sorted ( ) . iter ( ) . map ( |slice| ( * slice) . into ( ) ) . collect ( ) ,
750
+ }
751
+ . into ( ) ,
752
+ ) ;
753
+ }
730
754
CommitTransaction => ( ) ,
731
755
CreateEmptyFolder { mut container_path } => {
732
756
let id = generate_uuid ( ) ;
@@ -743,12 +767,15 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
743
767
DebugPrintDocument => {
744
768
log:: debug!( "{:#?}\n {:#?}" , self . graphene_document, self . layer_metadata) ;
745
769
}
746
- DeleteLayer { layer_path } => responses. push_front ( DocumentOperation :: DeleteLayer { path : layer_path } . into ( ) ) ,
770
+ DeleteLayer { layer_path } => {
771
+ responses. push_front ( DocumentOperation :: DeleteLayer { path : layer_path. clone ( ) } . into ( ) ) ;
772
+ responses. push_back ( PropertiesPanelMessage :: CheckSelectedWasDeleted { path : layer_path } . into ( ) ) ;
773
+ }
747
774
DeleteSelectedLayers => {
748
775
self . backup ( responses) ;
749
776
750
777
for path in self . selected_layers_without_children ( ) {
751
- responses. push_front ( DocumentOperation :: DeleteLayer { path : path. to_vec ( ) } . into ( ) ) ;
778
+ responses. push_front ( DocumentMessage :: DeleteLayer { layer_path : path. to_vec ( ) } . into ( ) ) ;
752
779
}
753
780
754
781
responses. push_front ( DocumentMessage :: SelectionChanged . into ( ) ) ;
@@ -781,7 +808,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
781
808
}
782
809
}
783
810
ExportDocument => {
784
- // TODO(MFISH33 ): Add Dialog to select artboards
811
+ // TODO(mfish33 ): Add Dialog to select artboards
785
812
let bbox = self . document_bounds ( ) . unwrap_or_else ( || [ DVec2 :: ZERO , ipp. viewport_bounds . size ( ) ] ) ;
786
813
let size = bbox[ 1 ] - bbox[ 0 ] ;
787
814
let name = match self . name . ends_with ( FILE_SAVE_SUFFIX ) {
@@ -861,9 +888,10 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
861
888
) ;
862
889
}
863
890
LayerChanged { affected_layer_path } => {
864
- if let Ok ( layer_entry) = self . layer_panel_entry ( affected_layer_path) {
891
+ if let Ok ( layer_entry) = self . layer_panel_entry ( affected_layer_path. clone ( ) ) {
865
892
responses. push_back ( FrontendMessage :: UpdateDocumentLayer { data : layer_entry } . into ( ) ) ;
866
893
}
894
+ responses. push_back ( PropertiesPanelMessage :: CheckSelectedWasUpdated { path : affected_layer_path } . into ( ) ) ;
867
895
}
868
896
MoveSelectedLayersTo {
869
897
folder_path,
@@ -902,7 +930,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
902
930
responses. push_back ( ToolMessage :: DocumentIsDirty . into ( ) ) ;
903
931
}
904
932
Redo => {
905
- responses. push_back ( SelectMessage :: Abort . into ( ) ) ;
933
+ responses. push_back ( SelectToolMessage :: Abort . into ( ) ) ;
906
934
responses. push_back ( DocumentHistoryForward . into ( ) ) ;
907
935
responses. push_back ( ToolMessage :: DocumentIsDirty . into ( ) ) ;
908
936
responses. push_back ( RenderDocument . into ( ) ) ;
@@ -1159,7 +1187,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
1159
1187
responses. push_back ( ToolMessage :: DocumentIsDirty . into ( ) ) ;
1160
1188
}
1161
1189
Undo => {
1162
- responses. push_back ( SelectMessage :: Abort . into ( ) ) ;
1190
+ responses. push_back ( SelectToolMessage :: Abort . into ( ) ) ;
1163
1191
responses. push_back ( DocumentHistoryBackward . into ( ) ) ;
1164
1192
responses. push_back ( ToolMessage :: DocumentIsDirty . into ( ) ) ;
1165
1193
responses. push_back ( RenderDocument . into ( ) ) ;
0 commit comments