diff --git a/ChangeLog b/ChangeLog index 93e924765d..537e018f97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2001-06-17 Dave Peticolas + + * src/FileDialog.c (gncFileSave): save the window state on a save + (gncFileQuerySave): don't provide cancel option when the ui can't + + * src/scm/main-window.scm (gnc:main-window-save-state): new func + don't save state when the ui can't + + * src/gnome/window-main.c + (gnc_main_window_can_cancel_exit): new func + (gnc_main_window_can_save): new func + (gnc_main_window_has_apps): new func + + * src/gnc-ui.h: add new api + + * src/gnome/top-level.c (gnc_ui_can_cancel_exit): new func + 2001-06-16 Dave Peticolas * src/guile/gnc.gwp: update for api change diff --git a/src/FileDialog.c b/src/FileDialog.c index 8537081ed9..4088f2c544 100644 --- a/src/FileDialog.c +++ b/src/FileDialog.c @@ -298,8 +298,15 @@ gncFileQuerySave (void) const char *message = _("Changes have been made since the last " "Save. Save the data to file?"); - result = gnc_verify_cancel_dialog (message, GNC_VERIFY_YES); - + if (gnc_ui_can_cancel_save ()) + result = gnc_verify_cancel_dialog (message, GNC_VERIFY_YES); + else + { + gboolean do_save = gnc_verify_dialog (message, TRUE); + + result = do_save ? GNC_VERIFY_YES : GNC_VERIFY_NO; + } + if (result == GNC_VERIFY_CANCEL) return FALSE; @@ -543,6 +550,11 @@ gncFileSave (void) gncAddHistory (book); gnc_book_mark_saved(book); + + /* save the main window state */ + gh_call1(gh_eval_str("gnc:main-window-save-state"), + gh_str02scm(gnc_book_get_url(current_book))); + LEAVE (" "); } diff --git a/src/gnc-ui.h b/src/gnc-ui.h index 95e263e764..e1cfde95cb 100644 --- a/src/gnc-ui.h +++ b/src/gnc-ui.h @@ -112,6 +112,8 @@ void gnc_ui_shutdown (void); void gnc_ui_destroy_all_subwindows (void); gncUIWidget gnc_ui_get_toplevel(void); +gboolean gnc_ui_can_cancel_save (void); + /* Changing the GUI Cursor ******************************************/ void gnc_set_busy_cursor(gncUIWidget w, gboolean update_now); diff --git a/src/gnome/top-level.c b/src/gnome/top-level.c index 3e040f4d7c..0780d8f3ca 100644 --- a/src/gnome/top-level.c +++ b/src/gnome/top-level.c @@ -150,7 +150,13 @@ gnc_ui_get_toplevel(void) { /* FIXME */ return gnc_main_window_get_toplevel(app); } - + +gboolean +gnc_ui_can_cancel_save (void) +{ + return gnc_main_window_can_cancel_save (app); +} + static const char* gnc_scheme_remaining_var = "gnc:*command-line-remaining*"; diff --git a/src/gnome/window-main.c b/src/gnome/window-main.c index 8b89cc5a1b..b10d02f1f3 100644 --- a/src/gnome/window-main.c +++ b/src/gnome/window-main.c @@ -77,7 +77,7 @@ static void gnc_main_window_create_menus(GNCMainInfo * maininfo); ********************************************************************/ static void -gnc_main_window_destroy_cb(GtkObject * w) { +gnc_main_window_destroy_cb(GtkObject * w, gpointer data) { gnc_shutdown (0); } @@ -116,7 +116,6 @@ gnc_main_window_app_destroyed_cb(GnomeApp * app, gpointer user_data) { } } - /******************************************************************** * gnc_main_window_app_created_cb() * called when a new top-level GnomeApp is created. @@ -451,6 +450,45 @@ gnc_main_window_child_save_func(GnomeMDIChild * child, gpointer user_data) { } +/******************************************************************** + * gnc_main_window_can_*() + ********************************************************************/ + +static gboolean +gnc_main_window_has_apps (GNCMainInfo * wind) +{ + GList *toplevels; + + toplevels = gtk_container_get_toplevels (); + while (toplevels) + { + if (GNOME_IS_APP (toplevels->data) && + !GTK_OBJECT_DESTROYED (toplevels->data)) + return TRUE; + + toplevels = toplevels->next; + } + + return FALSE; +} + +gboolean +gnc_main_window_can_save (GNCMainInfo * wind) +{ + if (!wind) return FALSE; + + return gnc_main_window_has_apps (wind); +} + +gboolean +gnc_main_window_can_cancel_save (GNCMainInfo *wind) +{ + if (!wind) return FALSE; + + return gnc_main_window_has_apps (wind); +} + + /******************************************************************** * gnc_main_window_save() * save the status of the MDI session @@ -469,6 +507,7 @@ gnc_main_window_save(GNCMainInfo * wind, char * filename) { if(filename && *filename != '\0') { gnome_mdi_save_state(GNOME_MDI(wind->mdi), session_name); } + g_free(session_name); } diff --git a/src/gnome/window-main.h b/src/gnome/window-main.h index 69d5f2bbce..7475bc7f5b 100644 --- a/src/gnome/window-main.h +++ b/src/gnome/window-main.h @@ -53,6 +53,8 @@ typedef struct { GNCMainInfo * gnc_main_window_new(void); void gnc_main_window_destroy(GNCMainInfo * wind); +gboolean gnc_main_window_can_save(GNCMainInfo * wind); +gboolean gnc_main_window_can_cancel_save (GNCMainInfo *wind); void gnc_main_window_save(GNCMainInfo * wind, char * session); void gnc_main_window_restore(GNCMainInfo * wind, const char * session); diff --git a/src/scm/main-window.scm b/src/scm/main-window.scm index 3c9b72927d..1d6292c84c 100644 --- a/src/scm/main-window.scm +++ b/src/scm/main-window.scm @@ -118,20 +118,20 @@ the account instead of opening a register.") #f)) ;; book close. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define (gnc:main-window-book-close-handler book-url) +(define (gnc:main-window-save-state book-url) (let* ((conf-file-name (gnc:html-encode-string book-url)) (dotgnucash-dir (build-path (getenv "HOME") ".gnucash")) (file-dir (build-path dotgnucash-dir "books")) (book-path #f)) - + ;; make sure ~/.gnucash is there (if (not (access? dotgnucash-dir X_OK)) (mkdir dotgnucash-dir #o700)) ;; make sure the books directory is there - + (if (not (access? file-dir X_OK)) (mkdir file-dir #o700)) - - (if conf-file-name + + (if (and conf-file-name (gnc:main-window-can-save? (gnc:get-ui-data))) (let ((book-path (build-path (getenv "HOME") ".gnucash" "books" conf-file-name))) (with-output-to-port (open-output-file book-path) @@ -149,7 +149,10 @@ the account instead of opening a register.") #f)) #t gnc:*acct-tree-options*) (force-output))) - (gnc:main-window-save (gnc:get-ui-data) book-url))) + (gnc:main-window-save (gnc:get-ui-data) book-url))))) + +(define (gnc:main-window-book-close-handler book-url) + (gnc:main-window-save-state book-url) (let ((dead-reports '())) ;; get a list of the reports we'll be needing to nuke @@ -163,8 +166,8 @@ the account instead of opening a register.") #f)) (for-each (lambda (dr) (hash-remove! *gnc:_reports_* dr)) - dead-reports)))) - + dead-reports))) + (define (gnc:main-window-book-open-handler book-url) (define (try-load file-suffix) (let ((file (build-path (getenv "HOME") ".gnucash" "books" file-suffix)))