feat: file tree opens when new folder loads
mellbacon committed
Aug 1, 2023 at 15:56 UTC
1e6047944042c52e7ab642c911d143c5a4e67feb
2 files changed
+16
-5
src/lib/File.ts
+2
@@ -3,6 +3,7 @@ import { get, writable } from 'svelte/store';
3
import { tabs, addEditorTab, renameTab } from "./EditorTabList.svelte";
4
import { filetree } from "./FileTree.svelte";
5
import { watch } from "tauri-plugin-fs-watch-api";
6
+import { openFileTree } from "./Sidebar.svelte";
7
8
export async function openFile() {
9
let newPath = await dialog.open() as string;
@@ -37,6 +38,7 @@ export async function openFolder() {
38
)
39
40
workspaceName.set(directoryName);
41
+ openFileTree();
42
}
43
44
export const treeLoading = writable(false);
src/lib/Sidebar.svelte
+14
-5
@@ -3,13 +3,10 @@
3
import SidebarTab from "./SidebarTab.svelte";
4
import FileTree from "./FileTree.svelte";
5
6
- export let tabs = [
7
- {id: 0, tabname: "Explorer", icon: Folder, content: FileTree}
8
- ];
6
</script>
7
8
<div id="sidebar">
12
- {#each tabs as tab}
9
+ {#each $sidebartabs as tab}
10
<SidebarTab id={`tool-${tab.id}`} active={$activeid === tab.id} label={tab.tabname} on:click={() => {toggleActive(tab)}}>
11
<svelte:component this={tab.icon}/>
12
</SidebarTab>
@@ -19,7 +16,7 @@
16
</div>
17
18
<script lang="ts" context="module">
22
- import { writable } from "svelte/store";
19
+ import { writable, get } from "svelte/store";
20
class Tool {
21
tabname: string;
22
content;
@@ -29,6 +26,8 @@
26
}
27
}
28
29
+ const sidebartabs = writable([{id: 0, tabname: "Explorer", icon: Folder, content: FileTree}]);
30
+
31
export let activeid = writable(-1);
32
let active = -1;
33
export let showsidebarview = writable(false);
@@ -47,6 +46,16 @@
46
tool.set(new Tool(tab.tabname, tab.content));
47
}
48
}
49
+
50
+ export function openFileTree() {
51
+ const tab = get(sidebartabs)[0];
52
+ if (active === tab.id) return;
53
+
54
+ activeid.set(tab.id);
55
+ active = tab.id;
56
+ showsidebarview.set(true);
57
+ tool.set(new Tool(tab.tabname, tab.content));
58
+ }
59
</script>
60
61
<style lang="scss">