mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
register shortcut to global menu
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
967fddc603
commit
f54f1c31a4
@ -10,6 +10,7 @@ import { extensionsURL } from "../renderer/components/+extensions/extensions.rou
|
|||||||
import { menuRegistry } from "../extensions/registries/menu-registry";
|
import { menuRegistry } from "../extensions/registries/menu-registry";
|
||||||
import logger from "./logger";
|
import logger from "./logger";
|
||||||
import { exitApp } from "./exit-app";
|
import { exitApp } from "./exit-app";
|
||||||
|
import { broadcastMessage } from "../common/ipc";
|
||||||
|
|
||||||
export type MenuTopId = "mac" | "file" | "edit" | "view" | "help";
|
export type MenuTopId = "mac" | "file" | "edit" | "view" | "help";
|
||||||
|
|
||||||
@ -173,6 +174,14 @@ export function buildMenu(windowManager: WindowManager) {
|
|||||||
const viewMenu: MenuItemConstructorOptions = {
|
const viewMenu: MenuItemConstructorOptions = {
|
||||||
label: "View",
|
label: "View",
|
||||||
submenu: [
|
submenu: [
|
||||||
|
{
|
||||||
|
label: "Command Palette...",
|
||||||
|
accelerator: "Shift+CmdOrCtrl+P",
|
||||||
|
click() {
|
||||||
|
broadcastMessage("command-palette:open");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ type: "separator" },
|
||||||
{
|
{
|
||||||
label: "Back",
|
label: "Back",
|
||||||
accelerator: "CmdOrCtrl+[",
|
accelerator: "CmdOrCtrl+[",
|
||||||
|
|||||||
@ -6,9 +6,9 @@ import { observer } from "mobx-react";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { commandRegistry } from "../../../extensions/registries/command-registry";
|
import { commandRegistry } from "../../../extensions/registries/command-registry";
|
||||||
import { Dialog } from "../dialog";
|
import { Dialog } from "../dialog";
|
||||||
import { isMac } from "../../../common/vars";
|
|
||||||
import { clusterStore } from "../../../common/cluster-store";
|
import { clusterStore } from "../../../common/cluster-store";
|
||||||
import { workspaceStore } from "../../../common/workspace-store";
|
import { workspaceStore } from "../../../common/workspace-store";
|
||||||
|
import { subscribeToBroadcast } from "../../../common/ipc";
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class CommandDialog extends React.Component {
|
export class CommandDialog extends React.Component {
|
||||||
@ -23,22 +23,9 @@ export class CommandDialog extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
private shortcutHandler(event: KeyboardEvent) {
|
private shortcutHandler() {
|
||||||
console.log(event);
|
|
||||||
|
|
||||||
if (isMac) {
|
|
||||||
if (event.shiftKey && event.metaKey && event.key === "p") {
|
|
||||||
this.visible = true;
|
this.visible = true;
|
||||||
this.menuIsOpen = true;
|
this.menuIsOpen = true;
|
||||||
event.stopPropagation();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (event.shiftKey && event.ctrlKey && event.key === "p") {
|
|
||||||
this.visible = true;
|
|
||||||
this.menuIsOpen = true;
|
|
||||||
event.stopPropagation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private closeDialog() {
|
private closeDialog() {
|
||||||
@ -50,11 +37,7 @@ export class CommandDialog extends React.Component {
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
window.addEventListener("keyup", (e) => this.escHandler(e), true);
|
window.addEventListener("keyup", (e) => this.escHandler(e), true);
|
||||||
window.addEventListener("keydown", (e) => this.shortcutHandler(e), true);
|
subscribeToBroadcast("command-palette:open", () => this.shortcutHandler());
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
window.removeEventListener("keyup", this.escHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get options() {
|
@computed get options() {
|
||||||
@ -66,8 +49,6 @@ export class CommandDialog extends React.Component {
|
|||||||
private onChange(value: string) {
|
private onChange(value: string) {
|
||||||
const command = commandRegistry.getItems().find((cmd) => cmd.id === value);
|
const command = commandRegistry.getItems().find((cmd) => cmd.id === value);
|
||||||
|
|
||||||
console.log(value, command);
|
|
||||||
|
|
||||||
if (!command) {
|
if (!command) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -89,7 +70,7 @@ export class CommandDialog extends React.Component {
|
|||||||
<Dialog isOpen={this.visible}>
|
<Dialog isOpen={this.visible}>
|
||||||
<div id="command-dialog">
|
<div id="command-dialog">
|
||||||
<Select
|
<Select
|
||||||
onChange={(v) => this.onChange(v)}
|
onChange={(v) => this.onChange(v.value)}
|
||||||
components={{ DropdownIndicator: null, IndicatorSeparator: null }}
|
components={{ DropdownIndicator: null, IndicatorSeparator: null }}
|
||||||
menuIsOpen={this.menuIsOpen}
|
menuIsOpen={this.menuIsOpen}
|
||||||
options={this.options}
|
options={this.options}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user