Revision: 3417 http://geany.svn.sourceforge.net/geany/?rev=3417&view=rev Author: ntrel Date: 2008-12-22 16:03:16 +0000 (Mon, 22 Dec 2008)
Log Message: ----------- Remove remaining PrefEntry code, use Stash instead. Add stash_group_add_spin_button_integer(), stash_group_add_combo_box().
Modified Paths: -------------- trunk/ChangeLog trunk/src/keyfile.c trunk/src/prefs.c trunk/src/stash.c trunk/src/stash.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-12-22 13:01:50 UTC (rev 3416) +++ trunk/ChangeLog 2008-12-22 16:03:16 UTC (rev 3417) @@ -3,6 +3,10 @@ * src/stash.c, src/stash.h, src/keyfile.c: Rename stash_group_load() -> stash_group_load_from_key_file(). Rename stash_group_save() -> stash_group_save_to_key_file(). + * src/prefs.c, src/stash.c, src/stash.h, src/keyfile.c: + Remove remaining PrefEntry code, use Stash instead. + Add stash_group_add_spin_button_integer(), + stash_group_add_combo_box().
2008-12-21 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/src/keyfile.c =================================================================== --- trunk/src/keyfile.c 2008-12-22 13:01:50 UTC (rev 3416) +++ trunk/src/keyfile.c 2008-12-22 16:03:16 UTC (rev 3417) @@ -131,20 +131,21 @@ "check_detect_indent", FALSE, "check_detect_indent"); stash_group_add_toggle_button(group, &editor_prefs.use_tab_to_indent, "use_tab_to_indent", TRUE, "check_tab_key_indents"); - stash_group_add_integer(group, &editor_prefs.indentation->width, - "pref_editor_tab_width", 4); - stash_group_add_integer(group, &editor_prefs.indentation->hard_tab_width, - "indent_hard_tab_width", 8); - stash_group_add_integer(group, (gint*)&editor_prefs.indentation->auto_indent_mode, - "indent_mode", GEANY_AUTOINDENT_CURRENTCHARS); + stash_group_add_spin_button_integer(group, &editor_prefs.indentation->width, + "pref_editor_tab_width", 4, "spin_indent_width"); + stash_group_add_spin_button_integer(group, &editor_prefs.indentation->hard_tab_width, + "indent_hard_tab_width", 8, "spin_tab_width"); + stash_group_add_combo_box(group, (gint*)&editor_prefs.indentation->auto_indent_mode, + "indent_mode", GEANY_AUTOINDENT_CURRENTCHARS, "combo_auto_indent_mode"); stash_group_add_radio_buttons(group, (gint*)&editor_prefs.indentation->type, "indent_type", GEANY_INDENT_TYPE_TABS, "radio_indent_spaces", GEANY_INDENT_TYPE_SPACES, "radio_indent_tabs", GEANY_INDENT_TYPE_TABS, "radio_indent_both", GEANY_INDENT_TYPE_BOTH, NULL); - stash_group_add_integer(group, (gint*)&editor_prefs.autocompletion_max_entries, - "autocompletion_max_entries", GEANY_MAX_AUTOCOMPLETE_WORDS); + stash_group_add_spin_button_integer(group, (gint*)&editor_prefs.autocompletion_max_entries, + "autocompletion_max_entries", GEANY_MAX_AUTOCOMPLETE_WORDS, + "spin_autocompletion_max_entries");
/* hidden prefs (don't overwrite them so users can edit them manually) */ group = stash_group_new(PACKAGE);
Modified: trunk/src/prefs.c =================================================================== --- trunk/src/prefs.c 2008-12-22 13:01:50 UTC (rev 3416) +++ trunk/src/prefs.c 2008-12-22 16:03:16 UTC (rev 3417) @@ -23,6 +23,7 @@
/* * Preferences dialog support functions. + * New prefs should use Stash code in keyfile.c - init_pref_groups(). */
#include <stdlib.h> @@ -100,83 +101,9 @@ PrefCallbackAction;
-typedef struct PrefEntry -{ - const gchar *widget_name; - gpointer setting; -} -PrefEntry; - - -static void spin_prefs_foreach(PrefCallbackAction action) -{ - guint i; - PrefEntry items[] = - { - {"spin_indent_width", &editor_prefs.indentation->width}, - {"spin_tab_width", &editor_prefs.indentation->hard_tab_width}, - {"spin_autocompletion_max_entries", &editor_prefs.autocompletion_max_entries} - }; - - for (i = 0; i < G_N_ELEMENTS(items); i++) - { - PrefEntry *pe = &items[i]; - GtkWidget *widget = ui_lookup_widget(ui_widgets.prefs_dialog, pe->widget_name); - gint *setting = pe->setting; - - switch (action) - { - case PREF_DISPLAY: - gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), *setting); - break; - case PREF_UPDATE: - *setting = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); - break; - } - } -} - - -static void combo_prefs_foreach(PrefCallbackAction action) -{ - guint i; - PrefEntry items[] = - { - {"combo_auto_indent_mode", &editor_prefs.indentation->auto_indent_mode} - }; - - for (i = 0; i < G_N_ELEMENTS(items); i++) - { - PrefEntry *pe = &items[i]; - GtkWidget *widget = ui_lookup_widget(ui_widgets.prefs_dialog, pe->widget_name); - gint *setting = pe->setting; - - switch (action) - { - case PREF_DISPLAY: - gtk_combo_box_set_active(GTK_COMBO_BOX(widget), *setting); - break; - case PREF_UPDATE: - *setting = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); - break; - } - } -} - - -typedef void (*PrefItemsCallback)(PrefCallbackAction action); - -/* List of functions which hold the PrefEntry arrays. These allow access to - * runtime setting fields like EditorPrefs::indentation->width. */ -PrefItemsCallback pref_item_callbacks[] = { - spin_prefs_foreach, - combo_prefs_foreach -}; - - +/* Synchronize Stash settings with widgets (see keyfile.c - init_pref_groups()). */ static void prefs_action(PrefCallbackAction action) { - guint i; GeanyPrefGroup *group; gpointer *ptr;
@@ -192,9 +119,6 @@ break; } } - - for (i = 0; i < G_N_ELEMENTS(pref_item_callbacks); i++) - pref_item_callbacks[i](action); }
@@ -271,11 +195,13 @@ }
+/* note: new prefs should use Stash code in keyfile.c */ void prefs_init_dialog(void) { GtkWidget *widget; GdkColor *color;
+ /* Synchronize with Stash settings */ prefs_action(PREF_DISPLAY);
/* General settings */ @@ -683,6 +609,7 @@ /* * callbacks */ +/* note: new prefs should use Stash code in keyfile.c */ static void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data) { @@ -692,6 +619,7 @@ guint i; guint autoclose_brackets[5];
+ /* Synchronize Stash settings */ prefs_action(PREF_UPDATE);
/* General settings */
Modified: trunk/src/stash.c =================================================================== --- trunk/src/stash.c 2008-12-22 13:01:50 UTC (rev 3416) +++ trunk/src/stash.c 2008-12-22 16:03:16 UTC (rev 3417) @@ -257,6 +257,42 @@ }
+static void handle_spin_button(GtkWidget *widget, GeanyPrefEntry *entry, + PrefAction action) +{ + gint *setting = entry->setting; + + g_assert(entry->type == G_TYPE_INT); /* only int spin prefs */ + + switch (action) + { + case PREF_DISPLAY: + gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), *setting); + break; + case PREF_UPDATE: + *setting = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); + break; + } +} + + +static void handle_combo_box(GtkWidget *widget, GeanyPrefEntry *entry, + PrefAction action) +{ + gint *setting = entry->setting; + + switch (action) + { + case PREF_DISPLAY: + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), *setting); + break; + case PREF_UPDATE: + *setting = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); + break; + } +} + + /* taken from Glade 2.x generated support.c */ static GtkWidget* lookup_widget (GtkWidget *widget, @@ -372,8 +408,13 @@ continue; }
+ /* note: can't use switch for GTK_TYPE macros */ if (entry->widget_type == GTK_TYPE_TOGGLE_BUTTON) handle_toggle_button(widget, entry->setting, action); + else if (entry->widget_type == GTK_TYPE_SPIN_BUTTON) + handle_spin_button(widget, entry, action); + else if (entry->widget_type == GTK_TYPE_COMBO_BOX) + handle_combo_box(widget, entry, action); else g_warning("Unhandled type for %s::%s in %s!", group->name, entry->key_name, G_GNUC_FUNCTION); @@ -471,3 +512,20 @@ }
+void stash_group_add_spin_button_integer(GeanyPrefGroup *group, gint *setting, + const gchar *key_name, gint default_value, gpointer widget_id) +{ + add_widget_pref(group, G_TYPE_INT, setting, key_name, GINT_TO_POINTER(default_value), + GTK_TYPE_SPIN_BUTTON, widget_id); +} + + +/* TODO: stash_group_add_combo_box_entry(). */ +void stash_group_add_combo_box(GeanyPrefGroup *group, gint *setting, + const gchar *key_name, gint default_value, gpointer widget_id) +{ + add_widget_pref(group, G_TYPE_INT, setting, key_name, GINT_TO_POINTER(default_value), + GTK_TYPE_COMBO_BOX, widget_id); +} + +
Modified: trunk/src/stash.h =================================================================== --- trunk/src/stash.h 2008-12-22 13:01:50 UTC (rev 3416) +++ trunk/src/stash.h 2008-12-22 16:03:16 UTC (rev 3417) @@ -43,13 +43,6 @@ void stash_group_add_string(GeanyPrefGroup *group, gchar **setting, const gchar *key_name, const gchar *default_value);
-void stash_group_add_toggle_button(GeanyPrefGroup *group, gboolean *setting, - const gchar *key_name, gboolean default_value, gpointer widget_id); - -void stash_group_add_radio_buttons(GeanyPrefGroup *group, gint *setting, - const gchar *key_name, gint default_value, - gpointer widget_id, gint enum_id, ...) G_GNUC_NULL_TERMINATED; - void stash_group_load_from_key_file(GeanyPrefGroup *group, GKeyFile *keyfile);
void stash_group_save_to_key_file(GeanyPrefGroup *group, GKeyFile *keyfile); @@ -60,4 +53,20 @@
void stash_group_free(GeanyPrefGroup *group);
+ +/* *** GTK-related functions *** */ + +void stash_group_add_toggle_button(GeanyPrefGroup *group, gboolean *setting, + const gchar *key_name, gboolean default_value, gpointer widget_id); + +void stash_group_add_radio_buttons(GeanyPrefGroup *group, gint *setting, + const gchar *key_name, gint default_value, + gpointer widget_id, gint enum_id, ...) G_GNUC_NULL_TERMINATED; + +void stash_group_add_spin_button_integer(GeanyPrefGroup *group, gint *setting, + const gchar *key_name, gint default_value, gpointer widget_id); + +void stash_group_add_combo_box(GeanyPrefGroup *group, gint *setting, + const gchar *key_name, gint default_value, gpointer widget_id); + #endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.