Skip to content

Show shortcuts in Electron native menu items.GH-1923 #8973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions web/pgadmin/browser/static/js/MainMenuFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ const MAIN_MENUS = [

export default class MainMenuFactory {
static electronCallbacks = {};
// Use to convert shortcut to accelerator for electron.
static convertShortcutToAccelerator({ control, meta, shift, alt, key } = {}) {
// Store active modifier keys into an array.
const mods = [
control && 'Ctrl',
meta && 'Cmd',
shift && 'Shift',
alt && 'Alt',
].filter(Boolean); // Remove any falsy values
// Get the actual key character and convert to uppercase.
const k = key?.char?.toUpperCase();
if (!k) return;
// Combine modifiers and key into a single string.
return [...mods, k].join('+');
}

static toElectron() {
// we support 2 levels of submenu
Expand All @@ -34,10 +49,12 @@ export default class MainMenuFactory {
MainMenuFactory.electronCallbacks[smName] = sm.callback;
return {
...sm.serialize(),
accelerator: MainMenuFactory.convertShortcutToAccelerator(sm.shortcut),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accelerator will actually register a shortcut. It is not just for labelling. Did you test triggering the shortcut?
Although, it will trigger double shortcut.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the electron side by console when hit the shortcut, it’s not being called twice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what you checked but it is opening 3 query tools for query tool shortcut.

Screen.Recording.2025-07-21.at.09.55.21.mov

submenu: sm.getMenuItems()?.map((smsm)=>{
MainMenuFactory.electronCallbacks[`${smName}_${smsm.name}`] = smsm.callback;
return {
...smsm.serialize(),
accelerator: MainMenuFactory.convertShortcutToAccelerator(smsm.shortcut),
};
})
};
Expand Down Expand Up @@ -123,6 +140,7 @@ export default class MainMenuFactory {
static subscribeShortcutChanges() {
MainMenuFactory.updateShortcutsFromPreferences(usePreferences.getState());
usePreferences.subscribe(MainMenuFactory.updateShortcutsFromPreferences);
MainMenuFactory.createMainMenus();
}

static enableDisableMenus(item) {
Expand Down
1 change: 1 addition & 0 deletions web/pgadmin/browser/static/js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ define('pgadmin.browser', [
_m.callback = () => {
showQuickSearch();
};
_m.shortcut_preference =['browser', 'open_quick_search'];
}

return {
Expand Down
1 change: 0 additions & 1 deletion web/pgadmin/static/js/components/Menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export const PgMenuItem = (({hasCheck=false, checked=false, accesskey, shortcut,
<Box
sx={{
marginLeft: 'auto',
fontSize: '0.8em',
paddingLeft: '12px',
display: 'flex',
gap: '1px',
Expand Down
Loading