Revision: 3419 http://geany.svn.sourceforge.net/geany/?rev=3419&view=rev Author: ntrel Date: 2008-12-22 17:13:37 +0000 (Mon, 22 Dec 2008)
Log Message: ----------- Add stash_group_add_combo_box_entry(), stash_group_add_entry().
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 16:14:48 UTC (rev 3418) +++ trunk/ChangeLog 2008-12-22 17:13:37 UTC (rev 3419) @@ -7,6 +7,8 @@ Remove remaining PrefEntry code, use Stash instead. Add stash_group_add_spin_button_integer(), stash_group_add_combo_box(). + * src/prefs.c, src/stash.c, src/stash.h, src/keyfile.c: + Add stash_group_add_combo_box_entry(), stash_group_add_entry().
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 16:14:48 UTC (rev 3418) +++ trunk/src/keyfile.c 2008-12-22 17:13:37 UTC (rev 3419) @@ -113,8 +113,8 @@
group = stash_group_new(PACKAGE); configuration_add_pref_group(group, TRUE); - stash_group_add_string(group, &prefs.default_open_path, - "default_open_path", ""); + stash_group_add_entry(group, &prefs.default_open_path, + "default_open_path", "", "startup_path_entry");
stash_group_add_toggle_button(group, &file_prefs.cmdline_new_files, "cmdline_new_files", TRUE, "check_cmdline_new_files");
Modified: trunk/src/prefs.c =================================================================== --- trunk/src/prefs.c 2008-12-22 16:14:48 UTC (rev 3418) +++ trunk/src/prefs.c 2008-12-22 17:13:37 UTC (rev 3419) @@ -240,9 +240,6 @@ widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_contextaction"); gtk_entry_set_text(GTK_ENTRY(widget), tool_prefs.context_action_cmd);
- widget = ui_lookup_widget(ui_widgets.prefs_dialog, "startup_path_entry"); - gtk_entry_set_text(GTK_ENTRY(widget), prefs.default_open_path); - project_setup_prefs(); /* project files path */
@@ -659,10 +656,6 @@ g_free(tool_prefs.context_action_cmd); tool_prefs.context_action_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget)));
- widget = ui_lookup_widget(ui_widgets.prefs_dialog, "startup_path_entry"); - g_free(prefs.default_open_path); - prefs.default_open_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget))); - project_apply_prefs(); /* project file path */
Modified: trunk/src/stash.c =================================================================== --- trunk/src/stash.c 2008-12-22 16:14:48 UTC (rev 3418) +++ trunk/src/stash.c 2008-12-22 17:13:37 UTC (rev 3419) @@ -25,19 +25,21 @@ /* Mini-library for reading/writing GKeyFile settings and synchronizing widgets with * C variables. */
-/* Memory Usage +/* Terms + * 'Setting' is used only for data stored on disk or in memory. + * 'Pref' can also include visual widget information. + * + * Memory Usage * Stash will not duplicate strings if they are normally static arrays, such as - * keyfile group names and key names. - * - * Terms - * 'Setting' is used for data stored on disk or in memory. - * 'Pref' is used mainly for visual widget information. */ + * keyfile group names and key names, string default values or widget_id names. + * String settings and other dynamically allocated settings must be initialized to NULL. + */
#include <gtk/gtk.h>
#include "stash.h" -#include "utils.h" /* utils_get_setting_*() */ +#include "utils.h" /* only for utils_get_setting_*(). Stash should not depend on Geany. */
#define foreach_array(type, item, array) \ foreach_c_array(item, ((type*)(gpointer)array->data), array->len) @@ -236,7 +238,9 @@ }
-/* @param default_value Not duplicated. */ +/* The contents of @a setting will be freed before being replaced, so make sure it is + * 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) { @@ -297,6 +301,32 @@ }
+static void handle_entry(GtkWidget *widget, GeanyPrefEntry *entry, + PrefAction action) +{ + gchararray *setting = entry->setting; + + switch (action) + { + case PREF_DISPLAY: + gtk_entry_set_text(GTK_ENTRY(widget), *setting); + break; + case PREF_UPDATE: + g_free(*setting); + *setting = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget))); + break; + } +} + + +static void handle_combo_box_entry(GtkWidget *widget, GeanyPrefEntry *entry, + PrefAction action) +{ + widget = gtk_bin_get_child(GTK_BIN(widget)); + handle_entry(widget, entry, action); +} + + /* taken from Glade 2.x generated support.c */ static GtkWidget* lookup_widget (GtkWidget *widget, @@ -419,6 +449,10 @@ handle_spin_button(widget, entry, action); else if (entry->widget_type == GTK_TYPE_COMBO_BOX) handle_combo_box(widget, entry, action); + else if (entry->widget_type == GTK_TYPE_COMBO_BOX_ENTRY) + handle_combo_box_entry(widget, entry, action); + else if (entry->widget_type == GTK_TYPE_ENTRY) + handle_entry(widget, entry, action); else g_warning("Unhandled type for %s::%s in %s!", group->name, entry->key_name, G_GNUC_FUNCTION); @@ -524,7 +558,7 @@ }
-/* TODO: stash_group_add_combo_box_entry(). */ +/* @see 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) { @@ -533,3 +567,19 @@ }
+void stash_group_add_combo_box_entry(GeanyPrefGroup *group, gchar **setting, + const gchar *key_name, const gchar *default_value, gpointer widget_id) +{ + add_widget_pref(group, G_TYPE_STRING, setting, key_name, (gpointer)default_value, + GTK_TYPE_COMBO_BOX_ENTRY, widget_id); +} + + +void stash_group_add_entry(GeanyPrefGroup *group, gchar **setting, + const gchar *key_name, const gchar *default_value, gpointer widget_id) +{ + add_widget_pref(group, G_TYPE_STRING, setting, key_name, (gpointer)default_value, + GTK_TYPE_ENTRY, widget_id); +} + +
Modified: trunk/src/stash.h =================================================================== --- trunk/src/stash.h 2008-12-22 16:14:48 UTC (rev 3418) +++ trunk/src/stash.h 2008-12-22 17:13:37 UTC (rev 3419) @@ -69,4 +69,10 @@ void stash_group_add_combo_box(GeanyPrefGroup *group, gint *setting, const gchar *key_name, gint default_value, gpointer widget_id);
+void stash_group_add_combo_box_entry(GeanyPrefGroup *group, gchar **setting, + const gchar *key_name, const gchar *default_value, gpointer widget_id); + +void stash_group_add_entry(GeanyPrefGroup *group, gchar **setting, + const gchar *key_name, const gchar *default_value, gpointer widget_id); + #endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.