[PATCH] gnome-terminal shortcut fonts menu



This patch adds the xterm-like feature of putting your favorite fonts on
the gnome-terminal menu.  It adds a "fonts" tab to the preferences
dialog allowing you to edit these fonts.

I've heard this feature requested on gnome-list a few times, and is also
wishlist item #3527.

I'd be grateful to hear any comments on this.  Is this correct place to
send patches?

cheers,

Paul
Index: gnome-terminal.c
===================================================================
RCS file: /cvs/gnome/gnome-core/gnome-terminal/gnome-terminal.c,v
retrieving revision 1.175
diff -u -r1.175 gnome-terminal.c
--- gnome-terminal.c	2000/07/16 11:02:36	1.175
+++ gnome-terminal.c	2000/07/26 00:16:18
@@ -118,8 +118,14 @@
 	char *wordclass;			/* select-by-word character class */
 	char *termname;				/* TERM variable setting, store as TERM=xxx */
 	GdkColor palette[18];			/* the full palette */
+	GList *font_list;			/* favorite fonts */
 } ;
 
+typedef struct {
+	char *shortcut_name;
+	char *font_name;
+} font_item_t;
+
 /* Initial command */
 char **initial_command = NULL;
 
@@ -167,6 +173,9 @@
 	GtkWidget *back_label;
 	GtkWidget *palette_label;
 	GtkWidget *palette[18];
+	GtkWidget *font_list;
+	GtkWidget *font_edit_button;
+	GtkWidget *font_delete_button;
 	int changed;
 } preferences_t;
 
@@ -376,6 +385,13 @@
 		       0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff,
 			0x0,    0x0 };
 
+/* Default font list */
+
+#define DEFAULT_FONT_COUNT 3
+char* default_font_list[] = { "Small", "7x14",
+			      "Medium", "9x15",
+			      "Large", "10x20" };
+
 /* point to the other tables */
 gushort *scheme_red[] = { linux_red, xterm_red, rxvt_red, rxvt_red };
 gushort *scheme_blue[] = { linux_blu, xterm_blu, rxvt_blu, rxvt_blu };
@@ -477,9 +493,11 @@
 	char *fore_color = NULL;
 	char *back_color = NULL;
 	struct terminal_config *cfg = g_malloc (sizeof (*cfg));
-	int colour_count;
-	char **colours;
+	int colour_count, font_count;
+	char **colours, **fonts;
+	font_item_t *font_item;
 	int i;
+	gboolean b;
 
 	/* It's very odd that these are here */
 	cfg->font = NULL;
@@ -563,6 +581,22 @@
 	}
 	g_free(colours);
 
+        /* load the font shortcuts list */
+
+	cfg->font_list = NULL;
+
+	gnome_config_get_vector_with_default("font_list", &font_count, &fonts, &b);
+	if (b) {
+		fonts = (char**)default_font_list;
+		font_count = DEFAULT_FONT_COUNT * 2;
+	}
+	for (i=0;i<font_count-1;i+=2) {
+                font_item = g_malloc(sizeof(font_item_t));
+                font_item->shortcut_name = g_strdup(fonts[i]);
+                font_item->font_name = g_strdup(fonts[i+1]);
+                cfg->font_list = g_list_append(cfg->font_list,font_item); 
+        }
+	if (!b) g_free(fonts);
 	return cfg;
 }
 
@@ -573,6 +607,8 @@
 	gushort r, g, b;
 	struct terminal_config *newcfg = g_malloc (sizeof (*newcfg));
 	int i;
+	font_item_t *font_item;
+	char *s;
 
 	memset (newcfg, 0, sizeof (*newcfg));
 
@@ -618,6 +654,18 @@
 		newcfg->palette[i].blue  = b;
 	}
 
+	for (i=0;i<GTK_CLIST(prefs->font_list)->rows;i++) {
+		font_item = g_malloc(sizeof(font_item_t));
+
+		gtk_clist_get_text(GTK_CLIST(prefs->font_list),i,0,&s);
+
+		font_item->shortcut_name = g_strdup(s);
+		gtk_clist_get_text(GTK_CLIST(prefs->font_list),i,1,&s);
+
+		font_item->font_name = g_strdup(s);
+		newcfg->font_list = g_list_append(newcfg->font_list,font_item);
+	}
+
 	return newcfg;
 }
 
@@ -625,6 +673,8 @@
 terminal_config_dup (struct terminal_config *cfg)
 {
 	struct terminal_config *n;
+	GList *font_list;
+	font_item_t *font_item;
 
 	n = g_malloc (sizeof (*n));
 	*n = *cfg;
@@ -632,6 +682,17 @@
 	n->font = g_strdup  (cfg->font);
 	n->wordclass = g_strdup  (cfg->wordclass);
 	n->termname = g_strdup  (cfg->termname);
+	n->font_list = NULL;	
+	font_list = cfg->font_list;
+	while (font_list) {
+		font_item = g_malloc (sizeof(font_item_t));
+		font_item->shortcut_name = 
+			g_strdup (((font_item_t*)font_list->data)->shortcut_name);
+		font_item->font_name = 
+			g_strdup (((font_item_t*)font_list->data)->font_name);
+		n->font_list = g_list_append (n->font_list,font_item);
+		font_list = g_list_next (font_list);
+	}
 
 	return n;
 }
@@ -639,10 +700,19 @@
 static void
 terminal_config_free (struct terminal_config *cfg)
 {
+	GList * font_list;
+
 	g_free (cfg->class);
 	g_free (cfg->font);
 	g_free (cfg->wordclass);
 	g_free (cfg->termname);
+	font_list = cfg->font_list;
+	while (font_list) {
+		g_free (((font_item_t*)font_list->data)->shortcut_name);
+		g_free (((font_item_t*)font_list->data)->font_name);
+		font_list = g_list_next (font_list);
+	}
+	g_list_free (cfg->font_list); 
 	g_free (cfg);
 }
 
@@ -856,6 +926,14 @@
 }
 
 static void
+row_moved (GtkWidget *w, gint arg1, gint arg2, preferences_t *prefs)
+{
+	prop_changed (w, prefs);
+}
+
+/* Keeps edit control and font picker synchronised.  This is used by both the */
+/* prefs dialog and the Edit Font Shortcut dialog (with prefs==NULL)          */
+static void
 font_changed (GtkWidget *w, preferences_t *prefs)
 {
 	char *font;
@@ -868,10 +946,167 @@
 		font = gtk_entry_get_text (GTK_ENTRY(w));
 		peer = gtk_object_get_user_data (GTK_OBJECT(w));
 		gnome_font_picker_set_font_name (GNOME_FONT_PICKER(peer), font);
+		if (prefs) prop_changed (w, prefs);
+	}
+}
+
+/* Called when a font is selected in the font prefs clist widget */
+static void
+font_selected (GtkWidget *w, gint row, gint column, GdkEventButton *event, preferences_t *prefs)
+{
+	char *font;
+	GtkWidget *peer;
+	if (event->type == GDK_2BUTTON_PRESS) {
+		gtk_clist_get_text (GTK_CLIST (w), row, 1, &font);
+		peer = gtk_object_get_user_data (GTK_OBJECT (w));
+		gtk_entry_set_text (GTK_ENTRY (peer), font);
+		prop_changed (w, prefs);
+	}
+	gtk_widget_set_sensitive (GTK_WIDGET (prefs->font_delete_button), TRUE);
+	gtk_widget_set_sensitive (GTK_WIDGET (prefs->font_edit_button), TRUE);
+}
+
+/* font_unselected: deactivates Edit and Delete buttons if no font is selected */
+static void
+font_unselected (GtkWidget *w, gint row, gint column, GdkEventButton *event, preferences_t *prefs)
+{
+	gtk_widget_set_sensitive (GTK_WIDGET (prefs->font_delete_button), FALSE);
+	gtk_widget_set_sensitive (GTK_WIDGET (prefs->font_edit_button), FALSE);
+}
+
+/* Deactivate OK button if shortcut_name is blank */
+static void
+font_edit_shortcut_changed (GtkWidget *w, GtkWidget *dialog)
+{
+	gnome_dialog_set_sensitive (GNOME_DIALOG (dialog), 0,
+		strlen (gtk_entry_get_text (GTK_ENTRY (w))));
+}
+
+/* Run dialog to add or edit a font shortcut.  */
+static gboolean
+font_edit_shortcut (char **font_name, char **shortcut_name)
+{
+
+        GtkWidget *table, *l, *f, *dialog;
+	GtkWidget *font_name_entry, *shortcut_name_entry;
+	int ret;
+	
+        dialog = gnome_dialog_new (N_("Edit font shortcut"),
+	                           GNOME_STOCK_BUTTON_OK,
+				   GNOME_STOCK_BUTTON_CANCEL,
+				   NULL);
+
+	table = gtk_table_new (3, 2, FALSE);
+	gtk_container_set_border_width (GTK_CONTAINER (table), 4);
+
+	l = aligned_label (_("Font name:"));
+	gtk_table_attach (GTK_TABLE(table), l,
+	                  0, 1, 0, 1, GTK_FILL, 0, 0, 0);
+
+	shortcut_name_entry = gtk_entry_new ();
+	gtk_signal_connect (GTK_OBJECT (shortcut_name_entry), "changed",
+			    GTK_SIGNAL_FUNC (font_edit_shortcut_changed), dialog);
+	if (*shortcut_name) {
+		gtk_entry_set_text (GTK_ENTRY (shortcut_name_entry),
+				    *shortcut_name);
+	} else {
+		gnome_dialog_set_sensitive (GNOME_DIALOG (dialog), 0, FALSE);
+	}
+
+	gtk_table_attach (GTK_TABLE (table), shortcut_name_entry, 
+	                  1, 2, 0, 1, GTK_FILL, 0, 0, 0);
+	
+	l = aligned_label (_("Font:"));
+	gtk_table_attach (GTK_TABLE (table), l,
+	                  0, 1, 1, 2, GTK_FILL, 0, 0, 0);
+
+	font_name_entry = gtk_entry_new ();
+	gtk_table_attach (GTK_TABLE(table), font_name_entry,
+	                  1, 2, 1, 2, GTK_FILL, 0, 0, 0);
+	gtk_signal_connect (GTK_OBJECT (font_name_entry), "changed", 
+	                    GTK_SIGNAL_FUNC (font_changed), NULL);
+
+	f = gnome_font_picker_new ();
+	gnome_font_picker_set_mode (GNOME_FONT_PICKER (f),
+	                            GNOME_FONT_PICKER_MODE_USER_WIDGET);
+	gtk_table_attach (GTK_TABLE (table), f, 
+	                  2, 3, 1, 2, GTK_FILL, 0, 0, 0);
+
+	l = gtk_label_new (_("Browse..."));
+	gnome_font_picker_uw_set_widget (GNOME_FONT_PICKER (f), GTK_WIDGET (l));
+	
+	gtk_signal_connect (GTK_OBJECT (f), "font_set", 
+	                    GTK_SIGNAL_FUNC (font_changed), NULL);
+	gtk_object_set_user_data (GTK_OBJECT (f), font_name_entry);
+	gtk_object_set_user_data (GTK_OBJECT (font_name_entry), f);
+	if (*font_name) {
+		gtk_entry_set_text (GTK_ENTRY (font_name_entry), *font_name);
+	}
+	gnome_font_picker_set_font_name (GNOME_FONT_PICKER (f), *font_name);
+
+	gtk_box_pack_end (GTK_BOX (GNOME_DIALOG (dialog)->vbox),
+	                  table, TRUE, TRUE, 0);
+ 
+	gtk_widget_show_all (GTK_WIDGET (dialog));
+        ret = gnome_dialog_run (GNOME_DIALOG (dialog));
+
+	if (ret == 0) {	/* OK button pressed */
+		*font_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (font_name_entry)));
+		*shortcut_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (shortcut_name_entry)));
+	}
+	if (ret >= 0) {
+		gnome_dialog_close (GNOME_DIALOG (dialog));
+	}
+	return (ret==0);
+}
+
+static void
+font_add (GtkWidget *w, preferences_t *prefs)
+{
+	char *font_name, *shortcut_name;
+	char *font_row[2];
+	font_name = gtk_entry_get_text (GTK_ENTRY (prefs->font_entry));
+	shortcut_name = NULL;
+	if (font_edit_shortcut (&font_name, &shortcut_name)) {
+		font_row[0] = shortcut_name;
+		font_row[1] = font_name;
+		gtk_clist_append (GTK_CLIST (prefs->font_list), (char**) &font_row);
+		g_free (font_name);
+		g_free (shortcut_name);
 		prop_changed (w, prefs);
 	}
 }
 
+static void
+font_edit (GtkWidget *w, preferences_t *prefs)
+{
+	char *font_name, *shortcut_name;
+	int row;
+	if (!GTK_CLIST (prefs->font_list)->selection) return;
+	 
+	row = GPOINTER_TO_INT (GTK_CLIST (prefs->font_list)->selection->data);
+	gtk_clist_get_text (GTK_CLIST (prefs->font_list), row, 0, &shortcut_name);
+	gtk_clist_get_text (GTK_CLIST (prefs->font_list), row, 1, &font_name);
+	if (font_edit_shortcut (&font_name, &shortcut_name)) {
+		gtk_clist_set_text (GTK_CLIST (prefs->font_list), row, 0, shortcut_name);
+		gtk_clist_set_text (GTK_CLIST (prefs->font_list), row, 1, font_name);
+		g_free (font_name);
+		g_free (shortcut_name);	
+		prop_changed (w, prefs);
+	}
+}
+
+static void
+font_delete (GtkWidget *w, preferences_t *prefs)
+{
+        GtkObject *clist;
+        clist = gtk_object_get_user_data (GTK_OBJECT (w));
+        if (GTK_CLIST (clist)->selection) {
+                gtk_clist_remove (GTK_CLIST (clist), 
+                                  GPOINTER_TO_INT (GTK_CLIST(clist)->selection->data));
+                prop_changed (w, prefs);
+        }
+}
 
 /*
 static void
@@ -1018,6 +1253,9 @@
 {
 	char *colours[18];
 	int i;
+	int font_count;
+	char **font_vector;
+	GList *font_item;
 	char *scheme[4] = { "linux", "xterm", "rxvt", "custom" };
 
 	if (cfg->font)
@@ -1056,6 +1294,16 @@
 	for (i=0;i<18;i++)
 		g_free(colours[i]);
 
+	font_count = g_list_length(cfg->font_list);
+	font_vector = g_malloc(font_count * 2 * sizeof(char*));
+	font_item = cfg->font_list; 
+	for (i=0;i<font_count;i++) {
+		font_vector[i*2] = ((font_item_t*)font_item->data)->shortcut_name;
+		font_vector[i*2+1] = ((font_item_t*)font_item->data)->font_name;
+		font_item = g_list_next(font_item);
+	}
+	gnome_config_set_vector ("font_list", font_count*2, (const char**)font_vector);
+	g_free(font_vector);
 	gnome_config_sync ();
 }
 
@@ -1089,10 +1337,13 @@
 preferences_cmd (GtkWidget *widget, ZvtTerm *term)
 {
 	GtkWidget *l, *table, *picker, *label, *b1, *b2;
-	GtkWidget *r, *frame, *hbox, *subtable, *paltable;
+	GtkWidget *r, *frame, *hbox, *subtable, *paltable, *vbox;
+	GtkWidget *scrolled_window;
 	preferences_t *prefs;
 	GtkAdjustment *adj;
 	GList *class_list = NULL;
+	GList *font_list;
+	char *font_row[2];
 	void *iter;
 	char *some_class;
 	struct terminal_config *cfg;
@@ -1123,36 +1374,6 @@
 	gnome_property_box_append_page (GNOME_PROPERTY_BOX (prefs->prop_win),
 					table, gtk_label_new (_("General")));
 
-	/* Font */
-	l = aligned_label (_("Font:"));
-	gtk_table_attach (GTK_TABLE (table), l,
-			  1, 2, FONT_ROW, FONT_ROW+1, GTK_FILL, 0, 0, 0);
-	prefs->font_entry = gtk_entry_new ();
-	gtk_entry_set_text (GTK_ENTRY (prefs->font_entry),
-			    gtk_object_get_user_data (GTK_OBJECT (term)));
-	gtk_entry_set_position (GTK_ENTRY (prefs->font_entry), 0);
-	gtk_signal_connect (GTK_OBJECT (prefs->font_entry), "changed",
-			    GTK_SIGNAL_FUNC (font_changed), prefs);
-	gtk_table_attach (GTK_TABLE (table), prefs->font_entry,
-			  2, 3, FONT_ROW, FONT_ROW+1, GTK_FILL, 0, 0, 0);
-	gnome_dialog_editable_enters (GNOME_DIALOG (prefs->prop_win),
-				      GTK_EDITABLE (prefs->font_entry));
-
-	picker = gnome_font_picker_new();
-	gnome_font_picker_set_font_name(GNOME_FONT_PICKER(picker),
-					gtk_entry_get_text(GTK_ENTRY (prefs->font_entry)));
-	gnome_font_picker_set_mode(GNOME_FONT_PICKER (picker),
-				   GNOME_FONT_PICKER_MODE_USER_WIDGET);
-	
-	gtk_signal_connect (GTK_OBJECT (picker), "font_set",
-			    GTK_SIGNAL_FUNC (font_changed), prefs);
-	label = gtk_label_new (_("Browse..."));
-	gnome_font_picker_uw_set_widget(GNOME_FONT_PICKER(picker), GTK_WIDGET(label));
-	gtk_object_set_user_data(GTK_OBJECT(picker), GTK_OBJECT(prefs->font_entry)); 
-	gtk_object_set_user_data (GTK_OBJECT(prefs->font_entry), GTK_OBJECT(picker)); 
-
-	gtk_table_attach (GTK_TABLE (table), picker,
-			  3, 5, FONT_ROW, FONT_ROW+1, GTK_FILL, 0, 0, 0);
 	/* Terminal class */
 	l = aligned_label (_("Terminal Class"));
 	gtk_table_attach (GTK_TABLE (table), l,
@@ -1481,6 +1702,98 @@
 	gtk_table_attach (GTK_TABLE (table), prefs->scroll_out_checkbox, 2, 3, 
 			  OUTSCROLL_ROW, OUTSCROLL_ROW+1, GTK_FILL, 0, 0, 0);
 
+	/* Font page */
+	vbox = gtk_vbox_new (FALSE,0);
+
+	gnome_property_box_append_page (GNOME_PROPERTY_BOX (prefs->prop_win), vbox, 
+					gtk_label_new (_("Fonts")));
+
+	table = gtk_table_new (5, 1, FALSE);
+	gtk_container_set_border_width (GTK_CONTAINER (table), 4);
+	gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (table), FALSE, FALSE, 0);
+
+	/* Font */
+	l = aligned_label (_("Font:"));
+	gtk_table_attach (GTK_TABLE (table), l,
+			  1, 2, 0, 1, GTK_FILL, 0, 0, 0);
+	prefs->font_entry = gtk_entry_new ();
+	gtk_entry_set_text (GTK_ENTRY (prefs->font_entry),
+			    gtk_object_get_user_data (GTK_OBJECT (term)));
+	gtk_entry_set_position (GTK_ENTRY (prefs->font_entry), 0);
+	gtk_signal_connect (GTK_OBJECT (prefs->font_entry), "changed",
+			    GTK_SIGNAL_FUNC (font_changed), prefs);
+	gtk_table_attach (GTK_TABLE (table), prefs->font_entry,
+			  2, 3, 0, 1, GTK_FILL, 0, 0, 0);
+	gnome_dialog_editable_enters (GNOME_DIALOG (prefs->prop_win),
+				      GTK_EDITABLE (prefs->font_entry));
+
+	picker = gnome_font_picker_new ();
+	gnome_font_picker_set_font_name (GNOME_FONT_PICKER (picker),
+					 gtk_entry_get_text (GTK_ENTRY (prefs->font_entry)));
+	gnome_font_picker_set_mode (GNOME_FONT_PICKER (picker),
+				    GNOME_FONT_PICKER_MODE_USER_WIDGET);
+	
+	gtk_signal_connect (GTK_OBJECT (picker), "font_set",
+			    GTK_SIGNAL_FUNC (font_changed), prefs);
+	label = gtk_label_new (_("Browse..."));
+	gnome_font_picker_uw_set_widget (GNOME_FONT_PICKER (picker), GTK_WIDGET (label));
+	gtk_object_set_user_data (GTK_OBJECT (picker), GTK_OBJECT (prefs->font_entry)); 
+	gtk_object_set_user_data (GTK_OBJECT (prefs->font_entry), GTK_OBJECT (picker)); 
+
+	gtk_table_attach (GTK_TABLE (table), picker,
+			  3, 5, 0, 1, GTK_FILL, 0, 0, 0);
+
+	/* Font shortcuts list */
+	scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
+	                                GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+	gtk_box_pack_start (GTK_BOX(vbox),GTK_WIDGET(scrolled_window),TRUE,TRUE,0);
+
+	prefs->font_list = gtk_clist_new(2);
+	gtk_clist_set_column_width (GTK_CLIST (prefs->font_list), 0, 100);
+	gtk_clist_set_column_width (GTK_CLIST (prefs->font_list), 1, 100);
+	gtk_clist_set_reorderable (GTK_CLIST (prefs->font_list), TRUE);
+	gtk_object_set_user_data (GTK_OBJECT (prefs->font_list), GTK_OBJECT(prefs->font_entry));
+	gtk_signal_connect (GTK_OBJECT (prefs->font_list), "row-move",
+			    GTK_SIGNAL_FUNC (row_moved), prefs);
+	gtk_signal_connect (GTK_OBJECT (prefs->font_list), "select-row",
+                            GTK_SIGNAL_FUNC (font_selected), prefs);
+	gtk_signal_connect (GTK_OBJECT (prefs->font_list), "unselect-row",
+			    GTK_SIGNAL_FUNC (font_unselected), prefs);
+	gtk_container_add (GTK_CONTAINER (scrolled_window), prefs->font_list);
+
+	/* Populate the clist */
+	font_list = cfg->font_list;
+	while (font_list != NULL) {
+		font_row[0] = ((font_item_t*)font_list->data)->shortcut_name;
+		font_row[1] = ((font_item_t*)font_list->data)->font_name;
+		gtk_clist_append(GTK_CLIST (prefs->font_list), (char**)&font_row);
+		font_list = g_list_next(font_list);
+	}
+
+	hbox = gtk_hbox_new(FALSE,0);
+	gtk_box_pack_start(GTK_BOX(vbox),GTK_WIDGET(hbox),FALSE,FALSE,0);
+
+	prefs->font_delete_button = gtk_button_new_with_label( "Delete" );
+	gtk_box_pack_end(GTK_BOX(hbox),GTK_WIDGET(prefs->font_delete_button),
+			 FALSE,FALSE,GNOME_PAD);
+	gtk_signal_connect(GTK_OBJECT(prefs->font_delete_button), "clicked",
+                           GTK_SIGNAL_FUNC (font_delete), prefs);
+	gtk_widget_set_sensitive(GTK_WIDGET(prefs->font_delete_button),FALSE);
+
+	prefs->font_edit_button = gtk_button_new_with_label( "Edit..." );
+	gtk_box_pack_end(GTK_BOX(hbox),GTK_WIDGET(prefs->font_edit_button),
+		         FALSE,FALSE,GNOME_PAD);
+	gtk_signal_connect(GTK_OBJECT(prefs->font_edit_button), "clicked",
+			   GTK_SIGNAL_FUNC (font_edit), prefs);
+	gtk_widget_set_sensitive(GTK_WIDGET(prefs->font_edit_button),FALSE);
+
+	b1 = gtk_button_new_with_label( "Add..." );
+	gtk_box_pack_end(GTK_BOX(hbox),GTK_WIDGET(b1),FALSE,FALSE,GNOME_PAD);
+	gtk_signal_connect(GTK_OBJECT(b1), "clicked",
+                           GTK_SIGNAL_FUNC (font_add), prefs);
+
+
 	/* connect the property box signals */
 	gtk_signal_connect (GTK_OBJECT (prefs->prop_win), "apply",
 			    GTK_SIGNAL_FUNC (apply_changes_cmd), term);
@@ -1733,7 +2046,7 @@
 {
 	GnomeApp *app = GNOME_APP (gtk_widget_get_toplevel (GTK_WIDGET (data)));
 
-	close_app (app);
+	close_app (GTK_WIDGET(app));
 }
 
 /* called for "title_changed" event.  Use it to change the window title */
@@ -1884,6 +2197,10 @@
 	GnomeUIInfo *uiinfo;
 	struct terminal_config *cfg;
 	GtkCheckMenuItem *toggle_item;
+	int font_index, menu_length;
+	GList * font_list;
+	int i;
+	int ret;
 #ifdef ZVT_TERM_MATCH_SUPPORT
 	char *match;
 	int x,y;
@@ -1910,12 +2227,28 @@
 
 	gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "button_press_event");
 
+	cfg = gtk_object_get_data (GTK_OBJECT (term), "config");
+
+	/* construct popup menu by joining the static menu to entries in cfg->font_list */
+
+	/* Add 2: one for SEPARATOR, one for END */
+
+	menu_length = POPUP_MENU_LAST_INDEX + g_list_length(cfg->font_list) + 2;
+
+	uiinfo = g_malloc(menu_length * sizeof(GnomeUIInfo));
+
+	memcpy(&uiinfo[0], 
+		&gnome_terminal_popup_menu[0],
+		sizeof(gnome_terminal_popup_menu));
+
+	font_index = POPUP_MENU_LAST_INDEX;
+
 #ifdef ZVT_TERM_MATCH_SUPPORT
 	/* construct the popup menu properly */
 	if (match) {
 		char *tmp;
 
-		memcpy(&gnome_terminal_popup_menu[POPUP_MENU_DYNAMIC_INDEX],
+		memcpy(&uiinfo[POPUP_MENU_DYNAMIC_INDEX],
 		       &gnome_terminal_popup_menu_url[0],
 		       sizeof(gnome_terminal_popup_menu_url));
 
@@ -1923,18 +2256,43 @@
 		if (tmp)
 			g_free(tmp);
 		gtk_object_set_data (GTK_OBJECT (term), "matchstr", g_strdup(match));
+		font_index = POPUP_MENU_DYNAMIC_INDEX + 1;
 	} else {
 		/* make sure the optional menu isn't there */
-		memcpy(&gnome_terminal_popup_menu[POPUP_MENU_DYNAMIC_INDEX],
-		       &gnome_terminal_popup_menu[POPUP_MENU_LAST_INDEX],
-		       sizeof(gnome_terminal_popup_menu[0]));
+		font_index = POPUP_MENU_DYNAMIC_INDEX;
 	}
+
 #endif
-	uiinfo = gnome_terminal_popup_menu;
-	menu = gnome_popup_menu_new (gnome_terminal_popup_menu);
 
-	cfg = gtk_object_get_data (GTK_OBJECT (term), "config");
+	font_list = cfg->font_list;
+
+	i = font_index;
+	font_index++;
+
+        /* Add a separator and build the font menu from cfg->font_list */ 
+	if (font_list) {
+		uiinfo[i].type = GNOME_APP_UI_SEPARATOR;
+		uiinfo[i].label = uiinfo[i].hint = NULL;
+		i++;
+        
+		while (font_list != NULL) {
+			uiinfo[i].type = GNOME_APP_UI_ITEM;
+			uiinfo[i].label = ((font_item_t*)font_list->data)->shortcut_name;
+			uiinfo[i].moreinfo = uiinfo[i].user_data = uiinfo[i].unused_data = NULL;
+			uiinfo[i].pixmap_type = GNOME_APP_PIXMAP_NONE;
+			uiinfo[i].pixmap_info = NULL;
+			uiinfo[i].accelerator_key = 0;
 
+			font_list = g_list_next(font_list);
+			i++;
+		}
+	}
+
+	uiinfo[i].type = GNOME_APP_UI_ENDOFINFO;
+	uiinfo[i].label = uiinfo[i].hint = NULL;
+
+	menu = gnome_popup_menu_new (uiinfo);
+
 	/*
 	 * Set the toggle state for the "show menubar"
 	 * menu item.
@@ -1948,9 +2306,18 @@
 	 */
 	toggle_item = GTK_CHECK_MENU_ITEM (uiinfo [POPUP_MENU_TOGGLE_INDEX_SECURE].widget);
 	toggle_item->active = cfg->keyboard_secured;
+
+	ret = gnome_popup_menu_do_popup_modal (menu, NULL, NULL, event, term);
+
+	if (ret >= font_index) {
+		font_list = g_list_nth(cfg->font_list,ret-font_index);
+		gnome_term_set_font(term,
+				    ((font_item_t*)font_list->data)->font_name,
+				    cfg->use_bold);
+	}
 
-	gnome_popup_menu_do_popup_modal (menu, NULL, NULL, event, term);
 	gtk_widget_destroy (menu);
+	g_free(uiinfo);
 
 	/*
 	 * The popup menu ungrabs the keyboard if it was grabbed,


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