1- use graphene_std:: Color ;
2- use graphene_std:: raster:: Image ;
31use graphite_editor:: messages:: clipboard:: utility_types:: ClipboardContentRaw ;
42use graphite_editor:: messages:: prelude:: * ;
53
@@ -14,9 +12,9 @@ pub(super) fn handle_desktop_wrapper_message(dispatcher: &mut DesktopWrapperMess
1412 DesktopWrapperMessage :: Input ( message) => {
1513 dispatcher. queue_editor_message ( EditorMessage :: InputPreprocessor ( message) ) ;
1614 }
17- DesktopWrapperMessage :: OpenFileDialogResult { path, content, context } => match context {
18- OpenFileDialogContext :: Document => {
19- dispatcher. queue_desktop_wrapper_message ( DesktopWrapperMessage :: OpenDocument { path, content } ) ;
15+ DesktopWrapperMessage :: FileDialogResult { path, content, context } => match context {
16+ OpenFileDialogContext :: Open => {
17+ dispatcher. queue_desktop_wrapper_message ( DesktopWrapperMessage :: OpenFile { path, content } ) ;
2018 }
2119 OpenFileDialogContext :: Import => {
2220 dispatcher. queue_desktop_wrapper_message ( DesktopWrapperMessage :: ImportFile { path, content } ) ;
@@ -35,78 +33,11 @@ pub(super) fn handle_desktop_wrapper_message(dispatcher: &mut DesktopWrapperMess
3533 }
3634 } ,
3735 DesktopWrapperMessage :: OpenFile { path, content } => {
38- let extension = path. extension ( ) . and_then ( |s| s. to_str ( ) ) . unwrap_or_default ( ) . to_lowercase ( ) ;
39- match extension. as_str ( ) {
40- "graphite" => {
41- dispatcher. queue_desktop_wrapper_message ( DesktopWrapperMessage :: OpenDocument { path, content } ) ;
42- }
43- _ => {
44- dispatcher. queue_desktop_wrapper_message ( DesktopWrapperMessage :: ImportFile { path, content } ) ;
45- }
46- }
47- }
48- DesktopWrapperMessage :: OpenDocument { path, content } => {
49- let Ok ( content) = String :: from_utf8 ( content) else {
50- tracing:: warn!( "Document file is invalid: {}" , path. display( ) ) ;
51- return ;
52- } ;
53-
54- let message = PortfolioMessage :: OpenDocumentFile {
55- document_name : None ,
56- document_path : Some ( path) ,
57- document_serialized_content : content,
58- } ;
36+ let message = PortfolioMessage :: OpenFile { path, content } ;
5937 dispatcher. queue_editor_message ( message) ;
6038 }
6139 DesktopWrapperMessage :: ImportFile { path, content } => {
62- let extension = path. extension ( ) . and_then ( |s| s. to_str ( ) ) . unwrap_or_default ( ) . to_lowercase ( ) ;
63- match extension. as_str ( ) {
64- "svg" => {
65- dispatcher. queue_desktop_wrapper_message ( DesktopWrapperMessage :: ImportSvg { path, content } ) ;
66- }
67- _ => {
68- dispatcher. queue_desktop_wrapper_message ( DesktopWrapperMessage :: ImportImage { path, content } ) ;
69- }
70- }
71- }
72- DesktopWrapperMessage :: ImportSvg { path, content } => {
73- let Ok ( content) = String :: from_utf8 ( content) else {
74- tracing:: warn!( "Svg file is invalid: {}" , path. display( ) ) ;
75- return ;
76- } ;
77-
78- let message = PortfolioMessage :: PasteSvg {
79- name : path. file_stem ( ) . map ( |s| s. to_string_lossy ( ) . to_string ( ) ) ,
80- svg : content,
81- mouse : None ,
82- parent_and_insert_index : None ,
83- } ;
84- dispatcher. queue_editor_message ( message) ;
85- }
86- DesktopWrapperMessage :: ImportImage { path, content } => {
87- let name = path. file_stem ( ) . and_then ( |s| s. to_str ( ) ) . map ( |s| s. to_string ( ) ) ;
88- let extension = path. extension ( ) . and_then ( |s| s. to_str ( ) ) . unwrap_or_default ( ) . to_lowercase ( ) ;
89- let Some ( image_format) = image:: ImageFormat :: from_extension ( & extension) else {
90- tracing:: warn!( "Unsupported file type: {}" , path. display( ) ) ;
91- return ;
92- } ;
93- let reader = image:: ImageReader :: with_format ( std:: io:: Cursor :: new ( content) , image_format) ;
94- let Ok ( image) = reader. decode ( ) else {
95- tracing:: error!( "Failed to decode image: {}" , path. display( ) ) ;
96- return ;
97- } ;
98- let width = image. width ( ) ;
99- let height = image. height ( ) ;
100-
101- // TODO: Handle Image formats with more than 8 bits per channel
102- let image_data = image. to_rgba8 ( ) ;
103- let image = Image :: < Color > :: from_image_data ( image_data. as_raw ( ) , width, height) ;
104- let message = PortfolioMessage :: PasteImage {
105- name,
106- image,
107- mouse : None ,
108- parent_and_insert_index : None ,
109- } ;
40+ let message = PortfolioMessage :: ImportFile { path, content } ;
11041 dispatcher. queue_editor_message ( message) ;
11142 }
11243 DesktopWrapperMessage :: PollNodeGraphEvaluation => dispatcher. poll_node_graph_evaluation ( ) ,
0 commit comments