From 7ca10817122d3b7b30fabb1cadb75e5ee14b364e Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 18 Nov 2011 06:08:56 +0000 Subject: Mega-commit with features and tweaks for 1.0: * Performance improvements * Support for splitting CPU meters into two or four columns (thanks to Wim Heirman) * Switch from PLPA, which is now deprecated, to HWLOC. * Bring back support for native Linux sched_setaffinity, so we don't have to use HWLOC where we don't need to. * Support for typing in user names and column fields in selection panels. --- Panel.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'Panel.c') diff --git a/Panel.c b/Panel.c index 43432602..56e19488 100644 --- a/Panel.c +++ b/Panel.c @@ -93,6 +93,7 @@ void Panel_init(Panel* this, int x, int y, int w, int h, char* type, bool owner) this->w = w; this->h = h; this->eventHandler = NULL; + this->eventHandlerBuffer = NULL; this->items = Vector_new(type, owner, DEFAULT_SIZE, ListItem_compare); this->scrollV = 0; this->scrollH = 0; @@ -108,6 +109,7 @@ void Panel_init(Panel* this, int x, int y, int w, int h, char* type, bool owner) void Panel_done(Panel* this) { assert (this != NULL); + free(this->eventHandlerBuffer); Vector_delete(this->items); RichString_end(this->header); } @@ -405,3 +407,38 @@ bool Panel_onKey(Panel* this, int key) { } return false; } + + +HandlerResult Panel_selectByTyping(Panel* this, int ch) { + int size = Panel_size(this); + if (!this->eventHandlerBuffer) + this->eventHandlerBuffer = calloc(100, 1); + + if (isalnum(ch)) { + int len = strlen(this->eventHandlerBuffer); + if (len < 99) { + this->eventHandlerBuffer[len] = ch; + this->eventHandlerBuffer[len+1] = '\0'; + } + for (int try = 0; try < 2; try++) { + len = strlen(this->eventHandlerBuffer); + for (int i = 0; i < size; i++) { + char* cur = ((ListItem*) Panel_get(this, i))->value; + while (*cur == ' ') cur++; + if (strncasecmp(cur, this->eventHandlerBuffer, len) == 0) { + Panel_setSelected(this, i); + return HANDLED; + } + } + this->eventHandlerBuffer[0] = ch; + this->eventHandlerBuffer[1] = '\0'; + } + return HANDLED; + } else if (ch != ERR) { + this->eventHandlerBuffer[0] = '\0'; + } + if (ch == 13) { + return BREAK_LOOP; + } + return IGNORED; +} -- cgit v1.2.3