Reduced the number of unnecessary error returns based on MSDN. The TODOs that used to be there have been moved to a new file; similar files for Mac and Linux will also be made.
This commit is contained in:
parent
dce24dae3f
commit
d1768f2787
|
@ -42,11 +42,7 @@ func (c *Checkbox) Checked() bool {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
check, err := c.sysData.isChecked()
|
return c.sysData.isChecked()
|
||||||
if err != nil {
|
|
||||||
panic(err) // TODO
|
|
||||||
}
|
|
||||||
return check
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Checkbox) make(window *sysData) error {
|
func (c *Checkbox) make(window *sysData) error {
|
||||||
|
|
|
@ -29,14 +29,14 @@ func NewCombobox(editable bool, items ...string) (c *Combobox) {
|
||||||
// TODO Append, InsertBefore, Delete
|
// TODO Append, InsertBefore, Delete
|
||||||
|
|
||||||
// Selection returns the current selection.
|
// Selection returns the current selection.
|
||||||
func (c *Combobox) Selection() (string, error) {
|
func (c *Combobox) Selection() string {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
if c.created {
|
if c.created {
|
||||||
return c.sysData.text()
|
return c.sysData.text()
|
||||||
}
|
}
|
||||||
return "", nil
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO SelectedIndex
|
// TODO SelectedIndex
|
||||||
|
|
|
@ -27,14 +27,14 @@ func NewLineEdit(text string) *LineEdit {
|
||||||
// TODO SetText
|
// TODO SetText
|
||||||
|
|
||||||
// Text returns the LineEdit's text.
|
// Text returns the LineEdit's text.
|
||||||
func (l *LineEdit) Text() (string, error) {
|
func (l *LineEdit) Text() string {
|
||||||
l.lock.Lock()
|
l.lock.Lock()
|
||||||
defer l.lock.Unlock()
|
defer l.lock.Unlock()
|
||||||
|
|
||||||
if l.created {
|
if l.created {
|
||||||
return l.sysData.text()
|
return l.sysData.text()
|
||||||
}
|
}
|
||||||
return l.initText, nil
|
return l.initText
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO adorn errors with what failed
|
// TODO adorn errors with what failed
|
||||||
|
|
18
main.go
18
main.go
|
@ -30,19 +30,11 @@ mainloop:
|
||||||
case <-w.Closing:
|
case <-w.Closing:
|
||||||
break mainloop
|
break mainloop
|
||||||
case <-b.Clicked:
|
case <-b.Clicked:
|
||||||
cs1, err := cb1.Selection()
|
err = w.SetTitle(fmt.Sprintf("%v | %s | %s | %s",
|
||||||
if err != nil {
|
c.Checked(),
|
||||||
panic(err)
|
cb1.Selection(),
|
||||||
}
|
cb2.Selection(),
|
||||||
cs2, err := cb2.Selection()
|
e.Text()))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
et, err := e.Text()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
err = w.SetTitle(fmt.Sprintf("%v | %s | %s | %s", c.Checked(), cs1, cs2, et))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ func (c *cSysData) setText(text string) error {
|
||||||
func (c *cSysData) setRect(x int, y int, width int, height int) error {
|
func (c *cSysData) setRect(x int, y int, width int, height int) error {
|
||||||
panic(runtime.GOOS + " sysData does not define setRect()")
|
panic(runtime.GOOS + " sysData does not define setRect()")
|
||||||
}
|
}
|
||||||
func (c *cSysData) isChecked() (bool, error) {
|
func (c *cSysData) isChecked() bool {
|
||||||
panic(runtime.GOOS + " sysData does not define isChecked()")
|
panic(runtime.GOOS + " sysData does not define isChecked()")
|
||||||
}
|
}
|
||||||
func (c *cSysData) text() (string, error) {
|
func (c *cSysData) text() (string, error) {
|
||||||
|
|
|
@ -244,8 +244,7 @@ func (s *sysData) setRect(x int, y int, width int, height int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO figure out how to handle error
|
func (s *sysData) isChecked() bool {
|
||||||
func (s *sysData) isChecked() (bool, error) {
|
|
||||||
ret := make(chan uiret)
|
ret := make(chan uiret)
|
||||||
defer close(ret)
|
defer close(ret)
|
||||||
uitask <- &uimsg{
|
uitask <- &uimsg{
|
||||||
|
@ -259,16 +258,14 @@ func (s *sysData) isChecked() (bool, error) {
|
||||||
ret: ret,
|
ret: ret,
|
||||||
}
|
}
|
||||||
r := <-ret
|
r := <-ret
|
||||||
return r.ret == _BST_CHECKED, nil
|
return r.ret == _BST_CHECKED
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO adorn error messages with which part failed
|
func (s *sysData) text() (str string) {
|
||||||
func (s *sysData) text() (str string, err error) {
|
|
||||||
var tc []uint16
|
var tc []uint16
|
||||||
|
|
||||||
ret := make(chan uiret)
|
ret := make(chan uiret)
|
||||||
defer close(ret)
|
defer close(ret)
|
||||||
// TODO figure out how to handle errors
|
|
||||||
uitask <- &uimsg{
|
uitask <- &uimsg{
|
||||||
call: _sendMessage,
|
call: _sendMessage,
|
||||||
p: []uintptr{
|
p: []uintptr{
|
||||||
|
@ -282,7 +279,6 @@ func (s *sysData) text() (str string, err error) {
|
||||||
r := <-ret
|
r := <-ret
|
||||||
length := r.ret + 1 // terminating null
|
length := r.ret + 1 // terminating null
|
||||||
tc = make([]uint16, length)
|
tc = make([]uint16, length)
|
||||||
// TODO figure out how to handle errors
|
|
||||||
uitask <- &uimsg{
|
uitask <- &uimsg{
|
||||||
call: _sendMessage,
|
call: _sendMessage,
|
||||||
p: []uintptr{
|
p: []uintptr{
|
||||||
|
@ -294,8 +290,7 @@ func (s *sysData) text() (str string, err error) {
|
||||||
ret: ret,
|
ret: ret,
|
||||||
}
|
}
|
||||||
<-ret
|
<-ret
|
||||||
// TODO check character count
|
return syscall.UTF16ToString(tc)
|
||||||
return syscall.UTF16ToString(tc), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO figure out how to handle errors
|
// TODO figure out how to handle errors
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
- all SendMessage() calls
|
||||||
|
- BM_GETCHECK (sysData.isChecked())
|
||||||
|
- WM_GETTEXTLENGTH (LRESULT is unsinged so) (sysData.text())
|
||||||
|
- WM_GETTEXT (WM_GETTEXTLENGTH docs say its result may be larger than the actual length, so we can't use that) (sysData.text())
|
Loading…
Reference in New Issue