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 menuspull/5630/head
parent
adfef8e2bb
commit
c752183199
|
@ -296,9 +296,10 @@ function launchPgAdminWindow() {
|
|||
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-refresh-menu-item', refreshMenuItems);
|
||||
pgadminWindow.window.pgAdmin.Browser.Events.on('pgadmin:nw-update-checked-menu-item', updateCheckedMenuItem);
|
||||
// Add Main Menus to native menu.
|
||||
pgadminWindow.window.pgAdmin.Browser.MainMenus.forEach((menu)=> {
|
||||
addMenu(pgadminWindow.window.pgAdmin.Browser, menu)
|
||||
addMenu(menu)
|
||||
})
|
||||
clearInterval(addMenuInterval);
|
||||
}
|
||||
|
@ -380,11 +381,11 @@ splashWindow.on('close', function () {
|
|||
});
|
||||
|
||||
|
||||
function addCommonMenus(pgBrowser, menu) {
|
||||
function addCommonMenus(menu) {
|
||||
let _menu = new gui.Menu();
|
||||
|
||||
menu.menuItems.forEach((menuItem) => {
|
||||
var submenu = getSubMenu(pgBrowser, menuItem);
|
||||
var submenu = getSubMenu(menuItem);
|
||||
|
||||
let _menuItem = new gui.MenuItem({
|
||||
label: menuItem.label,
|
||||
|
@ -427,7 +428,7 @@ function addCommonMenus(pgBrowser, menu) {
|
|||
|
||||
}
|
||||
|
||||
function getSubMenu(pgBrowser, menuItem) {
|
||||
function getSubMenu(menuItem) {
|
||||
let submenu = new gui.Menu();
|
||||
if (menuItem.menu_items) {
|
||||
menuItem.menu_items.forEach((item) => {
|
||||
|
@ -460,12 +461,12 @@ function getSubMenu(pgBrowser, menuItem) {
|
|||
return submenu;
|
||||
}
|
||||
|
||||
function addMacMenu(pgBrowser, menu) {
|
||||
function addMacMenu(menu) {
|
||||
if (menu.name == 'file' && platform() === 'darwin') {
|
||||
var rootMenu = nativeMenu.items[0].submenu;
|
||||
let indx = 0;
|
||||
menu.menuItems.forEach((menuItem) => {
|
||||
let submenu = getSubMenu(pgBrowser, menuItem);
|
||||
let submenu = getSubMenu(menuItem);
|
||||
|
||||
rootMenu.insert(
|
||||
new gui.MenuItem({
|
||||
|
@ -489,21 +490,21 @@ function addMacMenu(pgBrowser, menu) {
|
|||
|
||||
pgAdminMainScreen.menu = nativeMenu;
|
||||
} else {
|
||||
addCommonMenus(pgBrowser, menu)
|
||||
addCommonMenus(menu)
|
||||
}
|
||||
}
|
||||
|
||||
function addOtherOsMenu(pgBrowser, menu) {
|
||||
addCommonMenus(pgBrowser, menu)
|
||||
function addOtherOsMenu(menu) {
|
||||
addCommonMenus(menu)
|
||||
}
|
||||
|
||||
|
||||
function addMenu(pgBrowser, menu) {
|
||||
function addMenu(menu) {
|
||||
pgAdminMainScreen.isCustomMenusAdded = true;
|
||||
if (platform() === 'darwin') {
|
||||
addMacMenu(pgBrowser, menu);
|
||||
addMacMenu(menu);
|
||||
} else {
|
||||
addOtherOsMenu(pgBrowser, menu);
|
||||
addOtherOsMenu(menu);
|
||||
}
|
||||
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) {
|
||||
// Add menu item/option in specific menu.
|
||||
pgAdminMainScreen.menu.items.forEach(el => {
|
||||
|
|
|
@ -398,6 +398,9 @@ define('pgadmin.browser', [
|
|||
let is_all_option_dis = true;
|
||||
category[c].forEach((c)=> {
|
||||
c.is_disabled = c.disabled(d, item);
|
||||
|
||||
c.setDisabled( c.is_disabled);
|
||||
|
||||
if(is_all_option_dis)
|
||||
is_all_option_dis = c.is_disabled;
|
||||
});
|
||||
|
@ -478,8 +481,8 @@ define('pgadmin.browser', [
|
|||
let {name: browser} = getBrowser();
|
||||
if(browser == 'Nwjs') {
|
||||
pgBrowser.MainMenus.forEach((menu) => {
|
||||
menu.menuItems.forEach((_item) => {
|
||||
_item.setDisabled(_item.disabled(d, item));
|
||||
menu.menuItems.forEach((item) => {
|
||||
item.setDisabled(item.disabled(d, item));
|
||||
});
|
||||
});
|
||||
}else {
|
||||
|
|
|
@ -79,6 +79,8 @@ export class MainMenuItemFactory {
|
|||
}
|
||||
}}, (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);
|
||||
} else {
|
||||
this.menuItems.push(menuItem);
|
||||
|
||||
// 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;
|
||||
});
|
||||
Menu.sortMenus(this.menuItems);
|
||||
}
|
||||
} else {
|
||||
throw new Error(gettext('Invalid MenuItem instance'));
|
||||
|
@ -54,6 +45,12 @@ export default class Menu {
|
|||
if (item instanceof MenuItem) {
|
||||
item.parentMenu = this;
|
||||
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 {
|
||||
let subItems = Object.values(item);
|
||||
subItems.forEach((subItem)=> {
|
||||
|
@ -81,16 +78,25 @@ export default class Menu {
|
|||
|
||||
setMenuItems(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
|
||||
this.menuItems.sort(function (a, b) {
|
||||
menuItems.sort(function (a, b) {
|
||||
return a.label.localeCompare(b.label);
|
||||
});
|
||||
|
||||
// Sort by priority
|
||||
this.menuItems.sort(function (a, b) {
|
||||
menuItems.sort(function (a, b) {
|
||||
return a.priority - b.priority;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
getMenuItems() {
|
||||
|
@ -98,15 +104,7 @@ export default class Menu {
|
|||
}
|
||||
|
||||
static getContextMenus(menuList, item, node) {
|
||||
// Sort by alphanumeric ordered first
|
||||
menuList.sort(function (a, b) {
|
||||
return a.label.localeCompare(b.label);
|
||||
});
|
||||
|
||||
// Sort by priority
|
||||
menuList.sort(function (a, b) {
|
||||
return a.priority - b.priority;
|
||||
});
|
||||
Menu.sortMenus(menuList);
|
||||
|
||||
let ctxMenus = {};
|
||||
let ctxIndex = 1;
|
||||
|
@ -115,6 +113,7 @@ export default class Menu {
|
|||
let sub_ctx_item = {};
|
||||
ctx.is_disabled = ctx.disabled(node, item);
|
||||
if ('menu_items' in ctx && ctx.menu_items) {
|
||||
Menu.sortMenus(ctx.menu_items);
|
||||
ctx.menu_items.forEach((c) => {
|
||||
c.is_disabled = c.disabled(node, item);
|
||||
if (!c.is_disabled) {
|
||||
|
@ -138,7 +137,7 @@ export default class Menu {
|
|||
|
||||
|
||||
export class MenuItem {
|
||||
constructor(options, onDisableChange) {
|
||||
constructor(options, onDisableChange, onChangeChacked) {
|
||||
let menu_opts = [
|
||||
'name', 'label', 'priority', 'module', 'callback', 'data', 'enable',
|
||||
'category', 'target', 'url', 'node',
|
||||
|
@ -159,12 +158,18 @@ export class MenuItem {
|
|||
};
|
||||
}
|
||||
this.onDisableChange = onDisableChange;
|
||||
this.changeChecked = onChangeChacked;
|
||||
}
|
||||
|
||||
static create(options) {
|
||||
return MenuItem(options);
|
||||
}
|
||||
|
||||
change_checked(isChecked) {
|
||||
this.checked = isChecked;
|
||||
this.changeChecked?.(this);
|
||||
}
|
||||
|
||||
contextMenuCallback(self) {
|
||||
self.callback();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue