diff --git a/ChangeLog b/ChangeLog index 09859d0977..06eae3c75a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2001-05-10 Dave Peticolas + + * src/scm/main-window.scm ((gnc:main-window-book-open-handler + book-url)): restore the main window even if we can't get a + conf-file-name. + + * src/scm/main.scm (gnc:load-account-file): if we have a file to + open, only run book-opened-hook if file open returns false. + + * src/FileDialog.c (gncPostFileOpen): once book-closed-hook has + been run, run book-opened-hook if opening the file fails for some + reason. + + * src/guile/gnc.gwp: update ui-open-file api. + + * src/gnome/top-level.c (gnucash_ui_open_file): return TRUE/FALSE + for success/failure. use gboolean instead of int for boolean + returns. + 2001-05-10 Bill Gribble * src/gnome/dialog-column-view.c: change handling of component diff --git a/src/FileDialog.c b/src/FileDialog.c index 9a3914d185..89a52a81d8 100644 --- a/src/FileDialog.c +++ b/src/FileDialog.c @@ -305,7 +305,7 @@ gncFileQuerySave (void) /* ======================================================== */ /* private utilities for file open; done in two stages */ -static void +static gboolean gncPostFileOpen (const char * filename) { GNCBook *new_book; @@ -314,13 +314,13 @@ gncPostFileOpen (const char * filename) char * newfile; GNCBackendError io_err = ERR_BACKEND_NO_ERR; - if (!filename) return; + if (!filename) return FALSE; newfile = xaccResolveURL (filename); if (!newfile) { show_book_error (ERR_FILEIO_FILE_NOT_FOUND, filename); - return; + return FALSE; } /* disable events while moving over to the new set of accounts; @@ -336,7 +336,7 @@ gncPostFileOpen (const char * filename) gh_call2(gh_eval_str("gnc:hook-run-danglers"), gh_eval_str("gnc:*book-closed-hook*"), gh_str02scm(gnc_book_get_url(current_book))); - + gnc_book_destroy (current_book); current_book = NULL; @@ -419,24 +419,28 @@ gncPostFileOpen (const char * filename) * reason, we don't want to leave them high & dry without a * topgroup, because if the user continues, then bad things will * happen. */ - gncGetCurrentBook (); + current_book = gncGetCurrentBook (); g_free (newfile); gnc_engine_resume_events (); gnc_gui_refresh_all (); - return; + gh_call2(gh_eval_str("gnc:hook-run-danglers"), + gh_eval_str("gnc:*book-opened-hook*"), + gh_str02scm(gnc_book_get_url(current_book))); + + return FALSE; } /* if we got to here, then we've successfully gotten a new session */ /* close up the old file session (if any) */ current_book = new_book; - + gh_call2(gh_eval_str("gnc:hook-run-danglers"), gh_eval_str("gnc:*book-opened-hook*"), gh_str02scm(gnc_book_get_url(current_book))); - + /* --------------- END CORE SESSION CODE -------------- */ /* clean up old stuff, and then we're outta here. */ @@ -446,37 +450,42 @@ gncPostFileOpen (const char * filename) gnc_engine_resume_events (); gnc_gui_refresh_all (); + + return TRUE; } /* ======================================================== */ -void +gboolean gncFileOpen (void) { const char * newfile; + gboolean result; if (!gncFileQuerySave ()) - return; + return FALSE; newfile = fileBox(_("Open"), NULL, gnc_history_get_last()); - gncPostFileOpen (newfile); + result = gncPostFileOpen (newfile); /* This dialogue can show up early in the startup process. If the * user fails to pick a file (by e.g. hitting the cancel button), we * might be left with a null topgroup, which leads to nastiness when * user goes to create their very first account. So create one. */ gncGetCurrentBook (); + + return result; } -void +gboolean gncFileOpenFile (const char * newfile) { - if (!newfile) return; + if (!newfile) return FALSE; if (!gncFileQuerySave ()) - return; + return FALSE; - gncPostFileOpen (newfile); + return gncPostFileOpen (newfile); } /* ======================================================== */ diff --git a/src/FileDialog.h b/src/FileDialog.h index 745673cdd0..21197e6f4d 100644 --- a/src/FileDialog.h +++ b/src/FileDialog.h @@ -125,12 +125,12 @@ #include "gnc-book.h" void gncFileNew (void); -void gncFileOpen (void); +gboolean gncFileOpen (void); void gncFileQIFImport (void); void gncFileSave (void); void gncFileSaveAs (void); -void gncFileOpenFile (const char *); +gboolean gncFileOpenFile (const char *filename); gboolean gncFileQuerySave (void); diff --git a/src/gnome/top-level.c b/src/gnome/top-level.c index 16439263ee..5142f835a0 100644 --- a/src/gnome/top-level.c +++ b/src/gnome/top-level.c @@ -123,7 +123,7 @@ static SCM register_hint_font_callback_id = SCM_UNDEFINED; /* ============================================================== */ -int +gboolean gnucash_ui_is_running(void) { return gnome_is_running; @@ -131,7 +131,7 @@ gnucash_ui_is_running(void) /* ============================================================== */ -int +gboolean gnucash_ui_is_terminating(void) { return gnome_is_terminating; @@ -467,11 +467,10 @@ gnc_ui_main(void) /* ============================================================== */ -int +gboolean gnucash_ui_open_file(const char name[]) { - gncFileOpenFile(name); - return 1; + return gncFileOpenFile(name); } /* ============================================================== */ diff --git a/src/gnome/top-level.h b/src/gnome/top-level.h index ca96984247..898c53afdc 100644 --- a/src/gnome/top-level.h +++ b/src/gnome/top-level.h @@ -23,12 +23,14 @@ #ifndef __TOP_LEVEL_H__ #define __TOP_LEVEL_H__ +#include + #include "window-main.h" -int gnucash_ui_is_running(void); -int gnucash_ui_is_terminating(void); +gboolean gnucash_ui_is_running(void); +gboolean gnucash_ui_is_terminating(void); int gnucash_ui_init(void); -int gnucash_ui_open_file(const char * name); +gboolean gnucash_ui_open_file(const char * name); int gnucash_ui_select_file(void); GNCMainInfo * gnc_ui_get_data(void); diff --git a/src/scm/main-window.scm b/src/scm/main-window.scm index fe5cc9b8f8..d38aa46494 100644 --- a/src/scm/main-window.scm +++ b/src/scm/main-window.scm @@ -170,9 +170,8 @@ the account instead of opening a register.") #f)) (let ((conf-file-name (gnc:html-encode-string book-url)) (dead-reports '())) (if conf-file-name - (begin - (try-load conf-file-name) - (gnc:main-window-restore (gnc:get-ui-data) book-url))))) + (try-load conf-file-name)) + (gnc:main-window-restore (gnc:get-ui-data) book-url))) (gnc:hook-add-dangler gnc:*book-opened-hook* gnc:main-window-book-open-handler) diff --git a/src/scm/main.scm b/src/scm/main.scm index 791fac28d0..db355e6afd 100644 --- a/src/scm/main.scm +++ b/src/scm/main.scm @@ -108,8 +108,9 @@ (define (gnc:load-account-file) (let ((file (gnc:account-file-to-load))) - (if file - (gnc:ui-open-file file) + (if file + (and (not (gnc:ui-open-file file)) + (gnc:hook-run-danglers gnc:*book-opened-hook* #f)) (gnc:hook-run-danglers gnc:*book-opened-hook* #f)))) (define (gnc:main)