[gtk+/wip/csoriano/bookmarks: 39/40] gtkplacessidebar: make insensitive invalid drop targets



commit 7529788e72ddb291c966154dffdc1348c139edac
Author: Carlos Soriano <csoriano gnome org>
Date:   Mon Apr 13 01:24:10 2015 +0200

    gtkplacessidebar: make insensitive invalid drop targets
    
    https://bugzilla.gnome.org/show_bug.cgi?id=747793

 gtk/gtkplacessidebar.c                   |   58 ++++++++++++++++++++++++++++-
 gtk/theme/Adwaita/_common.scss           |    4 ++
 gtk/theme/Adwaita/gtk-contained-dark.css |    3 ++
 gtk/theme/Adwaita/gtk-contained.css      |    3 ++
 4 files changed, 66 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 32efe29..291581c 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -225,6 +225,7 @@ enum {
   PLACES_SIDEBAR_COLUMN_TOOLTIP,
   PLACES_SIDEBAR_COLUMN_SECTION_TYPE,
   PLACES_SIDEBAR_COLUMN_HEADING_TEXT,
+  PLACES_SIDEBAR_COLUMN_SENSITIVE,
   PLACES_SIDEBAR_COLUMN_COUNT
 };
 
@@ -527,6 +528,7 @@ add_place (GtkPlacesSidebar *sidebar,
                       PLACES_SIDEBAR_COLUMN_BOOKMARK, place_type != PLACES_BOOKMARK,
                       PLACES_SIDEBAR_COLUMN_TOOLTIP, tooltip,
                       PLACES_SIDEBAR_COLUMN_SECTION_TYPE, section_type,
+                      PLACES_SIDEBAR_COLUMN_SENSITIVE, TRUE,
                       -1);
 }
 
@@ -1450,6 +1452,50 @@ pos_is_into_or_before (GtkTreeViewDropPosition pos)
   return (pos == GTK_TREE_VIEW_DROP_BEFORE || pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
 }
 
+static void
+update_possible_drop_targets (GtkPlacesSidebar *sidebar,
+                              gboolean          dragging)
+{
+  GtkTreeIter iter;
+  PlaceType place_type;
+  gchar *uri;
+  gboolean sensitive;
+
+  if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (sidebar->store), &iter))
+    return;
+
+  do
+    {
+      sensitive = TRUE;
+      gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
+                          PLACES_SIDEBAR_COLUMN_ROW_TYPE, &place_type,
+                          PLACES_SIDEBAR_COLUMN_URI, &uri,
+                          -1);
+      if (dragging)
+        {
+          switch (place_type)
+            {
+              case PLACES_CONNECT_TO_SERVER:
+                sensitive = FALSE;
+                break;
+              case PLACES_BUILT_IN:
+                if (g_strcmp0 (uri, "recent:///") == 0)
+                  sensitive = FALSE;
+
+                break;
+              default:
+                break;
+           }
+        }
+
+      gtk_list_store_set (sidebar->store, &iter,
+                          PLACES_SIDEBAR_COLUMN_SENSITIVE, sensitive,
+                          -1);
+      g_free (uri);
+    }
+  while (gtk_tree_model_iter_next (GTK_TREE_MODEL (sidebar->store), &iter));
+}
+
 /* Computes the appropriate row and position for dropping */
 static gboolean
 compute_drop_position (GtkTreeView              *tree_view,
@@ -1730,12 +1776,14 @@ start_drop_feedback (GtkPlacesSidebar        *sidebar,
     {
       gtk_tree_view_set_drag_dest_row (sidebar->tree_view, path, pos);
     }
+  update_possible_drop_targets (sidebar, TRUE);
 }
 
 static void
 stop_drop_feedback (GtkPlacesSidebar *sidebar)
 {
   gtk_tree_view_set_drag_dest_row (sidebar->tree_view, NULL, 0);
+  update_possible_drop_targets (sidebar, FALSE);
 }
 
 static gboolean
@@ -1853,7 +1901,9 @@ on_drag_end (GtkPlacesSidebar *sidebar)
   free_drag_data (sidebar);
   /* we could call finalize when disposing the widget */
   if (sidebar->tree_view != NULL)
-    stop_drop_feedback (sidebar);
+    {
+      stop_drop_feedback (sidebar);
+    }
   remove_drop_bookmark_feedback_row (sidebar);
 
   if (sidebar->drag_leave_timeout_id)
@@ -4208,6 +4258,7 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
   gtk_tree_view_column_pack_start (col, cell, FALSE);
   gtk_tree_view_column_set_attributes (col, cell,
                                        "gicon", PLACES_SIDEBAR_COLUMN_GICON,
+                                       "sensitive", PLACES_SIDEBAR_COLUMN_SENSITIVE,
                                        NULL);
   gtk_tree_view_column_set_cell_data_func (col, cell,
                                            icon_cell_renderer_func,
@@ -4253,6 +4304,7 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
                                        "text", PLACES_SIDEBAR_COLUMN_NAME,
                                        "visible", PLACES_SIDEBAR_COLUMN_NO_EJECT,
                                        "editable-set", PLACES_SIDEBAR_COLUMN_BOOKMARK,
+                                       "sensitive", PLACES_SIDEBAR_COLUMN_SENSITIVE,
                                        NULL);
   g_object_set (cell,
                 "ellipsize", PANGO_ELLIPSIZE_END,
@@ -4854,7 +4906,8 @@ shortcuts_model_new (GtkPlacesSidebar *sidebar)
     G_TYPE_BOOLEAN,
     G_TYPE_STRING,
     G_TYPE_INT,
-    G_TYPE_STRING
+    G_TYPE_STRING,
+    G_TYPE_BOOLEAN
   };
 
   model = g_object_new (shortcuts_model_get_type (), NULL);
@@ -5396,6 +5449,7 @@ void
 gtk_places_sidebar_drop_hints_start (GtkPlacesSidebar *sidebar)
 {
   show_new_bookmark_row (sidebar, NULL);
+  update_possible_drop_targets (sidebar, TRUE);
   sidebar->drop_state = DROP_STATE_NEW_BOOKMARK_ARMED_PERMANENT;
 }
 
diff --git a/gtk/theme/Adwaita/_common.scss b/gtk/theme/Adwaita/_common.scss
index 03e3262..77eb944 100644
--- a/gtk/theme/Adwaita/_common.scss
+++ b/gtk/theme/Adwaita/_common.scss
@@ -2885,6 +2885,10 @@ GtkPlacesSidebar.sidebar .view {
 
   color: $fg_color;
   background-color: transparent;
+  &:insensitive {
+    background-color: $insensitive_bg_color;
+    color: $insensitive_fg_color;
+  }
 
   .separator,
   .separator:backdrop { @extend .separator; }
diff --git a/gtk/theme/Adwaita/gtk-contained-dark.css b/gtk/theme/Adwaita/gtk-contained-dark.css
index 38fad37..8084e35 100644
--- a/gtk/theme/Adwaita/gtk-contained-dark.css
+++ b/gtk/theme/Adwaita/gtk-contained-dark.css
@@ -3934,6 +3934,9 @@ GtkFileChooserDialog .dialog-action-box {
 GtkPlacesSidebar.sidebar .view {
   color: #eeeeec;
   background-color: transparent; }
+  GtkPlacesSidebar.sidebar .view:insensitive {
+    background-color: #323636;
+    color: #939695; }
   GtkPlacesSidebar.sidebar .view .image {
     color: #bbbdbc; }
     GtkPlacesSidebar.sidebar .view .image:selected {
diff --git a/gtk/theme/Adwaita/gtk-contained.css b/gtk/theme/Adwaita/gtk-contained.css
index 6295d79..5577963 100644
--- a/gtk/theme/Adwaita/gtk-contained.css
+++ b/gtk/theme/Adwaita/gtk-contained.css
@@ -4106,6 +4106,9 @@ GtkFileChooserDialog .dialog-action-box {
 GtkPlacesSidebar.sidebar .view {
   color: #2e3436;
   background-color: transparent; }
+  GtkPlacesSidebar.sidebar .view:insensitive {
+    background-color: #f4f4f4;
+    color: #8d9091; }
   GtkPlacesSidebar.sidebar .view .image {
     color: #6b6f70; }
     GtkPlacesSidebar.sidebar .view .image:selected {


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