mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed issues in native menus. #5503
1. Lock layout selection from native menus not reflecting in preferences dialogue. 2. Sort sub menus with labels and priority in the toolbar and context menus
This commit is contained in:
parent
adfef8e2bb
commit
c752183199
@ -296,9 +296,10 @@ function launchPgAdminWindow() {
|
|||||||
if (pgadminWindow?.window?.pgAdmin?.Browser?.Events && pgadminWindow?.window?.pgAdmin?.Browser?.MainMenus?.length > 0) {
|
if (pgadminWindow?.window?.pgAdmin?.Browser?.Events && pgadminWindow?.window?.pgAdmin?.Browser?.MainMenus?.length > 0) {
|
||||||
pgadminWindow.window.pgAdmin.Browser.Events.on('pgadmin:nw-enable-disable-menu-items', enableDisableMenuItem);
|
pgadminWindow.window.pgAdmin.Browser.Events.on('pgadmin:nw-enable-disable-menu-items', enableDisableMenuItem);
|
||||||
pgadminWindow.window.pgAdmin.Browser.Events.on('pgadmin:nw-refresh-menu-item', refreshMenuItems);
|
pgadminWindow.window.pgAdmin.Browser.Events.on('pgadmin:nw-refresh-menu-item', refreshMenuItems);
|
||||||
|
pgadminWindow.window.pgAdmin.Browser.Events.on('pgadmin:nw-update-checked-menu-item', updateCheckedMenuItem);
|
||||||
// Add Main Menus to native menu.
|
// Add Main Menus to native menu.
|
||||||
pgadminWindow.window.pgAdmin.Browser.MainMenus.forEach((menu)=> {
|
pgadminWindow.window.pgAdmin.Browser.MainMenus.forEach((menu)=> {
|
||||||
addMenu(pgadminWindow.window.pgAdmin.Browser, menu)
|
addMenu(menu)
|
||||||
})
|
})
|
||||||
clearInterval(addMenuInterval);
|
clearInterval(addMenuInterval);
|
||||||
}
|
}
|
||||||
@ -380,11 +381,11 @@ splashWindow.on('close', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function addCommonMenus(pgBrowser, menu) {
|
function addCommonMenus(menu) {
|
||||||
let _menu = new gui.Menu();
|
let _menu = new gui.Menu();
|
||||||
|
|
||||||
menu.menuItems.forEach((menuItem) => {
|
menu.menuItems.forEach((menuItem) => {
|
||||||
var submenu = getSubMenu(pgBrowser, menuItem);
|
var submenu = getSubMenu(menuItem);
|
||||||
|
|
||||||
let _menuItem = new gui.MenuItem({
|
let _menuItem = new gui.MenuItem({
|
||||||
label: menuItem.label,
|
label: menuItem.label,
|
||||||
@ -427,7 +428,7 @@ function addCommonMenus(pgBrowser, menu) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSubMenu(pgBrowser, menuItem) {
|
function getSubMenu(menuItem) {
|
||||||
let submenu = new gui.Menu();
|
let submenu = new gui.Menu();
|
||||||
if (menuItem.menu_items) {
|
if (menuItem.menu_items) {
|
||||||
menuItem.menu_items.forEach((item) => {
|
menuItem.menu_items.forEach((item) => {
|
||||||
@ -460,12 +461,12 @@ function getSubMenu(pgBrowser, menuItem) {
|
|||||||
return submenu;
|
return submenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addMacMenu(pgBrowser, menu) {
|
function addMacMenu(menu) {
|
||||||
if (menu.name == 'file' && platform() === 'darwin') {
|
if (menu.name == 'file' && platform() === 'darwin') {
|
||||||
var rootMenu = nativeMenu.items[0].submenu;
|
var rootMenu = nativeMenu.items[0].submenu;
|
||||||
let indx = 0;
|
let indx = 0;
|
||||||
menu.menuItems.forEach((menuItem) => {
|
menu.menuItems.forEach((menuItem) => {
|
||||||
let submenu = getSubMenu(pgBrowser, menuItem);
|
let submenu = getSubMenu(menuItem);
|
||||||
|
|
||||||
rootMenu.insert(
|
rootMenu.insert(
|
||||||
new gui.MenuItem({
|
new gui.MenuItem({
|
||||||
@ -489,21 +490,21 @@ function addMacMenu(pgBrowser, menu) {
|
|||||||
|
|
||||||
pgAdminMainScreen.menu = nativeMenu;
|
pgAdminMainScreen.menu = nativeMenu;
|
||||||
} else {
|
} else {
|
||||||
addCommonMenus(pgBrowser, menu)
|
addCommonMenus(menu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addOtherOsMenu(pgBrowser, menu) {
|
function addOtherOsMenu(menu) {
|
||||||
addCommonMenus(pgBrowser, menu)
|
addCommonMenus(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function addMenu(pgBrowser, menu) {
|
function addMenu(menu) {
|
||||||
pgAdminMainScreen.isCustomMenusAdded = true;
|
pgAdminMainScreen.isCustomMenusAdded = true;
|
||||||
if (platform() === 'darwin') {
|
if (platform() === 'darwin') {
|
||||||
addMacMenu(pgBrowser, menu);
|
addMacMenu(menu);
|
||||||
} else {
|
} else {
|
||||||
addOtherOsMenu(pgBrowser, menu);
|
addOtherOsMenu(menu);
|
||||||
}
|
}
|
||||||
addMenuCompleted = true;
|
addMenuCompleted = true;
|
||||||
}
|
}
|
||||||
@ -523,6 +524,25 @@ function enableDisableMenuItem(menu, menuItem) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateCheckedMenuItem(menuItem) {
|
||||||
|
// check/ uncheck specific menu item
|
||||||
|
pgAdminMainScreen.menu.items.forEach(el => {
|
||||||
|
el.submenu.items.forEach((sub) => {
|
||||||
|
if(sub.label == menuItem.parentMenu.label) {
|
||||||
|
sub.submenu.items.forEach((sm)=> {
|
||||||
|
if (sm.label == menuItem.label && sm.type == 'checkbox') {
|
||||||
|
sm.checked = menuItem.checked
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
if (sub.label == menuItem.label && type == 'checkbox') {
|
||||||
|
sub.checked = menuItem.checked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function refreshMenuItems(menu) {
|
function refreshMenuItems(menu) {
|
||||||
// Add menu item/option in specific menu.
|
// Add menu item/option in specific menu.
|
||||||
pgAdminMainScreen.menu.items.forEach(el => {
|
pgAdminMainScreen.menu.items.forEach(el => {
|
||||||
|
@ -398,6 +398,9 @@ define('pgadmin.browser', [
|
|||||||
let is_all_option_dis = true;
|
let is_all_option_dis = true;
|
||||||
category[c].forEach((c)=> {
|
category[c].forEach((c)=> {
|
||||||
c.is_disabled = c.disabled(d, item);
|
c.is_disabled = c.disabled(d, item);
|
||||||
|
|
||||||
|
c.setDisabled( c.is_disabled);
|
||||||
|
|
||||||
if(is_all_option_dis)
|
if(is_all_option_dis)
|
||||||
is_all_option_dis = c.is_disabled;
|
is_all_option_dis = c.is_disabled;
|
||||||
});
|
});
|
||||||
@ -478,8 +481,8 @@ define('pgadmin.browser', [
|
|||||||
let {name: browser} = getBrowser();
|
let {name: browser} = getBrowser();
|
||||||
if(browser == 'Nwjs') {
|
if(browser == 'Nwjs') {
|
||||||
pgBrowser.MainMenus.forEach((menu) => {
|
pgBrowser.MainMenus.forEach((menu) => {
|
||||||
menu.menuItems.forEach((_item) => {
|
menu.menuItems.forEach((item) => {
|
||||||
_item.setDisabled(_item.disabled(d, item));
|
item.setDisabled(item.disabled(d, item));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}else {
|
}else {
|
||||||
|
@ -79,6 +79,8 @@ export class MainMenuItemFactory {
|
|||||||
}
|
}
|
||||||
}}, (menu, item)=> {
|
}}, (menu, item)=> {
|
||||||
pgAdmin.Browser.Events.trigger('pgadmin:nw-enable-disable-menu-items', menu, item);
|
pgAdmin.Browser.Events.trigger('pgadmin:nw-enable-disable-menu-items', menu, item);
|
||||||
|
}, (item) => {
|
||||||
|
pgAdmin.Browser.Events.trigger('pgadmin:nw-update-checked-menu-item', item);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,16 +31,7 @@ export default class Menu {
|
|||||||
this.menuItems.splice(index, 0, menuItem);
|
this.menuItems.splice(index, 0, menuItem);
|
||||||
} else {
|
} else {
|
||||||
this.menuItems.push(menuItem);
|
this.menuItems.push(menuItem);
|
||||||
|
Menu.sortMenus(this.menuItems);
|
||||||
// Sort by alphanumeric ordered first
|
|
||||||
this.menuItems.sort(function (a, b) {
|
|
||||||
return a.label.localeCompare(b.label);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Sort by priority
|
|
||||||
this.menuItems.sort(function (a, b) {
|
|
||||||
return a.priority - b.priority;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(gettext('Invalid MenuItem instance'));
|
throw new Error(gettext('Invalid MenuItem instance'));
|
||||||
@ -54,6 +45,12 @@ export default class Menu {
|
|||||||
if (item instanceof MenuItem) {
|
if (item instanceof MenuItem) {
|
||||||
item.parentMenu = this;
|
item.parentMenu = this;
|
||||||
this.menuItems.push(item);
|
this.menuItems.push(item);
|
||||||
|
if(item?.menu_items && item.menu_items.length > 0) {
|
||||||
|
item.menu_items.forEach((i)=> {
|
||||||
|
i.parentMenu = item;
|
||||||
|
});
|
||||||
|
Menu.sortMenus(item.menu_items);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let subItems = Object.values(item);
|
let subItems = Object.values(item);
|
||||||
subItems.forEach((subItem)=> {
|
subItems.forEach((subItem)=> {
|
||||||
@ -81,16 +78,25 @@ export default class Menu {
|
|||||||
|
|
||||||
setMenuItems(menuItems) {
|
setMenuItems(menuItems) {
|
||||||
this.menuItems = menuItems;
|
this.menuItems = menuItems;
|
||||||
|
Menu.sortMenus(this.menuItems);
|
||||||
|
|
||||||
|
this.menuItems.forEach((item)=> {
|
||||||
|
if(item?.menu_items?.length > 0) {
|
||||||
|
Menu.sortMenus(item.menu_items);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static sortMenus(menuItems) {
|
||||||
// Sort by alphanumeric ordered first
|
// Sort by alphanumeric ordered first
|
||||||
this.menuItems.sort(function (a, b) {
|
menuItems.sort(function (a, b) {
|
||||||
return a.label.localeCompare(b.label);
|
return a.label.localeCompare(b.label);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sort by priority
|
// Sort by priority
|
||||||
this.menuItems.sort(function (a, b) {
|
menuItems.sort(function (a, b) {
|
||||||
return a.priority - b.priority;
|
return a.priority - b.priority;
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getMenuItems() {
|
getMenuItems() {
|
||||||
@ -98,15 +104,7 @@ export default class Menu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static getContextMenus(menuList, item, node) {
|
static getContextMenus(menuList, item, node) {
|
||||||
// Sort by alphanumeric ordered first
|
Menu.sortMenus(menuList);
|
||||||
menuList.sort(function (a, b) {
|
|
||||||
return a.label.localeCompare(b.label);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Sort by priority
|
|
||||||
menuList.sort(function (a, b) {
|
|
||||||
return a.priority - b.priority;
|
|
||||||
});
|
|
||||||
|
|
||||||
let ctxMenus = {};
|
let ctxMenus = {};
|
||||||
let ctxIndex = 1;
|
let ctxIndex = 1;
|
||||||
@ -115,6 +113,7 @@ export default class Menu {
|
|||||||
let sub_ctx_item = {};
|
let sub_ctx_item = {};
|
||||||
ctx.is_disabled = ctx.disabled(node, item);
|
ctx.is_disabled = ctx.disabled(node, item);
|
||||||
if ('menu_items' in ctx && ctx.menu_items) {
|
if ('menu_items' in ctx && ctx.menu_items) {
|
||||||
|
Menu.sortMenus(ctx.menu_items);
|
||||||
ctx.menu_items.forEach((c) => {
|
ctx.menu_items.forEach((c) => {
|
||||||
c.is_disabled = c.disabled(node, item);
|
c.is_disabled = c.disabled(node, item);
|
||||||
if (!c.is_disabled) {
|
if (!c.is_disabled) {
|
||||||
@ -138,7 +137,7 @@ export default class Menu {
|
|||||||
|
|
||||||
|
|
||||||
export class MenuItem {
|
export class MenuItem {
|
||||||
constructor(options, onDisableChange) {
|
constructor(options, onDisableChange, onChangeChacked) {
|
||||||
let menu_opts = [
|
let menu_opts = [
|
||||||
'name', 'label', 'priority', 'module', 'callback', 'data', 'enable',
|
'name', 'label', 'priority', 'module', 'callback', 'data', 'enable',
|
||||||
'category', 'target', 'url', 'node',
|
'category', 'target', 'url', 'node',
|
||||||
@ -159,12 +158,18 @@ export class MenuItem {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
this.onDisableChange = onDisableChange;
|
this.onDisableChange = onDisableChange;
|
||||||
|
this.changeChecked = onChangeChacked;
|
||||||
}
|
}
|
||||||
|
|
||||||
static create(options) {
|
static create(options) {
|
||||||
return MenuItem(options);
|
return MenuItem(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
change_checked(isChecked) {
|
||||||
|
this.checked = isChecked;
|
||||||
|
this.changeChecked?.(this);
|
||||||
|
}
|
||||||
|
|
||||||
contextMenuCallback(self) {
|
contextMenuCallback(self) {
|
||||||
self.callback();
|
self.callback();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user