@setoelkahfi / svara / commits / 6285444

Added config for shortcuts

mellobacon committed Nov 27, 2022 at 20:03 UTC 6285444d8b4e9ac1e60bb21996fd4c8a286df62e
3 files changed +113 -16
src/components/Header/menu.ts
+20 -16
@@ -1,24 +1,28 @@
1 import { appWindow } from "@tauri-apps/api/window";
2 import { addNewFile, openFile, openFolder, openSettings, saveOpenFile } from "./header_menus/FileMenu";
3 +import settings from "../../config/nucleus-settings.json";
4 +import { getShortcut } from "../../config/config";
5 +const shortcuts = settings.shortcuts;
6 +
7 export const filemenu = [
4 - { option: "New File...", shortcut: "Ctrl + N", onclick: addNewFile },
5 - { option: "Open File...", shortcut: "Ctrl + O", onclick: openFile },
6 - { option: "Open Folder", shortcut: "Ctrl + K", onclick: openFolder },
8 + { option: "New File...", shortcut: getShortcut(shortcuts["new-file-shortcut"]), onclick: addNewFile },
9 + { option: "Open File...", shortcut: getShortcut(shortcuts["open-file-shortcut"]), onclick: openFile },
10 + { option: "Open Folder", shortcut: getShortcut(shortcuts["open-folder-shortcut"]), onclick: openFolder },
11 { option: "Open Recent", onclick: () => { console.log("click"); } },
8 - { option: "Save File", shortcut: "Ctrl + S", onclick: saveOpenFile, divider: true },
9 - { option: "Save File As...", shortcut: "Ctrl + Shift + S", onclick: saveOpenFile },
12 + { option: "Save File", shortcut: getShortcut(shortcuts["save-file-shortcut"]), onclick: saveOpenFile, divider: true },
13 + { option: "Save File As...", shortcut: getShortcut(shortcuts["save-file-as-shortcut"]), onclick: saveOpenFile },
14 { option: "Settings", onclick: openSettings, divider: true },
15 { option: "Exit", onclick: async () => { await appWindow.close(); } }
16 ];
17 export const editmenu = [
14 - { option: "Undo", shortcut: "Ctrl + Z", onclick: () => { console.log("click"); } },
15 - { option: "Redo", shortcut: "Ctrl + Y", onclick: () => { console.log("click"); } },
16 - { option: "Delete", shortcut: "Delete", onclick: () => { console.log("click"); } },
17 - { option: "Cut", shortcut: "Ctrl + X", onclick: () => { console.log("click"); }, divider: true },
18 - { option: "Copy", shortcut: "Ctrl + C", onclick: () => { console.log("click"); } },
19 - { option: "Paste", shortcut: "Ctrl + V", onclick: () => { console.log("click"); } },
20 - { option: "Find", shortcut: "Ctrl + F", onclick: () => { console.log("click"); }, divider: true },
21 - { option: "Select All", shortcut:"Ctrl + A", onclick: () => { console.log("click"); } }
18 + { option: "Undo", shortcut: getShortcut(shortcuts["undo-shortcut"]), onclick: () => { console.log("click"); } },
19 + { option: "Redo", shortcut: getShortcut(shortcuts["redo-shortcut"]), onclick: () => { console.log("click"); } },
20 + { option: "Delete", shortcut: getShortcut(shortcuts["delete-shortcut"]), onclick: () => { console.log("click"); } },
21 + { option: "Cut", shortcut: getShortcut(shortcuts["cut-shortcut"]), onclick: () => { console.log("click"); }, divider: true },
22 + { option: "Copy", shortcut: getShortcut(shortcuts["copy-shortcut"]), onclick: () => { console.log("click"); } },
23 + { option: "Paste", shortcut: getShortcut(shortcuts["paste-shortcut"]), onclick: () => { console.log("click"); } },
24 + { option: "Find", shortcut: getShortcut(shortcuts["find-shortcut"]), onclick: () => { console.log("click"); }, divider: true },
25 + { option: "Select All", shortcut: getShortcut(shortcuts["select-all-text-shortcut"]), onclick: () => { console.log("click"); } }
26 ];
27 export const viewmenu = [
28 { option: "Layout", onclick: () => { console.log("click"); } },
@@ -28,9 +32,9 @@ export const viewmenu = [
32 { option: "Toggle Windows", onclick: () => { console.log("click"); } }
33 ];
34 export const runmenu = [
31 - { option: "Build", shortcut: "Ctrl + B", onclick: () => { console.log("click"); } },
32 - { option: "Run", shortcut: "Ctrl + F5", onclick: () => { console.log("click"); } },
33 - { option: "Run without debugging", shortcut: "F5", onclick: () => { console.log("click"); } },
35 + { option: "Build", shortcut: getShortcut(shortcuts["build-shortcut"]), onclick: () => { console.log("click"); } },
36 + { option: "Run", shortcut: getShortcut(shortcuts["run-shortcut"]), onclick: () => { console.log("click"); } },
37 + { option: "Run without debugging", shortcut: getShortcut(shortcuts["run-no-debug-shortcut"]), onclick: () => { console.log("click"); } },
38 { option: "Add configuration", onclick: () => { console.log("click"); }, divider: true },
39 { option: "Edit configuration", onclick: () => { console.log("click"); } },
40 { option: "Install debugger...", onclick: () => { console.log("click"); } },
src/config/config.ts new
+9
@@ -0,0 +1,9 @@
1 +export function getShortcut({ primaryKey, secondaryKey, modifier }) {
2 + if (modifier) {
3 + modifier = `${modifier} + `;
4 + }
5 + if (secondaryKey) {
6 + secondaryKey = `${secondaryKey} + `;
7 + }
8 + return `${modifier}${secondaryKey}${primaryKey}`;
9 +}
\ No newline at end of file
src/config/nucleus-settings.json new
+84
@@ -0,0 +1,84 @@
1 +{
2 + "shortcuts": {
3 + "new-file-shortcut": {
4 + "primaryKey": "N",
5 + "secondaryKey": "",
6 + "modifier": "Ctrl"
7 + },
8 + "open-file-shortcut": {
9 + "primaryKey": "O",
10 + "secondaryKey": "",
11 + "modifier": "Ctrl"
12 + },
13 + "open-folder-shortcut": {
14 + "primaryKey": "K",
15 + "secondaryKey": "",
16 + "modifier": "Ctrl"
17 + },
18 + "save-file-shortcut": {
19 + "primaryKey": "S",
20 + "secondaryKey": "",
21 + "modifier": "Ctrl"
22 + },
23 + "save-file-as-shortcut": {
24 + "primaryKey": "S",
25 + "secondaryKey": "LShift",
26 + "modifier": "Ctrl"
27 + },
28 + "undo-shortcut": {
29 + "primaryKey": "Z",
30 + "secondaryKey": "",
31 + "modifier": "Ctrl"
32 + },
33 + "redo-shortcut": {
34 + "primaryKey": "Y",
35 + "secondaryKey": "",
36 + "modifier": "Ctrl"
37 + },
38 + "delete-shortcut": {
39 + "primaryKey": "Delete",
40 + "secondaryKey": "",
41 + "modifier": ""
42 + },
43 + "cut-shortcut": {
44 + "primaryKey": "X",
45 + "secondaryKey": "",
46 + "modifier": "Ctrl"
47 + },
48 + "copy-shortcut": {
49 + "primaryKey": "C",
50 + "secondaryKey": "",
51 + "modifier": "Ctrl"
52 + },
53 + "paste-shortcut": {
54 + "primaryKey": "V",
55 + "secondaryKey": "",
56 + "modifier": "Ctrl"
57 + },
58 + "find-shortcut": {
59 + "primaryKey": "F",
60 + "secondaryKey": "",
61 + "modifier": "Ctrl"
62 + },
63 + "select-all-text-shortcut": {
64 + "primaryKey": "A",
65 + "secondaryKey": "",
66 + "modifier": "Ctrl"
67 + },
68 + "build-shortcut": {
69 + "primaryKey": "B",
70 + "secondaryKey": "",
71 + "modifier": "Ctrl"
72 + },
73 + "run-shortcut": {
74 + "primaryKey": "F5",
75 + "secondaryKey": "",
76 + "modifier": "Ctrl"
77 + },
78 + "run-no-debug-shortcut": {
79 + "primaryKey": "F5",
80 + "secondaryKey": "",
81 + "modifier": ""
82 + }
83 + }
84 +}
\ No newline at end of file