Don't forget active plugins after disabling plugin support.
Use Stash for plugin-related prefs. Add geany_object "save-settings" signal (for core only). Add stash_group_add_string_vector(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3425 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
1a7f04c8da
commit
0f575ea2b7
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
||||
2008-12-28 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
||||
|
||||
* src/prefs.c, src/geanyobject.c, src/geanyobject.h, src/stash.c,
|
||||
src/stash.h, src/keyfile.c, src/plugins.c, src/main.c,
|
||||
src/plugins.h:
|
||||
Don't forget active plugins after disabling plugin support.
|
||||
Use Stash for plugin-related prefs.
|
||||
Add geany_object "save-settings" signal (for core only).
|
||||
Add stash_group_add_string_vector().
|
||||
|
||||
|
||||
2008-12-27 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
||||
|
||||
* src/interface.c, src/interface.h, src/project.c, src/project.h,
|
||||
|
||||
@ -22,9 +22,14 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/* GObject used for connecting and emitting signals when certain events happen,
|
||||
/* A GObject used for connecting and emitting signals when certain events happen,
|
||||
* e.g. opening a document.
|
||||
* Mainly used for plugins - geany_object is created in plugins_init(). */
|
||||
* Mainly used for plugins - see the API docs.
|
||||
*
|
||||
* Core-only signals:
|
||||
* signal void save_settings(GObject *obj, GKeyFile *keyfile, gpointer user_data);
|
||||
* Emitted just before saving main keyfile settings.
|
||||
*/
|
||||
|
||||
#include "geany.h"
|
||||
#include "geanyobject.h"
|
||||
@ -255,6 +260,17 @@ static void create_signals(GObjectClass *g_object_class)
|
||||
geany_cclosure_marshal_BOOL__POINTER_POINTER,
|
||||
G_TYPE_BOOLEAN, 2,
|
||||
G_TYPE_POINTER, G_TYPE_POINTER);
|
||||
|
||||
/* Core-only signals */
|
||||
geany_object_signals[GCB_SAVE_SETTINGS] = g_signal_new (
|
||||
"save-settings",
|
||||
G_OBJECT_CLASS_TYPE (g_object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (GeanyObjectClass, save_settings),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__POINTER,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_POINTER);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -44,8 +44,10 @@ typedef enum
|
||||
GCB_PROJECT_CLOSE,
|
||||
GCB_UPDATE_EDITOR_MENU,
|
||||
GCB_EDITOR_NOTIFY,
|
||||
GCB_SAVE_SETTINGS,
|
||||
GCB_MAX
|
||||
} GeanyCallbackId;
|
||||
}
|
||||
GeanyCallbackId;
|
||||
|
||||
|
||||
#define GEANY_OBJECT_TYPE (geany_object_get_type())
|
||||
@ -83,6 +85,7 @@ struct _GeanyObjectClass
|
||||
void (*project_close)(void);
|
||||
void (*update_editor_menu)(const gchar *word, gint click_pos, GeanyDocument *doc);
|
||||
gboolean (*editor_notify)(GeanyEditor *editor, gpointer scnt);
|
||||
void (*save_settings)(GKeyFile *keyfile);
|
||||
};
|
||||
|
||||
GType geany_object_get_type (void);
|
||||
|
||||
@ -57,10 +57,10 @@
|
||||
#include "project.h"
|
||||
#include "editor.h"
|
||||
#include "printing.h"
|
||||
#include "plugins.h"
|
||||
#include "templates.h"
|
||||
#include "toolbar.h"
|
||||
#include "stash.h"
|
||||
#include "geanyobject.h"
|
||||
|
||||
|
||||
/* some default settings which are used at the very first start of Geany to fill
|
||||
@ -493,10 +493,10 @@ void configuration_save(void)
|
||||
|
||||
g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL);
|
||||
|
||||
/* this signal can be used e.g. to prepare any settings before Stash code reads them below */
|
||||
g_signal_emit_by_name(geany_object, "save-settings", config);
|
||||
|
||||
save_dialog_prefs(config);
|
||||
#ifdef HAVE_PLUGINS
|
||||
plugins_save_prefs(config);
|
||||
#endif
|
||||
save_ui_prefs(config);
|
||||
project_save_prefs(config); /* save project filename, etc. */
|
||||
save_recent_files(config);
|
||||
@ -877,9 +877,6 @@ gboolean configuration_load(void)
|
||||
g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL);
|
||||
|
||||
load_dialog_prefs(config);
|
||||
#ifdef HAVE_PLUGINS
|
||||
plugins_load_prefs(config);
|
||||
#endif
|
||||
load_ui_prefs(config);
|
||||
project_load_prefs(config);
|
||||
configuration_load_session_files(config);
|
||||
|
||||
11
src/main.c
11
src/main.c
@ -919,10 +919,14 @@ gint main(gint argc, gchar **argv)
|
||||
|
||||
encodings_init();
|
||||
editor_init();
|
||||
project_init();
|
||||
|
||||
configuration_init();
|
||||
/* init stash code before loading keyfile */
|
||||
search_init();
|
||||
project_init();
|
||||
#ifdef HAVE_PLUGINS
|
||||
plugins_init();
|
||||
#endif
|
||||
load_settings();
|
||||
|
||||
msgwin_init();
|
||||
@ -983,7 +987,7 @@ gint main(gint argc, gchar **argv)
|
||||
#ifdef HAVE_PLUGINS
|
||||
/* load any enabled plugins before we open any documents */
|
||||
if (want_plugins)
|
||||
plugins_init();
|
||||
plugins_load_active();
|
||||
#endif
|
||||
|
||||
/* load keybinding settings after plugins have added their groups */
|
||||
@ -1037,8 +1041,7 @@ void main_quit()
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PLUGINS
|
||||
if (want_plugins)
|
||||
plugins_free();
|
||||
plugins_finalize();
|
||||
#endif
|
||||
|
||||
navqueue_free();
|
||||
|
||||
@ -59,6 +59,8 @@
|
||||
#include "navqueue.h"
|
||||
#include "main.h"
|
||||
#include "toolbar.h"
|
||||
#include "stash.h"
|
||||
#include "keyfile.h"
|
||||
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
@ -95,6 +97,8 @@ typedef struct Plugin
|
||||
Plugin;
|
||||
|
||||
|
||||
static gboolean want_plugins = FALSE;
|
||||
|
||||
/* list of all available, loadable plugins, only valid as long as the plugin manager dialog is
|
||||
* opened, afterwards it will be destroyed */
|
||||
static GList *plugin_list = NULL;
|
||||
@ -833,10 +837,13 @@ static void on_tools_menu_show(GtkWidget *menu_item, G_GNUC_UNUSED gpointer user
|
||||
}
|
||||
|
||||
|
||||
void plugins_init()
|
||||
/* Calling this starts up plugin support */
|
||||
void plugins_load_active(void)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
|
||||
want_plugins = TRUE;
|
||||
|
||||
geany_data_init();
|
||||
|
||||
widget = gtk_separator_menu_item_new();
|
||||
@ -903,31 +910,32 @@ static void update_active_plugins_pref(void)
|
||||
}
|
||||
|
||||
|
||||
void plugins_save_prefs(GKeyFile *config)
|
||||
static void on_save_settings(GKeyFile *config)
|
||||
{
|
||||
g_key_file_set_boolean(config, "plugins", "load_plugins", prefs.load_plugins);
|
||||
|
||||
update_active_plugins_pref();
|
||||
if (active_plugins_pref != NULL)
|
||||
g_key_file_set_string_list(config, "plugins", "active_plugins",
|
||||
(const gchar**)active_plugins_pref, g_strv_length(active_plugins_pref));
|
||||
else
|
||||
{
|
||||
/* use an empty dummy array to override maybe exisiting value */
|
||||
const gchar *dummy[] = { "" };
|
||||
g_key_file_set_string_list(config, "plugins", "active_plugins", dummy, 1);
|
||||
}
|
||||
/* if plugins are disabled, don't clear list of active plugins */
|
||||
if (want_plugins)
|
||||
update_active_plugins_pref();
|
||||
}
|
||||
|
||||
|
||||
void plugins_load_prefs(GKeyFile *config)
|
||||
/* called even if plugin support is disabled */
|
||||
void plugins_init(void)
|
||||
{
|
||||
prefs.load_plugins = utils_get_setting_boolean(config, "plugins", "load_plugins", TRUE);
|
||||
active_plugins_pref = g_key_file_get_string_list(config, "plugins", "active_plugins", NULL, NULL);
|
||||
GeanyPrefGroup *group;
|
||||
|
||||
group = stash_group_new("plugins");
|
||||
configuration_add_pref_group(group, TRUE);
|
||||
|
||||
stash_group_add_toggle_button(group, &prefs.load_plugins,
|
||||
"load_plugins", TRUE, "check_plugins");
|
||||
|
||||
g_signal_connect(geany_object, "save-settings", G_CALLBACK(on_save_settings), NULL);
|
||||
stash_group_add_string_vector(group, &active_plugins_pref, "active_plugins", NULL);
|
||||
}
|
||||
|
||||
|
||||
void plugins_free(void)
|
||||
/* called even if plugin support is disabled */
|
||||
void plugins_finalize(void)
|
||||
{
|
||||
if (failed_plugins_list != NULL)
|
||||
{
|
||||
|
||||
@ -30,11 +30,9 @@
|
||||
|
||||
void plugins_init(void);
|
||||
|
||||
void plugins_free(void);
|
||||
void plugins_finalize(void);
|
||||
|
||||
void plugins_save_prefs(GKeyFile *config);
|
||||
|
||||
void plugins_load_prefs(GKeyFile *config);
|
||||
void plugins_load_active(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -221,9 +221,6 @@ static void prefs_init_dialog(void)
|
||||
widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_save_win_pos");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.save_winpos);
|
||||
|
||||
widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_plugins");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.load_plugins);
|
||||
|
||||
widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ask_for_quit");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.confirm_exit);
|
||||
|
||||
@ -636,9 +633,6 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data)
|
||||
widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_save_win_pos");
|
||||
prefs.save_winpos = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
|
||||
|
||||
widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_plugins");
|
||||
prefs.load_plugins = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
|
||||
|
||||
widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ask_for_quit");
|
||||
prefs.confirm_exit = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
|
||||
|
||||
|
||||
49
src/stash.c
49
src/stash.c
@ -155,6 +155,35 @@ static void handle_string_setting(GeanyPrefGroup *group, GeanyPrefEntry *se,
|
||||
}
|
||||
|
||||
|
||||
static void handle_strv_setting(GeanyPrefGroup *group, GeanyPrefEntry *se,
|
||||
GKeyFile *config, SettingAction action)
|
||||
{
|
||||
gchararray **setting = se->setting;
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case SETTING_READ:
|
||||
g_strfreev(*setting);
|
||||
*setting = g_key_file_get_string_list(config, group->name, se->key_name,
|
||||
NULL, NULL);
|
||||
if (*setting == NULL)
|
||||
*setting = g_strdupv(se->default_value);
|
||||
break;
|
||||
|
||||
case SETTING_WRITE:
|
||||
{
|
||||
/* don't try to save a NULL string vector */
|
||||
gchar *dummy[] = { "", NULL };
|
||||
gchar **strv = *setting ? *setting : dummy;
|
||||
|
||||
g_key_file_set_string_list(config, group->name, se->key_name,
|
||||
(const gchar**)strv, g_strv_length(strv));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void keyfile_action(SettingAction action, GeanyPrefGroup *group, GKeyFile *keyfile)
|
||||
{
|
||||
GeanyPrefEntry *entry;
|
||||
@ -179,8 +208,12 @@ static void keyfile_action(SettingAction action, GeanyPrefGroup *group, GKeyFile
|
||||
case G_TYPE_STRING:
|
||||
handle_string_setting(group, entry, keyfile, action); break;
|
||||
default:
|
||||
g_warning("Unhandled type for %s::%s in %s!", group->name, entry->key_name,
|
||||
G_GNUC_FUNCTION);
|
||||
/* G_TYPE_STRV is not a constant */
|
||||
if (entry->setting_type == G_TYPE_STRV)
|
||||
handle_strv_setting(group, entry, keyfile, action);
|
||||
else
|
||||
g_warning("Unhandled type for %s::%s in %s!", group->name, entry->key_name,
|
||||
G_GNUC_FUNCTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -271,7 +304,7 @@ void stash_group_add_integer(GeanyPrefGroup *group, gint *setting,
|
||||
|
||||
|
||||
/* The contents of @a setting will be freed before being replaced, so make sure it is
|
||||
* initialized to @c NULL.
|
||||
* allocated, or initialized to @c NULL.
|
||||
* @param default_value Not duplicated. */
|
||||
void stash_group_add_string(GeanyPrefGroup *group, gchar **setting,
|
||||
const gchar *key_name, const gchar *default_value)
|
||||
@ -280,6 +313,16 @@ void stash_group_add_string(GeanyPrefGroup *group, gchar **setting,
|
||||
}
|
||||
|
||||
|
||||
/* The contents of @a setting will be freed before being replaced, so make sure it is
|
||||
* allocated, or initialized to @c NULL.
|
||||
* @param default_value Not duplicated. */
|
||||
void stash_group_add_string_vector(GeanyPrefGroup *group, gchar ***setting,
|
||||
const gchar *key_name, const gchar **default_value)
|
||||
{
|
||||
add_pref(group, G_TYPE_STRV, setting, key_name, (gpointer)default_value);
|
||||
}
|
||||
|
||||
|
||||
/* *** GTK-related functions *** */
|
||||
|
||||
static void handle_toggle_button(GtkWidget *widget, gboolean *setting,
|
||||
|
||||
11
src/stash.h
11
src/stash.h
@ -45,14 +45,13 @@ void stash_group_add_integer(GeanyPrefGroup *group, gint *setting,
|
||||
void stash_group_add_string(GeanyPrefGroup *group, gchar **setting,
|
||||
const gchar *key_name, const gchar *default_value);
|
||||
|
||||
void stash_group_add_string_vector(GeanyPrefGroup *group, gchar ***setting,
|
||||
const gchar *key_name, const gchar **default_value);
|
||||
|
||||
void stash_group_load_from_key_file(GeanyPrefGroup *group, GKeyFile *keyfile);
|
||||
|
||||
void stash_group_save_to_key_file(GeanyPrefGroup *group, GKeyFile *keyfile);
|
||||
|
||||
void stash_group_display(GeanyPrefGroup *group, GtkWidget *owner);
|
||||
|
||||
void stash_group_update(GeanyPrefGroup *group, GtkWidget *owner);
|
||||
|
||||
void stash_group_free(GeanyPrefGroup *group);
|
||||
|
||||
|
||||
@ -77,4 +76,8 @@ void stash_group_add_combo_box_entry(GeanyPrefGroup *group, gchar **setting,
|
||||
void stash_group_add_entry(GeanyPrefGroup *group, gchar **setting,
|
||||
const gchar *key_name, const gchar *default_value, gpointer widget_id);
|
||||
|
||||
void stash_group_display(GeanyPrefGroup *group, GtkWidget *owner);
|
||||
|
||||
void stash_group_update(GeanyPrefGroup *group, GtkWidget *owner);
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user