Respect the history maxfiles key in gconf.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@11938 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton 2005-11-15 01:27:51 +00:00
parent 968730a00e
commit 5bef4a7fbf
2 changed files with 55 additions and 38 deletions

View File

@ -1,5 +1,9 @@
2005-11-14 David Hampton <hampton@employees.org>
* src/gnome-utils/gnc-plugin-file-history.c: Read the maxfiles key
from gconf. Move one function and change another to take a
partial key instead of a full key.
* src/gnome-utils/gnc-tree-model-commodity.c:
* src/gnome-utils/gnc-tree-model-price.c: Bump deleted item
removal to a higher priority.

View File

@ -123,18 +123,16 @@ gnc_history_gconf_index_to_key (guint index)
* uses sscanf to pull the number off the end of the key and convert
* it to an integer.
*
* @param fullkey The full gconf key starting with "/apps/...".
* @param key The last part of the gconf key.
*
* @return An index number that can be used with the
* gnc_plugin_actions array. */
static gint
gnc_history_gconf_key_to_index (const gchar *fullkey)
gnc_history_gconf_key_to_index (const gchar *key)
{
char *key;
gint index, result;
key = rindex(fullkey, '/');
result = sscanf(key+1, HISTORY_STRING_FILE_N, &index);
result = sscanf(key, HISTORY_STRING_FILE_N, &index);
if (result != 1)
return -1;
if ((index < 0) || (index >= gnc_plugin_n_actions))
@ -292,6 +290,7 @@ gnc_history_update_action (GncMainWindow *window,
GtkActionGroup *action_group;
GtkAction *action;
gchar *action_name, *label_name, *old_filename;
gint limit;
ENTER("window %p, index %d, filename %s", window, index, filename);
/* Get the action group */
@ -299,9 +298,13 @@ gnc_history_update_action (GncMainWindow *window,
gnc_main_window_get_action_group(window, PLUGIN_ACTIONS_NAME);
action_name = g_strdup_printf("RecentFile%dAction", index);
action = gtk_action_group_get_action (action_group, action_name);
action = gtk_action_group_get_action (action_group, action_name);
if (filename && (strlen(filename) > 0)) {
limit = gnc_gconf_get_int (HISTORY_STRING_SECTION,
HISTORY_STRING_MAXFILES,
NULL);
if (filename && (strlen(filename) > 0) && (index < limit)) {
/* set the menu label (w/accelerator) */
label_name = gnc_history_generate_label(index, filename);
g_object_set(G_OBJECT(action), "label", label_name, "visible", TRUE, NULL);
@ -320,6 +323,32 @@ gnc_history_update_action (GncMainWindow *window,
}
/** Update the file history menu for a window. This function walks
* the list of all possible gconf keys for the file history and
* forces a read/menu update on each key. It should only be called
* once when the window is created.
*
* @param window A pointer to the window whose file history menu
* should be updated.
*/
static void
gnc_history_update_menus (GncMainWindow *window)
{
gchar *filename, *key;
guint i;
ENTER("");
for (i = 0; i < MAX_HISTORY_FILES; i++) {
key = gnc_history_gconf_index_to_key(i);
filename = gnc_gconf_get_string(HISTORY_STRING_SECTION, key, NULL);
gnc_history_update_action(window, i, filename);
g_free(filename);
g_free(key);
}
LEAVE("");
}
/** Update an entry in the file history menu because a gconf entry
* changed. This function is called whenever an item in the gconf
* history section is changed. It is responsible for updating the
@ -343,16 +372,25 @@ gnc_plugin_history_list_changed (GConfClient *client,
{
GncMainWindow *window;
GConfValue *value;
const gchar *key, *filename;
const gchar *fullkey, *key, *filename;
gint index;
ENTER("");
key = gconf_entry_get_key(entry);
index = gnc_history_gconf_key_to_index(key);
if (index < 0)
return;
window = GNC_MAIN_WINDOW(user_data);
fullkey = gconf_entry_get_key(entry);
key = rindex(fullkey, '/') + 1;
if (strcmp(key, HISTORY_STRING_MAXFILES) == 0) {
gnc_history_update_menus (window);
LEAVE("updated maxfiles");
return;
}
index = gnc_history_gconf_key_to_index(key);
if (index < 0) {
LEAVE("bad index");
return;
}
value = gconf_entry_get_value(entry);
if (!value) {
LEAVE("No gconf value");
@ -365,31 +403,6 @@ gnc_plugin_history_list_changed (GConfClient *client,
LEAVE("");
}
/** Update the file history menu for a window. This function walks
* the list of all possible gconf keys for the file history and
* forces a read/menu update on each key. It should only be called
* once when the window is created.
*
* @param window A pointer to the window whose file history menu
* should be updated.
*/
static void
gnc_history_update_menus (GncMainWindow *window)
{
gchar *filename, *key;
guint i;
ENTER("");
for (i = 0; i < MAX_HISTORY_FILES; i++) {
key = gnc_history_gconf_index_to_key(i);
filename = gnc_gconf_get_string(HISTORY_STRING_SECTION, key, NULL);
gnc_history_update_action(window, i, filename);
g_free(filename);
g_free(key);
}
LEAVE("");
}
/************************************************************
* Object Implementation *