package ui import ( "path/filepath" "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/widget" ) // CustomFileSelector displays a custom file selection dialog func CustomFileSelector(window fyne.Window, setText func(string)) { // Get list of files in current directory files, _ := filepath.Glob("*") // Create list widget with files fileList := widget.NewList( func() int { return len(files) }, func() fyne.CanvasObject { return widget.NewLabel("File") }, func(id widget.ListItemID, obj fyne.CanvasObject) { obj.(*widget.Label).SetText(files[id]) }, ) // Set selection handler fileList.OnSelected = func(id widget.ListItemID) { setText(files[id]) // Set the selected path in the text field } // Create dialog title title := widget.NewLabel("Files in current directory:") title.Alignment = fyne.TextAlignCenter // Create layout with title and file list content := container.NewBorder( title, nil, nil, nil, // Title at the top container.NewMax(fileList), // List takes maximum space ) // Create and show dialog fileDialog := dialog.NewCustom("Select a file", "Close", content, window) fileDialog.Resize(fyne.NewSize(400, 500)) // Set dialog size fileDialog.Show() }