@@ -6,6 +6,7 @@ use super::{ArtboardMessageHandler, MovementMessageHandler, OverlaysMessageHandl
66use crate :: consts:: {
77 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 ,
88} ;
9+ use crate :: frontend:: utility_types:: FrontendImageData ;
910use crate :: input:: InputPreprocessorMessageHandler ;
1011use crate :: layout:: widgets:: {
1112 IconButton , LayoutRow , NumberInput , NumberInputIncrementBehavior , OptionalInput , PopoverButton , PropertyHolder , RadioEntryData , RadioInput , Separator , SeparatorDirection , SeparatorType , Widget ,
@@ -470,6 +471,33 @@ impl DocumentMessageHandler {
470471 path. push ( generate_uuid ( ) ) ;
471472 path
472473 }
474+
475+ /// Creates the blob URLs for the image data in the document
476+ pub fn load_image_data ( & self , responses : & mut VecDeque < Message > , root : & LayerDataType , mut path : Vec < LayerId > ) {
477+ let mut image_data = Vec :: new ( ) ;
478+ fn walk_layers ( data : & LayerDataType , path : & mut Vec < LayerId > , responses : & mut VecDeque < Message > , image_data : & mut Vec < FrontendImageData > ) {
479+ match data {
480+ LayerDataType :: Folder ( f) => {
481+ for ( id, layer) in f. layer_ids . iter ( ) . zip ( f. layers ( ) . iter ( ) ) {
482+ path. push ( * id) ;
483+ walk_layers ( & layer. data , path, responses, image_data) ;
484+ path. pop ( ) ;
485+ }
486+ }
487+ LayerDataType :: Image ( img) => image_data. push ( FrontendImageData {
488+ path : path. clone ( ) ,
489+ image_data : img. image_data . clone ( ) ,
490+ mime : img. mime . clone ( ) ,
491+ } ) ,
492+ _ => { }
493+ }
494+ }
495+
496+ walk_layers ( root, & mut path, responses, & mut image_data) ;
497+ if !image_data. is_empty ( ) {
498+ responses. push_front ( FrontendMessage :: UpdateImageData { image_data } . into ( ) ) ;
499+ }
500+ }
473501}
474502
475503impl PropertyHolder for DocumentMessageHandler {
@@ -783,7 +811,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
783811 }
784812 DirtyRenderDocument => {
785813 // Mark all non-overlay caches as dirty
786- GrapheneDocument :: visit_all_shapes ( & mut self . graphene_document . root , & mut |_| { } ) ;
814+ GrapheneDocument :: mark_children_as_dirty ( & mut self . graphene_document . root ) ;
787815
788816 responses. push_back ( DocumentMessage :: RenderDocument . into ( ) ) ;
789817 }
@@ -865,13 +893,13 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
865893
866894 new_folder_path. push ( generate_uuid ( ) ) ;
867895
868- responses. push_back ( PortfolioMessage :: Copy { clipboard : Clipboard :: System } . into ( ) ) ;
896+ responses. push_back ( PortfolioMessage :: Copy { clipboard : Clipboard :: Internal } . into ( ) ) ;
869897 responses. push_back ( DocumentMessage :: DeleteSelectedLayers . into ( ) ) ;
870898 responses. push_back ( DocumentOperation :: CreateFolder { path : new_folder_path. clone ( ) } . into ( ) ) ;
871899 responses. push_back ( DocumentMessage :: ToggleLayerExpansion { layer_path : new_folder_path. clone ( ) } . into ( ) ) ;
872900 responses. push_back (
873901 PortfolioMessage :: PasteIntoFolder {
874- clipboard : Clipboard :: System ,
902+ clipboard : Clipboard :: Internal ,
875903 folder_path : new_folder_path. clone ( ) ,
876904 insert_index : -1 ,
877905 }
@@ -904,11 +932,11 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
904932
905933 let insert_index = self . update_insert_index ( & selected_layers, & folder_path, insert_index, reverse_index) . unwrap ( ) ;
906934
907- responses. push_back ( PortfolioMessage :: Copy { clipboard : Clipboard :: System } . into ( ) ) ;
935+ responses. push_back ( PortfolioMessage :: Copy { clipboard : Clipboard :: Internal } . into ( ) ) ;
908936 responses. push_back ( DocumentMessage :: DeleteSelectedLayers . into ( ) ) ;
909937 responses. push_back (
910938 PortfolioMessage :: PasteIntoFolder {
911- clipboard : Clipboard :: System ,
939+ clipboard : Clipboard :: Internal ,
912940 folder_path,
913941 insert_index,
914942 }
@@ -926,6 +954,39 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
926954 }
927955 responses. push_back ( ToolMessage :: DocumentIsDirty . into ( ) ) ;
928956 }
957+ PasteImage { mime, image_data, mouse } => {
958+ let path = vec ! [ generate_uuid( ) ] ;
959+ responses. push_front (
960+ FrontendMessage :: UpdateImageData {
961+ image_data : vec ! [ FrontendImageData {
962+ path: path. clone( ) ,
963+ image_data: image_data. clone( ) ,
964+ mime: mime. clone( ) ,
965+ } ] ,
966+ }
967+ . into ( ) ,
968+ ) ;
969+ responses. push_back (
970+ DocumentOperation :: AddImage {
971+ path : path. clone ( ) ,
972+ transform : DAffine2 :: ZERO . to_cols_array ( ) ,
973+ insert_index : -1 ,
974+ mime,
975+ image_data,
976+ }
977+ . into ( ) ,
978+ ) ;
979+ responses. push_back (
980+ DocumentMessage :: SetSelectedLayers {
981+ replacement_selected_layers : vec ! [ path. clone( ) ] ,
982+ }
983+ . into ( ) ,
984+ ) ;
985+
986+ let mouse = mouse. map_or ( ipp. mouse . position , |pos| pos. into ( ) ) ;
987+ let transform = DAffine2 :: from_translation ( mouse - ipp. viewport_bounds . top_left ) . to_cols_array ( ) ;
988+ responses. push_back ( DocumentOperation :: SetLayerTransformInViewport { path, transform } . into ( ) ) ;
989+ }
929990 Redo => {
930991 responses. push_back ( SelectToolMessage :: Abort . into ( ) ) ;
931992 responses. push_back ( DocumentHistoryForward . into ( ) ) ;
@@ -1200,10 +1261,10 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
12001261 // Select them
12011262 DocumentMessage :: SetSelectedLayers { replacement_selected_layers : select } . into ( ) ,
12021263 // Copy them
1203- PortfolioMessage :: Copy { clipboard : Clipboard :: System } . into ( ) ,
1264+ PortfolioMessage :: Copy { clipboard : Clipboard :: Internal } . into ( ) ,
12041265 // Paste them into the folder above
12051266 PortfolioMessage :: PasteIntoFolder {
1206- clipboard : Clipboard :: System ,
1267+ clipboard : Clipboard :: Internal ,
12071268 folder_path : folder_path[ ..folder_path. len ( ) - 1 ] . to_vec ( ) ,
12081269 insert_index : -1 ,
12091270 }
0 commit comments