Skip to content

Fix menuitem listeners in MacOS #55

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

Merged
merged 4 commits into from
Feb 2, 2025
Merged
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
15 changes: 10 additions & 5 deletions src/second_sidebar/controllers/sidebar_main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SidebarMain } from "../xul/sidebar_main.mjs";
import { SidebarMainMenuPopup } from "../xul/sidebar_main_menupopup.mjs";
import { SidebarMainSettingsController } from "./sidebar_main_settings.mjs";
import { XULElement } from "../xul/base/xul_element.mjs";
import { isRightMouseButton } from "../utils/buttons.mjs";
/* eslint-enable no-unused-vars */

export class SidebarMainController {
Expand Down Expand Up @@ -32,11 +33,15 @@ export class SidebarMainController {
}

#setupListeners() {
this.sidebarMainMenuPopup.listenSettingsItemClick((event) => {
this.sidebarMainSettingsController.openPopup(
event.screenX,
event.screenY,
);
this.sidebarMain.addEventListener("mousedown", (event) => {
if (isRightMouseButton(event)) {
this.mouseX = event.clientX;
this.mouseY = event.clientY;
}
});

this.sidebarMainMenuPopup.listenSettingsItemClick(() => {
this.sidebarMainSettingsController.openPopup(this.mouseX, this.mouseY);
});

this.sidebarMainMenuPopup.listenCustomizeItemClick(() => {
Expand Down
10 changes: 7 additions & 3 deletions src/second_sidebar/xul/sidebar_main_menupopup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export class SidebarMainMenuPopup extends MenuPopup {

this.settingsItem = new MenuItem().setLabel("Sidebar settings");
this.customizeItem = new MenuItem().setLabel("Customize Toolbar...");
this.#compose();
}

#compose() {
this.appendChildren(
this.settingsItem,
new MenuSeparator(),
Expand All @@ -23,8 +27,8 @@ export class SidebarMainMenuPopup extends MenuPopup {
* @param {function(MouseEvent):void} callback
*/
listenSettingsItemClick(callback) {
this.settingsItem.addEventListener("click", (event) => {
callback(event);
this.settingsItem.addEventListener("command", () => {
callback();
});
}

Expand All @@ -33,7 +37,7 @@ export class SidebarMainMenuPopup extends MenuPopup {
* @param {function(MouseEvent):void} callback
*/
listenCustomizeItemClick(callback) {
this.customizeItem.addEventListener("click", (event) => {
this.customizeItem.addEventListener("command", (event) => {
callback(event);
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/second_sidebar/xul/web_panel_button_menupopup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class WebPanelButtonMenuPopup extends MenuPopup {
* @param {WebPanelsController} webPanelsController
*/
listenUnloadItemClick(callback) {
this.unloadItem.addEventListener("click", () => {
this.unloadItem.addEventListener("command", () => {
callback(this.webPanelController);
});
}
Expand All @@ -59,7 +59,7 @@ export class WebPanelButtonMenuPopup extends MenuPopup {
* @param {WebPanelsController} webPanelsController
*/
listenEditItemClick(callback) {
this.editItem.addEventListener("click", () => {
this.editItem.addEventListener("command", () => {
callback(this.webPanelController);
});
}
Expand All @@ -69,7 +69,7 @@ export class WebPanelButtonMenuPopup extends MenuPopup {
* @param {WebPanelsController} webPanelsController
*/
listenDeleteItemClick(callback) {
this.deleteItem.addEventListener("click", () => {
this.deleteItem.addEventListener("command", () => {
callback(this.webPanelController);
});
}
Expand All @@ -79,7 +79,7 @@ export class WebPanelButtonMenuPopup extends MenuPopup {
* @param {function(MouseEvent):void} callback
*/
listenCustomizeItemClick(callback) {
this.customizeItem.addEventListener("click", (event) => {
this.customizeItem.addEventListener("command", (event) => {
callback(event);
});
}
Expand Down
Loading