mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 00:56:02 +00:00
SYNC: disable commands on special pages
This commit is contained in:
committed by
Diflow
parent
e855365cbb
commit
dc452cdadf
@@ -85,7 +85,7 @@ function formatKeyText(keyText) {
|
|||||||
return keyText.replace('CtrlOrCommand+', 'Ctrl+');
|
return keyText.replace('CtrlOrCommand+', 'Ctrl+');
|
||||||
}
|
}
|
||||||
|
|
||||||
function commandItem(item, isModalOpened = false) {
|
function commandItem(item, disableAll = 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, isModalOpened = false) {
|
|||||||
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 && !isModalOpened : false,
|
enabled: command ? command.enabled && !disableAll : 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, isModalOpened = false) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildMenu(isModalOpened = false) {
|
function buildMenu(disableAll = 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, isModalOpened);
|
return commandItem(item, disableAll);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ function buildMenu(isModalOpened = false) {
|
|||||||
{
|
{
|
||||||
label: 'DbGate',
|
label: 'DbGate',
|
||||||
submenu: [
|
submenu: [
|
||||||
commandItem({ command: 'about.show' }, isModalOpened),
|
commandItem({ command: 'about.show' }, disableAll),
|
||||||
{ role: 'services' },
|
{ role: 'services' },
|
||||||
{ role: 'hide' },
|
{ role: 'hide' },
|
||||||
{ role: 'hideOthers' },
|
{ role: 'hideOthers' },
|
||||||
@@ -148,6 +148,7 @@ ipcMain.on('update-commands', async (event, arg) => {
|
|||||||
const parsed = JSON.parse(arg);
|
const parsed = JSON.parse(arg);
|
||||||
commands = parsed.commands;
|
commands = parsed.commands;
|
||||||
const isModalOpened = parsed.isModalOpened;
|
const isModalOpened = parsed.isModalOpened;
|
||||||
|
const dbgatePage = parsed.dbgatePage;
|
||||||
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;
|
||||||
@@ -155,14 +156,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(isModalOpened);
|
mainMenu = buildMenu(isModalOpened || !!dbgatePage);
|
||||||
|
|
||||||
Menu.setApplicationMenu(mainMenu);
|
Menu.setApplicationMenu(mainMenu);
|
||||||
// mainWindow.setMenu(mainMenu);
|
// mainWindow.setMenu(mainMenu);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.enabled = command.enabled && !isModalOpened;
|
menu.enabled = command.enabled && !isModalOpened && !dbgatePage;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ipcMain.on('quit-app', async (event, arg) => {
|
ipcMain.on('quit-app', async (event, arg) => {
|
||||||
|
|||||||
@@ -346,6 +346,7 @@ function dispatchUpdateCommands() {
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
isModalOpened: openedModalsValue?.length > 0,
|
isModalOpened: openedModalsValue?.length > 0,
|
||||||
commands: commandsValue,
|
commands: commandsValue,
|
||||||
|
dbgatePage: window['dbgate_page'],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user