Skip to content
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

Spruce up menus #22

Merged
merged 5 commits into from
Dec 19, 2022
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
13 changes: 10 additions & 3 deletions src/renderer/menus/appMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export function useApplicationMenu(store: Store, config: Config): void {
label: "&File",
type: "submenu",
children: [
{
label: "New note",
type: "normal",
shortcut: shortcutLabels["sidebar.createNote"],
event: "sidebar.createNote",
eventInput: { root: true },
},
{
label: isEditing ? "Stop editing" : "Edit",
type: "normal",
Expand Down Expand Up @@ -104,19 +111,19 @@ export function useApplicationMenu(store: Store, config: Config): void {
label: "Cut",
type: "normal",
role: "cut",
disabled: focused !== "editor",
disabled: focused !== "editor" || !state.editor.isEditing,
},
{
label: "Copy",
type: "normal",
role: "copy",
disabled: focused !== "editor",
disabled: focused !== "editor" || !state.editor.isEditing,
},
{
label: "Paste",
type: "normal",
role: "paste",
disabled: focused !== "editor",
disabled: focused !== "editor" || !state.editor.isEditing,
},
],
},
Expand Down
34 changes: 31 additions & 3 deletions src/renderer/menus/contextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Section } from "../../shared/ui/app";
import { getEditorTabAttribute } from "../components/EditorTab";
import { IpcChannel } from "../../shared/ipc";
import { Config } from "../../shared/domain/config";
import { KeyCode, keyCodesToString } from "../../shared/io/keyCode";

export function useContextMenu(store: Store, config: Config): void {
const { state } = store;
Expand Down Expand Up @@ -46,6 +47,7 @@ export function useContextMenu(store: Store, config: Config): void {
type: "normal",
event: "sidebar.createNote",
eventInput: { parent: noteId },
shortcut: shortcutLabels["sidebar.createNote"],
});

if (noteId != null) {
Expand All @@ -55,7 +57,7 @@ export function useContextMenu(store: Store, config: Config): void {
type: "normal",
event: "sidebar.renameNote",
eventInput: noteId,
shortcut: shortcutLabels["sidebar.renameNote"],
shortcut: shortcutLabels["sidebar.renameSelectedNote"],
},
{
label: "Open attachments",
Expand All @@ -69,7 +71,7 @@ export function useContextMenu(store: Store, config: Config): void {
type: "normal",
event: "sidebar.deleteNote",
eventInput: noteId,
shortcut: shortcutLabels["sidebar.deleteNote"],
shortcut: shortcutLabels["sidebar.deleteSelectedNote"],
},
);
}
Expand Down Expand Up @@ -97,6 +99,29 @@ export function useContextMenu(store: Store, config: Config): void {
break;
}

case Section.Editor:
if (state.editor.isEditing) {
items.push({
label: "Cut",
type: "normal",
role: "cut",
shortcut: keyCodesToString([KeyCode.Control, KeyCode.LetterX]),
});
items.push({
label: "Copy",
type: "normal",
role: "copy",
shortcut: keyCodesToString([KeyCode.Control, KeyCode.LetterC]),
});
items.push({
label: "Paste",
type: "normal",
role: "paste",
shortcut: keyCodesToString([KeyCode.Control, KeyCode.LetterV]),
});
}
break;

case Section.EditorToolbar: {
const tabNoteId = getEditorTabAttribute(ev.target as HTMLElement);

Expand All @@ -106,7 +131,10 @@ export function useContextMenu(store: Store, config: Config): void {
type: "normal",
event: "editor.closeTab",
eventInput: tabNoteId,
shortcut: shortcutLabels["editor.closeTab"],
// Kinda a hack lol. We don't have a shortcut for closeTab because
// if we did it'd expect a parameter. We get around it by using the
// shortcut label for closeActiveTab
shortcut: shortcutLabels["editor.closeActiveTab"],
});
items.push({
label: "Close others",
Expand Down