summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2015-03-23 17:04:53 -0300
committerHisham Muhammad <hisham@gobolinux.org>2015-03-23 17:04:53 -0300
commitade7993fcb468433d28e569e16e90de4251114ab (patch)
treed9ff4a02e55373346b87acd174863639e20917fa
parentd0c72c3fb29d535f5bb12b651e3bcaa516650199 (diff)
incremental search and filter reintegrated!
-rw-r--r--Action.c4
-rw-r--r--IncSet.c35
-rw-r--r--IncSet.h5
-rw-r--r--MainPanel.c28
-rw-r--r--MainPanel.h3
-rw-r--r--OpenFilesScreen.c6
-rw-r--r--Panel.c2
-rw-r--r--Panel.h2
-rw-r--r--ScreenManager.c14
-rw-r--r--TraceScreen.c7
10 files changed, 63 insertions, 43 deletions
diff --git a/Action.c b/Action.c
index 30c0ab7d..6d4f49c4 100644
--- a/Action.c
+++ b/Action.c
@@ -224,13 +224,13 @@ static Htop_Reaction actionToggleTreeView(State* st) {
static Htop_Reaction actionIncFilter(State* st) {
IncSet* inc = ((MainPanel*)st->panel)->inc;
- IncSet_activate(inc, INC_FILTER);
+ IncSet_activate(inc, INC_FILTER, st->panel);
st->pl->incFilter = IncSet_filter(inc);
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
}
static Htop_Reaction actionIncSearch(State* st) {
- IncSet_activate(((MainPanel*)st->panel)->inc, INC_SEARCH);
+ IncSet_activate(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel);
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
}
diff --git a/IncSet.c b/IncSet.c
index d17bb131..fe8db49e 100644
--- a/IncSet.c
+++ b/IncSet.c
@@ -38,7 +38,6 @@ typedef struct IncMode_ {
typedef struct IncSet_ {
IncMode modes[2];
IncMode* active;
- FunctionBar* bar;
FunctionBar* defaultBar;
bool filtering;
} IncSet;
@@ -82,7 +81,6 @@ IncSet* IncSet_new(FunctionBar* bar) {
IncMode_initFilter(&(this->modes[INC_FILTER]));
this->active = NULL;
this->filtering = false;
- this->bar = bar;
this->defaultBar = bar;
return this;
}
@@ -137,7 +135,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
return true;
IncMode* mode = this->active;
int size = Panel_size(panel);
- bool filterChange = false;
+ bool filterChanged = false;
bool doSearch = true;
if (ch == KEY_F(3)) {
if (size == 0) return true;
@@ -158,14 +156,14 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
mode->index++;
mode->buffer[mode->index] = 0;
if (mode->isFilter) {
- filterChange = true;
+ filterChanged = true;
if (mode->index == 1) this->filtering = true;
}
} else if ((ch == KEY_BACKSPACE || ch == 127) && (mode->index > 0)) {
mode->index--;
mode->buffer[mode->index] = 0;
if (mode->isFilter) {
- filterChange = true;
+ filterChanged = true;
if (mode->index == 0) {
this->filtering = false;
IncMode_reset(mode);
@@ -173,7 +171,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
}
} else {
if (mode->isFilter) {
- filterChange = true;
+ filterChanged = true;
if (ch == 27) {
this->filtering = false;
IncMode_reset(mode);
@@ -182,17 +180,17 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
IncMode_reset(mode);
}
this->active = NULL;
- this->bar = this->defaultBar;
+ Panel_setDefaultBar(panel);
FunctionBar_draw(this->defaultBar, NULL);
doSearch = false;
}
if (doSearch) {
search(mode, panel, getPanelValue);
}
- if (filterChange && lines) {
+ if (filterChanged && lines) {
updateWeakPanel(this, panel, lines);
}
- return filterChange;
+ return filterChanged;
}
const char* IncSet_getListItemValue(Panel* panel, int i) {
@@ -202,13 +200,24 @@ const char* IncSet_getListItemValue(Panel* panel, int i) {
return "";
}
-void IncSet_activate(IncSet* this, IncType type, FunctionBar** setBar) {
+void IncSet_activate(IncSet* this, IncType type, Panel* panel) {
this->active = &(this->modes[type]);
- this->bar = this->active->bar;
FunctionBar_draw(this->active->bar, this->active->buffer);
- setBar =
+ panel->currentBar = this->active->bar;
}
void IncSet_drawBar(IncSet* this) {
- FunctionBar_draw(this->bar, this->active ? this->active->buffer : NULL);
+ if (this->active) {
+ FunctionBar_draw(this->active->bar, this->active->buffer);
+ } else {
+ FunctionBar_draw(this->defaultBar, NULL);
+ }
+}
+
+int IncSet_synthesizeEvent(IncSet* this, int x) {
+ if (this->active) {
+ return FunctionBar_synthesizeEvent(this->active->bar, x);
+ } else {
+ return FunctionBar_synthesizeEvent(this->defaultBar, x);
+ }
}
diff --git a/IncSet.h b/IncSet.h
index c528f18c..db05eccd 100644
--- a/IncSet.h
+++ b/IncSet.h
@@ -33,7 +33,6 @@ typedef struct IncMode_ {
typedef struct IncSet_ {
IncMode modes[2];
IncMode* active;
- FunctionBar* bar;
FunctionBar* defaultBar;
bool filtering;
} IncSet;
@@ -49,8 +48,10 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
const char* IncSet_getListItemValue(Panel* panel, int i);
-void IncSet_activate(IncSet* this, IncType type);
+void IncSet_activate(IncSet* this, IncType type, Panel* panel);
void IncSet_drawBar(IncSet* this);
+int IncSet_synthesizeEvent(IncSet* this, int x);
+
#endif
diff --git a/MainPanel.c b/MainPanel.c
index 7d7e72db..9927dee3 100644
--- a/MainPanel.c
+++ b/MainPanel.c
@@ -21,24 +21,26 @@ typedef struct MainPanel_ {
Panel super;
State* state;
IncSet* inc;
- FunctionBar* fuBar;
Htop_Action *keys;
pid_t pidSearch;
} MainPanel;
typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
+#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
+
}*/
static const char* MainFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL};
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) {
+ FunctionBar* bar = MainPanel_getFunctionBar(this);
if (mode) {
- FunctionBar_setLabel(this->fuBar, KEY_F(5), "Sorted");
- FunctionBar_setLabel(this->fuBar, KEY_F(6), "Collap");
+ FunctionBar_setLabel(bar, KEY_F(5), "Sorted");
+ FunctionBar_setLabel(bar, KEY_F(6), "Collap");
} else {
- FunctionBar_setLabel(this->fuBar, KEY_F(5), "Tree ");
- FunctionBar_setLabel(this->fuBar, KEY_F(6), "SortBy");
+ FunctionBar_setLabel(bar, KEY_F(5), "Tree ");
+ FunctionBar_setLabel(bar, KEY_F(6), "SortBy");
}
}
@@ -65,15 +67,16 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
Htop_Reaction reaction = HTOP_OK;
- if (ch == 27) {
- return HANDLED;
- }
if (ch != ERR && this->inc->active) {
- bool redraw = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL);
- if (redraw) {
+ bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL);
+ if (filterChanged) {
+ this->state->pl->incFilter = IncSet_filter(this->inc);
reaction = HTOP_REFRESH | HTOP_REDRAW_BAR;
}
reaction |= HTOP_KEEP_FOLLOWING;
+ result = HANDLED;
+ } else if (ch == 27) {
+ return HANDLED;
} else if (ch != ERR && this->keys[ch]) {
reaction |= (this->keys[ch])(this->state);
result = HANDLED;
@@ -169,10 +172,9 @@ PanelClass MainPanel_class = {
MainPanel* MainPanel_new() {
MainPanel* this = AllocThis(MainPanel);
- this->fuBar = FunctionBar_new(MainFunctions, NULL, NULL);
- Panel_init((Panel*) this, 1, 1, 1, 1, Class(Process), false, this->fuBar);
+ Panel_init((Panel*) this, 1, 1, 1, 1, Class(Process), false, FunctionBar_new(MainFunctions, NULL, NULL));
this->keys = calloc(KEY_MAX, sizeof(Htop_Action));
- this->inc = IncSet_new(this->fuBar);
+ this->inc = IncSet_new(MainPanel_getFunctionBar(this));
Action_setBindings(this->keys);
Platform_setBindings(this->keys);
diff --git a/MainPanel.h b/MainPanel.h
index 5e2ca989..83253d66 100644
--- a/MainPanel.h
+++ b/MainPanel.h
@@ -17,13 +17,14 @@ typedef struct MainPanel_ {
Panel super;
State* state;
IncSet* inc;
- FunctionBar* fuBar;
Htop_Action *keys;
pid_t pidSearch;
} MainPanel;
typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
+#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
+
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode);
diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c
index 168c6c14..296fdaf7 100644
--- a/OpenFilesScreen.c
+++ b/OpenFilesScreen.c
@@ -198,7 +198,7 @@ void OpenFilesScreen_run(OpenFilesScreen* this) {
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV);
ch = 0;
} if (mevent.y == LINES - 1)
- ch = FunctionBar_synthesizeEvent(inc->bar, mevent.x);
+ ch = IncSet_synthesizeEvent(inc, mevent.x);
}
if (inc->active) {
@@ -211,11 +211,11 @@ void OpenFilesScreen_run(OpenFilesScreen* this) {
continue;
case KEY_F(3):
case '/':
- IncSet_activate(inc, INC_SEARCH);
+ IncSet_activate(inc, INC_SEARCH, panel);
break;
case KEY_F(4):
case '\\':
- IncSet_activate(inc, INC_FILTER);
+ IncSet_activate(inc, INC_FILTER, panel);
break;
case KEY_F(5):
clear();
diff --git a/Panel.c b/Panel.c
index 3c24b61d..42cbbfce 100644
--- a/Panel.c
+++ b/Panel.c
@@ -67,6 +67,8 @@ struct Panel_ {
RichString header;
};
+#define Panel_setDefaultBar(this_) do{ (this_)->currentBar = (this_)->defaultBar; }while(0)
+
}*/
#ifndef MIN
diff --git a/Panel.h b/Panel.h
index ac3065d9..21428418 100644
--- a/Panel.h
+++ b/Panel.h
@@ -56,6 +56,8 @@ struct Panel_ {
RichString header;
};
+#define Panel_setDefaultBar(this_) do{ (this_)->currentBar = (this_)->defaultBar; }while(0)
+
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
diff --git a/ScreenManager.c b/ScreenManager.c
index de462ac0..e0993612 100644
--- a/ScreenManager.c
+++ b/ScreenManager.c
@@ -156,11 +156,16 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus) {
}
}
+static Panel* setCurrentPanel(Panel* panel) {
+ FunctionBar_draw(panel->currentBar, NULL);
+ return panel;
+}
+
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
bool quit = false;
int focus = 0;
- Panel* panelFocus = (Panel*) Vector_get(this->panels, focus);
+ Panel* panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
double oldTime = 0.0;
@@ -180,7 +185,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
if (redraw) {
ScreenManager_drawPanels(this, focus);
- FunctionBar_draw(panelFocus->currentBar, NULL);
}
int prevCh = ch;
@@ -199,7 +203,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
mevent.y > panel->y && mevent.y <= panel->y+panel->h &&
(this->allowFocusChange || panelFocus == panel) ) {
focus = i;
- panelFocus = panel;
+ panelFocus = setCurrentPanel(panel);
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
break;
}
@@ -255,7 +259,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
tryLeft:
if (focus > 0)
focus--;
- panelFocus = (Panel*) Vector_get(this->panels, focus);
+ panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
if (Panel_size(panelFocus) == 0 && focus > 0)
goto tryLeft;
break;
@@ -267,7 +271,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
tryRight:
if (focus < this->panelCount - 1)
focus++;
- panelFocus = (Panel*) Vector_get(this->panels, focus);
+ panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1)
goto tryRight;
break;
diff --git a/TraceScreen.c b/TraceScreen.c
index 48274bda..6f871267 100644
--- a/TraceScreen.c
+++ b/TraceScreen.c
@@ -79,7 +79,6 @@ static inline void appendLine(const char* line, Vector* lines, Panel* panel, con
}
void TraceScreen_run(TraceScreen* this) {
-// if (this->process->pid == getpid()) return;
char buffer[1001];
int fdpair[2];
int err = pipe(fdpair);
@@ -167,7 +166,7 @@ void TraceScreen_run(TraceScreen* this) {
follow = false;
ch = 0;
} if (mevent.y == LINES - 1)
- ch = FunctionBar_synthesizeEvent(inc->bar, mevent.x);
+ ch = IncSet_synthesizeEvent(inc, mevent.x);
}
if (inc->active) {
@@ -186,11 +185,11 @@ void TraceScreen_run(TraceScreen* this) {
break;
case KEY_F(3):
case '/':
- IncSet_activate(inc, INC_SEARCH);
+ IncSet_activate(inc, INC_SEARCH, panel);
break;
case KEY_F(4):
case '\\':
- IncSet_activate(inc, INC_FILTER);
+ IncSet_activate(inc, INC_FILTER, panel);
break;
case 'f':
case KEY_F(8):

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