mirror of https://github.com/xzeldon/htop.git
Screens: Fix "New Screen" option
This commit is contained in:
parent
e6c98b6e8e
commit
2df1f61d77
|
@ -53,9 +53,9 @@ ObjectClass ScreenListItem_class = {
|
|||
.compare = ListItem_compare
|
||||
};
|
||||
|
||||
ScreenListItem* ScreenListItem_new(const char* value, int key, ScreenSettings* ss) {
|
||||
ScreenListItem* ScreenListItem_new(const char* value, ScreenSettings* ss) {
|
||||
ScreenListItem* this = AllocThis(ScreenListItem);
|
||||
ListItem_init((ListItem*)this, value, key);
|
||||
ListItem_init((ListItem*)this, value, 0);
|
||||
this->ss = ss;
|
||||
return this;
|
||||
}
|
||||
|
@ -150,6 +150,17 @@ static void rebuildSettingsArray(Panel* super) {
|
|||
}
|
||||
}
|
||||
|
||||
static void addNewScreen(Panel* super) {
|
||||
ScreensPanel* const this = (ScreensPanel*) super;
|
||||
|
||||
char* name = "New";
|
||||
ScreenSettings* ss = Settings_newScreen(this->settings, name, "PID Command");
|
||||
ScreenListItem* item = ScreenListItem_new(name, ss);
|
||||
int idx = Panel_getSelectedIndex(super);
|
||||
Panel_insert(super, idx + 1, (Object*) item);
|
||||
Panel_setSelected(super, idx + 1);
|
||||
}
|
||||
|
||||
static HandlerResult ScreensPanel_eventHandlerNormal(Panel* super, int ch) {
|
||||
ScreensPanel* const this = (ScreensPanel*) super;
|
||||
|
||||
|
@ -190,10 +201,7 @@ static HandlerResult ScreensPanel_eventHandlerNormal(Panel* super, int ch) {
|
|||
case KEY_F(5):
|
||||
case KEY_CTRL('N'):
|
||||
{
|
||||
ListItem* item = ListItem_new("", 0);
|
||||
int idx = Panel_getSelectedIndex(super);
|
||||
Panel_insert(super, idx + 1, (Object*) item);
|
||||
Panel_setSelected(super, idx + 1);
|
||||
addNewScreen(super);
|
||||
startRenaming(super);
|
||||
shouldRebuildArray = true;
|
||||
result = HANDLED;
|
||||
|
@ -300,7 +308,7 @@ ScreensPanel* ScreensPanel_new(Settings* settings) {
|
|||
for (unsigned int i = 0; i < settings->nScreens; i++) {
|
||||
ScreenSettings* ss = settings->screens[i];
|
||||
char* name = ss->name;
|
||||
Panel_add(super, (Object*) ScreenListItem_new(name, i, ss));
|
||||
Panel_add(super, (Object*) ScreenListItem_new(name, ss));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ typedef struct ScreenListItem_ {
|
|||
|
||||
extern ObjectClass ScreenListItem_class;
|
||||
|
||||
ScreenListItem* ScreenListItem_new(const char* value, int key, ScreenSettings* ss);
|
||||
ScreenListItem* ScreenListItem_new(const char* value, ScreenSettings* ss);
|
||||
|
||||
extern PanelClass ScreensPanel_class;
|
||||
|
||||
|
|
|
@ -246,7 +246,7 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
|
|||
String_freeArray(ids);
|
||||
}
|
||||
|
||||
static void Settings_readScreen(Settings* this, const char* name, const char* line) {
|
||||
ScreenSettings* Settings_newScreen(Settings* this, const char* name, const char* line) {
|
||||
ScreenSettings* ss = xCalloc(sizeof(ScreenSettings), 1);
|
||||
ss->name = xStrdup(name);
|
||||
ss->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField));
|
||||
|
@ -258,11 +258,12 @@ static void Settings_readScreen(Settings* this, const char* name, const char* li
|
|||
this->nScreens++;
|
||||
this->screens = xRealloc(this->screens, sizeof(ScreenSettings*) * (this->nScreens + 1));
|
||||
this->screens[this->nScreens] = NULL;
|
||||
return ss;
|
||||
}
|
||||
|
||||
static void Settings_defaultScreens(Settings* this) {
|
||||
Settings_readScreen(this, "Default", "PID USER PRIORITY NICE M_SIZE M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command");
|
||||
Settings_readScreen(this, "I/O", "PID IO_PRIORITY USER IO_READ_RATE IO_WRITE_RATE Command");
|
||||
Settings_newScreen(this, "Default", "PID USER PRIORITY NICE M_SIZE M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command");
|
||||
Settings_newScreen(this, "I/O", "PID IO_PRIORITY USER IO_READ_RATE IO_WRITE_RATE Command");
|
||||
}
|
||||
|
||||
static bool Settings_read(Settings* this, const char* fileName) {
|
||||
|
@ -343,7 +344,7 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
|||
Settings_readMeterModes(this, option[1], 1);
|
||||
didReadMeters = true;
|
||||
} else if (strncmp(option[0], "screen:", 7) == 0) {
|
||||
Settings_readScreen(this, option[0] + 7, option[1]);
|
||||
Settings_newScreen(this, option[0] + 7, option[1]);
|
||||
} else if (String_eq(option[0], ".tree_view")) {
|
||||
if (this->nScreens > 0) {
|
||||
this->screens[this->nScreens - 1]->treeView = atoi(option[1]);
|
||||
|
|
|
@ -74,6 +74,8 @@ typedef struct Settings_ {
|
|||
|
||||
void Settings_delete(Settings* this);
|
||||
|
||||
ScreenSettings* Settings_newScreen(Settings* this, const char* name, const char* line);
|
||||
|
||||
bool Settings_write(Settings* this);
|
||||
|
||||
Settings* Settings_new(int cpuCount);
|
||||
|
|
Loading…
Reference in New Issue