summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--gtk/gtkrecentchooserdefault.c102
-rw-r--r--gtk/gtkrecentchoosermenu.c57
-rw-r--r--tests/testrecentchooser.c2
-rw-r--r--tests/testrecentchoosermenu.c1
5 files changed, 109 insertions, 67 deletions
diff --git a/ChangeLog b/ChangeLog
index fdcee16571..2e0acea460 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-07-23 Emmanuele Bassi <ebassi@gnome.org>
+
+ * gtk/gtkrecentchooserdefault.c: Port the GtkRecentChooser default
+ implementation widget to the new tooltips API, and make it look
+ like the GtkFileChooser widget in recent files mode (move the
+ full path from the widget to a tooltip on the row) to improve
+ consistency.
+
+ * gtk/gtkrecentchoosermenu.c: Port the GtkRecentChooserMenu widget
+ to the new tooltips API.
+
+ * tests/testrecentchooser.c:
+ * tests/testrecentchoosermenu.c: Exercise the tooltips code paths.
+
2007-07-22 Ross Burton <ross@openedhand.com>
* gtk/gtkscrolledwindow.c:
diff --git a/gtk/gtkrecentchooserdefault.c b/gtk/gtkrecentchooserdefault.c
index d4350d8621..5629245597 100644
--- a/gtk/gtkrecentchooserdefault.c
+++ b/gtk/gtkrecentchooserdefault.c
@@ -64,7 +64,7 @@
#include "gtktreemodelfilter.h"
#include "gtktreeselection.h"
#include "gtktreestore.h"
-#include "gtktooltips.h"
+#include "gtktooltip.h"
#include "gtktypebuiltins.h"
#include "gtkvbox.h"
@@ -111,8 +111,6 @@ struct _GtkRecentChooserDefault
gpointer sort_data;
GDestroyNotify sort_data_destroy;
- GtkTooltips *tooltips;
-
GtkIconTheme *icon_theme;
GtkWidget *recent_view;
@@ -280,6 +278,14 @@ static void recent_view_drag_data_get_cb (GtkWidget *widget,
guint info,
guint32 time_,
gpointer data);
+static gboolean recent_view_query_tooltip_cb (GtkWidget *widget,
+ gint x,
+ gint y,
+ gboolean keyboard_tip,
+ GtkTooltip *tooltip,
+ gpointer user_data);
+
+
G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserDefault,
_gtk_recent_chooser_default,
@@ -348,9 +354,6 @@ _gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl)
impl->current_filter = NULL;
- impl->tooltips = gtk_tooltips_new ();
- g_object_ref_sink (impl->tooltips);
-
impl->recent_items = NULL;
impl->n_recent_items = 0;
impl->loaded_items = 0;
@@ -400,6 +403,10 @@ gtk_recent_chooser_default_constructor (GType type,
g_signal_connect (impl->recent_view, "drag_data_get",
G_CALLBACK (recent_view_drag_data_get_cb), impl);
+ g_object_set (impl->recent_view, "has-tooltip", TRUE, NULL);
+ g_signal_connect (impl->recent_view, "query-tooltip",
+ G_CALLBACK (recent_view_query_tooltip_cb), impl);
+
g_object_set_data (G_OBJECT (impl->recent_view),
"GtkRecentChooserDefault", impl);
@@ -454,10 +461,8 @@ gtk_recent_chooser_default_constructor (GType type,
gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE);
g_signal_connect (impl->filter_combo, "changed",
G_CALLBACK (filter_combo_changed_cb), impl);
- gtk_tooltips_set_tip (impl->tooltips,
- impl->filter_combo,
- _("Select which type of documents are shown"),
- NULL);
+ gtk_widget_set_tooltip_text (impl->filter_combo,
+ _("Select which type of documents are shown"));
gtk_box_pack_end (GTK_BOX (impl->filter_combo_hbox),
impl->filter_combo,
@@ -506,11 +511,6 @@ gtk_recent_chooser_default_set_property (GObject *object,
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
impl->show_tips = g_value_get_boolean (value);
-
- if (impl->show_tips)
- gtk_tooltips_enable (impl->tooltips);
- else
- gtk_tooltips_disable (impl->tooltips);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
impl->show_icons = g_value_get_boolean (value);
@@ -632,12 +632,6 @@ gtk_recent_chooser_default_dispose (GObject *object)
impl->recent_store = NULL;
}
- if (impl->tooltips)
- {
- g_object_unref (impl->tooltips);
- impl->tooltips = NULL;
- }
-
G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->dispose (object);
}
@@ -976,6 +970,8 @@ recent_icon_data_func (GtkTreeViewColumn *tree_column,
if (pixbuf)
g_object_unref (pixbuf);
+
+ gtk_recent_info_unref (info);
}
static void
@@ -986,8 +982,7 @@ recent_meta_data_func (GtkTreeViewColumn *tree_column,
gpointer user_data)
{
GtkRecentInfo *info = NULL;
- gchar *uri, *name, *str;
- gchar *escaped_name, *escaped_location;
+ gchar *name;
gtk_tree_model_get (model, iter,
RECENT_DISPLAY_NAME_COLUMN, &name,
@@ -995,23 +990,11 @@ recent_meta_data_func (GtkTreeViewColumn *tree_column,
-1);
g_assert (info != NULL);
- uri = gtk_recent_info_get_uri_display (info);
-
if (!name)
name = gtk_recent_info_get_short_name (info);
- escaped_name = g_markup_printf_escaped ("<b>%s</b>", name);
- escaped_location = g_markup_printf_escaped ("<small>%s: %s</small>",
- _("Location"),
- uri);
- str = g_strjoin ("\n", escaped_name, escaped_location, NULL);
- g_free (escaped_name);
- g_free (escaped_location);
+ g_object_set (cell, "text", name, NULL);
- g_object_set (cell, "markup", str, NULL);
-
- g_free (str);
- g_free (uri);
g_free (name);
gtk_recent_info_unref (info);
}
@@ -1573,7 +1556,54 @@ recent_view_drag_data_get_cb (GtkWidget *widget,
g_free (drag_data);
}
+static gboolean
+recent_view_query_tooltip_cb (GtkWidget *widget,
+ gint x,
+ gint y,
+ gboolean keyboard_tip,
+ GtkTooltip *tooltip,
+ gpointer user_data)
+{
+ GtkRecentChooserDefault *impl = user_data;
+ GtkTreeView *tree_view;
+ GtkTreeIter iter;
+ GtkTreePath *path = NULL;
+ GtkRecentInfo *info = NULL;
+ gchar *uri_display;
+ if (!impl->show_tips)
+ return FALSE;
+
+ tree_view = GTK_TREE_VIEW (impl->recent_view);
+
+ gtk_tree_view_get_tooltip_context (tree_view,
+ &x, &y,
+ keyboard_tip,
+ NULL, &path, NULL);
+ if (!path)
+ return FALSE;
+
+ if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_store), &iter, path))
+ {
+ gtk_tree_path_free (path);
+ return FALSE;
+ }
+
+ gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_store), &iter,
+ RECENT_INFO_COLUMN, &info,
+ -1);
+
+ uri_display = gtk_recent_info_get_uri_display (info);
+
+ gtk_tooltip_set_text (tooltip, uri_display);
+ gtk_tree_view_set_tooltip_row (tree_view, tooltip, path);
+
+ g_free (uri_display);
+ gtk_tree_path_free (path);
+ gtk_recent_info_unref (info);
+
+ return TRUE;
+}
static void
remove_selected_from_list (GtkRecentChooserDefault *impl)
diff --git a/gtk/gtkrecentchoosermenu.c b/gtk/gtkrecentchoosermenu.c
index fb2ab4f1e1..aecbbcd5d5 100644
--- a/gtk/gtkrecentchoosermenu.c
+++ b/gtk/gtkrecentchoosermenu.c
@@ -44,7 +44,7 @@
#include "gtkimage.h"
#include "gtklabel.h"
#include "gtkobject.h"
-#include "gtktooltips.h"
+#include "gtktooltip.h"
#include "gtktypebuiltins.h"
#include "gtkprivate.h"
#include "gtkalias.h"
@@ -85,9 +85,6 @@ struct _GtkRecentChooserMenuPrivate
gulong manager_changed_id;
gulong populate_id;
-
- /* tooltips for our bookmark items*/
- GtkTooltips *tooltips;
};
enum {
@@ -242,9 +239,6 @@ gtk_recent_chooser_menu_init (GtkRecentChooserMenu *menu)
priv->placeholder = NULL;
priv->current_filter = NULL;
-
- priv->tooltips = gtk_tooltips_new ();
- g_object_ref_sink (priv->tooltips);
}
static void
@@ -287,12 +281,6 @@ gtk_recent_chooser_menu_dispose (GObject *object)
priv->populate_id = 0;
}
- if (priv->tooltips)
- {
- g_object_unref (priv->tooltips);
- priv->tooltips = NULL;
- }
-
if (priv->current_filter)
{
g_object_unref (priv->current_filter);
@@ -741,25 +729,20 @@ gtk_recent_chooser_menu_add_tip (GtkRecentChooserMenu *menu,
GtkWidget *item)
{
GtkRecentChooserMenuPrivate *priv;
- gchar *path, *tip_text;
+ gchar *path;
g_assert (info != NULL);
g_assert (item != NULL);
priv = menu->priv;
- if (!priv->tooltips)
- return;
-
path = gtk_recent_info_get_uri_display (info);
if (path)
{
- tip_text = g_strdup_printf (_("Open '%s'"), path);
+ gchar *tip_text = g_strdup_printf (_("Open '%s'"), path);
- gtk_tooltips_set_tip (priv->tooltips,
- item,
- tip_text,
- NULL);
+ gtk_widget_set_tooltip_text (item, tip_text);
+ gtk_widget_set_has_tooltip (item, priv->show_tips);
g_free (path);
g_free (tip_text);
@@ -1124,20 +1107,32 @@ get_icon_size_for_widget (GtkWidget *widget)
}
static void
+foreach_set_shot_tips (GtkWidget *widget,
+ gpointer user_data)
+{
+ GtkRecentChooserMenu *menu = user_data;
+ GtkRecentChooserMenuPrivate *priv = menu->priv;
+ gboolean has_mark;
+
+ /* toggle the tooltip only on the items we create */
+ has_mark =
+ GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "gtk-recent-menu-mark"));
+
+ if (has_mark)
+ gtk_widget_set_has_tooltip (widget, priv->show_tips);
+}
+
+static void
gtk_recent_chooser_menu_set_show_tips (GtkRecentChooserMenu *menu,
gboolean show_tips)
{
- if (menu->priv->show_tips == show_tips)
+ GtkRecentChooserMenuPrivate *priv = menu->priv;
+
+ if (priv->show_tips == show_tips)
return;
- g_assert (menu->priv->tooltips != NULL);
-
- if (show_tips)
- gtk_tooltips_enable (menu->priv->tooltips);
- else
- gtk_tooltips_disable (menu->priv->tooltips);
-
- menu->priv->show_tips = show_tips;
+ priv->show_tips = show_tips;
+ gtk_container_foreach (GTK_CONTAINER (menu), foreach_set_shot_tips, menu);
}
/*
diff --git a/tests/testrecentchooser.c b/tests/testrecentchooser.c
index eeb80238d5..e3a7d48549 100644
--- a/tests/testrecentchooser.c
+++ b/tests/testrecentchooser.c
@@ -130,6 +130,8 @@ main (int argc,
dialog = g_object_new (GTK_TYPE_RECENT_CHOOSER_DIALOG,
"select-multiple", multiple,
+ "show-tips", TRUE,
+ "show-icons", TRUE,
NULL);
gtk_window_set_title (GTK_WINDOW (dialog), "Select a file");
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
diff --git a/tests/testrecentchoosermenu.c b/tests/testrecentchoosermenu.c
index d1110ee1a1..d22ef012e3 100644
--- a/tests/testrecentchoosermenu.c
+++ b/tests/testrecentchoosermenu.c
@@ -65,6 +65,7 @@ create_recent_chooser_menu (gint limit)
gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (menu), limit);
gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (menu), TRUE);
gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (menu), TRUE);
+ gtk_recent_chooser_set_show_tips (GTK_RECENT_CHOOSER (menu), TRUE);
gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu),
GTK_RECENT_SORT_MRU);
gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (menu),