]> Pileus Git - ~andy/gtk/commitdiff
Apply a patch by Emmanuele Bassi to add tooltips to the file lists in
authorMatthias Clasen <mclasen@redhat.com>
Fri, 20 Jul 2007 09:53:20 +0000 (09:53 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Fri, 20 Jul 2007 09:53:20 +0000 (09:53 +0000)
2007-07-20  Matthias Clasen  <mclasen@redhat.com>

        * gtk/gtkfilechooserdefault.c: Apply a patch by Emmanuele
        Bassi to add tooltips to the file lists in recent files and
        search modes.

svn path=/trunk/; revision=18508

ChangeLog
gtk/gtkfilechooserdefault.c

index f2db9026c2c8dc16dbbd1df180615f2c0148a20d..c92cdad61641a7e25ed334e0fc01d7f264e95e53 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-07-20  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtkfilechooserdefault.c: Apply a patch by Emmanuele
+       Bassi to add tooltips to the file lists in recent files and
+       search modes.
+
 2007-07-20  Ryan Lortie  <desrt@desrt.ca>
 
        * gtk/gtkwidget.c (gtk_widget_is_composited): add note that the
index 96063a72e8c237437ab852c699fb53ee8020cbeb..372f6c9bdabfc497aae2ab1fbd3c034683b486c8 100644 (file)
@@ -63,6 +63,7 @@
 #include "gtksizegroup.h"
 #include "gtkstock.h"
 #include "gtktable.h"
+#include "gtktooltip.h"
 #include "gtktreednd.h"
 #include "gtktreeprivate.h"
 #include "gtktreeselection.h"
@@ -4469,6 +4470,82 @@ file_list_set_sort_column_ids (GtkFileChooserDefault *impl)
   gtk_tree_view_column_set_sort_column_id (impl->list_mtime_column, mtime_id);
 }
 
+static gboolean
+file_list_query_tooltip_cb (GtkWidget  *widget,
+                            gint        x,
+                            gint        y,
+                            gboolean    keyboard_tip,
+                            GtkTooltip *tooltip,
+                            gpointer    user_data)
+{
+  GtkFileChooserDefault *impl = user_data;
+  GtkTreeIter iter, child_iter;
+  GtkTreePath *path = NULL;
+  GtkFilePath *file_path = NULL;
+  gchar *filename;
+
+  if (impl->operation_mode == OPERATION_MODE_BROWSE)
+    return FALSE;
+
+
+  gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (impl->browse_files_tree_view),
+                                     &x, &y,
+                                     keyboard_tip,
+                                     NULL, &path, NULL);
+                                       
+  if (!path)
+    return FALSE;
+
+  switch (impl->operation_mode)
+    {
+    case OPERATION_MODE_SEARCH:
+      if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->search_model_sort), &iter, path))
+        {
+          gtk_tree_path_free (path);
+          return FALSE;
+        }
+
+      search_get_valid_child_iter (impl, &child_iter, &iter);
+      gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
+                          SEARCH_MODEL_COL_PATH, &file_path,
+                          -1);
+      break;
+    
+    case OPERATION_MODE_RECENT:
+      if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_model_sort), &iter, path))
+        {
+          gtk_tree_path_free (path);
+          return FALSE;
+        }
+
+      recent_get_valid_child_iter (impl, &child_iter, &iter);
+      gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &child_iter,
+                          RECENT_MODEL_COL_PATH, &file_path,
+                          -1);
+      break;
+
+    case OPERATION_MODE_BROWSE:
+      g_assert_not_reached ();
+      return FALSE;
+    }
+
+  if (!file_path)
+    {
+      gtk_tree_path_free (path);
+      return FALSE;
+    }
+
+  filename = gtk_file_system_path_to_filename (impl->file_system, file_path);
+  gtk_tooltip_set_text (tooltip, filename);
+  gtk_tree_view_set_tooltip_row (GTK_TREE_VIEW (impl->browse_files_tree_view),
+                                 tooltip,
+                                 path);
+
+  g_free (filename);
+  gtk_tree_path_free (path);
+
+  return TRUE;
+}
 
 /* Creates the widgets for the file list */
 static GtkWidget *
@@ -4521,6 +4598,10 @@ create_file_list (GtkFileChooserDefault *impl)
   g_signal_connect (impl->browse_files_tree_view, "drag_motion",
                     G_CALLBACK (file_list_drag_motion_cb), impl);
 
+  g_object_set (impl->browse_files_tree_view, "has-tooltip", TRUE, NULL);
+  g_signal_connect (impl->browse_files_tree_view, "query-tooltip",
+                    G_CALLBACK (file_list_query_tooltip_cb), impl);
+
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
   gtk_tree_selection_set_select_function (selection,
                                          list_select_func,
@@ -10728,22 +10809,15 @@ list_name_data_func (GtkTreeViewColumn *tree_column,
   if (impl->operation_mode == OPERATION_MODE_SEARCH)
     {
       GtkTreeIter child_iter;
-      GtkFilePath *file_path;
-      gchar *display_name, *tmp;
-      gchar *text;
+      gchar *display_name;
       gboolean is_folder;
 
       search_get_valid_child_iter (impl, &child_iter, iter);
       gtk_tree_model_get (GTK_TREE_MODEL (impl->search_model), &child_iter,
-                          SEARCH_MODEL_COL_PATH, &file_path,
                           SEARCH_MODEL_COL_DISPLAY_NAME, &display_name,
                           SEARCH_MODEL_COL_IS_FOLDER, &is_folder,
                          -1);
 
-      tmp = gtk_file_system_path_to_filename (impl->file_system, file_path);
-      text = g_strdup_printf ("<b>%s</b>\n%s", display_name, tmp);
-      g_free (tmp);
-
       if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
           impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
         {
@@ -10751,13 +10825,11 @@ list_name_data_func (GtkTreeViewColumn *tree_column,
         }
 
       g_object_set (cell,
-                   "markup", text,
+                   "text", display_name,
                    "sensitive", sensitive,
                    "ellipsize", PANGO_ELLIPSIZE_END,
                    NULL);
       
-      g_free (text);
-
       return;
     }
 
@@ -10765,7 +10837,7 @@ list_name_data_func (GtkTreeViewColumn *tree_column,
     {
       GtkTreeIter child_iter;
       GtkRecentInfo *recent_info;
-      gchar *tmp, *text;
+      gchar *display_name;
       gboolean is_folder;
 
       recent_get_valid_child_iter (impl, &child_iter, iter);
@@ -10774,11 +10846,7 @@ list_name_data_func (GtkTreeViewColumn *tree_column,
                           RECENT_MODEL_COL_IS_FOLDER, &is_folder,
                           -1);
       
-      tmp = gtk_recent_info_get_short_name (recent_info);
-      text = g_strdup_printf ("<b>%s</b>\n%s",
-                              tmp,
-                              gtk_recent_info_get_uri_display (recent_info));
-      g_free (tmp);
+      display_name = gtk_recent_info_get_short_name (recent_info);
 
       if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
           impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
@@ -10787,11 +10855,12 @@ list_name_data_func (GtkTreeViewColumn *tree_column,
         }
 
       g_object_set (cell,
-                    "markup", text,
+                    "text", display_name,
                     "sensitive", sensitive,
                     "ellipsize", PANGO_ELLIPSIZE_END,
                     NULL);
-      g_free (text);
+
+      g_free (display_name);
 
       return;
     }