[nautilus/wip/gbsneto/actionbar-final: 17/24] view: add NautilusView::selection property



commit b063d0c7ec7caf1f3840ec96c02cb50cb1554198
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 |    9 +++++++++
 src/nautilus-trash-bar.c   |    5 +++--
 src/nautilus-view.c        |   11 +++++++++++
 4 files changed, 40 insertions(+), 19 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index a386e19..1e2c934 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -135,7 +135,6 @@ enum {
         FILE_CHANGED,
         MOVE_COPY_ITEMS,
         REMOVE_FILE,
-        SELECTION_CHANGED,
         TRASH,
         DELETE,
         LAST_SIGNAL
@@ -150,6 +149,7 @@ enum {
         PROP_IS_LOADING,
         PROP_LOCATION,
         PROP_SEARCH_QUERY,
+        PROP_SELECTION,
         NUM_PROPERTIES
 };
 
@@ -2793,6 +2793,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.
@@ -3105,12 +3107,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)
 {
@@ -3236,6 +3232,8 @@ done_loading (NautilusFilesView *view,
                         }
                 }
                 nautilus_files_view_display_selection_info (view);
+
+                g_object_notify (G_OBJECT (view), "selection");
         }
 
         view->details->loading = FALSE;
@@ -3708,7 +3706,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");
                 }
 
                 g_signal_emit (view, signals[END_FILE_CHANGES], 0);
@@ -3746,7 +3744,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));
 
@@ -7644,6 +7643,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 ();
 
@@ -7687,6 +7690,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;
@@ -8074,14 +8081,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_backing_uri = real_get_backing_uri;
         klass->using_manual_layout = real_using_manual_layout;
@@ -8117,6 +8116,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 f6214f8..96d290e 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
 };
 
@@ -164,6 +165,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);
         }
@@ -186,6 +191,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);
         }
@@ -336,6 +344,7 @@ nautilus_places_view_class_init (NautilusPlacesViewClass *klass)
         g_object_class_override_property (object_class, PROP_IS_SEARCHING, "is-searching");
         g_object_class_override_property (object_class, PROP_LOCATION, "location");
         g_object_class_override_property (object_class, PROP_SEARCH_QUERY, "search-query");
+        g_object_class_override_property (object_class, PROP_SELECTION, "selection");
         g_object_class_override_property (object_class, PROP_VIEW_WIDGET, "view-widget");
 }
 
diff --git a/src/nautilus-trash-bar.c b/src/nautilus-trash-bar.c
index dd4327a..b2139db 100644
--- a/src/nautilus-trash-bar.c
+++ b/src/nautilus-trash-bar.c
@@ -54,6 +54,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;
@@ -73,10 +74,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]