mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 02:48:12 +08:00
Desktop: Open file dialogs in the folder containing the document (#3934)
Desktop: Open save file dialogs in document parent folder
This commit is contained in:
@@ -89,10 +89,12 @@ pub enum FrontendMessage {
|
||||
document_id: DocumentId,
|
||||
name: String,
|
||||
path: Option<PathBuf>,
|
||||
folder: Option<PathBuf>,
|
||||
content: serde_bytes::ByteBuf,
|
||||
},
|
||||
TriggerSaveFile {
|
||||
name: String,
|
||||
folder: Option<PathBuf>,
|
||||
content: serde_bytes::ByteBuf,
|
||||
},
|
||||
TriggerExportImage {
|
||||
|
||||
@@ -835,26 +835,28 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
|
||||
});
|
||||
}
|
||||
DocumentMessage::SaveDocument | DocumentMessage::SaveDocumentAs => {
|
||||
if let DocumentMessage::SaveDocumentAs = message {
|
||||
self.path = None;
|
||||
responses.add(PortfolioMessage::AutoSaveActiveDocument);
|
||||
|
||||
let path = if let DocumentMessage::SaveDocumentAs = message { None } else { self.path.clone() };
|
||||
if path.is_some() {
|
||||
responses.add(DocumentMessage::MarkAsSaved);
|
||||
}
|
||||
|
||||
self.set_save_state(true);
|
||||
responses.add(PortfolioMessage::AutoSaveActiveDocument);
|
||||
// Update the save status of the just saved document
|
||||
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
|
||||
let folder = self.path.as_ref().and_then(|path| path.parent()).map(|parent| parent.to_path_buf());
|
||||
|
||||
responses.add(FrontendMessage::TriggerSaveDocument {
|
||||
document_id,
|
||||
name: format!("{}.{}", self.name.clone(), FILE_EXTENSION),
|
||||
path: self.path.clone(),
|
||||
path,
|
||||
folder,
|
||||
content: self.serialize_document().into_bytes().into(),
|
||||
})
|
||||
});
|
||||
}
|
||||
DocumentMessage::SavedDocument { path } => {
|
||||
self.path = path;
|
||||
|
||||
responses.add(PortfolioMessage::AutoSaveActiveDocument);
|
||||
responses.add(DocumentMessage::MarkAsSaved);
|
||||
|
||||
// Update the name to match the file stem
|
||||
let document_name_from_path = self.path.as_ref().and_then(|path| {
|
||||
|
||||
@@ -485,9 +485,10 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
|
||||
let name = path.file_stem().map(|n| n.to_string_lossy().to_string());
|
||||
match Self::read_file(&path, content) {
|
||||
FileContent::Document(content) => {
|
||||
let document_path = if path.is_absolute() { Some(path) } else { None };
|
||||
responses.add(PortfolioMessage::OpenDocumentFile {
|
||||
document_name: name,
|
||||
document_path: Some(path),
|
||||
document_path,
|
||||
document_serialized_content: content,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ impl NodeGraphExecutor {
|
||||
|
||||
if let Some(export_config) = execution_context.export_config {
|
||||
// Special handling for exporting the artwork
|
||||
self.process_export(node_graph_output, export_config, responses)?;
|
||||
self.process_export(node_graph_output, export_config, document, responses)?;
|
||||
} else {
|
||||
self.process_node_graph_output(node_graph_output, responses)?;
|
||||
}
|
||||
@@ -435,7 +435,7 @@ impl NodeGraphExecutor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn process_export(&self, node_graph_output: TaggedValue, export_config: ExportConfig, responses: &mut VecDeque<Message>) -> Result<(), String> {
|
||||
fn process_export(&self, node_graph_output: TaggedValue, export_config: ExportConfig, document: &DocumentMessageHandler, responses: &mut VecDeque<Message>) -> Result<(), String> {
|
||||
let ExportConfig {
|
||||
file_type,
|
||||
name,
|
||||
@@ -455,6 +455,7 @@ impl NodeGraphExecutor {
|
||||
_ => name,
|
||||
};
|
||||
let name = format!("{base_name}.{file_extension}");
|
||||
let folder = document.path.as_ref().and_then(|path| path.parent()).map(|parent| parent.to_path_buf());
|
||||
|
||||
match node_graph_output {
|
||||
TaggedValue::RenderOutput(RenderOutput {
|
||||
@@ -464,6 +465,7 @@ impl NodeGraphExecutor {
|
||||
if file_type == FileType::Svg {
|
||||
responses.add(FrontendMessage::TriggerSaveFile {
|
||||
name,
|
||||
folder,
|
||||
content: svg.into_bytes().into(),
|
||||
});
|
||||
} else {
|
||||
@@ -506,7 +508,11 @@ impl NodeGraphExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
responses.add(FrontendMessage::TriggerSaveFile { name, content: encoded.into() });
|
||||
responses.add(FrontendMessage::TriggerSaveFile {
|
||||
name,
|
||||
folder,
|
||||
content: encoded.into(),
|
||||
});
|
||||
}
|
||||
_ => {
|
||||
return Err(format!("Incorrect render type for exporting to an SVG ({file_type:?}, {node_graph_output})"));
|
||||
|
||||
Reference in New Issue
Block a user