Simplify and cleanup encoding menu building
Rewrite a part of `encodings_init()` to remove duplication and some hard-coded values. This gives us the item for UHC back, that was lost when adding CP932 in 9d9f40cd15ad121ff3e3fffd40073706c297f2dd, due to a missing update of the hard-coded group elements count.
This commit is contained in:
parent
1a84bb6e34
commit
8f9f9c5cf3
100
src/encodings.c
100
src/encodings.c
@ -404,14 +404,19 @@ void encodings_finalize(void)
|
|||||||
|
|
||||||
void encodings_init(void)
|
void encodings_init(void)
|
||||||
{
|
{
|
||||||
GtkWidget *item, *menu[2], *submenu, *menu_westeuro, *menu_easteuro, *menu_eastasian, *menu_asian,
|
GtkWidget *menu[2];
|
||||||
*menu_utf8, *menu_middleeast, *item_westeuro, *item_easteuro, *item_eastasian,
|
|
||||||
*item_asian, *item_utf8, *item_middleeast;
|
|
||||||
GCallback cb_func[2];
|
GCallback cb_func[2];
|
||||||
GSList *group = NULL;
|
gint group_sizes[GEANY_ENCODING_GROUPS_MAX] = { 0 };
|
||||||
gchar *label;
|
const gchar *const groups[GEANY_ENCODING_GROUPS_MAX] =
|
||||||
gint order, group_size;
|
{
|
||||||
guint i, j, k;
|
[NONE] = NULL,
|
||||||
|
[WESTEUROPEAN] = N_("_West European"),
|
||||||
|
[EASTEUROPEAN] = N_("_East European"),
|
||||||
|
[EASTASIAN] = N_("East _Asian"),
|
||||||
|
[ASIAN] = N_("_SE & SW Asian"),
|
||||||
|
[MIDDLEEASTERN] = N_("_Middle Eastern"),
|
||||||
|
[UNICODE] = N_("_Unicode"),
|
||||||
|
};
|
||||||
|
|
||||||
init_encodings();
|
init_encodings();
|
||||||
|
|
||||||
@ -428,67 +433,41 @@ void encodings_init(void)
|
|||||||
cb_func[0] = G_CALLBACK(encodings_radio_item_change_cb);
|
cb_func[0] = G_CALLBACK(encodings_radio_item_change_cb);
|
||||||
cb_func[1] = G_CALLBACK(encodings_reload_radio_item_change_cb);
|
cb_func[1] = G_CALLBACK(encodings_reload_radio_item_change_cb);
|
||||||
|
|
||||||
for (k = 0; k < 2; k++)
|
for (guint i = 0; i < G_N_ELEMENTS(encodings); i++)
|
||||||
|
group_sizes[encodings[i].group]++;
|
||||||
|
|
||||||
|
for (guint k = 0; k < 2; k++)
|
||||||
{
|
{
|
||||||
menu_westeuro = gtk_menu_new();
|
GSList *group = NULL;
|
||||||
item_westeuro = gtk_menu_item_new_with_mnemonic(_("_West European"));
|
GtkWidget *submenus[GEANY_ENCODING_GROUPS_MAX];
|
||||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item_westeuro), menu_westeuro);
|
|
||||||
gtk_container_add(GTK_CONTAINER(menu[k]), item_westeuro);
|
|
||||||
gtk_widget_show_all(item_westeuro);
|
|
||||||
|
|
||||||
menu_easteuro = gtk_menu_new();
|
for (guint i = 0; i < GEANY_ENCODING_GROUPS_MAX; i++)
|
||||||
item_easteuro = gtk_menu_item_new_with_mnemonic(_("_East European"));
|
{
|
||||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item_easteuro), menu_easteuro);
|
if (! groups[i]) /* NONE */
|
||||||
gtk_container_add(GTK_CONTAINER(menu[k]), item_easteuro);
|
submenus[i] = menu[k];
|
||||||
gtk_widget_show_all(item_easteuro);
|
else
|
||||||
|
{
|
||||||
menu_eastasian = gtk_menu_new();
|
GtkWidget *item = gtk_menu_item_new_with_mnemonic(_(groups[i]));
|
||||||
item_eastasian = gtk_menu_item_new_with_mnemonic(_("East _Asian"));
|
submenus[i] = gtk_menu_new();
|
||||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item_eastasian), menu_eastasian);
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenus[i]);
|
||||||
gtk_container_add(GTK_CONTAINER(menu[k]), item_eastasian);
|
gtk_container_add(GTK_CONTAINER(menu[k]), item);
|
||||||
gtk_widget_show_all(item_eastasian);
|
gtk_widget_show_all(item);
|
||||||
|
}
|
||||||
menu_asian = gtk_menu_new();
|
}
|
||||||
item_asian = gtk_menu_item_new_with_mnemonic(_("_SE & SW Asian"));
|
|
||||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item_asian), menu_asian);
|
|
||||||
gtk_container_add(GTK_CONTAINER(menu[k]), item_asian);
|
|
||||||
gtk_widget_show_all(item_asian);
|
|
||||||
|
|
||||||
menu_middleeast = gtk_menu_new();
|
|
||||||
item_middleeast = gtk_menu_item_new_with_mnemonic(_("_Middle Eastern"));
|
|
||||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item_middleeast), menu_middleeast);
|
|
||||||
gtk_container_add(GTK_CONTAINER(menu[k]), item_middleeast);
|
|
||||||
gtk_widget_show_all(item_middleeast);
|
|
||||||
|
|
||||||
menu_utf8 = gtk_menu_new();
|
|
||||||
item_utf8 = gtk_menu_item_new_with_mnemonic(_("_Unicode"));
|
|
||||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item_utf8), menu_utf8);
|
|
||||||
gtk_container_add(GTK_CONTAINER(menu[k]), item_utf8);
|
|
||||||
gtk_widget_show_all(item_utf8);
|
|
||||||
|
|
||||||
/** TODO can it be optimized? ATM 3782 runs at line "if (encodings[j].group ...)" */
|
/** TODO can it be optimized? ATM 3782 runs at line "if (encodings[j].group ...)" */
|
||||||
for (i = 0; i < GEANY_ENCODING_GROUPS_MAX; i++)
|
for (guint i = 0; i < GEANY_ENCODING_GROUPS_MAX; i++)
|
||||||
{
|
{
|
||||||
order = 0;
|
for (gint order = 0; order < group_sizes[i]; order++)
|
||||||
switch (i)
|
|
||||||
{
|
{
|
||||||
case WESTEUROPEAN: submenu = menu_westeuro; group_size = 9; break;
|
for (guint j = 0; j < GEANY_ENCODINGS_MAX; j++)
|
||||||
case EASTEUROPEAN: submenu = menu_easteuro; group_size = 14; break;
|
|
||||||
case EASTASIAN: submenu = menu_eastasian; group_size = 14; break;
|
|
||||||
case ASIAN: submenu = menu_asian; group_size = 9; break;
|
|
||||||
case MIDDLEEASTERN: submenu = menu_middleeast; group_size = 7; break;
|
|
||||||
case UNICODE: submenu = menu_utf8; group_size = 8; break;
|
|
||||||
default: submenu = menu[k]; group_size = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (order < group_size) /* the biggest group has 13 elements */
|
|
||||||
{
|
|
||||||
for (j = 0; j < GEANY_ENCODINGS_MAX; j++)
|
|
||||||
{
|
{
|
||||||
if (encodings[j].group == i && encodings[j].order == order)
|
if (encodings[j].group == i && encodings[j].order == order)
|
||||||
{
|
{
|
||||||
label = encodings_to_string(&encodings[j]);
|
GtkWidget *item;
|
||||||
if (k == 0)
|
gchar *label = encodings_to_string(&encodings[j]);
|
||||||
|
|
||||||
|
if (k == 0) /* Set Encoding menu */
|
||||||
{
|
{
|
||||||
item = gtk_radio_menu_item_new_with_label(group, label);
|
item = gtk_radio_menu_item_new_with_label(group, label);
|
||||||
group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item));
|
group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item));
|
||||||
@ -497,14 +476,13 @@ void encodings_init(void)
|
|||||||
else
|
else
|
||||||
item = gtk_menu_item_new_with_label(label);
|
item = gtk_menu_item_new_with_label(label);
|
||||||
gtk_widget_show(item);
|
gtk_widget_show(item);
|
||||||
gtk_container_add(GTK_CONTAINER(submenu), item);
|
gtk_container_add(GTK_CONTAINER(submenus[i]), item);
|
||||||
g_signal_connect(item, "activate", cb_func[k],
|
g_signal_connect(item, "activate", cb_func[k],
|
||||||
(gpointer) encodings[j].charset);
|
(gpointer) encodings[j].charset);
|
||||||
g_free(label);
|
g_free(label);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
order++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user