From 9856635d8b07c1ecac01533b077bd07d5d5a3e56 Mon Sep 17 00:00:00 2001 From: Bruce Thompson Date: Fri, 18 Oct 2024 19:31:59 -0600 Subject: [PATCH 1/3] Fix for https://github.com/fyne-io/fyne/issues/5207 --- dialog/file.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dialog/file.go b/dialog/file.go index b0441067c5..69269efb73 100644 --- a/dialog/file.go +++ b/dialog/file.go @@ -474,8 +474,11 @@ func (f *fileDialog) setLocation(dir fyne.URI) error { d = buildDir buildDir = d + string(os.PathSeparator) } - - newDir := storage.NewFileURI(buildDir) + newURL := dir.Scheme() + "://" + filepath.ToSlash(buildDir) + newDir, err := storage.ParseURI(newURL) + if err != nil { + return err + } isDir, err := storage.CanList(newDir) if err != nil { return err From 89531664c19c855dc17809718f57e30605db275a Mon Sep 17 00:00:00 2001 From: Bruce Thompson Date: Sat, 19 Oct 2024 06:57:54 -0600 Subject: [PATCH 2/3] Fixed path manipulation to be for RFC 3986 path --- dialog/file.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dialog/file.go b/dialog/file.go index 69269efb73..86f27d578b 100644 --- a/dialog/file.go +++ b/dialog/file.go @@ -469,12 +469,12 @@ func (f *fileDialog) setLocation(dir fyne.URI) error { buildDir = "/" d = "/" } else if i > 0 { - buildDir = filepath.Join(buildDir, d) + buildDir = buildDir + "/" + d } else { d = buildDir - buildDir = d + string(os.PathSeparator) + buildDir = d + "/" } - newURL := dir.Scheme() + "://" + filepath.ToSlash(buildDir) + newURL := dir.Scheme() + "://" + buildDir newDir, err := storage.ParseURI(newURL) if err != nil { return err From 5bd17a90397ca5602896b71fae75bcac6794dcd6 Mon Sep 17 00:00:00 2001 From: Bruce Thompson Date: Sat, 19 Oct 2024 09:13:17 -0600 Subject: [PATCH 3/3] Fixes for non "file" repositories" --- dialog/file.go | 88 ++++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/dialog/file.go b/dialog/file.go index 86f27d578b..e25b219316 100644 --- a/dialog/file.go +++ b/dialog/file.go @@ -176,29 +176,36 @@ func (f *fileDialog) makeUI() fyne.CanvasObject { } }) f.setView(view) - - f.loadFavorites() - - f.favoritesList = widget.NewList( - func() int { - return len(f.favorites) - }, - func() fyne.CanvasObject { - return container.NewHBox(container.New(&iconPaddingLayout{}, widget.NewIcon(theme.DocumentIcon())), widget.NewLabel("Template Object")) - }, - func(id widget.ListItemID, item fyne.CanvasObject) { - item.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Icon).SetResource(f.favorites[id].locIcon) - item.(*fyne.Container).Objects[1].(*widget.Label).SetText(f.favorites[id].locName) - }, - ) - f.favoritesList.OnSelected = func(id widget.ListItemID) { - f.setLocation(f.favorites[id].loc) + fileinfo := f.file + createFavorites := true + if fileinfo.startingLocation != nil { + if fileinfo.startingLocation.Scheme() != "file" { + createFavorites = false + } } - var optionsButton *widget.Button - optionsButton = widget.NewButtonWithIcon("", theme.SettingsIcon(), func() { - f.optionsMenu(fyne.CurrentApp().Driver().AbsolutePositionForObject(optionsButton), optionsButton.Size()) - }) + if createFavorites { + f.loadFavorites() + + f.favoritesList = widget.NewList( + func() int { + return len(f.favorites) + }, + func() fyne.CanvasObject { + return container.NewHBox(container.New(&iconPaddingLayout{}, widget.NewIcon(theme.DocumentIcon())), widget.NewLabel("Template Object")) + }, + func(id widget.ListItemID, item fyne.CanvasObject) { + item.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Icon).SetResource(f.favorites[id].locIcon) + item.(*fyne.Container).Objects[1].(*widget.Label).SetText(f.favorites[id].locName) + }, + ) + f.favoritesList.OnSelected = func(id widget.ListItemID) { + f.setLocation(f.favorites[id].loc) + } + optionsButton = widget.NewButtonWithIcon("", theme.SettingsIcon(), func() { + f.optionsMenu(fyne.CurrentApp().Driver().AbsolutePositionForObject(optionsButton), optionsButton.Size()) + }) + } newFolderButton := widget.NewButtonWithIcon("", theme.FolderNewIcon(), func() { newFolderEntry := widget.NewEntry() @@ -224,12 +231,17 @@ func (f *fileDialog) makeUI() fyne.CanvasObject { f.refreshDir(f.dir) }, f.file.parent) }) - - optionsbuttons := container.NewHBox( - newFolderButton, - f.toggleViewButton, - optionsButton, - ) + var optionsbuttons *fyne.Container + if optionsButton != nil { + optionsbuttons = container.NewHBox( + newFolderButton, + f.toggleViewButton, + optionsButton) + } else { + optionsbuttons = container.NewHBox( + newFolderButton, + f.toggleViewButton) + } header := container.NewBorder(nil, nil, nil, optionsbuttons, optionsbuttons, widget.NewLabelWithStyle(title, fyne.TextAlignLeading, fyne.TextStyle{Bold: true}), @@ -238,16 +250,16 @@ func (f *fileDialog) makeUI() fyne.CanvasObject { footer := container.NewBorder(nil, nil, nil, buttons, buttons, container.NewHScroll(f.fileName), ) - - body := container.NewHSplit( - f.favoritesList, - container.NewBorder(f.breadcrumbScroll, nil, nil, nil, - f.breadcrumbScroll, f.filesScroll, - ), + fileList := container.NewBorder(f.breadcrumbScroll, nil, nil, nil, + f.breadcrumbScroll, f.filesScroll, ) - body.SetOffset(0) // Set the minimum offset so that the favoritesList takes only it's minimal width - - return container.NewBorder(header, footer, nil, nil, body) + if f.favoritesList != nil { + body := container.NewHSplit(f.favoritesList, fileList) + body.SetOffset(0) // Set the minimum offset so that the favoritesList takes only it's minimal width + return container.NewBorder(header, footer, nil, nil, body) + } else { + return container.NewBorder(header, footer, nil, nil, fileList) + } } func (f *fileDialog) makeOpenButton(label string) *widget.Button { @@ -443,13 +455,13 @@ func (f *fileDialog) setLocation(dir fyne.URI) error { if fav.loc == nil { continue } - if fav.loc.Path() == dir.Path() { + if (fav.loc.Path() == dir.Path()) && (f.favoritesList != nil) { f.favoritesList.Select(i) isFav = true break } } - if !isFav { + if !isFav && (f.favoritesList != nil) { f.favoritesList.UnselectAll() }