From 1a4decd96265fc02ae63fd8c32025134e4f12ba7 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 17 Feb 2022 12:15:27 +0100 Subject: [PATCH] save split button --- .../src/buttons/ToolStripSaveButton.svelte | 20 ++++++++++++++ packages/web/src/commands/stdCommands.ts | 13 ++++++--- packages/web/src/tabs/DiagramTab.svelte | 3 ++- packages/web/src/tabs/QueryDesignTab.svelte | 3 ++- packages/web/src/tabs/QueryTab.svelte | 4 +-- packages/web/src/tabs/ShellTab.svelte | 3 ++- packages/web/src/utility/saveTabFile.ts | 27 +++++++++++++++++-- 7 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 packages/web/src/buttons/ToolStripSaveButton.svelte diff --git a/packages/web/src/buttons/ToolStripSaveButton.svelte b/packages/web/src/buttons/ToolStripSaveButton.svelte new file mode 100644 index 00000000..bdbcc672 --- /dev/null +++ b/packages/web/src/buttons/ToolStripSaveButton.svelte @@ -0,0 +1,20 @@ + + + diff --git a/packages/web/src/commands/stdCommands.ts b/packages/web/src/commands/stdCommands.ts index 9ad588f5..c2902ff8 100644 --- a/packages/web/src/commands/stdCommands.ts +++ b/packages/web/src/commands/stdCommands.ts @@ -103,7 +103,7 @@ registerCommand({ category: 'New', icon: 'img shell', name: 'JavaScript Shell', - menuName:' New JavaScript shell', + menuName: ' New JavaScript shell', onClick: () => { openNewTab({ title: 'Shell #', @@ -480,7 +480,7 @@ export function registerFileCommands({ toolbar: true, isRelatedToTab: true, testEnabled: () => getCurrentEditor() != null, - onClick: () => saveTabFile(getCurrentEditor(), false, folder, format, fileExtension), + onClick: () => saveTabFile(getCurrentEditor(), 'save', folder, format, fileExtension), }); registerCommand({ id: idPrefix + '.saveAs', @@ -488,7 +488,14 @@ export function registerFileCommands({ category, name: 'Save As', testEnabled: () => getCurrentEditor() != null, - onClick: () => saveTabFile(getCurrentEditor(), true, folder, format, fileExtension), + onClick: () => saveTabFile(getCurrentEditor(), 'save-as', folder, format, fileExtension), + }); + registerCommand({ + id: idPrefix + '.saveToDisk', + category, + name: 'Save to disk', + testEnabled: () => getCurrentEditor() != null && getElectron() != null, + onClick: () => saveTabFile(getCurrentEditor(), 'save-to-disk', folder, format, fileExtension), }); } diff --git a/packages/web/src/tabs/DiagramTab.svelte b/packages/web/src/tabs/DiagramTab.svelte index c3b0f9b2..f57ee5e4 100644 --- a/packages/web/src/tabs/DiagramTab.svelte +++ b/packages/web/src/tabs/DiagramTab.svelte @@ -26,6 +26,7 @@ import ToolStripContainer from '../buttons/ToolStripContainer.svelte'; import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte'; import invalidateCommands from '../commands/invalidateCommands'; + import ToolStripSaveButton from '../buttons/ToolStripSaveButton.svelte'; export let tabid; export let conid; @@ -102,7 +103,7 @@ - + diff --git a/packages/web/src/tabs/QueryDesignTab.svelte b/packages/web/src/tabs/QueryDesignTab.svelte index 5d9923ca..5a416d80 100644 --- a/packages/web/src/tabs/QueryDesignTab.svelte +++ b/packages/web/src/tabs/QueryDesignTab.svelte @@ -53,6 +53,7 @@ import ToolStripContainer from '../buttons/ToolStripContainer.svelte'; import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte'; import ToolStripExportButton, { createQuickExportHandlerRef } from '../buttons/ToolStripExportButton.svelte'; + import ToolStripSaveButton from '../buttons/ToolStripSaveButton.svelte'; export let tabid; export let conid; @@ -293,7 +294,7 @@ - + diff --git a/packages/web/src/tabs/QueryTab.svelte b/packages/web/src/tabs/QueryTab.svelte index b8f5e4be..43bc5244 100644 --- a/packages/web/src/tabs/QueryTab.svelte +++ b/packages/web/src/tabs/QueryTab.svelte @@ -73,6 +73,7 @@ import ToolStripExportButton, { createQuickExportHandlerRef } from '../buttons/ToolStripExportButton.svelte'; import ToolStripSplitButton from '../buttons/ToolStripSplitButton.svelte'; import ToolStripSplitDropDownButton from '../buttons/ToolStripSplitDropDownButton.svelte'; +import ToolStripSaveButton from '../buttons/ToolStripSaveButton.svelte'; export let tabid; export let conid; @@ -331,9 +332,8 @@ component={ToolStripSplitDropDownButton} menu={[{ command: 'query.execute' }, { command: 'query.executeCurrent' }]} /> - - + {#if resultCount == 1} diff --git a/packages/web/src/tabs/ShellTab.svelte b/packages/web/src/tabs/ShellTab.svelte index 840f4ca8..ad15ad46 100644 --- a/packages/web/src/tabs/ShellTab.svelte +++ b/packages/web/src/tabs/ShellTab.svelte @@ -39,6 +39,7 @@ import { getContext } from 'svelte'; import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte'; import ToolStripContainer from '../buttons/ToolStripContainer.svelte'; +import ToolStripSaveButton from '../buttons/ToolStripSaveButton.svelte'; import invalidateCommands from '../commands/invalidateCommands'; import registerCommand from '../commands/registerCommand'; @@ -235,7 +236,7 @@ import ToolStripContainer from '../buttons/ToolStripContainer.svelte'; - + diff --git a/packages/web/src/utility/saveTabFile.ts b/packages/web/src/utility/saveTabFile.ts index d41cbb00..778807fc 100644 --- a/packages/web/src/utility/saveTabFile.ts +++ b/packages/web/src/utility/saveTabFile.ts @@ -5,12 +5,13 @@ import { changeTab } from './common'; import SaveFileModal from '../modals/SaveFileModal.svelte'; import registerCommand from '../commands/registerCommand'; import { apiCall } from './api'; +import getElectron from './getElectron'; // export function saveTabEnabledStore(editorStore) { // return derived(editorStore, editor => editor != null); // } -export default function saveTabFile(editor, saveAs, folder, format, fileExtension) { +export default async function saveTabFile(editor, saveMode, folder, format, fileExtension) { const tabs = get(openedTabs); const tabid = editor.activator.tabid; const data = editor.getData(); @@ -37,7 +38,29 @@ export default function saveTabFile(editor, saveAs, folder, format, fileExtensio })); }; - if ((savedFile || savedFilePath) && !saveAs) { + if (saveMode == 'save-to-disk') { + const electron = getElectron(); + const file = await electron.showSaveDialog({ + filters: [ + { name: `${fileExtension.toUpperCase()} files`, extensions: [fileExtension] }, + { name: `All files`, extensions: ['*'] }, + ], + defaultPath: savedFilePath || `file.${fileExtension}`, + properties: ['showOverwriteConfirmation'], + }); + if (file) { + await apiCall('files/save-as', { filePath: file, data, format }); + + const path = window.require('path'); + const parsed = path.parse(file); + + onSave(parsed.name, { + savedFile: null, + savedFolder: null, + savedFilePath: file, + }); + } + } else if ((savedFile || savedFilePath) && saveMode == 'save') { handleSave(); } else { showModal(SaveFileModal, {