diff --git a/src/gnome-utils/Makefile.am b/src/gnome-utils/Makefile.am index 77e59c76dd..533e4df08a 100644 --- a/src/gnome-utils/Makefile.am +++ b/src/gnome-utils/Makefile.am @@ -1,6 +1,6 @@ SUBDIRS = . test -pkglib_LTLIBRARIES = libgncmod-gnome-utils.la +pkglib_LTLIBRARIES = libgncmod-gnome-utils.la libgw-gnome-utils.la CFLAGS = \ @CFLAGS@ \ @@ -81,6 +81,12 @@ libgncmod_gnome_utils_la_LIBADD = \ ${GUPPI_LIBS} \ ${GLIB_LIBS} +libgw_gnome_utils_la_SOURCES = gw-gnome-utils.c +libgw_gnome_utils_la_LDFLAGS = -module + +gwmoddir = ${GNC_GWRAP_LIBDIR} +gwmod_DATA = gw-gnome-utils.scm gw-gnome-utils-spec.scm + gladedir = $(GNC_GLADE_DIR) glade_DATA = \ commodity.glade @@ -88,7 +94,8 @@ glade_DATA = \ EXTRA_DIST = \ .cvsignore \ gnc-dir.h.in \ - ${glade_DATA} + ${glade_DATA} \ + ${gwmod_DATA} dialog-utils.c: gnc-dir.h @@ -110,3 +117,21 @@ BUILT_SOURCES = gnc-dir.h # by all means, let us know... dist-hook: rm ${distdir}/gnc-dir.h + +.scm-links: + rm -f gnucash g-wrapped + ln -sf . gnucash + ln -sf . g-wrapped + touch .scm-links + +gw-gnome-utils.scm gw-gnome-utils.c gw-gnome-utils.h: .scm-links gw-gnome-utils-spec.scm + FLAVOR=gnome guile -c \ + "(set! %load-path (cons \"${G_WRAP_MODULE_DIR}\" %load-path)) \ + (set! %load-path (cons \"${PWD}\" %load-path)) \ + (set! %load-path (cons \"${top_srcdir}/src/engine\" %load-path)) \ + (primitive-load \"./gw-gnome-utils-spec.scm\") \ + (gw:generate-module \"gw-gnome-utils\")" + +BUILT_SOURCES = gw-gnome-utils.scm gw-gnome-utils.c gw-gnome-utils.h +CLEANFILES = gw-gnome-utils.scm gw-gnome-utils.c gw-gnome-utils.h \ + gw-gnome-utils.html gnucash g-wrapped .scm-links diff --git a/src/gnome-utils/gncmod-gnome-utils.c b/src/gnome-utils/gncmod-gnome-utils.c index 09b73c7932..1badd4ef39 100644 --- a/src/gnome-utils/gncmod-gnome-utils.c +++ b/src/gnome-utils/gncmod-gnome-utils.c @@ -32,6 +32,14 @@ gnc_module_description(void) { return g_strdup("Utilities for using Gnome/Gtk with GnuCash"); } +static void +lmod(char * mn) +{ + char * form = g_strdup_printf("(use-modules %s)\n", mn); + gh_eval_str(form); + g_free(form); +} + int gnc_module_init(int refcount) { /* load the engine (we depend on it) */ @@ -54,6 +62,9 @@ gnc_module_init(int refcount) { return FALSE; } + /* publish g-wrapped bindings */ + lmod("(g-wrapped gw-gnome-utils)"); + return TRUE; } diff --git a/src/gnome-utils/gw-gnome-utils-spec.scm b/src/gnome-utils/gw-gnome-utils-spec.scm new file mode 100644 index 0000000000..359fb464ff --- /dev/null +++ b/src/gnome-utils/gw-gnome-utils-spec.scm @@ -0,0 +1,80 @@ +(define-module (g-wrapped gw-gnome-utils-spec)) + +(use-modules (g-wrap)) +(use-modules (g-wrapped gw-engine-spec)) + +(debug-set! maxdepth 100000) +(debug-set! stack 2000000) + +(let ((mod (gw:new-module "gw-gnome-utils"))) + (define (standard-c-call-gen result func-call-code) + (list (gw:result-get-c-name result) " = " func-call-code ";\n")) + + (define (add-standard-result-handlers! type c->scm-converter) + (define (standard-pre-handler result) + (let* ((ret-type-name (gw:result-get-proper-c-type-name result)) + (ret-var-name (gw:result-get-c-name result))) + (list "{\n" + " " ret-type-name " " ret-var-name ";\n"))) + + (gw:type-set-pre-call-result-ccodegen! type standard-pre-handler) + + (gw:type-set-post-call-result-ccodegen! + type + (lambda (result) + (let* ((scm-name (gw:result-get-scm-name result)) + (c-name (gw:result-get-c-name result))) + (list + (c->scm-converter scm-name c-name) + " }\n"))))) + + (gw:module-depends-on mod "gw-runtime") + (gw:module-depends-on mod "gw-engine") + + (gw:module-set-guile-module! mod '(g-wrapped gw-gnome-utils)) + + (gw:module-set-declarations-ccodegen! + mod + (lambda (client-only?) + (list + "#include \n" + ))) + + (let ((nnt (gw:wrap-non-native-type + mod + ' + "GNCMDIInfo*" "const GNCMDIInfo*"))) + #t) + + (gw:wrap-function + mod + 'gnc:mdi-has-apps? + ' + "gnc_mdi_has_apps" + '() + "Return true if there are gnc mdi app windows open.") + + (gw:wrap-function + mod + 'gnc:mdi-get-current + ' + "gnc_mdi_get_current" + '() + "Return the main window data structure for the application.") + + (gw:wrap-function + mod + 'gnc:mdi-save + ' + "gnc_mdi_save" '(( mi) + (() bookname)) + "Save the MDI window configuration for the specified book") + + (gw:wrap-function + mod + 'gnc:mdi-restore + ' + "gnc_mdi_restore" '(( mi) + (( gw:const) bookname)) + "Restore MDI window configuration for the specified book") +) diff --git a/src/gnome/top-level.c b/src/gnome/top-level.c index b2085bc0ef..63bd0a4124 100644 --- a/src/gnome/top-level.c +++ b/src/gnome/top-level.c @@ -130,13 +130,6 @@ gnucash_ui_is_terminating(void) return gnome_is_terminating; } -static gboolean -gnc_ui_can_cancel_save (void) -{ - return gnc_main_window_can_cancel_save (gnc_mdi_get_current ()); -} - - static const char* gnc_scheme_remaining_var = "gnc:*command-line-remaining*"; static char** @@ -543,7 +536,7 @@ gnucash_ui_init(void) gnc_ui_commodity_set_help_callback (gnc_commodity_help_cb); - gnc_file_set_can_cancel_callback (gnc_ui_can_cancel_save); + gnc_file_set_can_cancel_callback (gnc_mdi_has_apps); gnc_options_dialog_set_global_help_cb (gnc_global_options_help_cb, NULL); diff --git a/src/gnome/window-main.c b/src/gnome/window-main.c index 611d2d76c2..4faf9ff1d7 100644 --- a/src/gnome/window-main.c +++ b/src/gnome/window-main.c @@ -192,22 +192,6 @@ gnc_main_window_create_child(const gchar * configstring) { * gnc_main_window_can_*() ********************************************************************/ -gboolean -gnc_main_window_can_save (GNCMDIInfo * wind) -{ - if (!wind) return FALSE; - - return gnc_mdi_has_apps (); -} - -gboolean -gnc_main_window_can_cancel_save (GNCMDIInfo *wind) -{ - if (!wind) return FALSE; - - return gnc_mdi_has_apps (); -} - static gboolean gnc_main_window_can_restore_cb (const char * filename) { diff --git a/src/gnome/window-main.h b/src/gnome/window-main.h index 8dd8aa6457..bc08ea411e 100644 --- a/src/gnome/window-main.h +++ b/src/gnome/window-main.h @@ -24,12 +24,8 @@ #ifndef WINDOW_MAIN_H #define WINDOW_MAIN_H -#include - #include "gnc-mdi-utils.h" -GNCMDIInfo * gnc_main_window_new (void); -gboolean gnc_main_window_can_save (GNCMDIInfo * wind); -gboolean gnc_main_window_can_cancel_save (GNCMDIInfo *wind); +GNCMDIInfo * gnc_main_window_new (void); #endif diff --git a/src/scm/main-window.scm b/src/scm/main-window.scm index 475d52dd40..61b3ff156a 100644 --- a/src/scm/main-window.scm +++ b/src/scm/main-window.scm @@ -128,8 +128,7 @@ the account instead of opening a register.") #f)) (if (not save-file?) (gnc:warn (_ "Can't save window state"))) - (if (and save-file? conf-file-name - (gnc:main-window-can-save? (gnc:mdi-get-current))) + (if (and save-file? conf-file-name (gnc:mdi-has-apps?)) (let ((book-path (build-path (getenv "HOME") ".gnucash" "books" conf-file-name))) (with-output-to-port (open-output-file book-path)