mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 00:56:02 +00:00
SYNC: disable commands when modal is opened
This commit is contained in:
committed by
Diflow
parent
7457328b59
commit
89ddced342
@@ -85,7 +85,7 @@ function formatKeyText(keyText) {
|
|||||||
return keyText.replace('CtrlOrCommand+', 'Ctrl+');
|
return keyText.replace('CtrlOrCommand+', 'Ctrl+');
|
||||||
}
|
}
|
||||||
|
|
||||||
function commandItem(item) {
|
function commandItem(item, isModalOpened = false) {
|
||||||
const id = item.command;
|
const id = item.command;
|
||||||
const command = commands[id];
|
const command = commands[id];
|
||||||
if (item.skipInApp) {
|
if (item.skipInApp) {
|
||||||
@@ -95,7 +95,7 @@ function commandItem(item) {
|
|||||||
id,
|
id,
|
||||||
label: command ? command.menuName || command.toolbarName || command.name : id,
|
label: command ? command.menuName || command.toolbarName || command.name : id,
|
||||||
accelerator: formatKeyText(command ? command.keyText : undefined),
|
accelerator: formatKeyText(command ? command.keyText : undefined),
|
||||||
enabled: command ? command.enabled : false,
|
enabled: command ? command.enabled && !isModalOpened : false,
|
||||||
click() {
|
click() {
|
||||||
if (mainWindow) {
|
if (mainWindow) {
|
||||||
mainWindow.webContents.send('run-command', id);
|
mainWindow.webContents.send('run-command', id);
|
||||||
@@ -107,14 +107,14 @@ function commandItem(item) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildMenu() {
|
function buildMenu(isModalOpened = false) {
|
||||||
let template = _cloneDeepWith(mainMenuDefinition({ editMenu: true, isMac: isMac() }), item => {
|
let template = _cloneDeepWith(mainMenuDefinition({ editMenu: true, isMac: isMac() }), item => {
|
||||||
if (item.divider) {
|
if (item.divider) {
|
||||||
return { type: 'separator' };
|
return { type: 'separator' };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.command) {
|
if (item.command) {
|
||||||
return commandItem(item);
|
return commandItem(item, isModalOpened);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ function buildMenu() {
|
|||||||
{
|
{
|
||||||
label: 'DbGate',
|
label: 'DbGate',
|
||||||
submenu: [
|
submenu: [
|
||||||
commandItem({ command: 'about.show' }),
|
commandItem({ command: 'about.show' }, isModalOpened),
|
||||||
{ role: 'services' },
|
{ role: 'services' },
|
||||||
{ role: 'hide' },
|
{ role: 'hide' },
|
||||||
{ role: 'hideOthers' },
|
{ role: 'hideOthers' },
|
||||||
@@ -145,7 +145,9 @@ function buildMenu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on('update-commands', async (event, arg) => {
|
ipcMain.on('update-commands', async (event, arg) => {
|
||||||
commands = JSON.parse(arg);
|
const parsed = JSON.parse(arg);
|
||||||
|
commands = parsed.commands;
|
||||||
|
const isModalOpened = parsed.isModalOpened;
|
||||||
for (const key of Object.keys(commands)) {
|
for (const key of Object.keys(commands)) {
|
||||||
const menu = mainMenu.getMenuItemById(key);
|
const menu = mainMenu.getMenuItemById(key);
|
||||||
if (!menu) continue;
|
if (!menu) continue;
|
||||||
@@ -153,14 +155,14 @@ ipcMain.on('update-commands', async (event, arg) => {
|
|||||||
|
|
||||||
// rebuild menu
|
// rebuild menu
|
||||||
if (menu.label != command.text || menu.accelerator != command.keyText) {
|
if (menu.label != command.text || menu.accelerator != command.keyText) {
|
||||||
mainMenu = buildMenu();
|
mainMenu = buildMenu(isModalOpened);
|
||||||
|
|
||||||
Menu.setApplicationMenu(mainMenu);
|
Menu.setApplicationMenu(mainMenu);
|
||||||
// mainWindow.setMenu(mainMenu);
|
// mainWindow.setMenu(mainMenu);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.enabled = command.enabled;
|
menu.enabled = command.enabled && !isModalOpened;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ipcMain.on('quit-app', async (event, arg) => {
|
ipcMain.on('quit-app', async (event, arg) => {
|
||||||
@@ -408,7 +410,7 @@ function createWindow() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// mainWindow.webContents.toggleDevTools();
|
mainWindow.webContents.toggleDevTools();
|
||||||
|
|
||||||
mainWindow.loadURL(startUrl);
|
mainWindow.loadURL(startUrl);
|
||||||
if (os.platform() == 'linux') {
|
if (os.platform() == 'linux') {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { safeJsonParse } from 'dbgate-tools';
|
|||||||
import { apiCall } from './utility/api';
|
import { apiCall } from './utility/api';
|
||||||
import { getOpenedTabsStorageName, isAdminPage } from './utility/pageDefs';
|
import { getOpenedTabsStorageName, isAdminPage } from './utility/pageDefs';
|
||||||
import { switchCurrentDatabase } from './utility/common';
|
import { switchCurrentDatabase } from './utility/common';
|
||||||
|
import { tick } from 'svelte';
|
||||||
|
|
||||||
export interface TabDefinition {
|
export interface TabDefinition {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -189,7 +190,6 @@ export const cloudConnectionsStore = writable({});
|
|||||||
|
|
||||||
export const promoWidgetPreview = writable(null);
|
export const promoWidgetPreview = writable(null);
|
||||||
|
|
||||||
|
|
||||||
export const DEFAULT_OBJECT_SEARCH_SETTINGS = {
|
export const DEFAULT_OBJECT_SEARCH_SETTINGS = {
|
||||||
pureName: true,
|
pureName: true,
|
||||||
schemaName: false,
|
schemaName: false,
|
||||||
@@ -310,17 +310,39 @@ openedTabs.subscribe(value => {
|
|||||||
});
|
});
|
||||||
export const getOpenedTabs = () => openedTabsValue;
|
export const getOpenedTabs = () => openedTabsValue;
|
||||||
|
|
||||||
|
let openedModalsValue = [];
|
||||||
|
openedModals.subscribe(value => {
|
||||||
|
openedModalsValue = value;
|
||||||
|
|
||||||
|
tick().then(() => {
|
||||||
|
dispatchUpdateCommands();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
export const getOpenedModals = () => openedModalsValue;
|
||||||
|
|
||||||
let commandsValue = null;
|
let commandsValue = null;
|
||||||
commands.subscribe(value => {
|
commands.subscribe(value => {
|
||||||
commandsValue = value;
|
commandsValue = value;
|
||||||
|
|
||||||
const electron = getElectron();
|
tick().then(() => {
|
||||||
if (electron) {
|
dispatchUpdateCommands();
|
||||||
electron.send('update-commands', JSON.stringify(value));
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
export const getCommands = () => commandsValue;
|
export const getCommands = () => commandsValue;
|
||||||
|
|
||||||
|
function dispatchUpdateCommands() {
|
||||||
|
const electron = getElectron();
|
||||||
|
if (electron) {
|
||||||
|
electron.send(
|
||||||
|
'update-commands',
|
||||||
|
JSON.stringify({
|
||||||
|
isModalOpened: openedModalsValue?.length > 0,
|
||||||
|
commands: commandsValue,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let activeTabValue = null;
|
let activeTabValue = null;
|
||||||
activeTab.subscribe(value => {
|
activeTab.subscribe(value => {
|
||||||
activeTabValue = value;
|
activeTabValue = value;
|
||||||
@@ -418,12 +440,6 @@ selectedDatabaseObjectAppObject.subscribe(value => {
|
|||||||
});
|
});
|
||||||
export const getSelectedDatabaseObjectAppObject = () => selectedDatabaseObjectAppObjectValue;
|
export const getSelectedDatabaseObjectAppObject = () => selectedDatabaseObjectAppObjectValue;
|
||||||
|
|
||||||
let openedModalsValue = [];
|
|
||||||
openedModals.subscribe(value => {
|
|
||||||
openedModalsValue = value;
|
|
||||||
});
|
|
||||||
export const getOpenedModals = () => openedModalsValue;
|
|
||||||
|
|
||||||
let focusedConnectionOrDatabaseValue = null;
|
let focusedConnectionOrDatabaseValue = null;
|
||||||
focusedConnectionOrDatabase.subscribe(value => {
|
focusedConnectionOrDatabase.subscribe(value => {
|
||||||
focusedConnectionOrDatabaseValue = value;
|
focusedConnectionOrDatabaseValue = value;
|
||||||
|
|||||||
Reference in New Issue
Block a user