summaryrefslogtreecommitdiffstats
path: root/Panel.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2011-11-18 06:08:56 +0000
committerHisham Muhammad <hisham@gobolinux.org>2011-11-18 06:08:56 +0000
commit7ca10817122d3b7b30fabb1cadb75e5ee14b364e (patch)
tree14fa282dcad8eac9401fa463484b0b1693f43e1f /Panel.c
parent38856488815711138aa9d0ba32cca66694717171 (diff)
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.
Diffstat (limited to 'Panel.c')
-rw-r--r--Panel.c37
1 files changed, 37 insertions, 0 deletions
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;
+}

© 2014-2024 Faster IT GmbH | imprint | privacy policy