Skip to content

Commit d11b7fe

Browse files
committed
Use document name for saved and exported files
We pass through the document name in the export and save messages. Additionally, we check if the appropriate file suffixes (.graphite and .svg) need to be added.
1 parent 3d7d502 commit d11b7fe

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

editor/src/document/document_file.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,15 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
293293
"\n",
294294
self.document.render_root()
295295
),
296+
name: self.name.clone(),
296297
}
297298
.into(),
298299
)
299300
}
300301
SaveDocument => responses.push_back(
301302
FrontendMessage::SaveDocument {
302303
document: self.document.serialize_document(),
304+
name: self.name.clone(),
303305
}
304306
.into(),
305307
),

editor/src/frontend/frontend_message_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub enum FrontendMessage {
1818
DisplayConfirmationToCloseAllDocuments,
1919
UpdateCanvas { document: String },
2020
UpdateLayer { path: Vec<LayerId>, data: LayerPanelEntry },
21-
ExportDocument { document: String },
22-
SaveDocument { document: String },
21+
ExportDocument { document: String, name: String },
22+
SaveDocument { document: String, name: String },
2323
EnableTextInput,
2424
DisableTextInput,
2525
UpdateWorkingColors { primary: Color, secondary: Color },

frontend/src/components/panels/Document.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ import OptionalInput from "@/components/widgets/inputs/OptionalInput.vue";
232232
import ToolOptions from "@/components/widgets/options/ToolOptions.vue";
233233
import { SectionsOfMenuListEntries } from "@/components/widgets/floating-menus/MenuList.vue";
234234
235+
const FILE_SUFFIX = ".graphite";
235236
const documentModeEntries: SectionsOfMenuListEntries = [
236237
[
237238
{ label: "Design Mode", icon: "ViewportDesignMode" },
@@ -332,11 +333,22 @@ export default defineComponent({
332333
});
333334
registerResponseHandler(ResponseType.ExportDocument, (responseData: Response) => {
334335
const updateData = responseData as ExportDocument;
335-
if (updateData) this.download("canvas.svg", updateData.document);
336+
if (!updateData) return;
337+
338+
let { name } = updateData;
339+
const target_suffix = ".svg";
340+
if (name.endsWith(FILE_SUFFIX)) name = name.replace(FILE_SUFFIX, target_suffix);
341+
if (!name.endsWith(target_suffix)) name = `${name}${target_suffix}`;
342+
343+
this.download(name, updateData.document);
336344
});
337345
registerResponseHandler(ResponseType.SaveDocument, (responseData: Response) => {
338346
const saveData = responseData as SaveDocument;
339-
if (saveData) this.download("canvas.graphite", saveData.document);
347+
if (!saveData) return;
348+
349+
let { name } = saveData;
350+
if (!name.endsWith(FILE_SUFFIX)) name = `${name}${FILE_SUFFIX}`;
351+
this.download(name, saveData.document);
340352
});
341353
registerResponseHandler(ResponseType.SetActiveTool, (responseData: Response) => {
342354
const toolData = responseData as SetActiveTool;

frontend/src/utilities/response-handler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,23 @@ function newUpdateCanvas(input: any): UpdateCanvas {
169169

170170
export interface ExportDocument {
171171
document: string;
172+
name: string;
172173
}
173-
function newExportDocument(input: any): UpdateCanvas {
174+
function newExportDocument(input: any): ExportDocument {
174175
return {
175176
document: input.document,
177+
name: input.name,
176178
};
177179
}
178180

179181
export interface SaveDocument {
180182
document: string;
183+
name: string;
181184
}
182185
function newSaveDocument(input: any): SaveDocument {
183186
return {
184187
document: input.document,
188+
name: input.name,
185189
};
186190
}
187191

0 commit comments

Comments
 (0)