From 9b2153ccdb0398b505bd5133414008629711a06b Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Mon, 8 May 2000 07:11:08 +0000 Subject: [PATCH] Robby Stephenson's patch to add file history selections to the main menu. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2272 57a11ea4-9604-0410-9ed3-97b8803252fd --- doc/README | 4 +- doc/html/C/xacc-about.html | 7 +- src/FileDialog.c | 3 + src/file-history.h | 31 ++++++ src/gnome/Makefile.in | 2 +- src/gnome/file-history.c | 197 +++++++++++++++++++++++++++++++++ src/gnome/window-adjust.c | 12 +- src/gnome/window-main.c | 2 + src/messages_i18n.h | 3 + src/scm/report/hello-world.scm | 3 + 10 files changed, 256 insertions(+), 8 deletions(-) create mode 100644 src/file-history.h create mode 100644 src/gnome/file-history.c diff --git a/doc/README b/doc/README index 689a2ff2f46..027c157c866 100644 --- a/doc/README +++ b/doc/README @@ -535,7 +535,7 @@ Rob Browning abused everyone for not using perl, Dave Peticolas hacks obsessively on GnuCash. But he can stop anytime he wants to. Really. -Bill Gribble works magic. If your checks print +Bill Gribble works magic. If your checks print wrong, blame him. If you don't like the amount printed on your checks, blame him. If you don't like your your bank balances, your bank, or your life, blame him too. @@ -601,7 +601,7 @@ Christopher Seawood for XbaeMatrix core dump Mike Simons misc configure.in patches Richard Skelton for Solaris cleanup Henning Spruth for German text & euro date rework -Robby Stephenson register patch +Robby Stephenson register & file history patches Herbert Thoma gnome register & euro support patches Diane Trout scheme qif import patch Richard Wackerbarth patch to gnc-prices diff --git a/doc/html/C/xacc-about.html b/doc/html/C/xacc-about.html index 587f818d3b0..8c8081f1aab 100644 --- a/doc/html/C/xacc-about.html +++ b/doc/html/C/xacc-about.html @@ -206,7 +206,7 @@

Lead Developers

hacks obsessively on GnuCash. But he can stop anytime he wants to. Really.
-
Bill Gribble +
Bill Gribble
works magic. If your checks print wrong, blame him. @@ -477,9 +477,10 @@

Fixers and Patchers

for German text and euro date rework
-
Robby Stephenson
+
Robby + Stephenson
-
register patch
+
register & file history patches
Herbert Thoma
diff --git a/src/FileDialog.c b/src/FileDialog.c index 3e147db5cdd..549c80dc156 100644 --- a/src/FileDialog.c +++ b/src/FileDialog.c @@ -34,6 +34,7 @@ #include "Destroy.h" #include "util.h" #include "ui-callbacks.h" +#include "file-history.h" /* This static indicates the debugging module that this .o belongs to. */ // static short module = MOD_GUI; @@ -279,6 +280,7 @@ gncPostFileOpen (const char * filename) /* clean up old stuff, and then we're outta here. */ xaccLogDisable(); xaccLogSetBaseName (newfile); + gnc_history_add_file (newfile); /* destroy open windows first, before destroying the group itself */ xaccGroupWindowDestroy (oldgrp); xaccFreeAccountGroup (oldgrp); @@ -375,6 +377,7 @@ gncFileSave (void) /* check for i/o error, put up appropriate error message */ io_error = xaccGetFileIOError(); newfile = xaccSessionGetFilePath(current_session); + gnc_history_add_file(newfile); SHOW_IO_ERR_MSG(io_error); /* going down -- abandon ship */ diff --git a/src/file-history.h b/src/file-history.h new file mode 100644 index 00000000000..8b23f21a08c --- /dev/null +++ b/src/file-history.h @@ -0,0 +1,31 @@ +/********************************************************************\ + * file-history.h -- functions to maintain file-history menu * + * Copyright (C) 2000 Robby Stephenson * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * +\********************************************************************/ + +#ifndef __HISTORY_H__ +#define __HISTORY_H__ + +#define MAX_HISTORY 4 + +void gnc_history_add_file(char *); +void gnc_history_update_menu(); + +#endif diff --git a/src/gnome/Makefile.in b/src/gnome/Makefile.in index 01e11a40ec2..73184910d92 100644 --- a/src/gnome/Makefile.in +++ b/src/gnome/Makefile.in @@ -70,7 +70,7 @@ GNOME_SRCS := top-level.c window-main.c window-register.c window-adjust.c \ extensions.c query-user.c reconcile-list.c \ window-report.c global-options.c gnc-dateedit.c \ dialog-qif-import.c glade-gnc-dialogs.c gnc-datedelta.c \ - dialog-account-picker.c print-session.c \ + dialog-account-picker.c print-session.c file-history.c \ dialog-print-check.c dialog-find-transactions.c ###################################################################### diff --git a/src/gnome/file-history.c b/src/gnome/file-history.c new file mode 100644 index 00000000000..a136dc96150 --- /dev/null +++ b/src/gnome/file-history.c @@ -0,0 +1,197 @@ +/********************************************************************\ + * file-history.c -- functions to maintain file history menu * + * Copyright (C) 2000 Robby Stephenson * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * +\********************************************************************/ + +#include "config.h" + +#include + +#include "file-history.h" +#include "FileDialog.h" +#include "ui-callbacks.h" +#include "messages.h" +#include "util.h" + +static GSList *history_list = NULL; +static gint num_menu_entries = -1; + +static void +__gnc_history_config_write() +{ + int max_files, i = 0; + char *key; + GSList *tmp; + + if(history_list == NULL) + return; + + key = g_strdup_printf("/GnuCash/History/MaxFiles=%d", MAX_HISTORY); + max_files = gnome_config_get_int(key); + g_free(key); + + gnome_config_clean_section("/GnuCash/History/"); + gnome_config_push_prefix("/GnuCash/History/"); + gnome_config_set_int("MaxFiles", max_files); + + for(tmp = history_list; tmp != NULL; tmp = tmp->next) { + key = g_strdup_printf("File%d", i); + gnome_config_set_string(key, (char *)tmp->data); + g_free(key); + i++; + } + + gnome_config_sync(); + gnome_config_pop_prefix(); +} + +static void +__gnc_history_get_list() +{ + int max_files, i; + char *key, *filename; + + key = g_strdup_printf("/GnuCash/History/MaxFiles=%d", MAX_HISTORY); + max_files = gnome_config_get_int(key); + g_free(key); + + gnome_config_push_prefix("/GnuCash/History/"); + + for(i = 0; i < max_files; i++) { + key = g_strdup_printf("File%d", i); + filename = gnome_config_get_string(key); + + if(filename == NULL) { + g_free(key); + break; + } + history_list = g_slist_prepend(history_list, filename); + g_free(key); + } + + gnome_config_pop_prefix(); + + history_list = g_slist_reverse(history_list); +} + +static void +__gnc_history_file_cb(GtkWidget *w, char *data) +{ + gncFileOpenFile(data); + gnc_refresh_main_window(); +} + +void +gnc_history_add_file(char *newfile) +{ + int i, max_files; + gboolean used_default, matched = FALSE; + char *key = NULL; + GSList *tmp, *new_list = NULL; + + if (newfile == NULL) + return; + + gnome_config_push_prefix("/GnuCash/History/"); + key = g_strdup_printf("/GnuCash/History/MaxFiles=%d", MAX_HISTORY); + max_files = gnome_config_get_int_with_default(key, &used_default); + g_free(key); + + if(used_default) + gnome_config_set_int("MaxFiles", max_files); + + if(history_list == NULL) + __gnc_history_get_list(); + + i = 0; + tmp = history_list; + while(tmp != NULL && i < max_files) { + if(!matched && /* no match yet */ + ((i == max_files - 1) || /* last entry */ + (strcmp(newfile, (char *)tmp->data) == 0)) ) { /* filename match */ + g_free(tmp->data); + matched = TRUE; + } else { + new_list = g_slist_prepend(new_list, tmp->data); + } + i++; + tmp = tmp->next; + } + + new_list = g_slist_reverse(new_list); + new_list = g_slist_prepend(new_list, g_strdup(newfile)); + g_slist_free(history_list); + history_list = new_list; + + __gnc_history_config_write(); +} + +void +gnc_history_update_menu() +{ + GnomeApp *app; + GnomeUIInfo *menu; + char *path; + int i, n; + + app = GNOME_APP(gnc_get_ui_data()); + if (app == NULL) + return; + + gnome_app_remove_menu_range(app, _("_File/"), 7, 1+num_menu_entries); + + if(history_list == NULL) + __gnc_history_get_list(); + + if(history_list == NULL) + return; + + n = g_slist_length(history_list); + /* one separator, plus one for each filename entry, plus one for end */ + menu = g_new(GnomeUIInfo, 2+n); + + menu->type = GNOME_APP_UI_SEPARATOR; + + for(i = 1; i <= n; i++) { + (menu+i)->type = GNOME_APP_UI_ITEM; + (menu+i)->label = g_strdup_printf("_%d. %s", i, + (char *)g_slist_nth_data(history_list, + i-1)); + (menu+i)->hint = NULL; + + (menu+i)->moreinfo = (gpointer)__gnc_history_file_cb; + (menu+i)->user_data = (char *)g_slist_nth_data(history_list, i-1); + (menu+i)->unused_data = NULL; + (menu+i)->pixmap_type = 0; + (menu+i)->pixmap_info = NULL; + (menu+i)->accelerator_key = 0; + } + (menu+i)->type = GNOME_APP_UI_ENDOFINFO; + + path = g_strdup_printf("%s/%s", _("_File"), IMPORT_QIF_E_STR_N); + gnome_app_insert_menus(GNOME_APP(app), path, menu); + num_menu_entries = n; + g_free(path); + + for(i = 1; i <= n; i++) + g_free( (menu+i)->label ); + + g_free(menu); +} diff --git a/src/gnome/window-adjust.c b/src/gnome/window-adjust.c index 4de34d60fa9..88a6a0a9ba3 100644 --- a/src/gnome/window-adjust.c +++ b/src/gnome/window-adjust.c @@ -217,7 +217,7 @@ adjBWindow(Account *account) GtkWidget *dialog, *frame, *vbox; AdjBWindow *adjBData; gchar *title; - + FETCH_FROM_LIST(AdjBWindow, adjBList, account, account, adjBData); title = gnc_adjb_make_window_name(account); @@ -245,12 +245,15 @@ adjBWindow(Account *account) gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); { + GtkTooltips *tooltips; GtkWidget *hbox, *vbox; GtkWidget *amount, *date; - GtkWidget *label; + GtkWidget *label, *entry; gchar *currency; gchar *string; + tooltips = gtk_tooltips_new(); + hbox = gtk_hbox_new(FALSE, 5); gtk_container_set_border_width(GTK_CONTAINER(hbox), 10); gtk_container_add(GTK_CONTAINER(frame), hbox); @@ -281,10 +284,15 @@ adjBWindow(Account *account) gtk_box_pack_start(GTK_BOX(vbox), date, TRUE, TRUE, 0); adjBData->date_entry = date; + entry = GNC_DATE_EDIT(date)->date_entry; + gtk_tooltips_set_tip(tooltips, entry, TOOLTIP_ADJUST_DATE, NULL); + amount = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(vbox), amount, TRUE, TRUE, 0); adjBData->balance_entry = amount; + gtk_tooltips_set_tip(tooltips, amount, TOOLTIP_ADJUST_AMOUNT, NULL); + currency = xaccAccountGetCurrency(account); string = xaccPrintAmount(0.0, PRTSEP, currency); gtk_entry_set_text(GTK_ENTRY(amount), string); diff --git a/src/gnome/window-main.c b/src/gnome/window-main.c index 5f1ae7a6cc5..2ebec0514d3 100644 --- a/src/gnome/window-main.c +++ b/src/gnome/window-main.c @@ -50,6 +50,7 @@ #include "dialog-edit.h" #include "dialog-qif-import.h" #include "dialog-find-transactions.h" +#include "file-history.h" #include "Scrub.h" #include "util.h" #include "gnc.h" @@ -194,6 +195,7 @@ gnc_refresh_main_window() { xaccRecomputeGroupBalance(gncGetCurrentGroup()); gnc_ui_refresh_statusbar(); + gnc_history_update_menu(GNOME_APP(gnc_get_ui_data())); gnc_account_tree_refresh_all(); } diff --git a/src/messages_i18n.h b/src/messages_i18n.h index 3f3db36d775..e8d59d4a8a5 100644 --- a/src/messages_i18n.h +++ b/src/messages_i18n.h @@ -167,6 +167,9 @@ /* Tooltip phrases */ #define TOOLTIP_ADJUST_N N_("Adjust the balance of the selected account") #define TOOLTIP_ADJUST _(TOOLTIP_ADJUST_N) +#define TOOLTIP_ADJUST_AMOUNT _("Enter the new balance") +#define TOOLTIP_ADJUST_DATE _("Enter the date you want the balance "\ + "adjusted") #define TOOLTIP_ADJUST_END_N N_("Adjust the ending balance") #define TOOLTIP_ADJUST_END _(TOOLTIP_ADJUST_END_N) #define TOOLTIP_ADJUST_REG_N N_("Adjust the balance of the main account "\ diff --git a/src/scm/report/hello-world.scm b/src/scm/report/hello-world.scm index 5baf210337c..f9f8f8e9de5 100644 --- a/src/scm/report/hello-world.scm +++ b/src/scm/report/hello-world.scm @@ -155,6 +155,9 @@ "Your reports probably shouldn't have an " "option like this.") #f)) + (gnc:options-set-default-section gnc:*hello-world-options* + "Hello, World!") + gnc:*hello-world-options*)