Remove shortcuts again, just trigger command pallete
This commit is contained in:
parent
4ada18a213
commit
94d0e31b30
@ -123,8 +123,6 @@ functions:
|
|||||||
command:
|
command:
|
||||||
name: "Template: Quick Note"
|
name: "Template: Quick Note"
|
||||||
key: "Alt-Shift-n"
|
key: "Alt-Shift-n"
|
||||||
shortcut:
|
|
||||||
label: "Quick note"
|
|
||||||
quickTaskCommand:
|
quickTaskCommand:
|
||||||
path: ./template.ts:quickTaskCommand
|
path: ./template.ts:quickTaskCommand
|
||||||
command:
|
command:
|
||||||
|
@ -10,8 +10,6 @@ functions:
|
|||||||
command:
|
command:
|
||||||
name: "Materialized Queries: Update"
|
name: "Materialized Queries: Update"
|
||||||
key: "Alt-q"
|
key: "Alt-q"
|
||||||
shortcut:
|
|
||||||
label: "Update queries"
|
|
||||||
events:
|
events:
|
||||||
- editor:pageLoaded
|
- editor:pageLoaded
|
||||||
indexData:
|
indexData:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { faRunning } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { ShortcutItem, Notification } from "../types";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import { Notification } from "../types";
|
||||||
|
|
||||||
function prettyName(s: string | undefined): string {
|
function prettyName(s: string | undefined): string {
|
||||||
if (!s) {
|
if (!s) {
|
||||||
@ -12,33 +13,19 @@ export function TopBar({
|
|||||||
pageName,
|
pageName,
|
||||||
unsavedChanges,
|
unsavedChanges,
|
||||||
notifications,
|
notifications,
|
||||||
shortcutItems,
|
|
||||||
onClick,
|
onClick,
|
||||||
|
onActionClick,
|
||||||
lhs,
|
lhs,
|
||||||
rhs,
|
rhs,
|
||||||
}: {
|
}: {
|
||||||
pageName?: string;
|
pageName?: string;
|
||||||
unsavedChanges: boolean;
|
unsavedChanges: boolean;
|
||||||
notifications: Notification[];
|
notifications: Notification[];
|
||||||
shortcutItems: ShortcutItem[];
|
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
|
onActionClick: () => void;
|
||||||
lhs?: React.ReactNode;
|
lhs?: React.ReactNode;
|
||||||
rhs?: React.ReactNode;
|
rhs?: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
const [menuExpanded, setMenuExpanded] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
function closer() {
|
|
||||||
setMenuExpanded(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener("click", closer);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
document.removeEventListener("click", closer);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="top" onClick={onClick}>
|
<div id="top" onClick={onClick}>
|
||||||
{lhs}
|
{lhs}
|
||||||
@ -59,31 +46,13 @@ export function TopBar({
|
|||||||
<div className="actions">
|
<div className="actions">
|
||||||
<button
|
<button
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
setMenuExpanded(!menuExpanded);
|
// setMenuExpanded(!menuExpanded);
|
||||||
|
onActionClick();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
...
|
<FontAwesomeIcon icon={faRunning} />
|
||||||
</button>
|
</button>
|
||||||
{menuExpanded && (
|
|
||||||
<ul>
|
|
||||||
{shortcutItems.map((actionButton, idx) => (
|
|
||||||
<li key={idx}>
|
|
||||||
<a
|
|
||||||
href="#"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
setMenuExpanded(false);
|
|
||||||
actionButton.run();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{actionButton.label}
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -127,11 +127,10 @@ export class Editor {
|
|||||||
// Command hook
|
// Command hook
|
||||||
this.commandHook = new CommandHook();
|
this.commandHook = new CommandHook();
|
||||||
this.commandHook.on({
|
this.commandHook.on({
|
||||||
commandsUpdated: (commandMap, shortcutItems) => {
|
commandsUpdated: (commandMap) => {
|
||||||
this.viewDispatch({
|
this.viewDispatch({
|
||||||
type: "update-commands",
|
type: "update-commands",
|
||||||
commands: commandMap,
|
commands: commandMap,
|
||||||
shortcutItems: shortcutItems,
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -660,7 +659,6 @@ export class Editor {
|
|||||||
placeholder={viewState.filterBoxPlaceHolder}
|
placeholder={viewState.filterBoxPlaceHolder}
|
||||||
options={viewState.filterBoxOptions}
|
options={viewState.filterBoxOptions}
|
||||||
allowNew={false}
|
allowNew={false}
|
||||||
// icon={faPersonRunning}
|
|
||||||
helpText={viewState.filterBoxHelpText}
|
helpText={viewState.filterBoxHelpText}
|
||||||
onSelect={viewState.filterBoxOnSelect}
|
onSelect={viewState.filterBoxOnSelect}
|
||||||
/>
|
/>
|
||||||
@ -669,19 +667,12 @@ export class Editor {
|
|||||||
pageName={viewState.currentPage}
|
pageName={viewState.currentPage}
|
||||||
notifications={viewState.notifications}
|
notifications={viewState.notifications}
|
||||||
unsavedChanges={viewState.unsavedChanges}
|
unsavedChanges={viewState.unsavedChanges}
|
||||||
shortcutItems={[
|
|
||||||
{
|
|
||||||
label: "Run command",
|
|
||||||
orderId: 0,
|
|
||||||
run: () => {
|
|
||||||
this.viewDispatch({ type: "show-palette" });
|
|
||||||
},
|
|
||||||
},
|
|
||||||
...viewState.shortcutItems,
|
|
||||||
]}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
dispatch({ type: "start-navigate" });
|
dispatch({ type: "start-navigate" });
|
||||||
}}
|
}}
|
||||||
|
onActionClick={() => {
|
||||||
|
dispatch({ type: "show-palette" });
|
||||||
|
}}
|
||||||
rhs={
|
rhs={
|
||||||
!!viewState.showRHS && (
|
!!viewState.showRHS && (
|
||||||
<div className="panel" style={{ flex: viewState.showRHS }} />
|
<div className="panel" style={{ flex: viewState.showRHS }} />
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { Hook, Manifest } from "@plugos/plugos/types";
|
import { Hook, Manifest } from "@plugos/plugos/types";
|
||||||
import { System } from "@plugos/plugos/system";
|
import { System } from "@plugos/plugos/system";
|
||||||
import { EventEmitter } from "@plugos/plugos/event";
|
import { EventEmitter } from "@plugos/plugos/event";
|
||||||
import { ShortcutItem } from "../types";
|
|
||||||
|
|
||||||
export type CommandDef = {
|
export type CommandDef = {
|
||||||
name: string;
|
name: string;
|
||||||
@ -11,13 +10,6 @@ export type CommandDef = {
|
|||||||
// Bind to keyboard shortcut
|
// Bind to keyboard shortcut
|
||||||
key?: string;
|
key?: string;
|
||||||
mac?: string;
|
mac?: string;
|
||||||
|
|
||||||
// Shortcuts in UI
|
|
||||||
shortcut?: ShortcutDef;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ShortcutDef = {
|
|
||||||
label: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AppCommand = {
|
export type AppCommand = {
|
||||||
@ -30,10 +22,7 @@ export type CommandHookT = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type CommandHookEvents = {
|
export type CommandHookEvents = {
|
||||||
commandsUpdated(
|
commandsUpdated(commandMap: Map<string, AppCommand>): void;
|
||||||
commandMap: Map<string, AppCommand>,
|
|
||||||
appButtons: ShortcutItem[]
|
|
||||||
): void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export class CommandHook
|
export class CommandHook
|
||||||
@ -41,11 +30,9 @@ export class CommandHook
|
|||||||
implements Hook<CommandHookT>
|
implements Hook<CommandHookT>
|
||||||
{
|
{
|
||||||
editorCommands = new Map<string, AppCommand>();
|
editorCommands = new Map<string, AppCommand>();
|
||||||
shortcutItems: ShortcutItem[] = [];
|
|
||||||
|
|
||||||
buildAllCommands(system: System<CommandHookT>) {
|
buildAllCommands(system: System<CommandHookT>) {
|
||||||
this.editorCommands.clear();
|
this.editorCommands.clear();
|
||||||
this.shortcutItems = [];
|
|
||||||
for (let plug of system.loadedPlugs.values()) {
|
for (let plug of system.loadedPlugs.values()) {
|
||||||
for (const [name, functionDef] of Object.entries(
|
for (const [name, functionDef] of Object.entries(
|
||||||
plug.manifest!.functions
|
plug.manifest!.functions
|
||||||
@ -60,17 +47,9 @@ export class CommandHook
|
|||||||
return plug.invoke(name, []);
|
return plug.invoke(name, []);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (cmd.shortcut) {
|
|
||||||
this.shortcutItems.push({
|
|
||||||
label: cmd.shortcut.label,
|
|
||||||
run: () => {
|
|
||||||
return plug.invoke(name, []);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.emit("commandsUpdated", this.editorCommands, this.shortcutItems);
|
this.emit("commandsUpdated", this.editorCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
apply(system: System<CommandHookT>): void {
|
apply(system: System<CommandHookT>): void {
|
||||||
|
@ -76,7 +76,6 @@ export default function reducer(
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
commands: action.commands,
|
commands: action.commands,
|
||||||
shortcutItems: action.shortcutItems,
|
|
||||||
};
|
};
|
||||||
case "show-notification":
|
case "show-notification":
|
||||||
return {
|
return {
|
||||||
|
@ -76,19 +76,19 @@ body {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|
||||||
// .status {
|
.status {
|
||||||
// position: absolute;
|
position: absolute;
|
||||||
// font-family: "iA-Mono";
|
font-family: "iA-Mono";
|
||||||
// bottom: 45px;
|
bottom: 45px;
|
||||||
// left: 5px;
|
left: 5px;
|
||||||
// right: 5px;
|
right: 5px;
|
||||||
// background-color: rgb(187, 221, 247);
|
background-color: rgb(187, 221, 247);
|
||||||
// border: rgb(41, 41, 41) 1px solid;
|
border: rgb(41, 41, 41) 1px solid;
|
||||||
// border-radius: 5px;
|
border-radius: 5px;
|
||||||
// padding: 3px;
|
padding: 3px;
|
||||||
// font-size: 15px;
|
font-size: 15px;
|
||||||
// z-index: 100;
|
z-index: 100;
|
||||||
// }
|
}
|
||||||
|
|
||||||
.current-page {
|
.current-page {
|
||||||
font-family: var(--ui-font);
|
font-family: var(--ui-font);
|
||||||
@ -97,15 +97,11 @@ body {
|
|||||||
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
// margin-right: 40px;
|
text-align: left;
|
||||||
display: block;
|
display: block;
|
||||||
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
// .icon {
|
|
||||||
// padding-left: 5px;
|
|
||||||
// padding-right: 10px;
|
|
||||||
// }
|
|
||||||
|
|
||||||
.saved {
|
.saved {
|
||||||
color: #111;
|
color: #111;
|
||||||
}
|
}
|
||||||
@ -115,10 +111,8 @@ body {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.actions {
|
.actions {
|
||||||
// float: right;
|
|
||||||
text-align: right;
|
text-align: right;
|
||||||
width: 40px;
|
width: 40px;
|
||||||
// margin-top: -35px;
|
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
|
@ -9,12 +9,6 @@ export type Notification = {
|
|||||||
date: Date;
|
date: Date;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ShortcutItem = {
|
|
||||||
label: string;
|
|
||||||
orderId?: number;
|
|
||||||
run: () => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type AppViewState = {
|
export type AppViewState = {
|
||||||
currentPage?: string;
|
currentPage?: string;
|
||||||
perm: "ro" | "rw";
|
perm: "ro" | "rw";
|
||||||
@ -34,7 +28,6 @@ export type AppViewState = {
|
|||||||
allPages: Set<PageMeta>;
|
allPages: Set<PageMeta>;
|
||||||
commands: Map<string, AppCommand>;
|
commands: Map<string, AppCommand>;
|
||||||
notifications: Notification[];
|
notifications: Notification[];
|
||||||
shortcutItems: ShortcutItem[];
|
|
||||||
recentCommands: Map<string, Date>;
|
recentCommands: Map<string, Date>;
|
||||||
|
|
||||||
showFilterBox: boolean;
|
showFilterBox: boolean;
|
||||||
@ -60,7 +53,6 @@ export const initialViewState: AppViewState = {
|
|||||||
commands: new Map(),
|
commands: new Map(),
|
||||||
recentCommands: new Map(),
|
recentCommands: new Map(),
|
||||||
notifications: [],
|
notifications: [],
|
||||||
shortcutItems: [],
|
|
||||||
showFilterBox: false,
|
showFilterBox: false,
|
||||||
filterBoxHelpText: "",
|
filterBoxHelpText: "",
|
||||||
filterBoxLabel: "",
|
filterBoxLabel: "",
|
||||||
@ -79,7 +71,6 @@ export type Action =
|
|||||||
| {
|
| {
|
||||||
type: "update-commands";
|
type: "update-commands";
|
||||||
commands: Map<string, AppCommand>;
|
commands: Map<string, AppCommand>;
|
||||||
shortcutItems: ShortcutItem[];
|
|
||||||
}
|
}
|
||||||
| { type: "show-palette"; context?: string }
|
| { type: "show-palette"; context?: string }
|
||||||
| { type: "hide-palette" }
|
| { type: "hide-palette" }
|
||||||
|
Loading…
Reference in New Issue
Block a user