Remove remaining PrefEntry code, use Stash instead.

Add stash_group_add_spin_button_integer(),
stash_group_add_combo_box().



git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3417 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2008-12-22 16:03:16 +00:00
parent e1cc154601
commit df5b4d85d9
5 changed files with 93 additions and 93 deletions

View File

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

View File

@ -131,20 +131,21 @@ static void init_pref_groups(void)
"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);

View File

@ -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 @@ typedef enum PrefCallbackAction
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 @@ static void prefs_action(PrefCallbackAction action)
break;
}
}
for (i = 0; i < G_N_ELEMENTS(pref_item_callbacks); i++)
pref_item_callbacks[i](action);
}
@ -271,11 +195,13 @@ static void init_keybindings(void)
}
/* 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 @@ void prefs_init_dialog(void)
/*
* 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 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data)
guint i;
guint autoclose_brackets[5];
/* Synchronize Stash settings */
prefs_action(PREF_UPDATE);
/* General settings */

View File

@ -257,6 +257,42 @@ static void handle_toggle_button(GtkWidget *widget, gboolean *setting,
}
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 @@ static void pref_action(PrefAction action, GeanyPrefGroup *group, GtkWidget *own
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_radio_buttons(GeanyPrefGroup *group, gint *setting,
}
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);
}

View File

@ -43,13 +43,6 @@ 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_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_update(GeanyPrefGroup *group, GtkWidget *owner);
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