Fix saving of header states, motion in Setup screen.

This commit is contained in:
Hisham Muhammad 2015-03-16 23:01:21 -03:00
parent 14a177800b
commit 9ff5d2b243
8 changed files with 58 additions and 12 deletions

View File

@ -112,6 +112,9 @@ static void Action_runSetup(Settings* settings, const Header* header, ProcessLis
int ch;
ScreenManager_run(scr, &panelFocus, &ch);
ScreenManager_delete(scr);
if (settings->changed) {
Header_writeBackToSettings(header);
}
}
static bool changePriority(MainPanel* panel, int delta) {

View File

@ -43,7 +43,7 @@ static void AvailableMetersPanel_delete(Object* object) {
static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, MeterClass* type, int param, int column) {
Meter* meter = (Meter*) Header_addMeterByClass(header, type, param, column);
Panel_add(panel, (Object*) Meter_toListItem(meter));
Panel_add(panel, (Object*) Meter_toListItem(meter, false));
Panel_setSelected(panel, Panel_size(panel) - 1);
((MetersPanel*)panel)->moving = true;
((ListItem*)Panel_getSelected(panel))->moving = true;

View File

@ -65,12 +65,41 @@ void Header_populateFromSettings(Header* this) {
MeterColumnSettings* colSettings = &this->settings->columns[col];
for (int i = 0; i < colSettings->len; i++) {
Header_addMeterByName(this, colSettings->names[i], col);
Header_setMode(this, i, colSettings->modes[i], col);
if (colSettings->modes[i] != 0) {
Header_setMode(this, i, colSettings->modes[i], col);
}
}
}
Header_calculateHeight(this);
}
void Header_writeBackToSettings(const Header* this) {
Header_forEachColumn(this, col) {
MeterColumnSettings* colSettings = &this->settings->columns[col];
String_freeArray(colSettings->names);
free(colSettings->modes);
Vector* vec = this->columns[col];
int len = Vector_size(vec);
colSettings->names = calloc(len+1, sizeof(char*));
colSettings->modes = calloc(len, sizeof(int));
for (int i = 0; i < len; i++) {
Meter* meter = (Meter*) Vector_get(vec, i);
char* name = calloc(64, sizeof(char*));
if (meter->param) {
snprintf(name, 63, "%s(%d)", As_Meter(meter)->name, meter->param);
} else {
snprintf(name, 63, "%s", As_Meter(meter)->name);
}
colSettings->names[i] = name;
colSettings->modes[i] = meter->mode;
}
}
}
MeterModeId Header_addMeterByName(Header* this, char* name, int column) {
Vector* meters = this->columns[column];

View File

@ -37,6 +37,8 @@ void Header_delete(Header* this);
void Header_populateFromSettings(Header* this);
void Header_writeBackToSettings(const Header* this);
MeterModeId Header_addMeterByName(Header* this, char* name, int column);
void Header_setMode(Header* this, int i, MeterModeId mode, int column);

View File

@ -191,7 +191,7 @@ void Meter_setMode(Meter* this, int modeIndex) {
this->mode = modeIndex;
}
ListItem* Meter_toListItem(Meter* this) {
ListItem* Meter_toListItem(Meter* this, bool moving) {
char mode[21];
if (this->mode)
snprintf(mode, 20, " [%s]", Meter_modes[this->mode]->uiName);
@ -204,7 +204,9 @@ ListItem* Meter_toListItem(Meter* this) {
number[0] = '\0';
char buffer[51];
snprintf(buffer, 50, "%s%s%s", Meter_uiName(this), number, mode);
return ListItem_new(buffer, 0);
ListItem* li = ListItem_new(buffer, 0);
li->moving = moving;
return li;
}
/* ---------- TextMeterMode ---------- */

View File

@ -111,7 +111,7 @@ void Meter_setCaption(Meter* this, const char* caption);
void Meter_setMode(Meter* this, int modeIndex);
ListItem* Meter_toListItem(Meter* this);
ListItem* Meter_toListItem(Meter* this, bool moving);
/* ---------- TextMeterMode ---------- */

View File

@ -40,16 +40,17 @@ static void MetersPanel_delete(Object* object) {
static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) {
Panel* super = (Panel*) this;
if (this->moving) {
this->moving = false;
((ListItem*)Panel_getSelected(super))->moving = false;
if (neighbor) {
if (selected < Vector_size(this->meters)) {
((ListItem*)Panel_getSelected(super))->moving = false;
Meter* meter = (Meter*) Vector_take(this->meters, selected);
Panel_remove(super, selected);
Vector_insert(neighbor->meters, selected, meter);
Panel_insert(&(neighbor->super), selected, (Object*) Meter_toListItem(meter));
Panel_insert(&(neighbor->super), selected, (Object*) Meter_toListItem(meter, false));
Panel_setSelected(&(neighbor->super), selected);
this->moving = false;
neighbor->moving = true;
((ListItem*)Panel_getSelected((Panel*)neighbor))->moving = true;
return true;
@ -84,7 +85,7 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
int mode = meter->mode + 1;
if (mode == LAST_METERMODE) mode = 1;
Meter_setMode(meter, mode);
Panel_set(super, selected, (Object*) Meter_toListItem(meter));
Panel_set(super, selected, (Object*) Meter_toListItem(meter, this->moving));
result = HANDLED;
break;
}
@ -123,13 +124,20 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
case KEY_RIGHT:
{
sideMove = moveToNeighbor(this, this->rightNeighbor, selected);
// don't set HANDLED; let ScreenManager handle focus.
if (this->moving && !sideMove) {
// lock user here until it exits positioning-mode
result = HANDLED;
}
// if user is free, don't set HANDLED;
// let ScreenManager handle focus.
break;
}
case KEY_LEFT:
{
sideMove = moveToNeighbor(this, this->leftNeighbor, selected);
// don't set HANDLED; let ScreenManager handle focus.
if (this->moving && !sideMove) {
result = HANDLED;
}
break;
}
case KEY_F(9):
@ -175,7 +183,7 @@ MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* met
Panel_setHeader(super, header);
for (int i = 0; i < Vector_size(meters); i++) {
Meter* meter = (Meter*) Vector_get(meters, i);
Panel_add(super, (Object*) Meter_toListItem(meter));
Panel_add(super, (Object*) Meter_toListItem(meter, false));
}
return this;
}

View File

@ -109,6 +109,7 @@ static void Settings_defaultMeters(Settings* this, int cpuCount) {
for (int i = 0; i < 2; i++) {
this->columns[i].names = calloc(sizes[i], sizeof(char*));
this->columns[i].modes = calloc(sizes[i], sizeof(int));
this->columns[i].len = sizes[i];
}
int r = 0;
@ -371,6 +372,7 @@ Settings* Settings_new(int cpuCount) {
this->hideKernelThreads = true;
this->highlightMegabytes = true;
this->highlightThreads = false;
this->headerMargin = true;
}
}
free(legacyDotfile);