Skip to content

Commit 42ef20b

Browse files
committed
Make "Add File" button work
1 parent 3562965 commit 42ef20b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

app.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,17 @@ func (a *App) PickFolder() string {
257257
return path
258258
}
259259

260+
func (a *App) PickTomlFile() string {
261+
path, err := zenity.SelectFile(zenity.FileFilter{
262+
Name: ".toml files",
263+
Patterns: []string{"*.toml"},
264+
})
265+
if err != nil {
266+
println("ERR: File picker failed")
267+
}
268+
return path
269+
}
270+
260271
func (a *App) ShowPathInExplorer(path string) error {
261272
fileInfo, err := os.Stat(path)
262273
if err != nil {

frontend/src/components/PathsViewer.svelte

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ function addFolder() {
6868
});
6969
}
7070
71+
function addFile() {
72+
App.PickTomlFile().then((result) => {
73+
if (result) {
74+
if (paths.some((x) => x.installPath === result)) {
75+
toast.error("Path already added");
76+
return;
77+
}
78+
79+
paths.push({
80+
installPath: result,
81+
repo: null,
82+
tagName: null,
83+
visible: true,
84+
});
85+
}
86+
});
87+
}
88+
7189
function confirmAddBotpack() {
7290
if (!installPath) {
7391
toast.error("Install path cannot be blank");
@@ -120,14 +138,14 @@ function confirmAddBotpack() {
120138
<div class="paths">
121139
<div class="button-row">
122140
<button onclick={addFolder}>Add folder</button>
123-
<button onclick={alert.bind(null, "TODO: not implemented yet")}>Add File</button>
141+
<button onclick={addFile}>Add File</button>
124142
<button onclick={openAddBotpackModal}>Add Botpack</button>
125143
</div>
126144

127145
{#each paths as path, i}
128146
<div class="path">
129-
<Switch bind:checked={path.visible} />
130147
<pre>{path.repo ? `${path.repo} @ ${path.installPath}` : path.installPath}</pre>
148+
<div><Switch bind:checked={path.visible} /></div>
131149
<button class="close" onclick={() => removePath(i)}>
132150
<img src={closeIcon} alt="X" />
133151
</button>
@@ -186,6 +204,9 @@ function confirmAddBotpack() {
186204
gap: 1rem;
187205
justify-content: space-between;
188206
}
207+
.path div {
208+
margin-left: auto;
209+
}
189210
.path pre {
190211
font-size: 1rem;
191212
margin: 0px;

0 commit comments

Comments
 (0)