#603 save and saveas change done

This commit is contained in:
agriyadev5
2021-08-23 19:50:27 +05:30
parent e79891c614
commit 9770eb56eb
5 changed files with 25 additions and 9 deletions

View File

@@ -18,6 +18,7 @@
import { fileOpen, fileSave } from 'browser-fs-access'; import { fileOpen, fileSave } from 'browser-fs-access';
const name = "opensave"; const name = "opensave";
let handle = null;
const loadExtensionTranslation = async function (svgEditor) { const loadExtensionTranslation = async function (svgEditor) {
let translationModule; let translationModule;
@@ -108,7 +109,7 @@ export default {
* *
* @returns {void} * @returns {void}
*/ */
const clickSave = async function () { const clickSave = async function (type, _) {
const $editorDialog = $id("se-svg-editor-dialog"); const $editorDialog = $id("se-svg-editor-dialog");
const editingsource = $editorDialog.getAttribute("dialog") === "open"; const editingsource = $editorDialog.getAttribute("dialog") === "open";
if (editingsource) { if (editingsource) {
@@ -135,10 +136,18 @@ export default {
const b64Data = svgCanvas.encode64(svg); const b64Data = svgCanvas.encode64(svg);
const blob = b64toBlob(b64Data, 'image/svg+xml'); const blob = b64toBlob(b64Data, 'image/svg+xml');
try { try {
await fileSave(blob, { if(type === "save" && handle !== null) {
fileName: 'icon.svg', const throwIfExistingHandleNotGood = false;
extensions: [ '.svg' ] handle = await fileSave(blob, {
}); fileName: 'icon.svg',
extensions: [ '.svg' ]
}, handle, throwIfExistingHandleNotGood);
} else {
handle = await fileSave(blob, {
fileName: 'icon.svg',
extensions: [ '.svg' ]
});
}
} catch (err) { } catch (err) {
if (err.name !== 'AbortError') { if (err.name !== 'AbortError') {
return console.error(err); return console.error(err);
@@ -159,10 +168,13 @@ export default {
svgCanvas.insertChildAtIndex($id('main_button'), openButtonTemplate, 1); svgCanvas.insertChildAtIndex($id('main_button'), openButtonTemplate, 1);
const saveButtonTemplate = `<se-menu-item id="tool_save" label="${svgEditor.i18next.t('tools.save_doc')}" shortcut="S" src="${imgPath}/saveImg.svg"></se-menu-item>`; const saveButtonTemplate = `<se-menu-item id="tool_save" label="${svgEditor.i18next.t('tools.save_doc')}" shortcut="S" src="${imgPath}/saveImg.svg"></se-menu-item>`;
svgCanvas.insertChildAtIndex($id('main_button'), saveButtonTemplate, 2); svgCanvas.insertChildAtIndex($id('main_button'), saveButtonTemplate, 2);
const saveAsButtonTemplate = `<se-menu-item id="tool_save_as" label="${svgEditor.i18next.t('tools.save_as_doc')}" src="${imgPath}/saveImg.svg"></se-menu-item>`;
svgCanvas.insertChildAtIndex($id('main_button'), saveAsButtonTemplate, 3);
// handler // handler
$id("tool_clear").addEventListener("click", clickClear.bind(this)); $id("tool_clear").addEventListener("click", clickClear.bind(this));
$id("tool_open").addEventListener("click", clickOpen.bind(this)); $id("tool_open").addEventListener("click", clickOpen.bind(this));
$id("tool_save").addEventListener("click", clickSave.bind(this)); $id("tool_save").addEventListener("click", clickSave.bind(this, "save"));
$id("tool_save_as").addEventListener("click", clickSave.bind(this, "saveas"));
} }
}; };
} }

View File

@@ -3,6 +3,7 @@ export default {
tools: { tools: {
new_doc: 'New Image', new_doc: 'New Image',
open_doc: 'Open SVG', open_doc: 'Open SVG',
save_doc: 'Save Image' save_doc: 'Save Image',
save_as_doc: 'Save As Image'
} }
}; };

View File

@@ -3,6 +3,7 @@ export default {
tools: { tools: {
new_doc: 'Nouvelle image', new_doc: 'Nouvelle image',
open_doc: 'Ouvrir le SVG', open_doc: 'Ouvrir le SVG',
save_doc: 'Enregistrer l\'image' save_doc: 'Enregistrer l\'image',
save_as_doc: 'Enregistrer en tant qu\'image'
} }
}; };

View File

@@ -3,6 +3,7 @@ export default {
tools: { tools: {
new_doc: '新图片', new_doc: '新图片',
open_doc: '打开 SVG', open_doc: '打开 SVG',
save_doc: '保存图像' save_doc: '保存图像',
save_as_doc: '另存为图像'
} }
}; };

View File

@@ -112,6 +112,7 @@ export default {
open_doc: 'Open SVG', open_doc: 'Open SVG',
export_img: 'Export', export_img: 'Export',
save_doc: 'Save Image', save_doc: 'Save Image',
save_as_doc: 'Save As Image',
import_doc: 'Import Image', import_doc: 'Import Image',
align_to_page: 'Align Element to Page', align_to_page: 'Align Element to Page',
align_bottom: 'Align Bottom', align_bottom: 'Align Bottom',