diff --git a/dialog/file.go b/dialog/file.go index cd1edb39c0..dec134e779 100644 --- a/dialog/file.go +++ b/dialog/file.go @@ -533,7 +533,14 @@ func (f *fileDialog) setSelected(file fyne.URI, id int) { func (f *fileDialog) setView(view ViewLayout) { f.view = view fyne.CurrentApp().Preferences().SetInt(viewLayoutKey, int(view)) - + var selectF func(id int) + choose := func(id int) { + selectF(id) + if file, ok := f.getDataItem(id); ok { + f.selectedID = id + f.setSelected(file, id) + } + } count := func() int { f.dataLock.RLock() defer f.dataLock.RUnlock() @@ -548,25 +555,25 @@ func (f *fileDialog) setView(view ViewLayout) { parent := id == 0 && len(dir.Path()) < len(f.dir.Path()) _, isDir := dir.(fyne.ListableURI) o.(*fileDialogItem).setLocation(dir, isDir || parent, parent) + o.(*fileDialogItem).choose = choose + o.(*fileDialogItem).id = id + o.(*fileDialogItem).open = f.open.OnTapped } } - choose := func(id int) { - if file, ok := f.getDataItem(id); ok { - f.selectedID = id - f.setSelected(file, id) - } - } - + // Actually, during the real interaction, the OnSelected won't be called. + // It will be called only when we directly calls container.select(i) if f.view == GridView { grid := widget.NewGridWrap(count, template, update) grid.OnSelected = choose f.files = grid f.toggleViewButton.SetIcon(theme.ListIcon()) + selectF = grid.Select } else { list := widget.NewList(count, template, update) list.OnSelected = choose f.files = list f.toggleViewButton.SetIcon(theme.GridIcon()) + selectF = list.Select } if f.dir != nil { diff --git a/dialog/fileitem.go b/dialog/fileitem.go index a915bd2f24..1cd9d9620f 100644 --- a/dialog/fileitem.go +++ b/dialog/fileitem.go @@ -2,6 +2,7 @@ package dialog import ( "path/filepath" + "time" "fyne.io/fyne/v2" "fyne.io/fyne/v2/lang" @@ -20,8 +21,13 @@ type fileDialogItem struct { picker *fileDialog name string + id int // id in the parent container + choose func(id int) + open func() location fyne.URI dir bool + + lastClick time.Time } func (i *fileDialogItem) CreateRenderer() fyne.WidgetRenderer { @@ -56,6 +62,18 @@ func (i *fileDialogItem) setLocation(l fyne.URI, dir, up bool) { i.Refresh() } +func (i *fileDialogItem) Tapped(*fyne.PointEvent) { + if i.choose != nil { + i.choose(i.id) + } + now := time.Now() + if !i.dir && now.Sub(i.lastClick) < fyne.CurrentApp().Driver().DoubleTapDelay() && i.open != nil { + // It is a double click, so we ask the dialog to open + i.open() + } + i.lastClick = now +} + func (f *fileDialog) newFileItem(location fyne.URI, dir, up bool) *fileDialogItem { item := &fileDialogItem{ picker: f,