Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit d0c72c3

Browse files
committed
Move FunctionBar inside Panel
1 parent 1084a3f commit d0c72c3

27 files changed

+134
-137
lines changed

Action.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,16 @@ typedef struct State_ {
6161
6262
}*/
6363

64-
Object* Action_pickFromVector(State* st, Panel* list, int x, const char** keyLabels) {
64+
Object* Action_pickFromVector(State* st, Panel* list, int x) {
6565
Panel* panel = st->panel;
6666
Header* header = st->header;
6767
Settings* settings = st->settings;
6868

6969
int y = panel->y;
70-
const char* fuKeys[] = {"Enter", "Esc", NULL};
71-
int fuEvents[] = {13, 27};
7270
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, false);
7371
scr->allowFocusChange = false;
74-
ScreenManager_add(scr, list, FunctionBar_new(keyLabels, fuKeys, fuEvents), x - 1);
75-
ScreenManager_add(scr, panel, NULL, -1);
72+
ScreenManager_add(scr, list, x - 1);
73+
ScreenManager_add(scr, panel, -1);
7674
Panel* panelFocus;
7775
int ch;
7876
bool unfollow = false;
@@ -100,12 +98,10 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, const char** keyLab
10098

10199
// ----------------------------------------
102100

103-
static const char* CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
104-
105101
static void Action_runSetup(Settings* settings, const Header* header, ProcessList* pl) {
106102
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true);
107103
CategoriesPanel* panelCategories = CategoriesPanel_new(scr, settings, (Header*) header, pl);
108-
ScreenManager_add(scr, (Panel*) panelCategories, FunctionBar_new(CategoriesFunctions, NULL, NULL), 16);
104+
ScreenManager_add(scr, (Panel*) panelCategories, 16);
109105
CategoriesPanel_makeMetersPage(panelCategories);
110106
Panel* panelFocus;
111107
int ch;
@@ -165,11 +161,14 @@ static inline Htop_Reaction setSortKey(Settings* settings, ProcessField sortKey)
165161
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_UPDATE_PANELHDR;
166162
}
167163

164+
static const char* SortFunctions[] = {"Sort ", "Cancel ", NULL};
165+
static const char* SortKeys[] = {"Enter", "Esc", NULL};
166+
static int SortEvents[] = {13, 27};
167+
168168
static Htop_Reaction sortBy(State* st) {
169169
Htop_Reaction reaction = HTOP_OK;
170-
Panel* sortPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem));
170+
Panel* sortPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem), FunctionBar_new(SortFunctions, SortKeys, SortEvents));
171171
Panel_setHeader(sortPanel, "Sort by");
172-
const char* fuFunctions[] = {"Sort ", "Cancel ", NULL};
173172
ProcessField* fields = st->settings->fields;
174173
for (int i = 0; fields[i]; i++) {
175174
char* name = String_trim(Process_fields[fields[i]].name);
@@ -178,7 +177,7 @@ static Htop_Reaction sortBy(State* st) {
178177
Panel_setSelected(sortPanel, i);
179178
free(name);
180179
}
181-
ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15, fuFunctions);
180+
ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15);
182181
if (field) {
183182
reaction |= setSortKey(st->settings, field->key);
184183
}
@@ -280,8 +279,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
280279
Panel* affinityPanel = AffinityPanel_new(st->pl, affinity);
281280
Affinity_delete(affinity);
282281

283-
const char* fuFunctions[] = {"Set ", "Cancel ", NULL};
284-
void* set = Action_pickFromVector(st, affinityPanel, 15, fuFunctions);
282+
void* set = Action_pickFromVector(st, affinityPanel, 15);
285283
if (set) {
286284
Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl);
287285
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (size_t) affinity, NULL);
@@ -295,8 +293,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
295293

296294
static Htop_Reaction actionKill(State* st) {
297295
Panel* signalsPanel = (Panel*) SignalsPanel_new();
298-
const char* fuFunctions[] = {"Send ", "Cancel ", NULL};
299-
ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15, fuFunctions);
296+
ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15);
300297
if (sgn) {
301298
if (sgn->key != 0) {
302299
Panel_setHeader(st->panel, "Sending...");
@@ -310,15 +307,18 @@ static Htop_Reaction actionKill(State* st) {
310307
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
311308
}
312309

310+
static const char* UsersFunctions[] = {"Show ", "Cancel ", NULL};
311+
static const char* UsersKeys[] = {"Enter", "Esc", NULL};
312+
static int UsersEvents[] = {13, 27};
313+
313314
static Htop_Reaction actionFilterByUser(State* st) {
314-
Panel* usersPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem));
315+
Panel* usersPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem), FunctionBar_new(UsersFunctions, UsersKeys, UsersEvents));
315316
Panel_setHeader(usersPanel, "Show processes of:");
316317
UsersTable_foreach(st->ut, addUserToVector, usersPanel);
317318
Vector_insertionSort(usersPanel->items);
318319
ListItem* allUsers = ListItem_new("All users", -1);
319320
Panel_insert(usersPanel, 0, (Object*) allUsers);
320-
const char* fuFunctions[] = {"Show ", "Cancel ", NULL};
321-
ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20, fuFunctions);
321+
ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20);
322322
if (picked) {
323323
if (picked == allUsers) {
324324
st->pl->userId = -1;

Action.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ typedef struct State_ {
3939
} State;
4040

4141

42-
Object* Action_pickFromVector(State* st, Panel* list, int x, const char** keyLabels);
42+
Object* Action_pickFromVector(State* st, Panel* list, int x);
4343

4444
// ----------------------------------------
4545

AffinityPanel.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ PanelClass AffinityPanel_class = {
4242
.eventHandler = AffinityPanel_eventHandler
4343
};
4444

45+
static const char* AffinityFunctions[] = {"Set ", "Cancel ", NULL};
46+
static const char* AffinityKeys[] = {"Enter", "Esc", NULL};
47+
static int AffinityEvents[] = {13, 27};
48+
4549
Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) {
46-
Panel* this = Panel_new(1, 1, 1, 1, true, Class(CheckItem));
50+
Panel* this = Panel_new(1, 1, 1, 1, true, Class(CheckItem), FunctionBar_new(AffinityFunctions, AffinityKeys, AffinityEvents));
4751
Object_setClass(this, Class(AffinityPanel));
4852

4953
Panel_setHeader(this, "Use CPUs:");

AvailableColumnsPanel.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ typedef struct AvailableColumnsPanel_ {
2626
2727
}*/
2828

29+
static const char* AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL};
30+
2931
static void AvailableColumnsPanel_delete(Object* object) {
3032
Panel* super = (Panel*) object;
3133
AvailableColumnsPanel* this = (AvailableColumnsPanel*) object;
@@ -71,7 +73,8 @@ PanelClass AvailableColumnsPanel_class = {
7173
AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns) {
7274
AvailableColumnsPanel* this = AllocThis(AvailableColumnsPanel);
7375
Panel* super = (Panel*) this;
74-
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true);
76+
FunctionBar* fuBar = FunctionBar_new(AvailableColumnsFunctions, NULL, NULL);
77+
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
7578

7679
Panel_setHeader(super, "Available Columns");
7780

AvailableMetersPanel.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ typedef struct AvailableMetersPanel_ {
3434
3535
}*/
3636

37+
static const char* AvailableMetersFunctions[] = {"Add ", "Done ", NULL};
38+
static const char* AvailableMetersKeys[] = {"Enter", "Esc"};
39+
static int AvailableMetersEvents[] = {13, 27};
40+
3741
static void AvailableMetersPanel_delete(Object* object) {
3842
Panel* super = (Panel*) object;
3943
AvailableMetersPanel* this = (AvailableMetersPanel*) object;
@@ -102,7 +106,8 @@ PanelClass AvailableMetersPanel_class = {
102106
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl) {
103107
AvailableMetersPanel* this = AllocThis(AvailableMetersPanel);
104108
Panel* super = (Panel*) this;
105-
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true);
109+
FunctionBar* fuBar = FunctionBar_new(AvailableMetersFunctions, AvailableMetersKeys, AvailableMetersEvents);
110+
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
106111

107112
this->settings = settings;
108113
this->header = header;

CategoriesPanel.c

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,7 @@ typedef struct CategoriesPanel_ {
3434
3535
}*/
3636

37-
static const char* MetersFunctions[] = {"Type ", "Move ", "Delete", "Done ", NULL};
38-
static const char* MetersKeys[] = {"Space", "Enter", "Del", "Esc"};
39-
static int MetersEvents[] = {' ', 13, 27, KEY_DC};
40-
41-
static const char* AvailableMetersFunctions[] = {"Add ", "Done ", NULL};
42-
static const char* AvailableMetersKeys[] = {"Enter", "Esc"};
43-
static int AvailableMetersEvents[] = {13, 27};
44-
45-
static const char* DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
46-
47-
static const char* ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
48-
49-
static const char* ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
50-
51-
static const char* AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL};
37+
static const char* CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
5238

5339
static void CategoriesPanel_delete(Object* object) {
5440
Panel* super = (Panel*) object;
@@ -63,26 +49,26 @@ void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
6349
leftMeters->rightNeighbor = rightMeters;
6450
rightMeters->leftNeighbor = leftMeters;
6551
Panel* availableMeters = (Panel*) AvailableMetersPanel_new(this->settings, this->header, (Panel*) leftMeters, (Panel*) rightMeters, this->scr, this->pl);
66-
ScreenManager_add(this->scr, (Panel*) leftMeters, FunctionBar_new(MetersFunctions, MetersKeys, MetersEvents), 20);
67-
ScreenManager_add(this->scr, (Panel*) rightMeters, FunctionBar_new(MetersFunctions, MetersKeys, MetersEvents), 20);
68-
ScreenManager_add(this->scr, availableMeters, FunctionBar_new(AvailableMetersFunctions, AvailableMetersKeys, AvailableMetersEvents), -1);
52+
ScreenManager_add(this->scr, (Panel*) leftMeters, 20);
53+
ScreenManager_add(this->scr, (Panel*) rightMeters, 20);
54+
ScreenManager_add(this->scr, availableMeters, -1);
6955
}
7056

7157
static void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) {
7258
Panel* displayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr);
73-
ScreenManager_add(this->scr, displayOptions, FunctionBar_new(DisplayOptionsFunctions, NULL, NULL), -1);
59+
ScreenManager_add(this->scr, displayOptions, -1);
7460
}
7561

7662
static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
7763
Panel* colors = (Panel*) ColorsPanel_new(this->settings, this->scr);
78-
ScreenManager_add(this->scr, colors, FunctionBar_new(ColorsFunctions, NULL, NULL), -1);
64+
ScreenManager_add(this->scr, colors, -1);
7965
}
8066

8167
static void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
8268
Panel* columns = (Panel*) ColumnsPanel_new(this->settings);
8369
Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(columns);
84-
ScreenManager_add(this->scr, columns, FunctionBar_new(ColumnsFunctions, NULL, NULL), 20);
85-
ScreenManager_add(this->scr, availableColumns, FunctionBar_new(AvailableColumnsFunctions, NULL, NULL), -1);
70+
ScreenManager_add(this->scr, columns, 20);
71+
ScreenManager_add(this->scr, availableColumns, -1);
8672
}
8773

8874
static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
@@ -150,7 +136,8 @@ PanelClass CategoriesPanel_class = {
150136
CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl) {
151137
CategoriesPanel* this = AllocThis(CategoriesPanel);
152138
Panel* super = (Panel*) this;
153-
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true);
139+
FunctionBar* fuBar = FunctionBar_new(CategoriesFunctions, NULL, NULL);
140+
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
154141

155142
this->scr = scr;
156143
this->settings = settings;

ColorsPanel.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ typedef struct ColorsPanel_ {
3434
3535
}*/
3636

37+
static const char* ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
38+
3739
static const char* ColorSchemeNames[] = {
3840
"Default",
3941
"Monochromatic",
@@ -94,7 +96,8 @@ PanelClass ColorsPanel_class = {
9496
ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
9597
ColorsPanel* this = AllocThis(ColorsPanel);
9698
Panel* super = (Panel*) this;
97-
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true);
99+
FunctionBar* fuBar = FunctionBar_new(ColorsFunctions, NULL, NULL);
100+
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar);
98101

99102
this->settings = settings;
100103
this->scr = scr;

ColumnsPanel.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ typedef struct ColumnsPanel_ {
2828
2929
}*/
3030

31+
static const char* ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
32+
3133
static void ColumnsPanel_delete(Object* object) {
3234
Panel* super = (Panel*) object;
3335
ColumnsPanel* this = (ColumnsPanel*) object;
@@ -121,7 +123,8 @@ PanelClass ColumnsPanel_class = {
121123
ColumnsPanel* ColumnsPanel_new(Settings* settings) {
122124
ColumnsPanel* this = AllocThis(ColumnsPanel);
123125
Panel* super = (Panel*) this;
124-
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true);
126+
FunctionBar* fuBar = FunctionBar_new(ColumnsFunctions, NULL, NULL);
127+
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
125128

126129
this->settings = settings;
127130
this->moving = false;

DisplayOptionsPanel.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ typedef struct DisplayOptionsPanel_ {
2727
2828
}*/
2929

30+
static const char* DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
31+
3032
static void DisplayOptionsPanel_delete(Object* object) {
3133
Panel* super = (Panel*) object;
3234
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
@@ -72,7 +74,8 @@ PanelClass DisplayOptionsPanel_class = {
7274
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
7375
DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel);
7476
Panel* super = (Panel*) this;
75-
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true);
77+
FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
78+
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar);
7679

7780
this->settings = settings;
7881
this->scr = scr;

FunctionBar.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ in the source distribution for its full text.
66
*/
77

88
#include "FunctionBar.h"
9-
109
#include "CRT.h"
10+
#include "RichString.h"
1111

1212
#include <assert.h>
1313
#include <string.h>
1414
#include <stdlib.h>
15-
#include <stdbool.h>
1615

1716
/*{
18-
#include "Object.h"
17+
18+
#include <stdbool.h>
1919
2020
typedef struct FunctionBar_ {
21-
Object super;
2221
int size;
2322
char** functions;
2423
char** keys;
@@ -34,12 +33,8 @@ static const char* FunctionBar_FLabels[] = {" ", " ", " ", "
3433

3534
static int FunctionBar_FEvents[] = {KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5), KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10)};
3635

37-
ObjectClass FunctionBar_class = {
38-
.delete = FunctionBar_delete
39-
};
40-
4136
FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* events) {
42-
FunctionBar* this = AllocThis(FunctionBar);
37+
FunctionBar* this = calloc(1, sizeof(FunctionBar));
4338
this->functions = calloc(16, sizeof(char*));
4439
if (!functions) {
4540
functions = FunctionBar_FLabels;
@@ -67,8 +62,7 @@ FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* eve
6762
return this;
6863
}
6964

70-
void FunctionBar_delete(Object* cast) {
71-
FunctionBar* this = (FunctionBar*) cast;
65+
void FunctionBar_delete(FunctionBar* this) {
7266
for (int i = 0; i < 15 && this->functions[i]; i++) {
7367
free(this->functions[i]);
7468
}

0 commit comments

Comments
 (0)