Simplify constructors.

This commit is contained in:
Hisham Muhammad 2015-03-23 19:24:34 -03:00
parent 8a11281c67
commit 7cb8cb05fb
7 changed files with 17 additions and 31 deletions

View File

@ -161,13 +161,9 @@ static inline Htop_Reaction setSortKey(Settings* settings, ProcessField sortKey)
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_UPDATE_PANELHDR;
}
static const char* SortFunctions[] = {"Sort ", "Cancel ", NULL};
static const char* SortKeys[] = {"Enter", "Esc", NULL};
static int SortEvents[] = {13, 27};
static Htop_Reaction sortBy(State* st) {
Htop_Reaction reaction = HTOP_OK;
Panel* sortPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem), FunctionBar_new(SortFunctions, SortKeys, SortEvents));
Panel* sortPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem), FunctionBar_newEnterEsc("Sort ", "Cancel "));
Panel_setHeader(sortPanel, "Sort by");
ProcessField* fields = st->settings->fields;
for (int i = 0; fields[i]; i++) {
@ -307,12 +303,8 @@ static Htop_Reaction actionKill(State* st) {
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
}
static const char* UsersFunctions[] = {"Show ", "Cancel ", NULL};
static const char* UsersKeys[] = {"Enter", "Esc", NULL};
static int UsersEvents[] = {13, 27};
static Htop_Reaction actionFilterByUser(State* st) {
Panel* usersPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem), FunctionBar_new(UsersFunctions, UsersKeys, UsersEvents));
Panel* usersPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem), FunctionBar_newEnterEsc("Show ", "Cancel "));
Panel_setHeader(usersPanel, "Show processes of:");
UsersTable_foreach(st->ut, addUserToVector, usersPanel);
Vector_insertionSort(usersPanel->items);

View File

@ -42,12 +42,8 @@ PanelClass AffinityPanel_class = {
.eventHandler = AffinityPanel_eventHandler
};
static const char* AffinityFunctions[] = {"Set ", "Cancel ", NULL};
static const char* AffinityKeys[] = {"Enter", "Esc", NULL};
static int AffinityEvents[] = {13, 27};
Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) {
Panel* this = Panel_new(1, 1, 1, 1, true, Class(CheckItem), FunctionBar_new(AffinityFunctions, AffinityKeys, AffinityEvents));
Panel* this = Panel_new(1, 1, 1, 1, true, Class(CheckItem), FunctionBar_newEnterEsc("Set ", "Cancel "));
Object_setClass(this, Class(AffinityPanel));
Panel_setHeader(this, "Use CPUs:");

View File

@ -34,10 +34,6 @@ typedef struct AvailableMetersPanel_ {
}*/
static const char* AvailableMetersFunctions[] = {"Add ", "Done ", NULL};
static const char* AvailableMetersKeys[] = {"Enter", "Esc"};
static int AvailableMetersEvents[] = {13, 27};
static void AvailableMetersPanel_delete(Object* object) {
Panel* super = (Panel*) object;
AvailableMetersPanel* this = (AvailableMetersPanel*) object;
@ -106,7 +102,7 @@ PanelClass AvailableMetersPanel_class = {
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl) {
AvailableMetersPanel* this = AllocThis(AvailableMetersPanel);
Panel* super = (Panel*) this;
FunctionBar* fuBar = FunctionBar_new(AvailableMetersFunctions, AvailableMetersKeys, AvailableMetersEvents);
FunctionBar* fuBar = FunctionBar_newEnterEsc("Add ", "Done ");
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
this->settings = settings;

View File

@ -33,6 +33,14 @@ static const char* FunctionBar_FLabels[] = {" ", " ", " ", "
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)};
static const char* FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL};
static int FunctionBar_EnterEscEvents[] = {13, 27};
FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) {
const char* functions[] = {enter, esc, NULL};
return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents);
}
FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* events) {
FunctionBar* this = calloc(1, sizeof(FunctionBar));
this->functions = calloc(16, sizeof(char*));

View File

@ -21,6 +21,9 @@ typedef struct FunctionBar_ {
} FunctionBar;
FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc);
FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* events);
void FunctionBar_delete(FunctionBar* this);

View File

@ -62,12 +62,8 @@ static SignalItem signals[] = {
{ .name = "31 SIGSYS", .number = 31 },
};
static const char* SignalsFunctions[] = {"Send ", "Cancel ", NULL};
static const char* SignalsKeys[] = {"Enter", "Esc", NULL};
static int SignalsEvents[] = {13, 27};
Panel* SignalsPanel_new() {
Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), FunctionBar_new(SignalsFunctions, SignalsKeys, SignalsEvents));
Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), FunctionBar_newEnterEsc("Send ", "Cancel "));
for(unsigned int i = 0; i < sizeof(signals)/sizeof(SignalItem); i++)
Panel_set(this, i, (Object*) ListItem_new(signals[i].name, signals[i].number));
Panel_setHeader(this, "Send signal:");

View File

@ -13,13 +13,8 @@ in the source distribution for its full text.
#include "ListItem.h"
}*/
static const char* IOPriorityFunctions[] = {"Set ", "Cancel ", NULL};
static const char* IOPriorityKeys[] = {"Enter", "Esc", NULL};
static int IOPriorityEvents[] = {13, 27};
Panel* IOPriorityPanel_new(IOPriority currPrio) {
FunctionBar* fuBar = FunctionBar_new(IOPriorityFunctions, IOPriorityKeys, IOPriorityEvents);
Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), fuBar);
Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), FunctionBar_newEnterEsc("Set ", "Cancel "));
Panel_setHeader(this, "IO Priority:");
Panel_add(this, (Object*) ListItem_new("None (based on nice)", IOPriority_None));