Revision: 4278 http://geany.svn.sourceforge.net/geany/?rev=4278&view=rev Author: ntrel Date: 2009-10-01 11:56:04 +0000 (Thu, 01 Oct 2009)
Log Message: ----------- Group 'New with template' items by filetype submenu (currently only for toolbar menu). Show custom file template items before filetype template items.
Modified Paths: -------------- trunk/ChangeLog trunk/src/templates.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-10-01 11:18:26 UTC (rev 4277) +++ trunk/ChangeLog 2009-10-01 11:56:04 UTC (rev 4278) @@ -5,6 +5,10 @@ filetypes. * src/highlighting.c: Use jscript_keyword for SCE_HB[A]_WORD markup styles. + * src/templates.c: + Group 'New with template' items by filetype submenu (currently only for + toolbar menu). + Show custom file template items before filetype template items.
2009-09-30 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/src/templates.c =================================================================== --- trunk/src/templates.c 2009-10-01 11:18:26 UTC (rev 4277) +++ trunk/src/templates.c 2009-10-01 11:56:04 UTC (rev 4278) @@ -258,9 +258,10 @@
/* template items for the new file menu */ -static void create_new_filetype_items(void) +static gboolean create_new_filetype_items(void) { GSList *node; + gboolean ret = FALSE;
foreach_slist(node, filetypes_by_title) { @@ -280,7 +281,10 @@ gtk_widget_show(tmp_button); gtk_container_add(GTK_CONTAINER(toolbar_new_file_menu), tmp_button); g_signal_connect(tmp_button, "activate", G_CALLBACK(on_new_with_filetype_template), ft); + + ret = TRUE; } + return ret; }
@@ -346,14 +350,15 @@ }
-static void add_file_item(gpointer data, gpointer user_data) +static void add_file_item(const gchar *fname, GtkWidget *menu) { GtkWidget *tmp_menu, *tmp_button; gchar *label;
- g_return_if_fail(data); + g_return_if_fail(fname); + g_return_if_fail(menu);
- label = utils_get_utf8_from_locale(data); + label = utils_get_utf8_from_locale(fname);
tmp_menu = gtk_menu_item_new_with_label(label); gtk_widget_show(tmp_menu); @@ -362,13 +367,42 @@
tmp_button = gtk_menu_item_new_with_label(label); gtk_widget_show(tmp_button); - gtk_container_add(GTK_CONTAINER(toolbar_new_file_menu), tmp_button); + gtk_container_add(GTK_CONTAINER(menu), tmp_button); g_signal_connect(tmp_button, "activate", G_CALLBACK(on_new_with_file_template), NULL);
g_free(label); }
+static void add_file_items(GSList *list) +{ + GSList *node; + gsize size = sizeof(GtkWidget*) * filetypes_array->len; + GtkWidget **menus = g_alloca(size); + + memset(menus, 0, size); /* if only we had g_newa0() */ + + foreach_slist(node, list) + { + const gchar *fname = node->data; + GeanyFiletype *ft = filetypes_detect_from_extension(fname); + GtkWidget *menu = menus[ft->id]; + GtkWidget *item; + + if (!menu) + { + item = gtk_menu_item_new_with_label(ft->name); + menu = gtk_menu_new(); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); + gtk_widget_show_all(item); + gtk_container_add(GTK_CONTAINER(toolbar_new_file_menu), item); + menus[ft->id] = menu; + } + add_file_item(fname, menu); + } +} + + static gint compare_filenames_by_filetype(gconstpointer a, gconstpointer b) { GeanyFiletype *ft_a = filetypes_detect_from_extension(a); @@ -427,7 +461,7 @@ utils_slist_remove_next(node); } } - g_slist_foreach(list, add_file_item, NULL); + add_file_items(list); g_slist_foreach(list, (GFunc) g_free, NULL); g_slist_free(list); g_free(path); @@ -437,26 +471,25 @@
static void create_file_template_menus(void) { - GtkWidget *sep1, *sep2 = NULL; + GtkWidget *sep1 = NULL, *sep2 = NULL;
new_with_template_menu = ui_lookup_widget(main_widgets.window, "menu_new_with_template1_menu"); toolbar_new_file_menu = gtk_menu_new(); /* we hold our own ref on the menu in case it is not used in the toolbar */ g_object_ref(toolbar_new_file_menu);
- create_new_filetype_items(); - - sep1 = gtk_separator_menu_item_new(); - gtk_container_add(GTK_CONTAINER(new_with_template_menu), sep1); - sep2 = gtk_separator_menu_item_new(); - gtk_container_add(GTK_CONTAINER(toolbar_new_file_menu), sep2); - if (add_custom_template_items()) { + sep1 = gtk_separator_menu_item_new(); + gtk_container_add(GTK_CONTAINER(new_with_template_menu), sep1); + sep2 = gtk_separator_menu_item_new(); + gtk_container_add(GTK_CONTAINER(toolbar_new_file_menu), sep2); + } + if (create_new_filetype_items() && sep1) + { gtk_widget_show(sep1); gtk_widget_show(sep2); } - geany_menu_button_action_set_menu(GEANY_MENU_BUTTON_ACTION( toolbar_get_action_by_name("New")), toolbar_new_file_menu); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.