Revision: 5278 http://geany.svn.sourceforge.net/geany/?rev=5278&view=rev Author: ntrel Date: 2010-10-04 14:29:44 +0000 (Mon, 04 Oct 2010)
Log Message: ----------- Read snippet keybindings from system keyfile also. Add keybinding example to default snippet.conf.
Modified Paths: -------------- trunk/ChangeLog trunk/data/snippets.conf trunk/src/editor.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-10-04 14:20:40 UTC (rev 5277) +++ trunk/ChangeLog 2010-10-04 14:29:44 UTC (rev 5278) @@ -12,6 +12,9 @@ Add snippet keybindings docs. * src/highlighting.c, src/utils.h: Move foreach_strv to utils.h. + * src/editor.c, data/snippets.conf: + Read snippet keybindings from system keyfile also. + Add keybinding example to default snippet.conf.
2010-09-30 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/data/snippets.conf =================================================================== --- trunk/data/snippets.conf 2010-10-04 14:20:40 UTC (rev 5277) +++ trunk/data/snippets.conf 2010-10-04 14:29:44 UTC (rev 5278) @@ -39,6 +39,11 @@ block_cursor=\n{\n\t%cursor%\n}\n%cursor% #wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
+# Optional keybindings to insert snippets +# Note: these can be overridden by Geany's configurable keybindings +[Keybindings] +#for=<Ctrl>7 + [C++] for=for (int i = 0; i < %cursor%; i++)%brace_open%\n%brace_close%
Modified: trunk/src/editor.c =================================================================== --- trunk/src/editor.c 2010-10-04 14:20:40 UTC (rev 5277) +++ trunk/src/editor.c 2010-10-04 14:29:44 UTC (rev 5278) @@ -229,19 +229,19 @@ }
-static void load_kb(GKeyFile *userconfig) +static const gchar kb_group[] = "Keybindings"; + +static void add_kb(GKeyFile *keyfile, gchar **keys) { - gchar group[] = "Keybindings"; - gsize len, j; - gchar **keys = g_key_file_get_keys(userconfig, group, &len, NULL); + gsize i;
if (!keys) return; - for (j = 0; j < len; j++) + for (i = 0; i < g_strv_length(keys); i++) { guint key; GdkModifierType mods; - gchar *accel_string = g_key_file_get_value(userconfig, group, keys[j], NULL); + gchar *accel_string = g_key_file_get_value(keyfile, kb_group, keys[i], NULL);
gtk_accelerator_parse(accel_string, &key, &mods); g_free(accel_string); @@ -253,9 +253,26 @@ } gtk_accel_group_connect(snippet_accel_group, key, mods, 0, g_cclosure_new_swap((GCallback)on_snippet_keybinding_activate, - g_strdup(keys[j]), (GClosureNotify)g_free)); + g_strdup(keys[i]), (GClosureNotify)g_free)); } +} + + +static void load_kb(GKeyFile *sysconfig, GKeyFile *userconfig) +{ + gchar **keys = g_key_file_get_keys(userconfig, kb_group, NULL, NULL); + gchar **ptr; + + /* remove overridden keys in sys file */ + foreach_strv(ptr, keys) + g_key_file_remove_key(sysconfig, kb_group, *ptr, NULL); + + add_kb(userconfig, keys); g_strfreev(keys); + + keys = g_key_file_get_keys(sysconfig, kb_group, NULL, NULL); + add_kb(sysconfig, keys); + g_strfreev(keys); }
@@ -284,7 +301,7 @@ /* setup snippet keybindings */ snippet_accel_group = gtk_accel_group_new(); gtk_window_add_accel_group(GTK_WINDOW(main_widgets.window), snippet_accel_group); - load_kb(userconfig); + load_kb(sysconfig, userconfig);
g_free(sysconfigfile); g_free(userconfigfile);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.