tableview.go
func (l *TableView) ProcessEvent(event Event) bool {
	if !l.Active() || !l.Enabled() {
		return false
	}

	switch event.Type {
	case EventKey:
		if l.onKeyPress != nil {
			res := l.onKeyPress(event.Key)
			if res {
				return true
			}
		}

		switch event.Key {
		case term.KeyHome:
			if event.Mod == term.ModAlt {
				l.selectedRow = 0
				l.EnsureRowVisible()
				l.emitSelectionChange()
			} else {
				l.home()
			}
			return true
		case term.KeyEnd:
			if event.Mod == term.ModAlt {
				l.selectedRow = l.rowCount - 1
				l.EnsureRowVisible()
				l.emitSelectionChange()
			} else {
				l.end()
			}
			return true
		case term.KeyArrowUp:
			l.moveUp(1)
			return true
		case term.KeyArrowDown:
			l.moveDown(1)
			return true
		case term.KeyArrowLeft:
			l.moveLeft(1)
			return true
		case term.KeyArrowRight:
			l.moveRight(1)
			return true
		case term.KeyPgdn:
			l.moveDown(l.height - 3)
			return true
		case term.KeyPgup:
			l.moveUp(l.height - 3)
			return true
		case term.KeyCtrlM, term.KeyF2:
			if l.selectedRow != -1 && l.selectedCol != -1 && l.onAction != nil {
				ev := TableEvent{Action: TableActionEdit, Col: l.selectedCol, Row: l.selectedRow}
				l.onAction(ev)
			}
		case term.KeyDelete:
			if l.selectedRow != -1 && l.onAction != nil {
				ev := TableEvent{Action: TableActionDelete, Col: l.selectedCol, Row: l.selectedRow}
				l.onAction(ev)
			}
		case term.KeyInsert:
			if l.onAction != nil {
				ev := TableEvent{Action: TableActionNew, Col: l.selectedCol, Row: l.selectedRow}
				l.onAction(ev)
			}
		case term.KeyF4:
			if l.onAction != nil {
				colID := l.selectedCol
				sort := l.columns[colID].Sort

				for idx := range l.columns {
					l.columns[idx].Sort = SortNone
				}

				if sort == SortAsc {
					sort = SortDesc
				} else if sort == SortNone {
					sort = SortAsc
				} else {
					sort = SortNone
				}
				l.columns[colID].Sort = sort

				ev := TableEvent{Action: TableActionSort, Col: colID, Row: -1, Sort: sort}
				l.onAction(ev)
			}
		default:
			return false
		}
	case EventMouse:
		return l.processMouseClick(event)
	}

	return false
}
func (l *TableView) ProcessEvent(event Event) bool {
	if !l.Active() || !l.Enabled() {
		return false
	}

	switch event.Type {
	case EventKey:
		if l.onKeyPress != nil {
			res := l.onKeyPress(event.Key)
			if res {
				return true
			}
		}

		switch event.Key {
		case term.KeyHome:
			if event.Mod == term.ModAlt {
				l.selectedRow = 0
				l.EnsureRowVisible()
				l.emitSelectionChange()
			} else {
				l.home()
			}
			return true
		case term.KeyEnd:
			if event.Mod == term.ModAlt {
				l.selectedRow = l.rowCount - 1
				l.EnsureRowVisible()
				l.emitSelectionChange()
			} else {
				l.end()
			}
			return true
		case term.KeyArrowUp:
			l.moveUp(1)
			return true
		case term.KeyArrowDown:
			l.moveDown(1)
			return true
		case term.KeyArrowLeft:
			l.moveLeft(1)
			return true
		case term.KeyArrowRight:
			l.moveRight(1)
			return true
		case term.KeyPgdn:
			l.moveDown(l.height - 3)
			return true
		case term.KeyPgup:
			l.moveUp(l.height - 3)
			return true
		case term.KeyCtrlM, term.KeyF2:
			if l.selectedRow != -1 && l.selectedCol != -1 && l.onAction != nil {
				ev := TableEvent{Action: TableActionEdit, Col: l.selectedCol, Row: l.selectedRow}
				l.onAction(ev)
			}
		case term.KeyDelete:
			if l.selectedRow != -1 && l.onAction != nil {
				ev := TableEvent{Action: TableActionDelete, Col: l.selectedCol, Row: l.selectedRow}
				l.onAction(ev)
			}
		case term.KeyInsert:
			if l.onAction != nil {
				ev := TableEvent{Action: TableActionNew, Col: l.selectedCol, Row: l.selectedRow}
				l.onAction(ev)
			}
		case term.KeyF4:
			if l.onAction != nil {
				colID := l.selectedCol
				sort := l.columns[colID].Sort

				for idx := range l.columns {
					l.columns[idx].Sort = SortNone
				}

				if sort == SortAsc {
					sort = SortDesc
				} else if sort == SortNone {
					sort = SortAsc
				} else {
					sort = SortNone
				}
				l.columns[colID].Sort = sort

				ev := TableEvent{Action: TableActionSort, Col: colID, Row: -1, Sort: sort}
				l.onAction(ev)
			}
		default:
			return false
		}
	case EventMouse:
		return l.processMouseClick(event)
	}

	return false
}
func ( l * TableView ) ProcessEvent ( event Event ) bool { if ! l . Active ( ) || ! l . Enabled ( ) { return false } switch event . Type { case EventKey : if l . onKeyPress != nil { res := l . onKeyPress ( event . Key ) if res { return true } } switch event . Key { case term . KeyHome : if event . Mod == term . ModAlt { l . selectedRow = 0 l . EnsureRowVisible ( ) l . emitSelectionChange ( ) } else { l . home ( ) } return true case term . KeyEnd : if event . Mod == term . ModAlt { l . selectedRow = l . rowCount - 1 l . EnsureRowVisible ( ) l . emitSelectionChange ( ) } else { l . end ( ) } return true case term . KeyArrowUp : l . moveUp ( 1 ) return true case term . KeyArrowDown : l . moveDown ( 1 ) return true case term . KeyArrowLeft : l . moveLeft ( 1 ) return true case term . KeyArrowRight : l . moveRight ( 1 ) return true case term . KeyPgdn : l . moveDown ( l . height - 3 ) return true case term . KeyPgup : l . moveUp ( l . height - 3 ) return true case term . KeyCtrlM , term . KeyF2 : if l . selectedRow != - 1 && l . selectedCol != - 1 && l . onAction != nil { ev := TableEvent { Action : TableActionEdit , Col : l . selectedCol , Row : l . selectedRow } l . onAction ( ev ) } case term . KeyDelete : if l . selectedRow != - 1 && l . onAction != nil { ev := TableEvent { Action : TableActionDelete , Col : l . selectedCol , Row : l . selectedRow } l . onAction ( ev ) } case term . KeyInsert : if l . onAction != nil { ev := TableEvent { Action : TableActionNew , Col : l . selectedCol , Row : l . selectedRow } l . onAction ( ev ) } case term . KeyF4 : if l . onAction != nil { colID := l . selectedCol sort := l . columns [ colID ] . Sort for idx := range l . columns { l . columns [ idx ] . Sort = SortNone } if sort == SortAsc { sort = SortDesc } else if sort == SortNone { sort = SortAsc } else { sort = SortNone } l . columns [ colID ] . Sort = sort ev := TableEvent { Action : TableActionSort , Col : colID , Row : - 1 , Sort : sort } l . onAction ( ev ) } default : return false } case EventMouse : return l . processMouseClick ( event ) } return false }
/*
ProcessEvent processes all events come from the control parent. If a control
processes an event it should return true. If the method returns false it means
that the control do not want or cannot process the event and the caller sends
the event to the control parent
*/
/ * ProcessEvent processes all events come from the control parent . If a control processes an event it should return true . If the method returns false it means that the control do not want or cannot process the event and the caller sends the event to the control parent