summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-20 01:35:05 -0400
committerPietro Gagliardi <[email protected]>2014-08-20 01:35:05 -0400
commitac1b8e3cca971c38c8091f60fedfe093e6fe78df (patch)
tree746ec1b161084b775b7e1260335f02eae9731210
parent5f830deec8374336d1d268a27e41f5ec492c866c (diff)
Added a test for TextField.Invalid() and implemented it on the GTK+ backend.
-rw-r--r--redo/textfield_unix.go14
-rw-r--r--redo/zz_test.go13
2 files changed, 26 insertions, 1 deletions
diff --git a/redo/textfield_unix.go b/redo/textfield_unix.go
index c4ce8b4..e9624ee 100644
--- a/redo/textfield_unix.go
+++ b/redo/textfield_unix.go
@@ -10,6 +10,11 @@ import (
// #include "gtk_unix.h"
// extern void textfieldChanged(GtkEditable *, gpointer);
+// /* because cgo doesn't like GTK_STOCK_DIALOG_ERROR */
+// static inline void setErrorIcon(GtkEntry *entry)
+// {
+// gtk_entry_set_icon_from_stock(entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_DIALOG_ERROR);
+// }
import "C"
type textfield struct {
@@ -58,7 +63,14 @@ func (t *textfield) OnChanged(f func()) {
}
func (t *textfield) Invalid(reason string) {
- // TODO
+ if reason == "" {
+ C.gtk_entry_set_icon_from_stock(t.entry, C.GTK_ENTRY_ICON_SECONDARY, nil)
+ return
+ }
+ C.setErrorIcon(t.entry)
+ creason := togstr(reason)
+ defer freegstr(creason)
+ C.gtk_entry_set_icon_tooltip_text(t.entry, C.GTK_ENTRY_ICON_SECONDARY, creason)
}
//export textfieldChanged
diff --git a/redo/zz_test.go b/redo/zz_test.go
index 2477de0..e1eb8fc 100644
--- a/redo/zz_test.go
+++ b/redo/zz_test.go
@@ -13,6 +13,7 @@ import (
"image/color"
"image/draw"
"time"
+ "strings"
)
var closeOnClick = flag.Bool("close", false, "close on click")
@@ -38,6 +39,7 @@ type testwin struct {
festart Button
felabel Label
festop Button
+ vedit TextField
openbtn Button
fnlabel Label
icons []icon
@@ -91,6 +93,14 @@ func (tw *testwin) addfe() {
tw.fe = nil
}
})
+ tw.vedit = NewTextField()
+ tw.vedit.OnChanged(func() {
+ if strings.Contains(tw.vedit.Text(), "bad") {
+ tw.vedit.Invalid("bad entered")
+ } else {
+ tw.vedit.Invalid("")
+ }
+ })
tw.openbtn = NewButton("Open")
tw.openbtn.OnClicked(func() {
fn := OpenFile()
@@ -102,8 +112,11 @@ func (tw *testwin) addfe() {
tw.fnlabel = NewStandaloneLabel("<no file selected>")
tw.festack = NewVerticalStack(tw.festart, tw.felabel, tw.festop,
Space(),
+ tw.vedit,
+ Space(),
tw.openbtn, tw.fnlabel)
tw.festack.SetStretchy(3)
+ tw.festack.SetStretchy(5)
tw.t.Append("Foreign Events", tw.festack)
}