Re: gnome-terminal macros and guile extensions




On Thu, 25 Feb 1999, Miguel de Icaza wrote:
> 
> Oh, I would love to see some magic here.  Hack and share the hack!
> 

Here is the lamest possible implementation. (Broken in many ways, this is 
just a demo of how simple it is. I'm leaving out a bunch of error
checking though.)

The config file is just:
(define (foothunk) (display "foo"))
(define (barthunk) (display "bar"))

(add-menuitems (list (cons "Foo" foothunk) 
                     (cons "Bar" barthunk)))

It's harcoded to be menu.scm in the current directory.

I didn't implement gnome-terminal-insert-text as a scheme proc but 
that is easy.

Patch for gnome-terminal.c, then patch to your hack.

===================================================================
RCS file: /cvs/gnome/gnome-core/gnome-terminal/Makefile.am,v
retrieving revision 1.11
diff -u -u -r1.11 Makefile.am
--- Makefile.am 1999/02/20 01:01:27     1.11
+++ Makefile.am 1999/02/26 06:59:08
@@ -14,7 +14,10 @@
        $(GNOME_LIBDIR)                                 \
        $(GNOMEUI_LIBS)                                 \
        $(ZVT_LIBS)                                     \
-       $(INTLLIBS)
+       $(INTLLIBS)                                     \
+       -L/usr/lib -lguile -lqthreads -ldl -lreadline -lm
+# For the above, substitute the contents of guile-config link on your
system
+# Or put the Guile check in the toplevel configure.in
 
 
 bin_PROGRAMS = gnome-terminal
Index: gnome-terminal.c
===================================================================
RCS file: /cvs/gnome/gnome-core/gnome-terminal/gnome-terminal.c,v
retrieving revision 1.113
diff -u -u -r1.113 gnome-terminal.c
--- gnome-terminal.c    1999/02/23 07:07:54     1.113
+++ gnome-terminal.c    1999/02/26 06:59:22
@@ -2052,10 +2052,16 @@
        return 0;
 }
 
+void real_main(void* closure, int argc, char** argv)
+{
+        main_terminal_program (argc, argv, environ);
+}
+
 int
 main (int argc, char *argv [], char **environ)
 {
-       return main_terminal_program (argc, argv, environ);
+  scm_boot_guile(argc, argv, real_main, 0);
+  return 1; /* not reached */
 }
 

Patch for Miguel's hack:

--- hook.c    Fri Feb 26 00:58:52 1999
+++ menuplugin.c        Fri Feb 26 01:06:15 1999
@@ -9,8 +9,14 @@
 #include <zvt/zvtterm.h>
 #include <gmodule.h>
 
+#include <stdlib.h>
+#include <libguile.h>
+#include <guile/gh.h>
+
 static ZvtTerm *find_zvt (GtkWidget *w);
 
+SCM menu_alist = SCM_LIST0;
+
 /*
  * Sample routine used to send text to the child process
  * in Zvt.
@@ -47,6 +53,17 @@
        do_insert_text (zvt, "emacs\n");
 }
 
+
+struct cbdata {
+  SCM thunk;
+};
+            
+static void
+eval_thunk(GtkWidget* menuitem, struct cbdata* d)
+{
+  gh_call0(d->thunk);
+}
+
 /*
  * This routine creates the sample menu
  */
@@ -55,20 +72,47 @@
 {
        GtkWidget *menu, *submenu;
        GtkWidget *item;
+        SCM tmp;
 
        submenu = gtk_menu_item_new_with_label ("Module");
        gtk_widget_show (submenu);
 
-       item = gtk_menu_item_new_with_label ("Run command `emacs'");
-       gtk_widget_show (item);
-       gtk_signal_connect (GTK_OBJECT (item), "activate",
-                           GTK_SIGNAL_FUNC(insert_text), toplevel);
-                           
        menu = gtk_menu_new ();
-       gtk_menu_append (GTK_MENU (menu), item);
        
        gtk_menu_item_set_submenu (GTK_MENU_ITEM (submenu), menu);
 
+        tmp = menu_alist;
+        while (!gh_null_p(tmp))
+          {
+            /* Type checking! */
+
+            SCM pair = gh_car(tmp);
+
+            char* name;
+            struct cbdata* data;
+
+            name = gh_scm2newstr(gh_car(pair), NULL);
+
+            g_message("Adding item %s", name);
+
+            item = gtk_menu_item_new_with_label (name);
+            gtk_widget_show (item);
+
+            free(name);
+
+            /* We never bother to free this */
+            data = g_malloc(sizeof(SCM));
+            data->thunk = gh_cdr(pair);
+
+            gtk_signal_connect (GTK_OBJECT (item), "activate",
+                                GTK_SIGNAL_FUNC(eval_thunk), 
+                                data);
+
+            gtk_menu_append (GTK_MENU (menu), item);
+
+            tmp = gh_cdr(tmp);
+          }
+
        return submenu;
 }
 
@@ -114,6 +158,15 @@
                signal, patch_the_menubar, "add");
 }
 
+/* Routine to add the menu items, must be called before the terminal 
+   GUI comes up */
+SCM add_items(SCM items)
+{
+  /* Type checking! */
+
+  menu_alist = items;
+}
+
 /*
  * Module bootstrap
  */
@@ -122,6 +175,14 @@
 void
 gtk_module_init (int *argc, char ***argv)
 {
+  SCM tmp; 
+
+  gh_new_procedure0_1("add-menuitems", add_items);
+
+  gh_load("menu.scm");
+
+  g_message("%u menu items", gh_length(menu_alist));
+
        hook ();
 }




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]