[nautilus/wip/gbsneto/actionbar: 32/35] view: add NautilusView::selection property



commit e6c549089cd0f1285b4ed98383e707632ff8a03c
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Mar 2 00:55:42 2016 -0300

    view: add NautilusView::selection property
    
    Currently we don't have any way to track selection
    changes, although NautilusView exposes selection. This
    is an inconsistency in code, and should be avoided.
    
    Fix that by adding a NautilusView::selection property
    and deprecating the NautilusFilesView::selection-changed
    signal.

 src/nautilus-files-view.c  |   34 +++++++++++++++++-----------------
 src/nautilus-places-view.c |    8 ++++++++
 src/nautilus-trash-bar.c   |    5 +++--
 src/nautilus-view.c        |   11 +++++++++++
 4 files changed, 39 insertions(+), 19 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 8043a84..5f5e337 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -139,7 +139,6 @@ enum {
         FILE_CHANGED,
         MOVE_COPY_ITEMS,
         REMOVE_FILE,
-        SELECTION_CHANGED,
         TRASH,
         DELETE,
         LAST_SIGNAL
@@ -154,6 +153,7 @@ enum {
         PROP_IS_LOADING,
         PROP_LOCATION,
         PROP_SEARCH_QUERY,
+        PROP_SELECTION,
         NUM_PROPERTIES
 };
 
@@ -2800,6 +2800,8 @@ nautilus_files_view_set_selection (NautilusView *nautilus_files_view,
                  */
                 nautilus_files_view_call_set_selection (view, selection);
                 nautilus_files_view_reveal_selection (view);
+
+                g_object_notify (G_OBJECT (view), "selection");
         } else {
                 /* If we are still loading, set the list of pending URIs instead.
                  * done_loading() will eventually select the pending URIs and reveal them.
@@ -3111,12 +3113,6 @@ nautilus_files_view_display_selection_info (NautilusFilesView *view)
 }
 
 static void
-nautilus_files_view_send_selection_change (NautilusFilesView *view)
-{
-        g_signal_emit (view, signals[SELECTION_CHANGED], 0);
-}
-
-static void
 nautilus_files_view_set_location (NautilusView *view,
                                   GFile        *location)
 {
@@ -3221,6 +3217,8 @@ done_loading (NautilusFilesView *view,
                         }
                 }
                 nautilus_files_view_display_selection_info (view);
+
+                g_object_notify (G_OBJECT (view), "selection");
         }
 
         view->details->loading = FALSE;
@@ -3644,7 +3642,7 @@ process_old_files (NautilusFilesView *view)
                 /* Send a selection change since some file names could
                  * have changed.
                  */
-                nautilus_files_view_send_selection_change (view);
+                g_object_notify (G_OBJECT (view), "selection");
         }
 }
 
@@ -3675,7 +3673,8 @@ display_selection_info_idle_callback (gpointer data)
 
         view->details->display_selection_idle_id = 0;
         nautilus_files_view_display_selection_info (view);
-        nautilus_files_view_send_selection_change (view);
+
+        g_object_notify (G_OBJECT (view), "selection");
 
         g_object_unref (G_OBJECT (view));
 
@@ -7606,6 +7605,10 @@ nautilus_files_view_get_property (GObject    *object,
                 g_value_set_object (value, view->details->search_query);
                 break;
 
+        case PROP_SELECTION:
+                g_value_set_pointer (value, nautilus_view_get_selection (NAUTILUS_VIEW (view)));
+                break;
+
         default:
                 g_assert_not_reached ();
 
@@ -7649,6 +7652,10 @@ nautilus_files_view_set_property (GObject      *object,
                 nautilus_view_set_search_query (NAUTILUS_VIEW (directory_view), g_value_get_object (value));
                 break;
 
+        case PROP_SELECTION:
+                nautilus_view_set_selection (NAUTILUS_VIEW (directory_view), g_value_get_pointer (value));
+                break;
+
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                 break;
@@ -8027,14 +8034,6 @@ nautilus_files_view_class_init (NautilusFilesViewClass *klass)
                               NULL, NULL,
                               g_cclosure_marshal_generic,
                               G_TYPE_NONE, 2, NAUTILUS_TYPE_FILE, NAUTILUS_TYPE_DIRECTORY);
-        signals[SELECTION_CHANGED] =
-                g_signal_new ("selection-changed",
-                              G_TYPE_FROM_CLASS (klass),
-                              G_SIGNAL_RUN_LAST,
-                              0,
-                              NULL, NULL,
-                              g_cclosure_marshal_VOID__VOID,
-                              G_TYPE_NONE, 0);
 
         klass->get_selected_icon_locations = real_get_selected_icon_locations;
         klass->is_read_only = real_is_read_only;
@@ -8072,6 +8071,7 @@ nautilus_files_view_class_init (NautilusFilesViewClass *klass)
         g_object_class_override_property (oclass, PROP_IS_SEARCH, "is-searching");
         g_object_class_override_property (oclass, PROP_LOCATION, "location");
         g_object_class_override_property (oclass, PROP_SEARCH_QUERY, "search-query");
+        g_object_class_override_property (oclass, PROP_SELECTION, "selection");
 }
 
 static void
diff --git a/src/nautilus-places-view.c b/src/nautilus-places-view.c
index 9a7cd1f..d54a23d 100644
--- a/src/nautilus-places-view.c
+++ b/src/nautilus-places-view.c
@@ -50,6 +50,7 @@ enum {
         PROP_VIEW_WIDGET,
         PROP_IS_LOADING,
         PROP_IS_SEARCHING,
+        PROP_SELECTION,
         LAST_PROP
 };
 
@@ -140,6 +141,10 @@ nautilus_places_view_get_property (GObject    *object,
                 g_value_set_object (value, nautilus_view_get_view_widget (view));
                 break;
 
+        case PROP_SELECTION:
+                g_value_set_pointer (value, NULL);
+                break;
+
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         }
@@ -162,6 +167,9 @@ nautilus_places_view_set_property (GObject      *object,
                 nautilus_view_set_search_query (view, g_value_get_object (value));
                 break;
 
+        case PROP_SELECTION:
+                break;
+
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         }
diff --git a/src/nautilus-trash-bar.c b/src/nautilus-trash-bar.c
index d7c62f5..0b85065 100644
--- a/src/nautilus-trash-bar.c
+++ b/src/nautilus-trash-bar.c
@@ -55,6 +55,7 @@ G_DEFINE_TYPE (NautilusTrashBar, nautilus_trash_bar, GTK_TYPE_INFO_BAR);
 
 static void
 selection_changed_cb (NautilusFilesView *view,
+                     GParamSpec        *pspec,
                      NautilusTrashBar *bar)
 {
         GList *selection;
@@ -74,10 +75,10 @@ static void
 connect_view_and_update_button (NautilusTrashBar *bar)
 {
        bar->priv->selection_handler_id =
-               g_signal_connect (bar->priv->view, "selection-changed",
+               g_signal_connect (bar->priv->view, "notify::selection",
                                  G_CALLBACK (selection_changed_cb), bar);
 
-       selection_changed_cb (bar->priv->view, bar);
+       selection_changed_cb (bar->priv->view, NULL, bar);
 }
 
 static void
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index f14b9f0..30f72f9 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -96,6 +96,17 @@ nautilus_view_default_init (NautilusViewInterface *iface)
                                                                   "The search query being performed on the 
view",
                                                                   NAUTILUS_TYPE_QUERY,
                                                                   G_PARAM_READWRITE));
+
+        /**
+         * NautilusView::selection:
+         *
+         * The current selection of the view.
+         */
+        g_object_interface_install_property (iface,
+                                             g_param_spec_pointer ("selection",
+                                                                   "Selection of the view",
+                                                                   "The selection of the view",
+                                                                    G_PARAM_READWRITE));
 }
 
 /**


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