Re: gnome-terminal macros and guile extensions
- From: Miguel de Icaza <miguel nuclecu unam mx>
- To: aldy uaa edu
- CC: gnome-list gnome org, gnome-devel-list gnome org
- Subject: Re: gnome-terminal macros and guile extensions
- Date: Thu, 25 Feb 1999 21:48:25 -0600
Hello guys,
> i don't know if this has been discussed before but i think it would be
> great to have a custom pulldown menu off of gnome-terminal with things
> such as common-typed commands.
So I got excited about the possiblity a few minutes ago, so I quickly
hacked a dynamic module that can be used to patch Gnome Terminal.
This little hack shows you hook up a menu to GnomeTerminal and the
sample I included runs the command "emacs" (well, it sends the string
"emacs\n" to the sub process).
This is very, Very, VERY, *VERY* exciting. I can picture lots of uses
for this sort of toys in GNOME. Boy, is this a cool hack. Jesus.
This is such a great hack.
So, in sort: the GTK type system is *SO VERSATILE*. I am impressed.
I really am. I kind of added good comments so that you could figure
out why things were done the way they were.
To compile do this:
gcc -fPIC -shared hook.c -o hook.so `gnome-config --cflags --libs gnomeui zvt`
Then copy the shared library to your favorite directory (or set
LD_LIBRARY_PATH to the directory where hook.so is), and then run
gnome-terminal like this:
gnome-terminal --gtk-module=hook
/*
* Sample hook code for the GnomeTerminal
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*/
#include <gnome.h>
#include <zvt/zvtterm.h>
#include <gmodule.h>
static ZvtTerm *find_zvt (GtkWidget *w);
/*
* Sample routine used to send text to the child process
* in Zvt.
*/
static void
do_insert_text (ZvtTerm *zvt, char *text)
{
struct _vtx *vx = zvt->vx;
vt_writechild (&vx->vt, text, strlen (text));
}
/*
* This routine inserts the text into the Zvt widget
*/
static void
insert_text (GtkWidget *menuitem, GtkWidget *top)
{
GtkWidget *toplevel;
ZvtTerm *zvt;
toplevel = gtk_widget_get_toplevel (top);
g_assert (GNOME_IS_APP (toplevel));
/*
* Pull the GnomeApp->contents widget, which is the Zvt widget
*/
zvt = find_zvt (GNOME_APP (toplevel)->contents);
g_assert (ZVT_IS_TERM (zvt));
do_insert_text (zvt, "emacs\n");
}
/*
* This routine creates the sample menu
*/
static GtkWidget *
make_menu (GtkWidget *toplevel)
{
GtkWidget *menu, *submenu;
GtkWidget *item;
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);
return submenu;
}
/*
* This routine is hooked to the "add" signal of the GtkContainer object
*
* We check when a GtkMenuBar is inserted into a GnomeDockItem, and at
* that point we insert our menu to the application
*/
static gboolean
patch_the_menubar (GtkObject *object, guint signal_id, guint n_args, GtkArg *args, gchar *signame)
{
GtkObject *target = GTK_VALUE_POINTER (args [0]);
if (GNOME_IS_DOCK_ITEM (object) && GTK_IS_MENU_BAR (target)){
GtkWidget *menu;
GtkWidget *toplevel;
GtkWidget *zvt;
/*
* Fetch the toplevel so that we can find out where the
* actual Zvt widget is
*/
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (object));
menu = make_menu (toplevel);
gtk_menu_bar_insert (GTK_MENU_BAR (target), menu, 2);
}
return TRUE;
}
/*
* This routine hooks up the patch_the_menubar to the
* signal "add" of GtkContainer
*/
static void
hook (void)
{
guint signal, tag;
signal = gtk_signal_lookup ("add", gtk_container_get_type ());
tag = gtk_signal_add_emission_hook (
signal, patch_the_menubar, "add");
}
/*
* Module bootstrap
*/
G_MODULE_EXPORT void gtk_module_init (gint *argc, gchar ***argv);
void
gtk_module_init (int *argc, char ***argv)
{
hook ();
}
static void
do_find_zvt (GtkWidget *w, gpointer data)
{
ZvtTerm **target = data;
if (ZVT_IS_TERM (w)){
*target = ZVT_TERM (w);
return;
}
if (GTK_IS_CONTAINER (w))
gtk_container_foreach (GTK_CONTAINER (w), do_find_zvt, target);
}
static ZvtTerm *
find_zvt (GtkWidget *w)
{
ZvtTerm *zvt = NULL;
do_find_zvt (w, &zvt);
return zvt;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]