From 673f098734a03a5643465563b5df3e7a69ed9d7a Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sat, 27 Jan 2018 23:28:37 -0200 Subject: Move responsibility for cursor placement to Panels --- IncSet.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'IncSet.c') diff --git a/IncSet.c b/IncSet.c index bb9f9544..d0cd5ec8 100644 --- a/IncSet.c +++ b/IncSet.c @@ -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); } -- cgit v1.2.3