mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 14:26:00 +00:00
close tab with confirmation on double ctrl+W
This commit is contained in:
@@ -2,15 +2,10 @@
|
|||||||
import { commandsCustomized, visibleCommandPalette } from '../stores';
|
import { commandsCustomized, visibleCommandPalette } from '../stores';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import { runGroupCommand } from './runCommand';
|
import { runGroupCommand } from './runCommand';
|
||||||
import { isMac, resolveKeyText } from '../utility/common';
|
import { getKeyTextFromEvent, isMac, resolveKeyText } from '../utility/common';
|
||||||
|
|
||||||
export function handleCommandKeyDown(e) {
|
export function handleCommandKeyDown(e) {
|
||||||
let keyText = '';
|
const keyText = getKeyTextFromEvent(e);
|
||||||
if (e.ctrlKey) keyText += 'Ctrl+';
|
|
||||||
if (e.metaKey) keyText += 'Command+';
|
|
||||||
if (e.shiftKey) keyText += 'Shift+';
|
|
||||||
if (e.altKey) keyText += 'Alt+';
|
|
||||||
keyText += e.key;
|
|
||||||
|
|
||||||
// console.log('keyText', keyText);
|
// console.log('keyText', keyText);
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,28 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { get } from 'svelte/store';
|
||||||
import FormStyledButton from '../buttons/FormStyledButton.svelte';
|
import FormStyledButton from '../buttons/FormStyledButton.svelte';
|
||||||
|
|
||||||
import FormProvider from '../forms/FormProvider.svelte';
|
import FormProvider from '../forms/FormProvider.svelte';
|
||||||
import FormSubmit from '../forms/FormSubmit.svelte';
|
import FormSubmit from '../forms/FormSubmit.svelte';
|
||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
|
import { getKeyTextFromEvent, resolveKeyText } from '../utility/common';
|
||||||
import ModalBase from './ModalBase.svelte';
|
import ModalBase from './ModalBase.svelte';
|
||||||
import { closeCurrentModal } from './modalTools';
|
import { closeCurrentModal } from './modalTools';
|
||||||
|
import { commandsCustomized } from '../stores';
|
||||||
|
|
||||||
export let tabs;
|
export let tabs;
|
||||||
export let onConfirm;
|
export let onConfirm;
|
||||||
export let onCancel;
|
export let onCancel;
|
||||||
|
|
||||||
|
function handleKeyDown(e) {
|
||||||
|
const commandsValue = get(commandsCustomized);
|
||||||
|
|
||||||
|
const command = commandsValue['tabs.closeTab'];
|
||||||
|
if (resolveKeyText(command.keyText).toLowerCase() == getKeyTextFromEvent(e).toLowerCase()) {
|
||||||
|
closeCurrentModal();
|
||||||
|
onConfirm();
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FormProvider>
|
<FormProvider>
|
||||||
@@ -45,3 +58,5 @@
|
|||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
</ModalBase>
|
</ModalBase>
|
||||||
</FormProvider>
|
</FormProvider>
|
||||||
|
|
||||||
|
<svelte:window on:keydown={handleKeyDown} />
|
||||||
|
|||||||
@@ -261,7 +261,7 @@
|
|||||||
id: 'tabs.closeTab',
|
id: 'tabs.closeTab',
|
||||||
category: 'Tabs',
|
category: 'Tabs',
|
||||||
name: _t('command.tabs.closeTab', { defaultMessage: 'Close tab' }),
|
name: _t('command.tabs.closeTab', { defaultMessage: 'Close tab' }),
|
||||||
keyText: isElectronAvailable() ? 'CtrlOrCommand+W' : 'CtrlOrCommand+Shift+W',
|
keyText: isElectronAvailable() ? 'CtrlOrCommand+W' : 'Alt+W',
|
||||||
testEnabled: () => {
|
testEnabled: () => {
|
||||||
const hasAnyOtherTab = getOpenedTabs().filter(x => !x.closedTime).length >= 1;
|
const hasAnyOtherTab = getOpenedTabs().filter(x => !x.closedTime).length >= 1;
|
||||||
const hasAnyModalOpen = getOpenedModals().length > 0;
|
const hasAnyModalOpen = getOpenedModals().length > 0;
|
||||||
|
|||||||
@@ -134,3 +134,13 @@ export async function switchCurrentDatabase(data) {
|
|||||||
currentDatabase.set(data);
|
currentDatabase.set(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getKeyTextFromEvent(e) {
|
||||||
|
let keyText = '';
|
||||||
|
if (e.ctrlKey) keyText += 'Ctrl+';
|
||||||
|
if (e.metaKey) keyText += 'Command+';
|
||||||
|
if (e.shiftKey) keyText += 'Shift+';
|
||||||
|
if (e.altKey) keyText += 'Alt+';
|
||||||
|
keyText += e.key;
|
||||||
|
return keyText;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user