[gtk+/wip/csoriano/gtkpathbar_rework: 114/120] gtkpathbar: allow more destinations as root



commit 1263dce4572a0a67a08f8fb788ca4fa83ef5c60c
Author: Carlos Soriano <csoriano gnome org>
Date:   Wed Mar 4 13:23:52 2015 +0100

    gtkpathbar: allow more destinations as root
    
    Like the Home folder etc. Matching what Nautilus does.

 gtk/gtkpathbar.c |   40 +++++-----------------------------------
 1 files changed, 5 insertions(+), 35 deletions(-)
---
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index f195998..97d2f5a 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -43,7 +43,6 @@ struct _GtkPathBarPrivate
 
   GList *button_list;
   GList *first_scrolled_button;
-  GList *fake_root;
   GtkWidget *up_slider_button;
   GtkWidget *down_slider_button;
   guint settings_signal_id;
@@ -89,6 +88,7 @@ struct _ButtonData
 {
   GtkWidget *button;
   ButtonType type;
+  gboolean is_root;
   char *dir_name;
   GFile *file;
   GtkWidget *image;
@@ -97,11 +97,6 @@ struct _ButtonData
   guint ignore_changes : 1;
   guint file_is_hidden : 1;
 };
-/* This macro is used to check if a button can be used as a fake root.
- * All buttons in front of a fake root are automatically hidden when in a
- * directory below a fake root and replaced with the "<" arrow button.
- */
-#define BUTTON_IS_FAKE_ROOT(button) ((button)->type == HOME_BUTTON)
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkPathBar, gtk_path_bar, GTK_TYPE_CONTAINER)
 
@@ -1047,8 +1042,6 @@ gtk_path_bar_scroll_up (GtkPathBar *path_bar)
     {
       if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
        {
-         if (list->prev == path_bar->priv->fake_root)
-           path_bar->priv->fake_root = NULL;
          path_bar->priv->first_scrolled_button = list;
          return;
        }
@@ -1170,7 +1163,7 @@ reload_icons (GtkPathBar *path_bar)
       gboolean current_dir;
 
       button_data = BUTTON_DATA (list->data);
-      if (button_data->type != NORMAL_BUTTON)
+      if (button_data->type != NORMAL_BUTTON || button_data->is_root)
        {
          current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
          gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
@@ -1230,7 +1223,6 @@ gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
       gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA 
(path_bar->priv->button_list->data)->button);
     }
   path_bar->priv->first_scrolled_button = NULL;
-  path_bar->priv->fake_root = NULL;
 }
 
 static void
@@ -1479,6 +1471,7 @@ gtk_path_bar_setup_button_type (ButtonData *button_data,
   else if (gtk_path_bar_is_home_directory (location))
     {
       button_data->type = HOME_BUTTON;
+      button_data->is_root = TRUE;
     }
   else if (gtk_path_bar_is_desktop_directory (location))
     {
@@ -1488,6 +1481,7 @@ gtk_path_bar_setup_button_type (ButtonData *button_data,
     {
       button_data->dir_name = g_mount_get_name (mount);
       button_data->type = MOUNT_BUTTON;
+      button_data->is_root = TRUE;
 
       g_object_unref (mount);
     }
@@ -1591,7 +1585,6 @@ gtk_path_bar_check_parent_path (GtkPathBar         *path_bar,
 {
   GList *list;
   GList *current_path = NULL;
-  gboolean need_new_fake_root = FALSE;
 
   for (list = path_bar->priv->button_list; list; list = list->next)
     {
@@ -1603,28 +1596,10 @@ gtk_path_bar_check_parent_path (GtkPathBar         *path_bar,
          current_path = list;
          break;
        }
-      if (list == path_bar->priv->fake_root)
-       need_new_fake_root = TRUE;
     }
 
   if (current_path)
     {
-      if (need_new_fake_root)
-       {
-         path_bar->priv->fake_root = NULL;
-         for (list = current_path; list; list = list->next)
-           {
-             ButtonData *button_data;
-
-             button_data = list->data;
-             if (BUTTON_IS_FAKE_ROOT (button_data))
-               {
-                 path_bar->priv->fake_root = list;
-                 break;
-               }
-           }
-       }
-
       for (list = path_bar->priv->button_list; list; list = list->next)
        {
          gtk_path_bar_update_button_appearance (path_bar,
@@ -1650,7 +1625,6 @@ struct SetFileInfo
   GFile *parent_file;
   GtkPathBar *path_bar;
   GList *new_buttons;
-  GList *fake_root;
   gboolean first_directory;
 };
 
@@ -1664,7 +1638,6 @@ gtk_path_bar_set_file_finish (struct SetFileInfo *info,
 
       gtk_path_bar_clear_buttons (info->path_bar);
       info->path_bar->priv->button_list = g_list_reverse (info->new_buttons);
-      info->path_bar->priv->fake_root = info->fake_root;
 
       for (l = info->path_bar->priv->button_list; l; l = l->next)
        {
@@ -1730,16 +1703,13 @@ gtk_path_bar_get_info_callback (GObject      *source,
 
   file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
 
-  if (BUTTON_IS_FAKE_ROOT (button_data))
-    file_info->fake_root = file_info->new_buttons;
-
   /* We have assigned the info for the innermost button, i.e. the deepest directory.
    * Now, go on to fetch the info for this directory's parent.
    */
   file_info->file = file_info->parent_file;
   file_info->first_directory = FALSE;
 
-  if (!file_info->file)
+  if (!file_info->file || button_data->is_root)
     {
       /* No parent?  Okay, we are done. */
       gtk_path_bar_set_file_finish (file_info, TRUE);


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