Revision: 5284 http://geany.svn.sourceforge.net/geany/?rev=5284&view=rev Author: ntrel Date: 2010-10-06 15:53:53 +0000 (Wed, 06 Oct 2010)
Log Message: ----------- Group Open dialog encoding options by submenus (patch by Adam Ples, thanks; #3047717).
Modified Paths: -------------- trunk/ChangeLog trunk/THANKS trunk/src/about.c trunk/src/dialogs.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-10-06 15:32:40 UTC (rev 5283) +++ trunk/ChangeLog 2010-10-06 15:53:53 UTC (rev 5284) @@ -2,6 +2,9 @@
* src/geanywraplabel.c: Fix build with GLib 2.8. + * src/dialogs.c, src/about.c, THANKS: + Group Open dialog encoding options by submenus (patch by Adam Ples, + thanks; #3047717).
2010-10-06 Frank Lanitz <frank(at)frank(dot)uvena(dot)de> @@ -19,7 +22,7 @@ Add utils_strv_join(). * tagmanager/basic.c: Parse property, constructor, destructor as functions (patch by - pottersson, thanks - #2992167). + pottersson, thanks; #2992167).
2010-10-01 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/THANKS =================================================================== --- trunk/THANKS 2010-10-06 15:32:40 UTC (rev 5283) +++ trunk/THANKS 2010-10-06 15:53:53 UTC (rev 5284) @@ -83,6 +83,7 @@ Jiří Techet <techet(at)gmail(dot)com> - Various patches Erik de Castro Lopo <mle+tools(at)mega-nerd(dot)com> - Various patches Thomas Huth <th(dot)huth(at)googlemail(dot)com> - Forth filetype +Adam Ples <adamples(at)users(dot)sourceforge(dot)net> - Group encodings in open dialog
Translators: ------------
Modified: trunk/src/about.c =================================================================== --- trunk/src/about.c 2010-10-06 15:32:40 UTC (rev 5283) +++ trunk/src/about.c 2010-10-06 15:53:53 UTC (rev 5284) @@ -59,7 +59,7 @@ { "it", "Max Baldinelli <m.baldinelli@agora.it>,\nDario Santomarco <dariello@yahoo.it>" }, { "ja", "Tarot Osuji <tarot@sdf.lonestar.org>\nChikahiro Masami <cmasa.z321@gmail.com>" }, { "ko", "Park Jang-heon <dotkabi@gmail.com>" }, - { "kk", "Baurzhan Muftakhidinov <baurthefirst@gmail.com>"}, + { "kk", "Baurzhan Muftakhidinov <baurthefirst@gmail.com>"}, { "lb", "Laurent Hoeltgen <hoeltgman@gmail.com>" }, { "nl", "Peter Scholtens <peter.scholtens@xs4all.nl>\nAyke van Laethem <aykevanlaethem@gmail.com>" }, { "pl_PL", "Jarosław Foksa <jfoksa@gmail.com>" }, @@ -84,6 +84,7 @@ static const gint prev_translators_len = G_N_ELEMENTS(prev_translators);
static const gchar *contributors = +"Adam Ples, " "Alexander Rodin, Alexey Antipov, Andrew Rowland, Anh Phạm, blackdog, Bo Lorentsen, Bob Doan, " "Bronisław Białek, Can Koy, Catalin Marinas, " "Chris Macksey, Christoph Berg, Colomban Wendling, Conrad Steenberg, Daniel Richard G., "
Modified: trunk/src/dialogs.c =================================================================== --- trunk/src/dialogs.c 2010-10-06 15:32:40 UTC (rev 5283) +++ trunk/src/dialogs.c 2010-10-06 15:53:53 UTC (rev 5284) @@ -85,8 +85,9 @@ GSList *filelist; gint filetype_idx = gtk_combo_box_get_active(GTK_COMBO_BOX( ui_lookup_widget(GTK_WIDGET(dialog), "filetype_combo"))); - gint encoding_idx = gtk_combo_box_get_active(GTK_COMBO_BOX( - ui_lookup_widget(GTK_WIDGET(dialog), "encoding_combo"))); + gint encoding_idx; + GtkTreeModel *encoding_model; + GtkTreeIter encoding_iter; GeanyFiletype *ft = NULL; const gchar *charset = NULL; gboolean ro = (response == GEANY_RESPONSE_VIEW); /* View clicked */ @@ -94,6 +95,12 @@ /* ignore detect from file item */ if (filetype_idx > 0) ft = g_slist_nth_data(filetypes_by_title, filetype_idx); + + encoding_model = gtk_combo_box_get_model(GTK_COMBO_BOX( + ui_lookup_widget(GTK_WIDGET(dialog), "encoding_combo"))); + gtk_combo_box_get_active_iter(GTK_COMBO_BOX( + ui_lookup_widget(GTK_WIDGET(dialog), "encoding_combo")), &encoding_iter); + gtk_tree_model_get(encoding_model, &encoding_iter, 0, &encoding_idx, -1); if (encoding_idx >= 0 && encoding_idx < GEANY_ENCODINGS_MAX) charset = encodings[encoding_idx].charset;
@@ -133,12 +140,100 @@ }
+static gint encoding_combo_store_sort_func(GtkTreeModel *model, + GtkTreeIter *a, + GtkTreeIter *b, + gpointer data) +{ + gboolean a_has_child = gtk_tree_model_iter_has_child(model, a); + gboolean b_has_child = gtk_tree_model_iter_has_child(model, b); + gchar *a_string; + gchar *b_string; + gint cmp_res; + + if (a_has_child != b_has_child) + return a_has_child ? -1 : 1; + + gtk_tree_model_get(model, a, 1, &a_string, -1); + gtk_tree_model_get(model, b, 1, &b_string, -1); + cmp_res = strcmp(a_string, b_string); + g_free(a_string); + g_free(b_string); + return cmp_res; +} + + +static GtkTreeStore *create_encoding_combo_store(GtkTreeIter *iter_detect) +{ + GtkTreeStore *store; + GtkTreeIter iter_current, iter_westeuro, iter_easteuro, iter_eastasian, iter_asian, + iter_utf8, iter_middleeast; + GtkTreeIter *iter_parent; + gchar *encoding_string; + guint i; + + store = gtk_tree_store_new(2, G_TYPE_INT, G_TYPE_STRING); + + gtk_tree_store_append(store, iter_detect, NULL); + gtk_tree_store_set(store, iter_detect, 0, GEANY_ENCODINGS_MAX, 1, _("Detect from file"), -1); + + gtk_tree_store_append(store, &iter_westeuro, NULL); + gtk_tree_store_set(store, &iter_westeuro, 0, -1, 1, _("West European"), -1); + gtk_tree_store_append(store, &iter_easteuro, NULL); + gtk_tree_store_set(store, &iter_easteuro, 0, -1, 1, _("East European"), -1); + gtk_tree_store_append(store, &iter_eastasian, NULL); + gtk_tree_store_set(store, &iter_eastasian, 0, -1, 1, _("East Asian"), -1); + gtk_tree_store_append(store, &iter_asian, NULL); + gtk_tree_store_set(store, &iter_asian, 0, -1, 1, _("SE & SW Asian"), -1); + gtk_tree_store_append(store, &iter_middleeast, NULL); + gtk_tree_store_set(store, &iter_middleeast, 0, -1, 1, _("Middle Eastern"), -1); + gtk_tree_store_append(store, &iter_utf8, NULL); + gtk_tree_store_set(store, &iter_utf8, 0, -1, 1, _("Unicode"), -1); + + for (i = 0; i < GEANY_ENCODINGS_MAX; i++) + { + switch (encodings[i].group) + { + case WESTEUROPEAN: iter_parent = &iter_westeuro; break; + case EASTEUROPEAN: iter_parent = &iter_easteuro; break; + case EASTASIAN: iter_parent = &iter_eastasian; break; + case ASIAN: iter_parent = &iter_asian; break; + case MIDDLEEASTERN: iter_parent = &iter_middleeast; break; + case UNICODE: iter_parent = &iter_utf8; break; + case NONE: + default: iter_parent = NULL; + } + gtk_tree_store_append(store, &iter_current, iter_parent); + encoding_string = encodings_to_string(&encodings[i]); + gtk_tree_store_set(store, &iter_current, 0, i, 1, encoding_string, -1); + g_free(encoding_string); + } + + gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), 1, GTK_SORT_ASCENDING); + gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), 1, encoding_combo_store_sort_func, NULL, NULL); + + return store; +} + + +static void encoding_combo_cell_data_func(GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + GtkTreeModel *tree_model, + GtkTreeIter *iter, + gpointer data) +{ + gboolean sensitive = !gtk_tree_model_iter_has_child(tree_model, iter); + + g_object_set(cell, "sensitive", sensitive, NULL); +} + + static void create_open_file_dialog(void) { GtkWidget *filetype_combo, *encoding_combo; GtkWidget *viewbtn; - guint i; - gchar *encoding_string; + GtkCellRenderer *encoding_renderer; + GtkTreeIter encoding_iter; GSList *node;
ui_widgets.open_filesel = gtk_file_chooser_dialog_new(_("Open File"), GTK_WINDOW(main_widgets.window), @@ -191,14 +286,14 @@
/* fill encoding combo box */ encoding_combo = ui_lookup_widget(ui_widgets.open_filesel, "encoding_combo"); - for (i = 0; i < GEANY_ENCODINGS_MAX; i++) - { - encoding_string = encodings_to_string(&encodings[i]); - gtk_combo_box_append_text(GTK_COMBO_BOX(encoding_combo), encoding_string); - g_free(encoding_string); - } - gtk_combo_box_append_text(GTK_COMBO_BOX(encoding_combo), _("Detect from file")); - gtk_combo_box_set_active(GTK_COMBO_BOX(encoding_combo), GEANY_ENCODINGS_MAX); + gtk_combo_box_set_model(GTK_COMBO_BOX(encoding_combo), GTK_TREE_MODEL( + create_encoding_combo_store(&encoding_iter))); + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(encoding_combo), &encoding_iter); + encoding_renderer = gtk_cell_renderer_text_new(); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(encoding_combo), encoding_renderer, TRUE); + gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(encoding_combo), encoding_renderer, "text", 1); + gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(encoding_combo), encoding_renderer, + encoding_combo_cell_data_func, NULL, NULL);
g_signal_connect(ui_widgets.open_filesel, "notify::show-hidden", G_CALLBACK(on_file_open_notify), NULL); @@ -284,8 +379,7 @@ (GtkAttachOptions) (0), 4, 5); /* the ebox is for the tooltip, because gtk_combo_box can't show tooltips */ encoding_ebox = gtk_event_box_new(); - encoding_combo = gtk_combo_box_new_text(); - gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(encoding_combo), 3); + encoding_combo = gtk_combo_box_new(); ui_widget_set_tooltip_text(encoding_ebox, _("Explicitly defines an encoding for the file, if it would not be detected. This is useful when you know that the encoding of a file cannot be detected correctly by Geany.\nNote if you choose multiple files, they will all be opened with the chosen encoding.")); gtk_container_add(GTK_CONTAINER(encoding_ebox), encoding_combo);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.