epiphany r8692 - in trunk: lib/widgets src



Author: diegoe
Date: Thu Jan 15 22:06:55 2009
New Revision: 8692
URL: http://svn.gnome.org/viewvc/epiphany?rev=8692&view=rev

Log:
Turn the location bar into the woohoo bar

Enhance the completion popup by showing a two line cell containing the favicon,
the title of the page and the url. On top of this, there's a bookmark
indication patch.

Modified:
   trunk/lib/widgets/ephy-location-entry.c
   trunk/src/ephy-completion-model.c

Modified: trunk/lib/widgets/ephy-location-entry.c
==============================================================================
--- trunk/lib/widgets/ephy-location-entry.c	(original)
+++ trunk/lib/widgets/ephy-location-entry.c	Thu Jan 15 22:06:55 2009
@@ -49,7 +49,6 @@
 	GdkColor secure_bg_colour;
 	GdkColor secure_fg_colour;
 
-	GtkCellRenderer *extracell;
 	GRegex *regex;
 
 	char *before_completion;
@@ -88,11 +87,11 @@
 static void ephy_location_entry_init (EphyLocationEntry *le);
 static gboolean ephy_location_entry_reset_internal (EphyLocationEntry *, gboolean);
 
-static void extracell_data_func (GtkCellLayout *cell_layout,
-				GtkCellRenderer *cell,
-				GtkTreeModel *tree_model,
-				GtkTreeIter *iter,
-				gpointer data);
+static void textcell_data_func (GtkCellLayout *cell_layout,
+			GtkCellRenderer *cell,
+			GtkTreeModel *tree_model,
+			GtkTreeIter *iter,
+			gpointer data);
 
 enum signalsEnum
 {
@@ -128,10 +127,6 @@
 	}
 
 	title_fg_colour = widget->style->text[GTK_STATE_INSENSITIVE];
-	g_object_set (entry->priv->extracell, 
-		      "foreground-gdk", &title_fg_colour,
-		      "foreground-set", TRUE,
-		      NULL);
 
 	settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
 	g_object_get (settings, "gtk-theme-name", &theme, NULL);
@@ -911,8 +906,13 @@
 			    &item, -1);
 	entry = gtk_entry_completion_get_entry (completion);
 
+	/* Prevent the update so we keep the highlight from our input.
+	 * See textcell_data_func().
+	 */
+	le->priv->block_update = TRUE;
 	gtk_entry_set_text (GTK_ENTRY (entry), item);
 	gtk_editable_set_position (GTK_EDITABLE (entry), -1);
+	le->priv->block_update = FALSE;
 
 	g_free (item);
 
@@ -920,32 +920,82 @@
 }
 
 static void
-extracell_data_func (GtkCellLayout *cell_layout,
+textcell_data_func (GtkCellLayout *cell_layout,
 			GtkCellRenderer *cell,
 			GtkTreeModel *tree_model,
 			GtkTreeIter *iter,
 			gpointer data)
 {
-	char *cdata;
-	GValue visible = { 0, };
-	GValue text = { 0, };
 	EphyLocationEntryPrivate *priv;
+	PangoAttrList *list;
+	PangoAttribute *att;
+	GMatchInfo *match;
+
+	int start, end;
+
+	char *ctext;
+	char *title;
+	char *url;
+
+	GtkStyle *style;
+	GdkColor color;
+
+	GValue text = { 0, };
 
 	priv = EPHY_LOCATION_ENTRY (data)->priv;
+	gtk_tree_model_get (tree_model, iter,
+			priv->text_col, &title,
+			priv->url_col, &url,
+			-1);
 
-	gtk_tree_model_get (tree_model, iter, priv->extra_col, &cdata, -1);
+	list = pango_attr_list_new ();
 
-	g_value_init (&text, G_TYPE_STRING);
-	g_value_init (&visible, G_TYPE_BOOLEAN);
-	
-	g_value_take_string (&text, cdata);
-	g_value_set_boolean (&visible, (cdata != NULL));
+	if (url)
+	{
+		ctext = g_strdup_printf ("%s\n%s", title, url);
+
+		style = gtk_widget_get_style (priv->entry);
+		color = style->text[GTK_STATE_INSENSITIVE];
+
+		att = pango_attr_foreground_new
+			(color.red, color.green, color.blue);
+		att->start_index = strlen (title)+1;
+
+		pango_attr_list_insert (list, att);
+	}
+	else
+	{
+		ctext = title;
+	}
+
+	g_regex_match (priv->regex, ctext, G_REGEX_MATCH_NOTEMPTY, &match);
+
+	while (g_match_info_matches (match))
+	{
+		g_match_info_fetch_pos (match, 0, &start, &end);
 
+		att = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
+		att->start_index = start;
+		att->end_index = end;
+
+		pango_attr_list_insert (list, att);
+		g_match_info_next (match, NULL);
+	}
+
+	g_object_set (G_OBJECT (cell),
+			"attributes", list,
+			NULL);
+
+	g_value_init (&text, G_TYPE_STRING);
+	g_value_take_string (&text, ctext);
 	g_object_set_property (G_OBJECT (cell), "text", &text);
-	g_object_set_property (G_OBJECT (cell), "visible", &visible);
-	
 	g_value_unset (&text);
-	g_value_unset (&visible);
+
+	pango_attr_list_unref (list);
+	g_match_info_free (match);
+
+	g_free (title);
+	g_free (url);
 }
 
 /**
@@ -1046,19 +1096,10 @@
 				    cell, TRUE);
 	gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (completion),
 				       cell, "text", text_col);
+	gtk_cell_renderer_text_set_fixed_height_from_font (GTK_CELL_RENDERER_TEXT (cell), 2);
 
-	entry->priv->extracell = gtk_cell_renderer_text_new ();
-	g_object_set (entry->priv->extracell,
-		      "ellipsize", PANGO_ELLIPSIZE_END,
-		      "ellipsize-set", TRUE,
-		      "alignment", PANGO_ALIGN_LEFT,
-		      NULL);
-
-	gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (completion),
-				  entry->priv->extracell, TRUE);
-	
 	gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (completion),
-					entry->priv->extracell, extracell_data_func, 
+					cell, textcell_data_func,
 					entry,
 					NULL);
 

Modified: trunk/src/ephy-completion-model.c
==============================================================================
--- trunk/src/ephy-completion-model.c	(original)
+++ trunk/src/ephy-completion-model.c	Thu Jan 15 22:06:55 2009
@@ -265,12 +265,9 @@
 	switch (group)
 	{
 		case BOOKMARKS_GROUP:
-			text = ephy_node_get_property_string
-				(node, EPHY_NODE_BMK_PROP_TITLE);
-			break;
 		case HISTORY_GROUP:
 			text = ephy_node_get_property_string
-				(node, EPHY_NODE_PAGE_PROP_LOCATION);
+				(node, EPHY_NODE_PAGE_PROP_TITLE);
 			break;
 
 		default:
@@ -460,17 +457,9 @@
 	{
 		case EPHY_COMPLETION_EXTRA_COL:
 			g_value_init (value, G_TYPE_STRING);
-			/* We set an additional text for the item title only for 
-			 * history, since we assume that people know the url of 
-			 * their bookmarks 
-			 */
-			if (group == HISTORY_GROUP)
-			{
-				const char *text;
-				text = ephy_node_get_property_string
-					(node, EPHY_NODE_PAGE_PROP_TITLE);
-				g_value_set_string (value, text);
-			}
+			g_value_set_string (value,
+					ephy_node_get_property_string
+					 (node, EPHY_NODE_PAGE_PROP_LOCATION));
 			break;
 		case EPHY_COMPLETION_TEXT_COL:
 			g_value_init (value, G_TYPE_STRING);



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