From a383074c996c45870a4576a6822a0dee574fac7e Mon Sep 17 00:00:00 2001 From: David Maciejak Date: Fri, 3 Mar 2023 19:11:30 +0800 Subject: [PATCH] WPrefs: sort alphabetically the key shortcut actions and expert options There are too many entries now in key shortcut actions and expert options, better to sort them dynamically. --- WPrefs.app/Expert.c | 16 +++++++++++++++- WPrefs.app/KeyboardShortcuts.c | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/WPrefs.app/Expert.c b/WPrefs.app/Expert.c index 8195d876..3a765c60 100644 --- a/WPrefs.app/Expert.c +++ b/WPrefs.app/Expert.c @@ -25,7 +25,7 @@ /* This structure containts the list of all the check-buttons to display in the * expert tab of the window with the corresponding information for effect */ -static const struct { +static struct expert_option { const char *label; /* Text displayed to user */ int def_state; /* True/False: the default value, if not defined in current config */ @@ -172,6 +172,19 @@ static void upButtonCallback(WMWidget *self, void *data) changeIntTextfield(data, 1); } +static int cmpExpertOptions(const void *v1, const void *v2) +{ + int rc; + const struct expert_option *opt1 = (struct expert_option *)v1; + const struct expert_option *opt2 = (struct expert_option *)v2; + + if ((rc = strcmp(opt1->label, opt2->label)) < 0) + return -1; + else if (rc > 0) + return 1; + return 0; +} + static void createPanel(Panel *p) { _Panel *panel = (_Panel *) p; @@ -195,6 +208,7 @@ static void createPanel(Panel *p) WMSetFrameRelief(f, WRFlat); udb = WMGetStandardUserDefaults(); + qsort(expert_options, wlengthof(expert_options), sizeof(expert_options[0]), cmpExpertOptions); for (i = 0; i < wlengthof(expert_options); i++) { if (expert_options[i].class != OPTION_WMAKER_INT) { panel->swi[i] = WMCreateSwitchButton(f); diff --git a/WPrefs.app/KeyboardShortcuts.c b/WPrefs.app/KeyboardShortcuts.c index 107f0e82..a6e223c8 100644 --- a/WPrefs.app/KeyboardShortcuts.c +++ b/WPrefs.app/KeyboardShortcuts.c @@ -65,7 +65,7 @@ typedef struct _Panel { * First parameter is the internal keyword known by WMaker * Second is the text displayed to the user */ -static const struct { +static struct keyOption { const char *key; const char *title; } keyOptions[] = { @@ -541,6 +541,20 @@ static void paintItem(WMList * lPtr, int index, Drawable d, char *text, int stat WMDrawString(scr, d, panel->black, panel->font, x + 20, y, text, strlen(text)); } +static int cmpKeyOptions(const void *v1, const void *v2) +{ + int rc; + const struct keyOption *opt1 = (struct keyOption *)v1; + const struct keyOption *opt2 = (struct keyOption *)v2; + + if ((rc = strcmp(opt1->title, opt2->title)) < 0) + return -1; + else if (rc > 0) + return 1; + return 0; +} + + static void createPanel(Panel * p) { _Panel *panel = (_Panel *) p; @@ -580,6 +594,7 @@ static void createPanel(Panel * p) WMSetListUserDrawProc(panel->actLs, paintItem); WMHangData(panel->actLs, panel); + qsort(keyOptions, wlengthof(keyOptions), sizeof(keyOptions[0]), cmpKeyOptions); for (i = 0; i < wlengthof(keyOptions); i++) { WMAddListItem(panel->actLs, _(keyOptions[i].title)); } -- 2.11.4.GIT