Skip to content

Commit

Permalink
capitalize error messages in dialog.NewError
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jul 27, 2024
1 parent 49ad989 commit 1941acb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dialog/information.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package dialog

import (
"unicode"
"unicode/utf8"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/lang"
Expand Down Expand Up @@ -35,7 +38,12 @@ func ShowInformation(title, message string, parent fyne.Window) {
// The message is extracted from the provided error (should not be nil).
// After creation you should call Show().
func NewError(err error, parent fyne.Window) Dialog {
return createInformationDialog(lang.L("Error"), err.Error(), theme.ErrorIcon(), parent)
dialogText := err.Error()
r, size := utf8.DecodeRuneInString(dialogText)
if r != utf8.RuneError {
dialogText = string(unicode.ToUpper(r)) + dialogText[size:]
}
return createInformationDialog(lang.L("Error"), dialogText, theme.ErrorIcon(), parent)
}

// ShowError shows a dialog over the specified window for an application error.
Expand Down
18 changes: 18 additions & 0 deletions dialog/information_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/test"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -109,3 +110,20 @@ func TestDialog_ErrorCallback(t *testing.T) {
assert.True(t, tapped)
assert.True(t, information.win.Hidden)
}

func TestDialog_ErrorCapitalize(t *testing.T) {
err := errors.New("here is an error msg")
d := NewError(err, test.NewTempWindow(t, nil))
assert.Equal(t, d.(*dialog).content.(*widget.Label).Text,
"Here is an error msg")

err = errors.New("這是一條錯誤訊息")
d = NewError(err, test.NewTempWindow(t, nil))
assert.Equal(t, d.(*dialog).content.(*widget.Label).Text,
"這是一條錯誤訊息")

err = errors.New("")
d = NewError(err, test.NewTempWindow(t, nil))
assert.Equal(t, d.(*dialog).content.(*widget.Label).Text,
"")
}

0 comments on commit 1941acb

Please sign in to comment.