Skip to content

Commit

Permalink
Merge pull request #5293 from ftl/filedialog_add_custom_title
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz authored Dec 4, 2024
2 parents 1f96b8d + 3367319 commit ce4fa86
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
19 changes: 18 additions & 1 deletion 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 @@ -235,7 +241,7 @@ func (f *fileDialog) makeUI() fyne.CanvasObject {
)

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

footer := container.NewBorder(nil, nil, nil, buttons,
Expand Down Expand Up @@ -767,6 +773,17 @@ func (f *FileDialog) SetDismissText(label string) {
f.dialog.win.Refresh()
}

// SetTitleText allows custom text to be set in the dialog title
//
// Since: 2.6
func (f *FileDialog) SetTitleText(label string) {
f.titleText = label
if f.dialog == nil {
return
}
f.dialog.title.SetText(label)
}

// SetLocation tells this FileDialog which location to display.
// This is normally called before the dialog is shown.
//
Expand Down
6 changes: 6 additions & 0 deletions dialog/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ func TestView(t *testing.T) {
assert.Nil(t, reader)
}, win)

dlg.SetTitleText("File Selection")
dlg.SetConfirmText("Yes")
dlg.SetDismissText("Dismiss")
dlg.Show()
Expand Down Expand Up @@ -521,6 +522,8 @@ func TestView(t *testing.T) {
assert.Equal(t, "", toggleViewButton.Text)
assert.Equal(t, theme.ListIcon().Name(), toggleViewButton.Icon.Name())

title := ui.Objects[1].(*fyne.Container).Objects[1].(*widget.Label)
assert.Equal(t, "File Selection", title.Text)
confirm := ui.Objects[2].(*fyne.Container).Objects[0].(*fyne.Container).Objects[1].(*widget.Button)
assert.Equal(t, "Yes", confirm.Text)
dismiss := ui.Objects[2].(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Button)
Expand All @@ -537,6 +540,7 @@ func TestSetView(t *testing.T) {
assert.Nil(t, reader)
}, win)

dlg.SetTitleText("File Selection")
dlg.SetConfirmText("Yes")
dlg.SetDismissText("Dismiss")

Expand All @@ -560,6 +564,8 @@ func TestSetView(t *testing.T) {
assert.Equal(t, "", toggleViewButton.Text)
assert.Equal(t, theme.GridIcon(), toggleViewButton.Icon)

title := ui.Objects[1].(*fyne.Container).Objects[1].(*widget.Label)
assert.Equal(t, "File Selection", title.Text)
confirm := ui.Objects[2].(*fyne.Container).Objects[0].(*fyne.Container).Objects[1].(*widget.Button)
assert.Equal(t, "Yes", confirm.Text)
dismiss := ui.Objects[2].(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Button)
Expand Down

0 comments on commit ce4fa86

Please sign in to comment.