opening file through file tree
mellbacon committed
Aug 23, 2022 at 13:22 UTC
405b83db7d8a5e41c6eb6ada3e2bc06bdf5b6c89
5 files changed
+11
-9
src/components/Content/Editor/EditorTabs.svelte
+1
-1
@@ -18,7 +18,7 @@
18
19
<div id="editor-tabs" bind:this={tabcontainer} class:hidden={$hidden}>
20
{#each $tabs as tab}
21
- <Tab label={tab.label} active={tab.active} id={tab.id} />
21
+ <Tab label={tab.label} path={tab.path} active={tab.active} id={tab.id} />
22
{/each}
23
</div>
24
src/components/Content/Editor/Tabs.ts
+3
-3
@@ -36,8 +36,8 @@ class Tab {
36
let id = 0;
37
let activeid;
38
let tablist: Tab[] = [];
39
-export async function addTab() {
40
- let file = await loadFile();
39
+export async function addTab(f) {
40
+ let file = await loadFile(f);
41
let editor = new CodeMirrorEditor({ target: document.getElementById("tabview"), props: { content: file.content } });
42
let tab = new Tab(id, file.filename, file.path, editor, file.content);
43
tablist = [...tablist, tab];
@@ -69,7 +69,7 @@ function updateEditorVisibility() {
69
}
70
}
71
72
-export function closeTab(id) {
72
+export function closeTab(id: number) {
73
tablist[id].editor.$destroy();
74
tablist = tablist.filter(t => t.id !== id);
75
tabs.set(tablist);
src/components/FileTree/TreeData.ts
+1
-2
@@ -21,8 +21,7 @@ class File {
21
this.content = content;
22
}
23
}
24
-export async function loadFile() {
25
- let file = await dialog.open() as string;
24
+export async function loadFile(file: string) {
25
if (file === null) return;
26
let filename = file.split(sep).pop();
27
let content = await readTextFile(file);
src/components/FileTree/TreeViewNode.svelte
+3
-2
@@ -41,6 +41,7 @@
41
export let icon = undefined;
42
43
import { afterUpdate, getContext } from "svelte";
44
+ import { addTab } from "../Content/Editor/Tabs";
45
import RenameModel from "../Modal/RenameModel.svelte";
46
import LeafNodeMenu from "./LeafNodeMenu.svelte";
47
@@ -88,8 +89,8 @@
89
if (disabled) return;
90
clickNode(node);
91
}}
91
- on:dblclick={() => {
92
- console.log(path);
92
+ on:dblclick={async () => {
93
+ await addTab(path);
94
}}
95
on:keydown={(e) => {
96
if (
src/components/Menu/menu.ts
+3
-1
@@ -1,10 +1,12 @@
1
import { filetree, workspacename } from "../FileTree/TreeStore";
2
import { data, workspace } from "../FileTree/TreeData";
3
import { addTab } from "../Content/Editor/Tabs";
4
+import { dialog } from "@tauri-apps/api";
5
export const filemenu = [
6
{ option: "New File...", shortcut: "Ctrl + N", onclick: async () => { console.log("click"); } },
7
{ option: "Open File...", shortcut: "Ctrl + O", onclick: async () => {
7
- await addTab();
8
+ let f = await dialog.open() as string;
9
+ await addTab(f);
10
} },
11
{ option: "Open Folder", shortcut: "Ctrl + K", onclick: async () => {
12
let treedata = await data();