Revision: 4815 http://geany.svn.sourceforge.net/geany/?rev=4815&view=rev Author: frlan Date: 2010-04-09 20:42:45 +0000 (Fri, 09 Apr 2010)
Log Message: ----------- Make HTMLchars plugin remember whether replacement of special characters was activated even after restart of Geany or reloading of plugin.
Modified Paths: -------------- trunk/ChangeLog trunk/plugins/htmlchars.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-04-09 12:46:55 UTC (rev 4814) +++ trunk/ChangeLog 2010-04-09 20:42:45 UTC (rev 4815) @@ -1,3 +1,10 @@ +2010-04-09 Frank Lanitz <frank(at)frank(dot)uvena(dot)de> + + * plugins/htmlchars.c: + Make plugin remember whether replacement of special characters was + activated even after restart of Geany or reloading of plugin. + + 2010-04-09 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/editor.c:
Modified: trunk/plugins/htmlchars.c =================================================================== --- trunk/plugins/htmlchars.c 2010-04-09 12:46:55 UTC (rev 4814) +++ trunk/plugins/htmlchars.c 2010-04-09 20:42:45 UTC (rev 4815) @@ -68,6 +68,9 @@ static GtkWidget *menu_htmltoggle = NULL; static gboolean plugin_active = FALSE;
+/* Configuration file */ +static gchar *config_file = NULL; + const gchar *chars[][2] ={ { N_("HTML characters"), NULL }, { """, """ }, @@ -344,12 +347,38 @@ /* Functions to toggle the status of plugin */ void set_status(gboolean new_status) { - /* No more function at the moment.*/ if (plugin_active != new_status) + { + GKeyFile *config = g_key_file_new(); + gchar *data; + gchar *config_dir = g_path_get_dirname(config_file); + plugin_active = new_status; -}
+ /* Now we save the new status into configuration file to + * remember next time */ + g_key_file_set_boolean(config, "general", "replacement_on_typing_active", + plugin_active);
+ if (!g_file_test(config_dir, G_FILE_TEST_IS_DIR) + && utils_mkdir(config_dir, TRUE) != 0) + { + dialogs_show_msgbox(GTK_MESSAGE_ERROR, + _("Plugin configuration directory could not be created.")); + } + else + { + /* write config to file */ + data = g_key_file_to_data(config, NULL, NULL); + utils_write_file(config_file, data); + g_free(data); + } + g_free(config_dir); + g_key_file_free(config); + } +} + + static void toggle_status(G_GNUC_UNUSED GtkMenuItem * menuitem) { if (plugin_active == TRUE) @@ -430,9 +459,13 @@ static void kbhtmltoggle_toggle(G_GNUC_UNUSED guint key_id) { if (plugin_active == TRUE) + { set_status(FALSE); + } else + { set_status(TRUE); + } }
@@ -674,12 +707,32 @@ }
-/* Called by Geany to initialize the plugin */ +static void init_configuration() +{ + GKeyFile *config = g_key_file_new(); + + /* loading configurations from file ...*/ + config_file = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S, + "plugins", G_DIR_SEPARATOR_S, + "htmchars", G_DIR_SEPARATOR_S, "general.conf", NULL); + + /* ... and initialising options from config file */ + g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL); + + plugin_active = utils_get_setting_boolean(config, "general", + "replacement_on_typing_active", FALSE); +} + + +/* Called by Geany to initialise the plugin */ void plugin_init(GeanyData *data) { GtkWidget *menu_item; const gchar *menu_text = _("_Insert Special HTML Characters");
+ /* First we catch the configuration and initialize them */ + init_configuration(); + /* Add an item to the Tools menu for html chars dialog*/ menu_item = gtk_menu_item_new_with_mnemonic(menu_text); gtk_widget_show(menu_item); @@ -739,6 +792,9 @@
if (sc_dialog != NULL) gtk_widget_destroy(sc_dialog); + + if (config_file != NULL) + g_free(config_file); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.