Updating branch refs/heads/jannis/new-shortcuts-pane
         to b47b184cc691668a6da42cce70d3ecfa9ff58331 (commit)
       from 5dea55ba646b654e1ab1f7058e957d990362a993 (commit)

commit b47b184cc691668a6da42cce70d3ecfa9ff58331
Author: Jannis Pohlmann <jan...@xfce.org>
Date:   Tue Jun 7 14:00:33 2011 +0200

    Select the shortcut row when the corresponding folder is opened.

 thunar/thunar-shortcut-row.c   |   18 +++++
 thunar/thunar-shortcut-row.h   |    2 +
 thunar/thunar-shortcuts-view.c |  134 ++++++++++++++++++++++++++++++----------
 3 files changed, 121 insertions(+), 33 deletions(-)

diff --git a/thunar/thunar-shortcut-row.c b/thunar/thunar-shortcut-row.c
index 3acab7b..4a70625 100644
--- a/thunar/thunar-shortcut-row.c
+++ b/thunar/thunar-shortcut-row.c
@@ -1221,6 +1221,15 @@ thunar_shortcut_row_set_file (ThunarShortcutRow *row,
 
 
 
+GFile *
+thunar_shortcut_row_get_file (ThunarShortcutRow *row)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT_ROW (row), NULL);
+  return row->file;
+}
+
+
+
 void
 thunar_shortcut_row_set_volume (ThunarShortcutRow *row,
                                 GVolume           *volume)
@@ -1246,6 +1255,15 @@ thunar_shortcut_row_set_volume (ThunarShortcutRow *row,
 
 
 
+GVolume *
+thunar_shortcut_row_get_volume (ThunarShortcutRow *row)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT_ROW (row), NULL);
+  return row->volume;
+}
+
+
+
 void
 thunar_shortcut_row_set_icon_size (ThunarShortcutRow *row,
                                    ThunarIconSize     icon_size)
diff --git a/thunar/thunar-shortcut-row.h b/thunar/thunar-shortcut-row.h
index 3acbccf..c824aad 100644
--- a/thunar/thunar-shortcut-row.h
+++ b/thunar/thunar-shortcut-row.h
@@ -50,8 +50,10 @@ void       thunar_shortcut_row_set_label      
(ThunarShortcutRow *row,
                                                const gchar       *label);
 void       thunar_shortcut_row_set_file       (ThunarShortcutRow *row,
                                                GFile             *file);
+GFile     *thunar_shortcut_row_get_file       (ThunarShortcutRow *row);
 void       thunar_shortcut_row_set_volume     (ThunarShortcutRow *row,
                                                GVolume           *volume);
+GVolume   *thunar_shortcut_row_get_volume     (ThunarShortcutRow *row);
 void       thunar_shortcut_row_set_icon_size  (ThunarShortcutRow *row,
                                                ThunarIconSize     icon_size);
 
diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c
index 2fb9aed..8a35a0e 100644
--- a/thunar/thunar-shortcuts-view.c
+++ b/thunar/thunar-shortcuts-view.c
@@ -74,37 +74,40 @@ typedef void (*ThunarShortcutsViewForeachRowFunc) 
(ThunarShortcutsView *view,
 
 
 
-static void       thunar_shortcuts_view_constructed       (GObject             
             *object);
-static void       thunar_shortcuts_view_finalize          (GObject             
             *object);
-static void       thunar_shortcuts_view_get_property      (GObject             
             *object,
-                                                           guint               
              prop_id,
-                                                           GValue              
             *value,
-                                                           GParamSpec          
             *pspec);
-static void       thunar_shortcuts_view_set_property      (GObject             
             *object,
-                                                           guint               
              prop_id,
-                                                           const GValue        
             *value,
-                                                           GParamSpec          
             *pspec);
-static void       thunar_shortcuts_view_row_inserted      (ThunarShortcutsView 
             *view,
-                                                           GtkTreePath         
             *path,
-                                                           GtkTreeIter         
             *iter,
-                                                           GtkTreeModel        
             *model);
-static GtkWidget *thunar_shortcuts_view_get_expander_at   (ThunarShortcutsView 
             *view,
-                                                           gint                
              index);
-static void       thunar_shortcuts_view_row_activated     (ThunarShortcutsView 
             *view,
-                                                           ThunarFile          
             *file,
-                                                           ThunarShortcutRow   
             *row);
-static void       thunar_shortcuts_view_row_state_changed (ThunarShortcutsView 
             *view,
-                                                           GtkStateType        
              previous_state,
-                                                           ThunarShortcutRow   
             *row);
-static void       thunar_shortcuts_view_open              (ThunarShortcutsView 
             *view,
-                                                           ThunarFile          
             *file,
-                                                           gboolean            
              new_window);
-static void       thunar_shortcuts_view_foreach_row       (ThunarShortcutsView 
             *view,
-                                                           
ThunarShortcutsViewForeachRowFunc func,
-                                                           gpointer            
              user_data);
-static void       thunar_shortcuts_view_unselect_rows     (ThunarShortcutsView 
             *view,
-                                                           ThunarShortcutRow   
             *row,
-                                                           gpointer            
              user_data);
+static void       thunar_shortcuts_view_constructed              (GObject      
                    *object);
+static void       thunar_shortcuts_view_finalize                 (GObject      
                    *object);
+static void       thunar_shortcuts_view_get_property             (GObject      
                    *object,
+                                                                  guint        
                     prop_id,
+                                                                  GValue       
                    *value,
+                                                                  GParamSpec   
                    *pspec);
+static void       thunar_shortcuts_view_set_property             (GObject      
                    *object,
+                                                                  guint        
                     prop_id,
+                                                                  const GValue 
                    *value,
+                                                                  GParamSpec   
                    *pspec);
+static void       thunar_shortcuts_view_row_inserted             
(ThunarShortcutsView              *view,
+                                                                  GtkTreePath  
                    *path,
+                                                                  GtkTreeIter  
                    *iter,
+                                                                  GtkTreeModel 
                    *model);
+static GtkWidget *thunar_shortcuts_view_get_expander_at          
(ThunarShortcutsView              *view,
+                                                                  gint         
                     index);
+static void       thunar_shortcuts_view_row_activated            
(ThunarShortcutsView              *view,
+                                                                  ThunarFile   
                    *file,
+                                                                  
ThunarShortcutRow                *row);
+static void       thunar_shortcuts_view_row_state_changed        
(ThunarShortcutsView              *view,
+                                                                  GtkStateType 
                     previous_state,
+                                                                  
ThunarShortcutRow                *row);
+static void       thunar_shortcuts_view_open                     
(ThunarShortcutsView              *view,
+                                                                  ThunarFile   
                    *file,
+                                                                  gboolean     
                     new_window);
+static void       thunar_shortcuts_view_foreach_row              
(ThunarShortcutsView              *view,
+                                                                  
ThunarShortcutsViewForeachRowFunc func,
+                                                                  gpointer     
                     user_data);
+static void       thunar_shortcuts_view_unselect_rows            
(ThunarShortcutsView              *view,
+                                                                  
ThunarShortcutRow                *row,
+                                                                  gpointer     
                     user_data);
+static void       thunar_shortcuts_view_update_selection_by_file 
(ThunarShortcutsView              *view,
+                                                                  
ThunarShortcutRow                *row,
+                                                                  gpointer     
                     user_data);
 
 
 
@@ -544,8 +547,69 @@ thunar_shortcuts_view_unselect_rows (ThunarShortcutsView 
*view,
   _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (selected_row));
 
   /* reset the row state if it is not the selected row */
-  if (row != selected_row)
-    gtk_widget_set_state (GTK_WIDGET (row), GTK_STATE_NORMAL);
+  if (row != selected_row && 
+      gtk_widget_get_state (GTK_WIDGET (row)) == GTK_STATE_SELECTED)
+    {
+      gtk_widget_set_state (GTK_WIDGET (row), GTK_STATE_NORMAL);
+    }
+}
+
+
+
+static void
+thunar_shortcuts_view_update_selection_by_file (ThunarShortcutsView *view,
+                                                ThunarShortcutRow   *row,
+                                                gpointer             user_data)
+{
+  ThunarFile *file = THUNAR_FILE (user_data);
+  gboolean    select_row = FALSE;
+  GVolume    *row_volume;
+  GMount     *mount;
+  GFile      *mount_point;
+  GFile      *row_file;
+
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
+  _thunar_return_if_fail (THUNAR_IS_FILE (file));
+
+  /* get the file and volume of the view */
+  row_file = thunar_shortcut_row_get_file (row);
+  row_volume = thunar_shortcut_row_get_volume (row);
+
+  /* check if we have a volume */
+  if (row_volume != NULL)
+    {
+      /* get the mount point */
+      mount = g_volume_get_mount (row_volume);
+      if (mount != NULL)
+        {
+          mount_point = g_mount_get_root (mount);
+
+          /* select the row if the mount point and the selected file are equal 
*/
+          if (g_file_equal (file->gfile, mount_point))
+            select_row = TRUE;
+
+          /* release mount point and mount */
+          g_object_unref (mount_point);
+          g_object_unref (mount);
+        }
+    }
+  else if (row_file != NULL)
+    {
+      /* select the row if the bookmark and the selected file are equal */
+      if (g_file_equal (file->gfile, row_file))
+        select_row = TRUE;
+    }
+
+  /* apply the selection / unselection */
+  if (select_row)
+    {
+      gtk_widget_set_state (GTK_WIDGET (row), GTK_STATE_SELECTED);
+    }
+  else if (gtk_widget_get_state (GTK_WIDGET (row)) == GTK_STATE_SELECTED)
+    {
+      gtk_widget_set_state (GTK_WIDGET (row), GTK_STATE_NORMAL);
+    }
 }
 
 
@@ -638,6 +702,10 @@ thunar_shortcuts_view_select_by_file (ThunarShortcutsView 
*view,
 {
   _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
   _thunar_return_if_fail (THUNAR_IS_FILE (file));
+
+  thunar_shortcuts_view_foreach_row (view,
+                                     
thunar_shortcuts_view_update_selection_by_file,
+                                     file);
 }
 
 
_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to