Skip to content

Commit

Permalink
allow to set a custom title for the FileDialog
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Thienel <[email protected]>
  • Loading branch information
ftl committed Dec 2, 2024
1 parent 55a6e1d commit 46626e4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions dialog/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type fileDialogPanel interface {
type fileDialog struct {
file *FileDialog
fileName textWidget
title *widget.Label
dismiss *widget.Button
open *widget.Button
breadcrumb *fyne.Container
Expand Down Expand Up @@ -87,6 +88,7 @@ type FileDialog struct {
parent fyne.Window
dialog *fileDialog

titleText string
confirmText, dismissText string
desiredSize fyne.Size
filter storage.FileFilter
Expand Down Expand Up @@ -153,6 +155,10 @@ func (f *fileDialog) makeUI() fyne.CanvasObject {
if f.file.isDirectory() {
title = label + " " + lang.L("Folder")
}
if f.file.titleText != "" {
title = f.file.titleText
}
f.title = widget.NewLabelWithStyle(title, fyne.TextAlignLeading, fyne.TextStyle{Bold: true})

view := ViewLayout(fyne.CurrentApp().Preferences().Int(viewLayoutKey))

Expand Down Expand Up @@ -234,9 +240,7 @@ func (f *fileDialog) makeUI() fyne.CanvasObject {
optionsButton,
)

header := container.NewBorder(nil, nil, nil, optionsbuttons,
optionsbuttons, widget.NewLabelWithStyle(title, fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
)
header := container.NewBorder(nil, nil, nil, optionsbuttons, optionsbuttons, f.title)

footer := container.NewBorder(nil, nil, nil, buttons,
buttons, container.NewHScroll(f.fileName),
Expand Down Expand Up @@ -745,6 +749,15 @@ func (f *FileDialog) Hide() {
}
}

func (f *FileDialog) SetTitleText(label string) {
f.titleText = label
if f.dialog == nil {
return
}
f.dialog.title.SetText(label)
f.dialog.win.Refresh()
}

// SetConfirmText allows custom text to be set in the confirmation button
//
// Since: 2.2
Expand Down

0 comments on commit 46626e4

Please sign in to comment.