Add some headers in the Setup -> Display options panel

This commit is contained in:
Daniel Lange 2022-05-04 21:26:33 +02:00 committed by BenBE
parent 0e29174211
commit 999801464a
3 changed files with 46 additions and 1 deletions

View File

@ -18,6 +18,7 @@ in the source distribution for its full text.
#include "Object.h" #include "Object.h"
#include "OptionItem.h" #include "OptionItem.h"
#include "ProvideCurses.h" #include "ProvideCurses.h"
#include "ScreensPanel.h"
static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
@ -43,6 +44,8 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
case KEY_RECLICK: case KEY_RECLICK:
case ' ': case ' ':
switch (OptionItem_kind(selected)) { switch (OptionItem_kind(selected)) {
case OPTION_ITEM_TEXT:
break;
case OPTION_ITEM_CHECK: case OPTION_ITEM_CHECK:
CheckItem_toggle((CheckItem*)selected); CheckItem_toggle((CheckItem*)selected);
result = HANDLED; result = HANDLED;
@ -97,9 +100,17 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
this->scr = scr; this->scr = scr;
Panel_setHeader(super, "Display options"); Panel_setHeader(super, "Display options");
Panel_add(super, (Object*) CheckItem_newByRef("Tree view (for the current Screen tab)", &(settings->ss->treeView)));
#define TABMSG "For current screen tab: \0"
char tabheader[sizeof(TABMSG) + SCREEN_NAME_LEN + 1] = TABMSG;
strncat(tabheader, settings->ss->name, SCREEN_NAME_LEN);
Panel_add(super, (Object*) TextItem_new(tabheader));
#undef TABMSG
Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->ss->treeView)));
Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is always sorted by PID (htop 2 behavior)", &(settings->ss->treeViewAlwaysByPID))); Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is always sorted by PID (htop 2 behavior)", &(settings->ss->treeViewAlwaysByPID)));
Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is collapsed by default", &(settings->ss->allBranchesCollapsed))); Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is collapsed by default", &(settings->ss->allBranchesCollapsed)));
Panel_add(super, (Object*) TextItem_new("Global options:"));
Panel_add(super, (Object*) CheckItem_newByRef("Show tabs for screens", &(settings->screenTabs))); Panel_add(super, (Object*) CheckItem_newByRef("Show tabs for screens", &(settings->screenTabs)));
Panel_add(super, (Object*) CheckItem_newByRef("Shadow other users' processes", &(settings->shadowOtherUsers))); Panel_add(super, (Object*) CheckItem_newByRef("Shadow other users' processes", &(settings->shadowOtherUsers)));
Panel_add(super, (Object*) CheckItem_newByRef("Hide kernel threads", &(settings->hideKernelThreads))); Panel_add(super, (Object*) CheckItem_newByRef("Hide kernel threads", &(settings->hideKernelThreads)));

View File

@ -25,6 +25,13 @@ static void OptionItem_delete(Object* cast) {
free(this); free(this);
} }
static void TextItem_display(const Object* cast, RichString* out) {
const TextItem* this = (const TextItem*)cast;
assert (this != NULL);
RichString_appendWide(out, CRT_colors[HELP_BOLD], this->super.text);
}
static void CheckItem_display(const Object* cast, RichString* out) { static void CheckItem_display(const Object* cast, RichString* out) {
const CheckItem* this = (const CheckItem*)cast; const CheckItem* this = (const CheckItem*)cast;
assert (this != NULL); assert (this != NULL);
@ -68,6 +75,16 @@ const OptionItemClass OptionItem_class = {
} }
}; };
const OptionItemClass TextItem_class = {
.super = {
.extends = Class(OptionItem),
.delete = OptionItem_delete,
.display = TextItem_display
},
.kind = OPTION_ITEM_TEXT
};
const OptionItemClass CheckItem_class = { const OptionItemClass CheckItem_class = {
.super = { .super = {
.extends = Class(OptionItem), .extends = Class(OptionItem),
@ -77,6 +94,7 @@ const OptionItemClass CheckItem_class = {
.kind = OPTION_ITEM_CHECK .kind = OPTION_ITEM_CHECK
}; };
const OptionItemClass NumberItem_class = { const OptionItemClass NumberItem_class = {
.super = { .super = {
.extends = Class(OptionItem), .extends = Class(OptionItem),
@ -86,6 +104,12 @@ const OptionItemClass NumberItem_class = {
.kind = OPTION_ITEM_NUMBER .kind = OPTION_ITEM_NUMBER
}; };
TextItem* TextItem_new(const char* text) {
TextItem* this = AllocThis(TextItem);
this->super.text = xStrdup(text);
return this;
}
CheckItem* CheckItem_newByRef(const char* text, bool* ref) { CheckItem* CheckItem_newByRef(const char* text, bool* ref) {
CheckItem* this = AllocThis(CheckItem); CheckItem* this = AllocThis(CheckItem);
this->super.text = xStrdup(text); this->super.text = xStrdup(text);

View File

@ -13,6 +13,7 @@ in the source distribution for its full text.
enum OptionItemType { enum OptionItemType {
OPTION_ITEM_TEXT,
OPTION_ITEM_CHECK, OPTION_ITEM_CHECK,
OPTION_ITEM_NUMBER, OPTION_ITEM_NUMBER,
}; };
@ -32,6 +33,12 @@ typedef struct OptionItem_ {
char* text; char* text;
} OptionItem; } OptionItem;
typedef struct TextItem_ {
OptionItem super;
char* text;
} TextItem;
typedef struct CheckItem_ { typedef struct CheckItem_ {
OptionItem super; OptionItem super;
@ -51,9 +58,12 @@ typedef struct NumberItem_ {
} NumberItem; } NumberItem;
extern const OptionItemClass OptionItem_class; extern const OptionItemClass OptionItem_class;
extern const OptionItemClass TextItem_class;
extern const OptionItemClass CheckItem_class; extern const OptionItemClass CheckItem_class;
extern const OptionItemClass NumberItem_class; extern const OptionItemClass NumberItem_class;
TextItem* TextItem_new(const char* text);
CheckItem* CheckItem_newByRef(const char* text, bool* ref); CheckItem* CheckItem_newByRef(const char* text, bool* ref);
CheckItem* CheckItem_newByVal(const char* text, bool value); CheckItem* CheckItem_newByVal(const char* text, bool value);
bool CheckItem_get(const CheckItem* this); bool CheckItem_get(const CheckItem* this);