Add stash_group_add_combo_box_entry(), stash_group_add_entry().

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3419 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2008-12-22 17:13:37 +00:00
parent 6a2f565931
commit c56f0c450b
5 changed files with 69 additions and 18 deletions

View File

@ -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>

View File

@ -113,8 +113,8 @@ static void init_pref_groups(void)
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");

View File

@ -240,9 +240,6 @@ void prefs_init_dialog(void)
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 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data)
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 */

View File

@ -25,19 +25,21 @@
/* Mini-library for reading/writing GKeyFile settings and synchronizing widgets with
* C variables. */
/* 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 only for data stored on disk or in memory.
* 'Pref' can also include visual widget information.
*
* Terms
* 'Setting' is used for data stored on disk or in memory.
* 'Pref' is used mainly for visual widget information. */
* Memory Usage
* Stash will not duplicate strings if they are normally static arrays, such as
* 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 @@ void stash_group_add_integer(GeanyPrefGroup *group, gint *setting,
}
/* @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_combo_box(GtkWidget *widget, GeanyPrefEntry *entry,
}
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 @@ static void pref_action(PrefAction action, GeanyPrefGroup *group, GtkWidget *own
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 @@ void stash_group_add_spin_button_integer(GeanyPrefGroup *group, gint *setting,
}
/* 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(GeanyPrefGroup *group, gint *setting,
}
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);
}

View File

@ -69,4 +69,10 @@ void stash_group_add_spin_button_integer(GeanyPrefGroup *group, gint *setting,
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