diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-01-27 23:28:37 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-01-30 12:51:27 -0200 |
commit | 673f098734a03a5643465563b5df3e7a69ed9d7a (patch) | |
tree | e4b5a09eff3f9996c130e563f6f393d9632b2706 /IncSet.c | |
parent | ad99187680585bf66f9de4f617e897dada8767f7 (diff) |
Move responsibility for cursor placement to Panels
Diffstat (limited to 'IncSet.c')
-rw-r--r-- | IncSet.c | 43 |
1 files changed, 25 insertions, 18 deletions
@@ -38,6 +38,7 @@ typedef struct IncMode_ { typedef struct IncSet_ { IncMode modes[2]; IncMode* active; + Panel* panel; FunctionBar* defaultBar; bool filtering; bool found; @@ -115,23 +116,35 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) { } } -static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) { +static bool search(IncSet* this, Panel* panel, IncMode_GetPanelValue getPanelValue) { int size = Panel_size(panel); bool found = false; for (int i = 0; i < size; i++) { - if (String_contains_i(getPanelValue(panel, i), mode->buffer)) { + if (String_contains_i(getPanelValue(panel, i), this->active->buffer)) { Panel_setSelected(panel, i); found = true; break; } } - if (found) - FunctionBar_draw(mode->bar, mode->buffer); - else - FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]); + IncSet_drawBar(this, found ? CRT_colors[FUNCTION_BAR] : CRT_colors[FAILED_SEARCH]); return found; } +void IncSet_activate(IncSet* this, IncType type, Panel* panel) { + this->active = &(this->modes[type]); + panel->currentBar = this->active->bar; + panel->cursorOn = true; + this->panel = panel; + IncSet_drawBar(this, CRT_colors[FUNCTION_BAR]); +} + +static void IncSet_deactivate(IncSet* this, Panel* panel) { + this->active = NULL; + Panel_setDefaultBar(panel); + panel->cursorOn = false; + FunctionBar_draw(this->defaultBar, NULL); +} + bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) { if (ch == ERR) return true; @@ -189,13 +202,11 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue } else { IncMode_reset(mode); } - this->active = NULL; - Panel_setDefaultBar(panel); - FunctionBar_draw(this->defaultBar, NULL); + IncSet_deactivate(this, panel); doSearch = false; } if (doSearch) { - this->found = search(mode, panel, getPanelValue); + this->found = search(this, panel, getPanelValue); } if (filterChanged && lines) { updateWeakPanel(this, panel, lines); @@ -210,15 +221,11 @@ const char* IncSet_getListItemValue(Panel* panel, int i) { return ""; } -void IncSet_activate(IncSet* this, IncType type, Panel* panel) { - this->active = &(this->modes[type]); - FunctionBar_draw(this->active->bar, this->active->buffer); - panel->currentBar = this->active->bar; -} - -void IncSet_drawBar(IncSet* this) { +void IncSet_drawBar(IncSet* this, int attr) { if (this->active) { - FunctionBar_draw(this->active->bar, this->active->buffer); + int cursorX = FunctionBar_drawAttr(this->active->bar, this->active->buffer, attr); + this->panel->cursorY = LINES - 1; + this->panel->cursorX = cursorX; } else { FunctionBar_draw(this->defaultBar, NULL); } |