Revision: 3700 http://geany.svn.sourceforge.net/geany/?rev=3700&view=rev Author: ntrel Date: 2009-04-08 12:25:47 +0000 (Wed, 08 Apr 2009)
Log Message: ----------- Sort Configuration Files menu. Add ui_menu_sort_by_label(). Add foreach_list() macro.
Modified Paths: -------------- trunk/ChangeLog trunk/src/ui_utils.c trunk/src/ui_utils.h trunk/src/utils.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-04-07 22:09:23 UTC (rev 3699) +++ trunk/ChangeLog 2009-04-08 12:25:47 UTC (rev 3700) @@ -1,3 +1,11 @@ +2009-04-08 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com> + + * src/ui_utils.h, src/utils.h, src/ui_utils.c: + Sort Configuration Files menu. + Add ui_menu_sort_by_label(). + Add foreach_list() macro. + + 2009-04-07 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/main.c:
Modified: trunk/src/ui_utils.c =================================================================== --- trunk/src/ui_utils.c 2009-04-07 22:09:23 UTC (rev 3699) +++ trunk/src/ui_utils.c 2009-04-08 12:25:47 UTC (rev 3700) @@ -1723,6 +1723,13 @@ }
+static gboolean sort_menu(gpointer data) +{ + ui_menu_sort_by_label(GTK_MENU(data)); + return FALSE; +} + + static void create_config_files_menu(void) { GtkWidget *menu, *item; @@ -1733,6 +1740,9 @@ gtk_widget_show(item); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), item); + + /* sort menu after all items added */ + g_idle_add(sort_menu, widgets.config_files_menu); }
@@ -1994,3 +2004,38 @@ } }
+ +static gint compare_menu_item_labels(gconstpointer a, gconstpointer b) +{ + GtkMenuItem *item_a = GTK_MENU_ITEM(a); + GtkMenuItem *item_b = GTK_MENU_ITEM(b); + gchar *sa, *sb; + gint result; + + sa = ui_menu_item_get_text(item_a); + sb = ui_menu_item_get_text(item_b); + result = utils_str_casecmp(sa, sb); + g_free(sa); + g_free(sb); + return result; +} + + +/* Currently @a menu should contain only GtkMenuItems with labels. */ +void ui_menu_sort_by_label(GtkMenu *menu) +{ + GList *list = gtk_container_get_children(GTK_CONTAINER(menu)); + GList *node; + GtkWidget *child; + gint pos; + + list = g_list_sort(list, compare_menu_item_labels); + pos = 0; + foreach_list(child, node, list) + { + gtk_menu_reorder_child(menu, child, pos); + pos++; + } + g_list_free(list); +} +
Modified: trunk/src/ui_utils.h =================================================================== --- trunk/src/ui_utils.h 2009-04-07 22:09:23 UTC (rev 3699) +++ trunk/src/ui_utils.h 2009-04-08 12:25:47 UTC (rev 3700) @@ -164,6 +164,8 @@
void ui_widget_modify_font_from_string(GtkWidget *wid, const gchar *str);
+void ui_menu_sort_by_label(GtkMenu *menu); + gchar *ui_menu_item_get_text(GtkMenuItem *menu_item);
GtkWidget *ui_frame_new_with_alignment(const gchar *label_text, GtkWidget **alignment); @@ -197,7 +199,7 @@
void ui_entry_add_clear_icon(GtkWidget *entry);
-/* End of 'generic' functions */ +/* End of general widget functions */
void ui_init(void);
Modified: trunk/src/utils.h =================================================================== --- trunk/src/utils.h 2009-04-07 22:09:23 UTC (rev 3699) +++ trunk/src/utils.h 2009-04-08 12:25:47 UTC (rev 3700) @@ -62,7 +62,12 @@ for (node = list, data_ptr = node ? node->data : NULL; node != NULL; \ node = g_slist_next(node), data_ptr = node ? node->data : NULL)
+/* @param node should be a (GList*), needed for implementation. */ +#define foreach_list(data_ptr, node, list) \ + for (node = list, data_ptr = node ? node->data : NULL; node != NULL; \ + node = g_list_next(node), data_ptr = node ? node->data : NULL)
+ void utils_open_browser(const gchar *uri);
gint utils_get_line_endings(const gchar* buffer, glong size);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.