mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-27 18:08:11 +08:00
Desktop: Add File > Save As… (#3034)
* Make file name and document name identical * Add save as action * Fix test errors * Add missing save as action * Desktop fix drop file open document file message * Address review comments * Replace file save suffix with file extension * Add comment specifying that the upload function takes a html input accept string * Fix remove file extension in web * Use let * Don't show save as menu entry in web * Don't add SaveDocumentAs in web * Remove file extension on all open document file calls --------- Co-authored-by: Dennis Kobert <dennis@kobert.dev>
This commit is contained in:
@@ -62,9 +62,16 @@ export function createPortfolioState(editor: Editor) {
|
||||
}
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(TriggerOpenDocument, async () => {
|
||||
const extension = editor.handle.fileSaveSuffix();
|
||||
const data = await upload(extension, "text");
|
||||
editor.handle.openDocumentFile(data.filename, data.content);
|
||||
const suffix = "." + editor.handle.fileExtension();
|
||||
const data = await upload(suffix, "text");
|
||||
|
||||
// Use filename as document name, removing the extension if it exists
|
||||
let documentName = data.filename;
|
||||
if (documentName.endsWith(suffix)) {
|
||||
documentName = documentName.slice(0, -suffix.length);
|
||||
}
|
||||
|
||||
editor.handle.openDocumentFile(documentName, data.content);
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(TriggerImport, async () => {
|
||||
const data = await upload("image/*", "both");
|
||||
@@ -76,8 +83,10 @@ export function createPortfolioState(editor: Editor) {
|
||||
}
|
||||
|
||||
// In case the user accidentally uploads a Graphite file, open it instead of failing to import it
|
||||
if (data.filename.endsWith(".graphite")) {
|
||||
editor.handle.openDocumentFile(data.filename, data.content.text);
|
||||
const graphiteFileSuffix = "." + editor.handle.fileExtension();
|
||||
if (data.filename.endsWith(graphiteFileSuffix)) {
|
||||
const documentName = data.filename.slice(0, -graphiteFileSuffix.length);
|
||||
editor.handle.openDocumentFile(documentName, data.content.text);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user