1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-02-13 20:35:54 +01:00

WPrefs: grouped the choices for Window Resize Display in a single place

By having an array, it makes the code simpler in many places, thus easier
to maintain and to implement new possibilities.

It is the opportunity to log an error message to user instead of silently
accepting invalid values.

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2014-12-21 18:13:16 +01:00
committed by Carlos R. Mafra
parent 6ef4b06cca
commit d2101b287a

View File

@@ -22,6 +22,19 @@
#include "WPrefs.h" #include "WPrefs.h"
/* Possible choices to display window information during a resize */
static const struct {
const char *db_value;
const char *label;
} resize_display[] = {
{ "corner", N_("Corner of screen") },
{ "center", N_("Center of screen") },
{ "floating", N_("Center of resized window") },
{ "line", N_("Technical drawing-like") },
{ "none", N_("Disabled") }
};
/* All the places where a balloon can be used to display more stuff to user */
static const struct { static const struct {
const char *db_key; const char *db_key;
const char *label; const char *label;
@@ -112,18 +125,18 @@ static void showData(_Panel * panel)
int x; int x;
str = GetStringForKey("ResizeDisplay"); str = GetStringForKey("ResizeDisplay");
if (!str) if (str != NULL) {
str = "corner"; for (x = 0; x < wlengthof(resize_display); x++) {
if (strcasecmp(str, "corner") == 0) if (strcasecmp(str, resize_display[x].db_value) == 0) {
WMSetPopUpButtonSelectedItem(panel->sizeP, 0); WMSetPopUpButtonSelectedItem(panel->sizeP, x);
else if (strcasecmp(str, "center") == 0) goto found_valid_resize_display;
WMSetPopUpButtonSelectedItem(panel->sizeP, 1); }
else if (strcasecmp(str, "floating") == 0) }
WMSetPopUpButtonSelectedItem(panel->sizeP, 2); wwarning(_("bad value \"%s\" for option %s, using default \"%s\""),
else if (strcasecmp(str, "line") == 0) str, "ResizeDisplay", resize_display[0].db_value);
WMSetPopUpButtonSelectedItem(panel->sizeP, 3); }
else if (strcasecmp(str, "none") == 0) WMSetPopUpButtonSelectedItem(panel->sizeP, 0);
WMSetPopUpButtonSelectedItem(panel->sizeP, 4); found_valid_resize_display:
str = GetStringForKey("MoveDisplay"); str = GetStringForKey("MoveDisplay");
if (!str) if (!str)
@@ -170,24 +183,8 @@ static void storeData(_Panel * panel)
Bool lr, tb; Bool lr, tb;
int i; int i;
switch (WMGetPopUpButtonSelectedItem(panel->sizeP)) { i = WMGetPopUpButtonSelectedItem(panel->sizeP);
case 0: SetStringForKey(resize_display[i].db_value, "ResizeDisplay");
str = "corner";
break;
case 1:
str = "center";
break;
case 2:
str = "floating";
break;
case 4:
str = "none";
break;
default:
str = "line";
break;
}
SetStringForKey(str, "ResizeDisplay");
switch (WMGetPopUpButtonSelectedItem(panel->posiP)) { switch (WMGetPopUpButtonSelectedItem(panel->posiP)) {
case 0: case 0:
@@ -245,11 +242,8 @@ static void createPanel(Panel * p)
panel->sizeP = WMCreatePopUpButton(panel->sizeF); panel->sizeP = WMCreatePopUpButton(panel->sizeF);
WMResizeWidget(panel->sizeP, 227, 20); WMResizeWidget(panel->sizeP, 227, 20);
WMMoveWidget(panel->sizeP, 14, 20); WMMoveWidget(panel->sizeP, 14, 20);
WMAddPopUpButtonItem(panel->sizeP, _("Corner of screen")); for (i = 0; i < wlengthof(resize_display); i++)
WMAddPopUpButtonItem(panel->sizeP, _("Center of screen")); WMAddPopUpButtonItem(panel->sizeP, _(resize_display[i].label));
WMAddPopUpButtonItem(panel->sizeP, _("Center of resized window"));
WMAddPopUpButtonItem(panel->sizeP, _("Technical drawing-like"));
WMAddPopUpButtonItem(panel->sizeP, _("Disabled"));
WMMapSubwidgets(panel->sizeF); WMMapSubwidgets(panel->sizeF);