Found a method in NSArrayController via Stack Overflow which lets me suppress selection-changing behavior on NSTableView inserts; use that on Listbox in Mac OS X. This means sysData.selectIndices() and its Mac OS X implementation can (and has) gone away, clearing TODOs on Windows and Unix by extension.

This commit is contained in:
Pietro Gagliardi 2014-05-17 12:42:00 -04:00
parent cc74fda950
commit be56293e9c
8 changed files with 4 additions and 38 deletions

View File

@ -146,8 +146,6 @@ func (l *Listbox) make(window *sysData) (err error) {
for _, s := range l.initItems { for _, s := range l.initItems {
l.sysData.append(s) l.sysData.append(s)
} }
// some platforms automatically select an item; undo that
l.sysData.selectIndices(nil)
l.created = true l.created = true
return nil return nil
} }

View File

@ -217,12 +217,3 @@ func listboxDelete(listbox C.id, index int) {
func listboxLen(listbox C.id) int { func listboxLen(listbox C.id) int {
return int(C.listboxLen(listboxInScrollView(listbox))) return int(C.listboxLen(listboxInScrollView(listbox)))
} }
func listboxSelectIndices(id C.id, indices []int) {
listbox := listboxInScrollView(id)
if len(indices) == 0 {
C.listboxDeselectAll(listbox)
return
}
panic("selectListboxIndices() > 0 not yet implemented (TODO)")
}

View File

@ -37,6 +37,10 @@ id makeListboxArray(void)
ac = [NSArrayController new]; ac = [NSArrayController new];
[ac setAutomaticallyRearrangesObjects:NO]; [ac setAutomaticallyRearrangesObjects:NO];
// we don't want Cocoa to change the selection when items are inserted
// found via TODO_get_Stack_Overflow_link; not sure how I missed it the first time
[ac setSelectsInsertedObjects:NO];
// TODO figure out how to inhibit this behavior on delete
return ac; return ac;
} }
@ -136,8 +140,3 @@ intptr_t listboxLen(id listbox)
{ {
return fromNSInteger([toNSTableView(listbox) numberOfRows]); return fromNSInteger([toNSTableView(listbox) numberOfRows]);
} }
void listboxDeselectAll(id listbox)
{
[toNSTableView(listbox) deselectAll:listbox];
}

View File

@ -79,7 +79,6 @@ extern uintptr_t listboxIndexesCount(id);
extern uintptr_t listboxIndexesFirst(id); extern uintptr_t listboxIndexesFirst(id);
extern uintptr_t listboxIndexesNext(id, uintptr_t); extern uintptr_t listboxIndexesNext(id, uintptr_t);
extern intptr_t listboxLen(id); extern intptr_t listboxLen(id);
extern void listboxDeselectAll(id);
/* prefsize_darwin.m */ /* prefsize_darwin.m */
extern struct xsize controlPrefSize(id); extern struct xsize controlPrefSize(id);

View File

@ -41,7 +41,6 @@ var _xSysData interface {
len() int len() int
setAreaSize(int, int) setAreaSize(int, int)
selectIndex(int) selectIndex(int)
selectIndices([]int)
} = &sysData{} // this line will error if there's an inconsistency } = &sysData{} // this line will error if there's an inconsistency
// signal sends the event signal. This raise is done asynchronously to avoid deadlocking the UI task. // signal sends the event signal. This raise is done asynchronously to avoid deadlocking the UI task.

View File

@ -33,7 +33,6 @@ type classData struct {
delete func(id C.id, index int) delete func(id C.id, index int)
len func(id C.id) int len func(id C.id) int
selectIndex func(id C.id, index int, alternate bool) selectIndex func(id C.id, index int, alternate bool)
selectIndices func(id C.id, indices []int)
} }
func addControl(parentWindow C.id, control C.id) { func addControl(parentWindow C.id, control C.id) {
@ -183,7 +182,6 @@ var classTypes = [nctypes]*classData{
selTexts: listboxSelectedTexts, selTexts: listboxSelectedTexts,
delete: listboxDelete, delete: listboxDelete,
len: listboxLen, len: listboxLen,
selectIndices: listboxSelectIndices,
}, },
c_progressbar: &classData{ c_progressbar: &classData{
make: func(parentWindow C.id, alternate bool, s *sysData) C.id { make: func(parentWindow C.id, alternate bool, s *sysData) C.id {
@ -419,13 +417,3 @@ func (s *sysData) selectIndex(index int) {
} }
<-ret <-ret
} }
func (s *sysData) selectIndices(indices []int) {
ret := make(chan struct{})
defer close(ret)
uitask <- func() {
classTypes[s.ctype].selectIndices(s.id, indices)
ret <- struct{}{}
}
<-ret
}

View File

@ -364,7 +364,3 @@ func (s *sysData) setAreaSize(width int, height int) {
func (s *sysData) selectIndex(index int) { func (s *sysData) selectIndex(index int) {
// TODO not yet implemented on Unix (added for Mac only right now) // TODO not yet implemented on Unix (added for Mac only right now)
} }
func (s *sysData) selectIndices(indices []int) {
// TODO not yet implemented on Windows (added for Mac only right now)
}

View File

@ -646,7 +646,3 @@ func (s *sysData) setAreaSize(width int, height int) {
func (s *sysData) selectIndex(index int) { func (s *sysData) selectIndex(index int) {
// TODO not yet implemented on Windows (added for Mac only right now) // TODO not yet implemented on Windows (added for Mac only right now)
} }
func (s *sysData) selectIndices(indices []int) {
// TODO not yet implemented on Windows (added for Mac only right now)
}