Skip to content

Commit

Permalink
fix: Path picker bug on cancel
Browse files Browse the repository at this point in the history
Elias-Gill committed Jan 5, 2024

Verified

This commit was signed with the committer’s verified signature.
lobis Luis Antonio Obis Aparicio
1 parent ff7e2a9 commit b50e67a
Showing 2 changed files with 18 additions and 11 deletions.
16 changes: 10 additions & 6 deletions gui/components/dialogs/path_Picker.go
Original file line number Diff line number Diff line change
@@ -3,17 +3,21 @@ package dialogs
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/dialog"
"github.com/elias-gill/walldo-in-go/globals"
)

// generates and show a new path picker from the file system.
func NewPathPicker(win fyne.Window, callback func(string)) {
dialog.NewFolderOpen(func(uri fyne.ListableURI, err error) {
picker := dialog.NewFolderOpen(func(uri fyne.ListableURI, err error) {
if err != nil {
panic("Error picking the file" + err.Error())
} else if uri == nil {
callback("")
} else {
callback(uri.Path())
}
}, win).Show()

if uri != nil {
callback(uri.Path())
}
}, win)

picker.Resize(fyne.NewSize(globals.Window.Canvas().Size().Width, globals.Window.Canvas().Size().Height))
picker.Show()
}
13 changes: 8 additions & 5 deletions gui/components/dialogs/settings_Window.go
Original file line number Diff line number Diff line change
@@ -56,25 +56,28 @@ func ConfigWindow(win *fyne.Window, app fyne.App, refresh func()) {
pathInput.SetPlaceHolder(`C:/User/user/fondos`)
pathInput.OnSubmitted = func(t string) {
data = append(data, t)
pathInput.Text = ""
pathInput.SetText("")

pathInput.Refresh()
pathsList.Refresh()
}
pathInput.Resize(fyne.NewSize(200, 500))

// open the file explorer to select a folder
pathPickerButton := widget.NewButton("+", func() {
NewPathPicker(*win, func(s string) {
pathInput.Text = s
pathPickerButton := widget.NewButton("Open explorer", func() {
NewPathPicker(*win, func(path string) {
data = append(data, path)
pathInput.SetText("")
pathInput.Refresh()
pathsList.Refresh()
})
})

// Window content
cont := []*widget.FormItem{
widget.NewFormItem("Images size", sizeSelector),
widget.NewFormItem("", container.NewBorder(container.NewMax(pathInput), nil, nil, container.NewHBox(pathPickerButton))),
widget.NewFormItem("", pathInput),
widget.NewFormItem("", pathPickerButton),
widget.NewFormItem("", container.NewMax(pathsList)),
}

0 comments on commit b50e67a

Please sign in to comment.