Skip to content

Commit

Permalink
Spruce up menus (#22)
Browse files Browse the repository at this point in the history
* Add missing shortcut label to close tab context menu option

* Add new note option to app menu

* Add missing shortcuts in sidebar context menu

* Add cut / copy / paste to editor

* Disable cut / copy /paste from app menu if not editting
  • Loading branch information
EddieAbbondanzio authored Dec 19, 2022
1 parent 45fc7b2 commit 95a5356
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
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

0 comments on commit 95a5356

Please sign in to comment.