M3.9: hamburger app menu
A slim header bar in MainLayout with a menu button (Lucide menu) whose dropdown lists every command with a menuPath, grouped File, Edit, View, Go, Help, with shortcuts and dimmed disabled entries. Keyboard: arrows, Home/End, Enter/Space, Escape/Tab, type-ahead. menu.open (Alt+M) opens it, also over uiCommand. It is an exclusive modal and a launcher under the one-modal rule. Menu paths for the user-facing engine and UI commands (buffer.close as File/Close Tab). Catalog strings, Vitest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
78709dd76b
commit
27ad30369c
14 changed files with 1004 additions and 25 deletions
|
|
@ -2,7 +2,7 @@
|
|||
* The modal rule (M1.15): at most one modal is open at a time.
|
||||
*
|
||||
* - **Exclusive modals:** the command palette, the go-to popup (M2.6), the
|
||||
* settings dialog and the close question of a dirty tab. Opening one closes the one that is open
|
||||
* app menu (M3.9), the settings dialog and the close question of a dirty tab. Opening one closes the one that is open
|
||||
* (the close question closes as Cancel). Each reports itself with
|
||||
* {@link useModalsStore}'s `opened` and `closed`; the close question is
|
||||
* followed from the editor store, so the editor needs no code for it.
|
||||
|
|
@ -15,14 +15,15 @@
|
|||
* `palette.open` closes it first (see `store.ts` › `execute`), so a
|
||||
* `uiCommand` from the control channel never leaves it open behind
|
||||
* what the command shows. The go-to popup is a launcher too: any command
|
||||
* but the go-to open commands closes it.
|
||||
* but the go-to open commands closes it. So is the app menu (M3.9): any
|
||||
* command but `menu.open` closes it.
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
import { ref, watch } from "vue";
|
||||
import { useEditorStore } from "../stores/editor";
|
||||
|
||||
/** The exclusive modals. */
|
||||
export type ModalId = "palette" | "goto" | "settings" | "closePrompt";
|
||||
export type ModalId = "palette" | "goto" | "menu" | "settings" | "closePrompt";
|
||||
|
||||
/** Store of the open exclusive modal. */
|
||||
export const useModalsStore = defineStore("modals", () => {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@
|
|||
* commands run with empty params.
|
||||
* - **Errors:** a failed command raises an error toast (M1.12).
|
||||
* - **Palette:** running any command but `palette.open` closes the palette
|
||||
* first (the modal rule, `modals.ts`).
|
||||
* first (the modal rule, `modals.ts`); likewise any command but
|
||||
* `menu.open` closes the app menu (M3.9).
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref, shallowReactive } from "vue";
|
||||
|
|
@ -49,11 +50,18 @@ export interface PaletteEntry {
|
|||
shortcut: string | null;
|
||||
/** Whether it can run now. */
|
||||
enabled: boolean;
|
||||
/** Menu path with `/` separators, or null if the command is in no menu (M3.9). */
|
||||
menuPath: string | null;
|
||||
/** Whether the frontend runs it (a UI command, label from the catalog). */
|
||||
ui: boolean;
|
||||
}
|
||||
|
||||
/** Most recently run commands remembered. */
|
||||
export const MAX_RECENT = 20;
|
||||
|
||||
/** The UI command that opens the app menu, which therefore keeps it open. */
|
||||
const MENU_OPEN = "menu.open";
|
||||
|
||||
/** The UI commands that open the go-to popup, which therefore keep it open. */
|
||||
const GOTO_OPEN = new Set(["goto.fileOpen", "goto.classOpen", "goto.symbolOpen"]);
|
||||
|
||||
|
|
@ -151,6 +159,8 @@ export const useCommandsStore = defineStore("commands", () => {
|
|||
label: labelOf(info),
|
||||
shortcut: typeof info.defaultShortcut === "string" ? formatShortcut(info.defaultShortcut, mac) : null,
|
||||
enabled: isEnabled(info.id),
|
||||
menuPath: typeof info.menuPath === "string" && info.menuPath !== "" ? info.menuPath : null,
|
||||
ui: info.ui === true,
|
||||
})),
|
||||
);
|
||||
|
||||
|
|
@ -187,8 +197,9 @@ export const useCommandsStore = defineStore("commands", () => {
|
|||
* Runs a command the user chose (keyboard or palette): through its
|
||||
* handler if a component supplied one, else through the engine. A
|
||||
* disabled command does nothing. A failure raises an error toast. Any
|
||||
* command but `palette.open` closes the palette before it runs, and any
|
||||
* command but the go-to open commands closes the go-to popup.
|
||||
* command but `palette.open` closes the palette before it runs, any
|
||||
* command but the go-to open commands closes the go-to popup, and any
|
||||
* command but `menu.open` closes the app menu.
|
||||
*
|
||||
* @param id - the command id.
|
||||
* @param params - the params.
|
||||
|
|
@ -204,6 +215,9 @@ export const useCommandsStore = defineStore("commands", () => {
|
|||
if (!GOTO_OPEN.has(id)) {
|
||||
modals.dismiss("goto");
|
||||
}
|
||||
if (id !== MENU_OPEN) {
|
||||
modals.dismiss("menu");
|
||||
}
|
||||
const handler = handlers.get(id);
|
||||
if (handler) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -22,12 +22,13 @@ export interface UiCommandSpec {
|
|||
/** The frontend's UI commands. */
|
||||
export const UI_COMMANDS: readonly UiCommandSpec[] = [
|
||||
{ id: "editor.reveal", labelKey: "command.editor.reveal" },
|
||||
{ id: "find.open", labelKey: "command.find.open", defaultShortcut: "Mod+Alt+F" },
|
||||
{ id: "goto.classOpen", labelKey: "command.goto.classOpen", defaultShortcut: "Mod+Alt+C" },
|
||||
{ id: "goto.fileOpen", labelKey: "command.goto.fileOpen", defaultShortcut: "Mod+P" },
|
||||
{ id: "goto.symbolOpen", labelKey: "command.goto.symbolOpen", defaultShortcut: "Mod+T" },
|
||||
{ id: "palette.open", labelKey: "command.palette.open", defaultShortcut: "Mod+Shift+P" },
|
||||
{ id: "settings.open", labelKey: "command.settings.open", defaultShortcut: "Mod+," },
|
||||
{ id: "view.toggleProjectTree", labelKey: "command.view.toggleProjectTree", defaultShortcut: "Mod+1" },
|
||||
{ id: "view.toggleStructure", labelKey: "command.view.toggleStructure", defaultShortcut: "Mod+2" },
|
||||
{ id: "find.open", labelKey: "command.find.open", menuPath: "View/Find in Files…", defaultShortcut: "Mod+Alt+F" },
|
||||
{ id: "goto.classOpen", labelKey: "command.goto.classOpen", menuPath: "Go/Class…", defaultShortcut: "Mod+Alt+C" },
|
||||
{ id: "goto.fileOpen", labelKey: "command.goto.fileOpen", menuPath: "Go/File…", defaultShortcut: "Mod+P" },
|
||||
{ id: "goto.symbolOpen", labelKey: "command.goto.symbolOpen", menuPath: "Go/Symbol…", defaultShortcut: "Mod+T" },
|
||||
{ id: "menu.open", labelKey: "command.menu.open", defaultShortcut: "Alt+M" },
|
||||
{ id: "palette.open", labelKey: "command.palette.open", menuPath: "View/Command Palette", defaultShortcut: "Mod+Shift+P" },
|
||||
{ id: "settings.open", labelKey: "command.settings.open", menuPath: "View/Settings…", defaultShortcut: "Mod+," },
|
||||
{ id: "view.toggleProjectTree", labelKey: "command.view.toggleProjectTree", menuPath: "View/Project", defaultShortcut: "Mod+1" },
|
||||
{ id: "view.toggleStructure", labelKey: "command.view.toggleStructure", menuPath: "View/Structure", defaultShortcut: "Mod+2" },
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue