Revision: 2738 http://geany.svn.sourceforge.net/geany/?rev=2738&view=rev Author: eht16 Date: 2008-06-30 09:14:55 -0700 (Mon, 30 Jun 2008)
Log Message: ----------- Move code to read snippets configuration to editor.c. Split editor_snippets_free() from editor_finalize().
Modified Paths: -------------- trunk/ChangeLog trunk/src/editor.c trunk/src/editor.h trunk/src/keyfile.c trunk/src/keyfile.h trunk/src/main.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-06-30 15:59:00 UTC (rev 2737) +++ trunk/ChangeLog 2008-06-30 16:14:55 UTC (rev 2738) @@ -8,6 +8,9 @@ In templates_free_templates() destroy also file template menu items. Add reload argument to filetypes_load_config() to allow re-reading of the settings. + * src/editor.c, src/editor.h, src/keyfile.c, src/keyfile.h, src/main.c: + Move code to read snippets configuration to editor.c. + Split editor_snippets_free() from editor_finalize().
2008-06-30 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/src/editor.c =================================================================== --- trunk/src/editor.c 2008-06-30 15:59:00 UTC (rev 2737) +++ trunk/src/editor.c 2008-06-30 16:14:55 UTC (rev 2738) @@ -80,6 +80,95 @@ static void editor_auto_table(GeanyDocument *doc, gint pos);
+ +void editor_snippets_free() +{ + g_hash_table_destroy(editor_prefs.snippets); +} + + +void editor_snippets_init(void) +{ + gsize i, j, len = 0, len_keys = 0; + gchar *sysconfigfile, *userconfigfile; + gchar **groups_user, **groups_sys; + gchar **keys_user, **keys_sys; + gchar *value; + GKeyFile *sysconfig = g_key_file_new(); + GKeyFile *userconfig = g_key_file_new(); + GHashTable *tmp; + + sysconfigfile = g_strconcat(app->datadir, G_DIR_SEPARATOR_S, "snippets.conf", NULL); + userconfigfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "snippets.conf", NULL); + + /* check for old autocomplete.conf files (backwards compatibility) */ + if (! g_file_test(userconfigfile, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK)) + setptr(userconfigfile, + g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "autocomplete.conf", NULL)); + + /* load the actual config files */ + g_key_file_load_from_file(sysconfig, sysconfigfile, G_KEY_FILE_NONE, NULL); + g_key_file_load_from_file(userconfig, userconfigfile, G_KEY_FILE_NONE, NULL); + + /* keys are strings, values are GHashTables, so use g_free and g_hash_table_destroy */ + editor_prefs.snippets = + g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_destroy); + + /* first read all globally defined auto completions */ + groups_sys = g_key_file_get_groups(sysconfig, &len); + for (i = 0; i < len; i++) + { + keys_sys = g_key_file_get_keys(sysconfig, groups_sys[i], &len_keys, NULL); + /* create new hash table for the read section (=> filetype) */ + tmp = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + g_hash_table_insert(editor_prefs.snippets, g_strdup(groups_sys[i]), tmp); + + for (j = 0; j < len_keys; j++) + { + g_hash_table_insert(tmp, g_strdup(keys_sys[j]), + utils_get_setting_string(sysconfig, groups_sys[i], keys_sys[j], "")); + } + g_strfreev(keys_sys); + } + + /* now read defined completions in user's configuration directory and add / replace them */ + groups_user = g_key_file_get_groups(userconfig, &len); + for (i = 0; i < len; i++) + { + keys_user = g_key_file_get_keys(userconfig, groups_user[i], &len_keys, NULL); + + tmp = g_hash_table_lookup(editor_prefs.snippets, groups_user[i]); + if (tmp == NULL) + { /* new key found, create hash table */ + tmp = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + g_hash_table_insert(editor_prefs.snippets, g_strdup(groups_user[i]), tmp); + } + for (j = 0; j < len_keys; j++) + { + value = g_hash_table_lookup(tmp, keys_user[j]); + if (value == NULL) + { /* value = NULL means the key doesn't yet exist, so insert */ + g_hash_table_insert(tmp, g_strdup(keys_user[j]), + utils_get_setting_string(userconfig, groups_user[i], keys_user[j], "")); + } + else + { /* old key and value will be freed by destroy function (g_free) */ + g_hash_table_replace(tmp, g_strdup(keys_user[j]), + utils_get_setting_string(userconfig, groups_user[i], keys_user[j], "")); + } + } + g_strfreev(keys_user); + } + + g_free(sysconfigfile); + g_free(userconfigfile); + g_strfreev(groups_sys); + g_strfreev(groups_user); + g_key_file_free(sysconfig); + g_key_file_free(userconfig); +} + + /* calls the edit popup menu in the editor */ static gboolean on_editor_button_press_event (GtkWidget *widget, @@ -2860,8 +2949,6 @@
void editor_finalize() { - g_hash_table_destroy(editor_prefs.snippets); - scintilla_release_resources(); }
Modified: trunk/src/editor.h =================================================================== --- trunk/src/editor.h 2008-06-30 15:59:00 UTC (rev 2737) +++ trunk/src/editor.h 2008-06-30 16:14:55 UTC (rev 2738) @@ -154,7 +154,10 @@
void editor_finalize(void);
+void editor_snippets_init(void);
+void editor_snippets_free(void); + /* General editing functions */
void editor_find_current_word(ScintillaObject *sci, gint pos, gchar *word, size_t wordlen,
Modified: trunk/src/keyfile.c =================================================================== --- trunk/src/keyfile.c 2008-06-30 15:59:00 UTC (rev 2737) +++ trunk/src/keyfile.c 2008-06-30 16:14:55 UTC (rev 2738) @@ -1093,84 +1093,3 @@ g_key_file_free(userconfig); }
- -void configuration_read_snippets(void) -{ - gsize i, j, len = 0, len_keys = 0; - gchar *sysconfigfile, *userconfigfile; - gchar **groups_user, **groups_sys; - gchar **keys_user, **keys_sys; - gchar *value; - GKeyFile *sysconfig = g_key_file_new(); - GKeyFile *userconfig = g_key_file_new(); - GHashTable *tmp; - - sysconfigfile = g_strconcat(app->datadir, G_DIR_SEPARATOR_S, "snippets.conf", NULL); - userconfigfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "snippets.conf", NULL); - - /* check for old autocomplete.conf files (backwards compatibility) */ - if (! g_file_test(userconfigfile, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK)) - setptr(userconfigfile, - g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "autocomplete.conf", NULL)); - - /* load the actual config files */ - g_key_file_load_from_file(sysconfig, sysconfigfile, G_KEY_FILE_NONE, NULL); - g_key_file_load_from_file(userconfig, userconfigfile, G_KEY_FILE_NONE, NULL); - - /* keys are strings, values are GHashTables, so use g_free and g_hash_table_destroy */ - editor_prefs.snippets = - g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_destroy); - - /* first read all globally defined auto completions */ - groups_sys = g_key_file_get_groups(sysconfig, &len); - for (i = 0; i < len; i++) - { - keys_sys = g_key_file_get_keys(sysconfig, groups_sys[i], &len_keys, NULL); - /* create new hash table for the read section (=> filetype) */ - tmp = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - g_hash_table_insert(editor_prefs.snippets, g_strdup(groups_sys[i]), tmp); - - for (j = 0; j < len_keys; j++) - { - g_hash_table_insert(tmp, g_strdup(keys_sys[j]), - utils_get_setting_string(sysconfig, groups_sys[i], keys_sys[j], "")); - } - g_strfreev(keys_sys); - } - - /* now read defined completions in user's configuration directory and add / replace them */ - groups_user = g_key_file_get_groups(userconfig, &len); - for (i = 0; i < len; i++) - { - keys_user = g_key_file_get_keys(userconfig, groups_user[i], &len_keys, NULL); - - tmp = g_hash_table_lookup(editor_prefs.snippets, groups_user[i]); - if (tmp == NULL) - { /* new key found, create hash table */ - tmp = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - g_hash_table_insert(editor_prefs.snippets, g_strdup(groups_user[i]), tmp); - } - for (j = 0; j < len_keys; j++) - { - value = g_hash_table_lookup(tmp, keys_user[j]); - if (value == NULL) - { /* value = NULL means the key doesn't yet exist, so insert */ - g_hash_table_insert(tmp, g_strdup(keys_user[j]), - utils_get_setting_string(userconfig, groups_user[i], keys_user[j], "")); - } - else - { /* old key and value will be freed by destroy function (g_free) */ - g_hash_table_replace(tmp, g_strdup(keys_user[j]), - utils_get_setting_string(userconfig, groups_user[i], keys_user[j], "")); - } - } - g_strfreev(keys_user); - } - - g_free(sysconfigfile); - g_free(userconfigfile); - g_strfreev(groups_sys); - g_strfreev(groups_user); - g_key_file_free(sysconfig); - g_key_file_free(userconfig); -}
Modified: trunk/src/keyfile.h =================================================================== --- trunk/src/keyfile.h 2008-06-30 15:59:00 UTC (rev 2737) +++ trunk/src/keyfile.h 2008-06-30 16:14:55 UTC (rev 2738) @@ -42,8 +42,6 @@
void configuration_read_filetype_extensions(void);
-void configuration_read_snippets(void); - /* set some settings which are already read from the config file, but need other things, like the * realisation of the main window */ void configuration_apply_settings(void);
Modified: trunk/src/main.c =================================================================== --- trunk/src/main.c 2008-06-30 15:59:00 UTC (rev 2737) +++ trunk/src/main.c 2008-06-30 16:14:55 UTC (rev 2738) @@ -834,7 +834,7 @@ document_init_doclist(); treeviews_init(); configuration_read_filetype_extensions(); - configuration_read_snippets(); + editor_snippets_init();
/* set window icon */ { @@ -962,6 +962,7 @@ document_finalize(); symbols_finalize(); editor_finalize(); + editor_snippets_free(); encodings_finalize();
tm_workspace_free(TM_WORK_OBJECT(app->tm_workspace));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.