@setoelkahfi / svara / commits / 5a16608

feat: added open in explorer command

opens file in windows explorer from the tree context menu

mellbacon committed May 29, 2023 at 11:24 UTC 5a1660828dc44bce9e70266904d651269f3162c5
7 files changed +53 -8
src-tauri/Cargo.lock
+22
@@ -1561,6 +1561,16 @@ dependencies = [
1561 "windows-sys 0.42.0",
1562 ]
1563
1564 +[[package]]
1565 +name = "os_pipe"
1566 +version = "1.1.4"
1567 +source = "registry+https://github.com/rust-lang/crates.io-index"
1568 +checksum = "0ae859aa07428ca9a929b936690f8b12dc5f11dd8c6992a18ca93919f28bc177"
1569 +dependencies = [
1570 + "libc",
1571 + "windows-sys 0.48.0",
1572 +]
1573 +
1574 [[package]]
1575 name = "overload"
1576 version = "0.1.1"
@@ -2237,6 +2247,16 @@ dependencies = [
2247 "lazy_static",
2248 ]
2249
2250 +[[package]]
2251 +name = "shared_child"
2252 +version = "1.0.0"
2253 +source = "registry+https://github.com/rust-lang/crates.io-index"
2254 +checksum = "b0d94659ad3c2137fef23ae75b03d5241d633f8acded53d672decfa0e6e0caef"
2255 +dependencies = [
2256 + "libc",
2257 + "winapi",
2258 +]
2259 +
2260 [[package]]
2261 name = "simd-adler32"
2262 version = "0.3.5"
@@ -2466,6 +2486,7 @@ dependencies = [
2486 "objc",
2487 "once_cell",
2488 "open",
2489 + "os_pipe",
2490 "percent-encoding",
2491 "rand 0.8.5",
2492 "raw-window-handle",
@@ -2476,6 +2497,7 @@ dependencies = [
2497 "serde_json",
2498 "serde_repr",
2499 "serialize-to-javascript",
2500 + "shared_child",
2501 "state",
2502 "tar",
2503 "tauri-macros",
src-tauri/Cargo.toml
+1 -1
@@ -15,7 +15,7 @@ tauri-build = { version = "1.2.1", features = [] }
15 [dependencies]
16 serde_json = "1.0"
17 serde = { version = "1.0", features = ["derive"] }
18 -tauri = { version = "1.2.5", features = ["dialog-ask", "dialog-confirm", "dialog-open", "dialog-save", "fs-read-dir", "fs-read-file", "fs-rename-file", "fs-write-file", "path-all", "shell-open", "window-center", "window-close", "window-create", "window-hide", "window-maximize", "window-minimize", "window-print", "window-set-decorations", "window-set-focus", "window-set-fullscreen", "window-set-icon", "window-show", "window-start-dragging", "window-unmaximize", "window-unminimize"] }
18 +tauri = { version = "1.2.5", features = ["dialog-ask", "dialog-confirm", "dialog-open", "dialog-save", "fs-read-dir", "fs-read-file", "fs-rename-file", "fs-write-file", "path-all", "shell-execute", "shell-open", "window-center", "window-close", "window-create", "window-hide", "window-maximize", "window-minimize", "window-print", "window-set-decorations", "window-set-focus", "window-set-fullscreen", "window-set-icon", "window-show", "window-start-dragging", "window-unmaximize", "window-unminimize"] }
19
20 [dev-dependencies]
21 windows = "0.32.0"
src-tauri/tauri.conf.json
+9 -1
@@ -15,7 +15,15 @@
15 "all": false,
16 "shell": {
17 "all": false,
18 - "open": true
18 + "open": true,
19 + "execute": true,
20 + "scope": [
21 + {
22 + "name": "explorer",
23 + "cmd": "explorer",
24 + "args": [{ "validator": "\\S+" }]
25 + }
26 + ]
27 },
28 "fs": {
29 "all": false,
src/lib/File.ts
+10
@@ -2,6 +2,7 @@ import { dialog, fs, path } from "@tauri-apps/api";
2 import { get, writable } from 'svelte/store';
3 import { tabs, addEditorTab } from "./EditorTabList.svelte";
4 import { filetree } from "./FileTree.svelte";
5 +import { Command } from '@tauri-apps/api/shell';
6
7 export async function openFile() {
8 let newPath = await dialog.open() as string;
@@ -116,4 +117,13 @@ export function updateSaveState(saved = true) {
117 tab.saved = false;
118 }
119 tab.setActive(tab.id);
120 +}
121 +
122 +export async function openInExplorer(path) {
123 + const explorer = new Command("explorer", path);
124 + try {
125 + await explorer.spawn();
126 + } catch (error) {
127 + console.error(error);
128 + }
129 }
\ No newline at end of file
src/lib/FileTree.svelte
+7 -3
@@ -2,13 +2,17 @@
2 import FileTreeView from "./FileTree/FileTreeView.svelte";
3 import ContextMenu from "./utility/ContextMenu.svelte";
4 import { addEditorTab } from "./EditorTabList.svelte";
5 - import { openFolder } from "./File";
5 + import { openFolder, openInExplorer } from "./File";
6 let treeDom;
7 let contextmenu = false;
8
9 + let path = null;
10 + let name = null;
11 +
12 function handleClick(e) {
13 treeDom = e.detail.target;
11 - console.log($filetree[0]);
14 + path = $filetree[0].path;
15 + name = $filetree[0].name;
16 contextmenu = e.detail.contextmenu;
17 }
18 function handleSelect(e) {
@@ -19,7 +23,7 @@
23 }
24
25 let contextmenuitems = [
22 - {name: "Open in File Explorer", shortcut: "", action: () => {console.warn("Feature not implemented yet.")}},
26 + {name: "Open in File Explorer", shortcut: "", action: async () => {await openInExplorer(path)}},
27 {name: "Copy", shortcut: "Ctrl + C", action: () => {console.warn("Feature not implemented yet.")}},
28 {name: "Cut", shortcut: "Ctrl + X", action: () => {console.warn("Feature not implemented yet.")}},
29 {name: "Paste", shortcut: "Ctrl + X", disabled: true, action: () => {console.warn("Feature not implemented yet.")}},
src/lib/FileTree/FileTreeList.svelte
+2 -2
@@ -10,7 +10,7 @@
10 import Directory from "../../util/icons/Directory.svelte";
11 import {filetree} from "../FileTree.svelte";
12 import ContextMenu from "../utility/ContextMenu.svelte";
13 - import { moveFile } from "../File";
13 + import { moveFile, openInExplorer } from "../File";
14
15 export let root = false;
16 export let isroot = false;
@@ -30,7 +30,7 @@
30
31 let contextmenu = false;
32 let contextmenuitems = [
33 - {name: "Open in File Explorer", shortcut: "", action: () => {console.warn("Feature not implemented yet.")}},
33 + {name: "Open in File Explorer", shortcut: "", action: async () => {await openInExplorer(path)}},
34 {name: "Copy", shortcut: "Ctrl + C", action: () => {console.warn("Feature not implemented yet.")}},
35 {name: "Cut", shortcut: "Ctrl + X", action: () => {console.warn("Feature not implemented yet.")}},
36 {name: "Paste", shortcut: "Ctrl + X", disabled: true, action: () => {console.warn("Feature not implemented yet.")}},
src/lib/FileTree/FileTreeNode.svelte
+2 -1
@@ -18,6 +18,7 @@
18 import { createEventDispatcher } from "svelte";
19 import File from "../../util/icons/File.svelte";
20 import ContextMenu from "../utility/ContextMenu.svelte";
21 + import { openInExplorer } from "../File";
22
23 export let id;
24 export let name;
@@ -31,7 +32,7 @@
32
33 let contextmenu = false;
34 let contextmenuitems = [
34 - {name: "Open in File Explorer", shortcut: "", action: () => {console.warn("Feature not implemented yet.")}},
35 + {name: "Open in File Explorer", shortcut: "", action: async () => {await openInExplorer(path)}},
36 {name: "Copy", shortcut: "Ctrl + C", action: () => {console.warn("Feature not implemented yet.")}},
37 {name: "Cut", shortcut: "Ctrl + X", action: () => {console.warn("Feature not implemented yet.")}},
38 {name: "Copy Filename", shortcut: "", action: () => {console.warn("Feature not implemented yet.")}},