@setoelkahfi / svara / commits / 0634f25

chore: replaced some functions with commands

mellbacon committed Aug 28, 2023 at 19:12 UTC 0634f2505a11826403941d33b4ba8a8f06e6b4b1
4 files changed +45 -17
src/config/commands.ts
+34 -3
@@ -1,6 +1,7 @@
1 +import { openRenameModal } from "../App.svelte";
2 import { append, copy, cut, deleteChars, redoChange, undoChange } from "../lib/Editor.svelte";
2 -import { addEditorTab } from "../lib/EditorTabList.svelte";
3 -import { saveFile, openFile, openFolder } from "../lib/File";
3 +import { addEditorTab, closeActiveTab, closeAllTabs } from "../lib/EditorTabList.svelte";
4 +import { saveFile, openFile, openFolder, openInExplorer, renameFile } from "../lib/File";
5 import { appWindow } from "@tauri-apps/api/window";
6
7 export const commands = {
@@ -115,7 +116,7 @@ export const commands = {
116 },
117 "fullscreen": {
118 "keybind": "F11",
118 - "disabled": "true",
119 + //"disabled": "true",
120 "command": async () => {
121 if (await appWindow.isFullscreen()) {
122 appWindow.setFullscreen(false);
@@ -174,6 +175,36 @@ export const commands = {
175 "command": async () => {
176 await appWindow.close();
177 }
178 + },
179 + "closeTab": {
180 + "keybind": "Control+F4",
181 + "command": () => {
182 + closeActiveTab();
183 + }
184 + },
185 + "closeAllTabs": {
186 + "keybind": "",
187 + "command": () => {
188 + closeAllTabs();
189 + }
190 + },
191 + "renameFile": {
192 + "keybind": "F2",
193 + "command": (filename, oldpath) => {
194 + if (!oldpath || oldpath === "") return;
195 + openRenameModal(`Rename ${filename}`,
196 + `Give a new name to ${filename}`, [
197 + {name: "Rename", action: async () => {await renameFile(filename, oldpath)}},
198 + {name: "Cancel", action: () => {}}
199 + ])
200 + }
201 + },
202 + "openInExplorer": {
203 + "keybind": "",
204 + "command": (path) => {
205 + if (!path || path === "") return;
206 + openInExplorer(path);
207 + }
208 }
209 }
210
src/lib/FileTree/FileTreeList.svelte
+3 -6
@@ -15,6 +15,7 @@
15 import { openInputModal, openRenameModal } from "../../App.svelte";
16 import { path as p } from "@tauri-apps/api";
17 import { onMount } from "svelte";
18 + import { commands } from "../../config/commands";
19
20 export let root = false;
21 export let isroot = false;
@@ -37,7 +38,7 @@
38
39 let contextmenu = false;
40 let contextmenuitems = [
40 - {name: "Open in File Explorer", shortcut: "", action: async () => {await openInExplorer(path)}},
41 + {name: "Open in File Explorer", shortcut: commands.openInExplorer.keybind, action: async () => {commands.openInExplorer.command(path)}},
42 {name: "New Folder...", shortcut: "", action: () => {openInputModal("Create New Folder",
43 `Create a new folder in ${path}`, [
44 {name: "Create Folder", action: async (name) => { await createFolder(`${path}${p.sep}${name}`)}},
@@ -53,11 +54,7 @@
54 {name: "Paste", shortcut: "Ctrl + X", disabled: true, action: () => {console.warn("Feature not implemented yet.")}},
55 {name: "Copy Filename", shortcut: "", action: async () => {await clipboard.writeText(name)}},
56 {name: "Copy Absolute Path", shortcut: "", action: async () => {await clipboard.writeText(path)}},
56 - {name: "Rename...", shortcut: "F2", action: () => {openRenameModal(`Rename ${name}`,
57 - `Give a new name to ${name}/`, [
58 - {name: "Rename", action: async (filename) => {await renameFile(filename, path)}},
59 - {name: "Cancel", action: () => {}}
60 - ])}},
57 + {name: "Rename...", shortcut: commands.renameFile.keybind, action: () => {commands.renameFile.command(name, path)}},
58 {name: "Delete", disabled: isroot, shortcut: "Delete", action: async () => {await moveToTrash(path)}}
59 ]
60
src/lib/FileTree/FileTreeNode.svelte
+3 -7
@@ -21,7 +21,7 @@
21 import { moveToTrash, openInExplorer, renameFile } from "../File";
22 import { addEditorTab } from "../EditorTabList.svelte";
23 import { clipboard } from "@tauri-apps/api";
24 - import { openRenameModal } from "../../App.svelte";
24 + import { commands } from "../../config/commands";
25
26 export let id;
27 export let name;
@@ -37,17 +37,13 @@
37
38 let contextmenu = false;
39 let contextmenuitems = [
40 - {name: "Open in File Explorer", shortcut: "", action: async () => {await openInExplorer(path)}},
40 + {name: "Open in File Explorer", shortcut: commands.openInExplorer.keybind, action: async () => {commands.openInExplorer.command(path)}},
41 {name: "Copy", shortcut: "Ctrl + C", action: () => {console.warn("Feature not implemented yet.")}},
42 {name: "Cut", shortcut: "Ctrl + X", action: () => {console.warn("Feature not implemented yet.")}},
43 {name: "Copy Filename", shortcut: "", action: async () => {await clipboard.writeText(name)}},
44 {name: "Copy Absolute Path", shortcut: "", action: async () => {await clipboard.writeText(path)}},
45 {name: "Edit", shortcut: "", action: () => {addEditorTab(path, name)}},
46 - {name: "Rename...", shortcut: "F2", action: () => {openRenameModal(`Rename ${name}`,
47 - `Give a new name to ${name}`, [
48 - {name: "Rename", action: async (filename) => {await renameFile(filename, path)}},
49 - {name: "Cancel", action: () => {}}
50 - ])}},
46 + {name: "Rename...", shortcut: commands.renameFile.keybind, action: () => {commands.renameFile.command(name, path)}},
47 {name: "Delete", shortcut: "Delete", action: async () => {await moveToTrash(path)}}
48 ]
49
src/lib/utility/ContextMenu.svelte
+5 -1
@@ -54,8 +54,12 @@
54 }
55 </script>
56
57 -<svelte:window on:contextmenu|preventDefault on:mousedown={(e) => {
57 +<svelte:window on:contextmenu|preventDefault on:click={(e) => {
58 menuOpen = false;
59 +}} on:mouseup={(e) => {
60 + if (e.button === 2) {
61 + menuOpen = false;
62 + }
63 }}></svelte:window>
64
65 {#if menuOpen}