@setoelkahfi / svara / commits / 158df41

chore: refactored modal logic

Signed-off-by: mellobacon <mellodev@outlook.com>

mellobacon committed Jan 19, 2024 at 17:34 UTC 158df41ce5ab91bc9305a07a69a73c03ccc87901
3 files changed +41 -34
src/config/commands.ts
+28 -4
@@ -1,7 +1,7 @@
1 -import { fs } from "@tauri-apps/api";
2 -import { openRenameModal } from "../App.svelte";
1 +import { fs, path as p } from "@tauri-apps/api";
2 +import { openInputModal, openRenameModal } from "../App.svelte";
3 import { addEditorTab, closeAllTabs } from "../lib/EditorTabList.svelte";
4 -import { saveFile, openFile, openFolder, openInExplorer, renameFile } from "../lib/File";
4 +import { saveFile, openFile, openFolder, openInExplorer, renameFile, createFolder, createFile } from "../lib/File";
5 import { appWindow } from "@tauri-apps/api/window";
6 import { info, warn } from "tauri-plugin-log-api";
7
@@ -197,12 +197,36 @@ export const commands = {
197 `Give a new name to ${filename}`,
198 [
199 {name: "Rename", action: async (name) => {await renameFile(name, oldpath)}},
200 - {name: "Cancel", cancel: true, action: () => {}}
200 + {name: "Cancel", cancel: true, style: "danger", action: () => {}}
201 ],
202 oldpath
203 )
204 }
205 },
206 + "createFolder": {
207 + "keybind": "",
208 + "command": (path) => {
209 + openInputModal("Create New Folder",
210 + `Create a new folder in ${path}`,
211 + [
212 + {name: "Create Folder", action: async (name) => { await createFolder(`${path}${p.sep}${name}`)}},
213 + {name: "Cancel", cancel: true, action: () => {}}
214 + ],
215 + {label: "Folder Name"}, path)
216 + }
217 + },
218 + "createFile": {
219 + "keybind": "",
220 + "command": (path) => {
221 + openInputModal("Create New File",
222 + `Create a new file in ${path}`,
223 + [
224 + {name: "Create File", action: (name) => {createFile(`${path}${p.sep}${name}`)}},
225 + {name: "Cancel", cancel: true, action: () => {}}
226 + ],
227 + {label: "File Name"}, path)
228 + }
229 + },
230 "openInExplorer": {
231 "keybind": "",
232 "command": async (path) => {
src/lib/FileTree.svelte
+9 -16
@@ -2,9 +2,10 @@
2 import FileTreeView from "./FileTree/FileTreeView.svelte";
3 import ContextMenu from "./utility/ContextMenu.svelte";
4 import { addEditorTab } from "./EditorTabList.svelte";
5 - import { openFolder, openInExplorer, createFile, createFolder } from "./File";
6 - import { clipboard, path as p } from "@tauri-apps/api";
7 - import { openInputModal } from "../App.svelte";
5 + import { openFolder } from "./File";
6 + import { clipboard } from "@tauri-apps/api";
7 + import Button from "./utility/Button.svelte";
8 + import { commands } from "../config/commands";
9
10 let treeDom;
11 let contextmenu = false;
@@ -26,17 +27,9 @@
27 }
28
29 let contextmenuitems = [
29 - {name: "Open in File Explorer", shortcut: "", action: async () => {await openInExplorer(path)}},
30 - {name: "New Folder...", shortcut: "", action: () => {openInputModal("Create New Folder",
31 - `Create a new folder in ${path}`, [
32 - {name: "Create Folder", action: async (name) => { await createFolder(`${path}${p.sep}${name}`)}},
33 - {name: "Cancel", cancel: true, action: () => {}}
34 - ], {label: "Folder Name"}, path)}},
35 - {name: "New File...", shortcut: "", action: () => {openInputModal("Create New File",
36 - `Create a new file in ${path}`, [
37 - {name: "Create File", action: (name) => {createFile(`${path}${p.sep}${name}`)}},
38 - {name: "Cancel", cancel: true, action: () => {}}
39 - ], {label: "File Name"}, path)}},
30 + {name: "Open in File Explorer", shortcut: "", action: async () => commands.openInExplorer.command(path)},
31 + {name: "New Folder...", shortcut: "", action: () => commands.createFolder.command(path)},
32 + {name: "New File...", shortcut: "", action: () => {commands.createFile.command(path)}},
33 {name: "Copy", shortcut: "Ctrl + C", action: () => {console.warn("Feature not implemented yet.")}},
34 {name: "Cut", disabled: true, shortcut: "Ctrl + X", action: () => {console.warn("Feature not implemented yet.")}},
35 {name: "Paste", shortcut: "Ctrl + X", disabled: true, action: () => {console.warn("Feature not implemented yet.")}},
@@ -56,7 +49,7 @@
49 {#if $filetree.length === 0}
50 <div class="container">
51 <span>No folder/workspace open</span>
59 - <button class="toolbar-button" on:click={async () => {await openFolder()}}>Open Folder</button>
52 + <Button _class="toolbar-button" style="secondary" label="Open Folder" on:click={async () => {await openFolder()}} />
53 </div>
54 {:else}
55 <FileTreeView tree={$filetree} on:nodeselect={handleSelect} on:dblnodeselect={handleDblSelect} on:rightclick={handleClick} contextMenuEnabled canDrag></FileTreeView>
@@ -68,7 +61,7 @@
61
62
63 <style lang="scss">
71 - .toolbar-button {
64 + :global(.toolbar-button) {
65 font-family: inherit;
66 text-align: center;
67 padding: 7px 30px;
src/lib/FileTree/FileTreeList.svelte
+4 -14
@@ -10,10 +10,8 @@
10 import Directory from "../../util/icons/Directory.svelte";
11 import {filetree} from "../FileTree.svelte";
12 import ContextMenu from "../utility/ContextMenu.svelte";
13 - import { createFile, createFolder, moveFile, moveToTrash } from "../File";
13 + import { moveFile, moveToTrash } from "../File";
14 import { clipboard } from "@tauri-apps/api";
15 - import { openInputModal } from "../../App.svelte";
16 - import { path as p } from "@tauri-apps/api";
15 import { onMount } from "svelte";
16 import { commands } from "../../config/commands";
17
@@ -39,17 +37,9 @@
37
38 let contextmenu = false;
39 let contextmenuitems = [
42 - {name: "Open in File Explorer", shortcut: commands.openInExplorer.keybind, action: async () => {commands.openInExplorer.command(path)}},
43 - {name: "New Folder...", shortcut: "", action: () => {openInputModal("Create New Folder",
44 - `Create a new folder in ${path}`, [
45 - {name: "Create Folder", action: async (name) => { await createFolder(`${path}${p.sep}${name}`)}},
46 - {name: "Cancel", cancel: true, action: () => {}}
47 - ], {label: "Folder Name"}, path)}},
48 - {name: "New File...", shortcut: "", action: () => {openInputModal("Create New File",
49 - `Create a new file in ${path}`, [
50 - {name: "Create File", action: (name) => {createFile(`${path}${p.sep}${name}`)}},
51 - {name: "Cancel", cancel: true, action: () => {}}
52 - ], {label: "File Name"}, path)}},
40 + {name: "Open in File Explorer", shortcut: commands.openInExplorer.keybind, action: async () => commands.openInExplorer.command(path)},
41 + {name: "New Folder...", shortcut: "", action: () => commands.createFolder.command(path)},
42 + {name: "New File...", shortcut: "", action: () => commands.createFile.command(path)},
43 {name: "Copy", shortcut: "Ctrl + C", action: () => {console.warn("Feature not implemented yet.")}},
44 {name: "Cut", disabled: isroot, shortcut: "Ctrl + X", action: () => {console.warn("Feature not implemented yet.")}},
45 {name: "Paste", shortcut: "Ctrl + X", disabled: true, action: () => {console.warn("Feature not implemented yet.")}},