소스 검색

Merge pull request #76 from tgreiser/master

Make SelectPos behave correctly
Daniel Salvadori 7 년 전
부모
커밋
4a6a4c3a3b
1개의 변경된 파일12개의 추가작업 그리고 7개의 파일을 삭제
  1. 12 7
      gui/dropdown.go

+ 12 - 7
gui/dropdown.go

@@ -128,8 +128,9 @@ func (dd *DropDown) SetSelected(item *ImageLabel) {
 
 // SelectPos selects the item at the specified position
 func (dd *DropDown) SelectPos(pos int) {
-
+    dd.list.SetSelected(dd.selItem, false)
 	dd.list.SelectPos(pos, true)
+    dd.Dispatch(OnChange, nil)
 }
 
 // onKeyEvent is called when key event is received when this dropdown has the key focus.
@@ -225,12 +226,16 @@ func (dd *DropDown) onListMouse(evname string, ev interface{}) {
 // copySelected copy to the dropdown panel the selected item
 // from the list.
 func (dd *DropDown) copySelected() {
-
-	dd.selItem = dd.list.Selected()[0].(*ImageLabel)
-	dd.litem.CopyFields(dd.selItem)
-	dd.litem.SetWidth(dd.selItem.Width())
-	dd.recalc()
-	dd.Dispatch(OnChange, nil)
+    selected := dd.list.Selected()
+    if len(selected) > 0 {
+        dd.selItem = selected[0].(*ImageLabel)
+        dd.litem.CopyFields(dd.selItem)
+        dd.litem.SetWidth(dd.selItem.Width())
+        dd.recalc()
+        dd.Dispatch(OnChange, nil)
+    } else {
+        return
+    }
 }
 
 // onListChangeEvent is called when an item in the list is selected