[nautilus/wip/csoriano/desktop-split: 13/53] files-view: use inheritance for querying special selection



commit 262eb15b4f1e4f9134ce858b0eaa049f90ee08c7
Author: Carlos Soriano <csoriano gnome org>
Date:   Fri Mar 18 16:29:42 2016 +0100

    files-view: use inheritance for querying special selection
    
    There is a few times that the file cannot be copied, moved etc.
    This usually happens with the special links in the desktop.
    We were querying whether the selection has special items or not
    in the files-view itself. However, this is something that every view
    could have special, like the desktop one.
    
    So use inheritance for it.

 src/nautilus-desktop-canvas-view.c |   26 +++++++++++++++++++++++++
 src/nautilus-files-view.c          |   37 +++++++++++------------------------
 src/nautilus-files-view.h          |    6 +++++
 3 files changed, 44 insertions(+), 25 deletions(-)
---
diff --git a/src/nautilus-desktop-canvas-view.c b/src/nautilus-desktop-canvas-view.c
index 32bd0c4..1d2e903 100644
--- a/src/nautilus-desktop-canvas-view.c
+++ b/src/nautilus-desktop-canvas-view.c
@@ -68,6 +68,8 @@ static void     default_zoom_level_changed                        (gpointer
 static void     real_update_context_menus                         (NautilusFilesView           *view);
 static char*    real_get_backing_uri                              (NautilusFilesView           *view);
 static void     real_check_empty_states                           (NautilusFilesView           *view);
+static gboolean real_special_link_in_selection                    (NautilusFilesView           *view,
+                                                                   GList                       *selection);
 static void     nautilus_desktop_canvas_view_update_canvas_container_fonts  (NautilusDesktopCanvasView      
*view);
 static void     font_changed_callback                             (gpointer                callback_data);
 
@@ -294,6 +296,7 @@ nautilus_desktop_canvas_view_class_init (NautilusDesktopCanvasViewClass *class)
        vclass->end_loading = nautilus_desktop_canvas_view_end_loading;
        vclass->get_backing_uri = real_get_backing_uri;
        vclass->check_empty_states = real_check_empty_states;
+        vclass->special_link_in_selection = real_special_link_in_selection;
 
        g_type_class_add_private (class, sizeof (NautilusDesktopCanvasViewDetails));
 }
@@ -560,6 +563,29 @@ const GActionEntry desktop_view_entries[] = {
        { "unstretch", action_unstretch },
 };
 
+static gboolean
+real_special_link_in_selection (NautilusFilesView *view,
+                                GList             *selection)
+{
+        gboolean saw_link;
+        GList *node;
+        NautilusFile *file;
+
+        saw_link = FALSE;
+
+        for (node = selection; node != NULL; node = node->next) {
+                file = NAUTILUS_FILE (node->data);
+
+                saw_link = NAUTILUS_IS_DESKTOP_ICON_FILE (file);
+
+                if (saw_link) {
+                        break;
+                }
+        }
+
+        return saw_link;
+}
+
 /* Do nothing */
 static void
 real_check_empty_states (NautilusFilesView *view)
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index ed9788a..2a964bd 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -4055,33 +4055,19 @@ offset_drop_points (GArray *relative_item_points,
         }
 }
 
-/* special_link_in_selection
- *
- * Return TRUE if one of our special links is in the selection.
- * Special links include the following:
- *         NAUTILUS_DESKTOP_LINK_TRASH, NAUTILUS_DESKTOP_LINK_HOME, NAUTILUS_DESKTOP_LINK_MOUNT
- */
-
 static gboolean
-special_link_in_selection (GList *selection)
+nautilus_files_view_special_link_in_selection (NautilusFilesView *view,
+                                               GList             *selection)
 {
-        gboolean saw_link;
-        GList *node;
-        NautilusFile *file;
-
-        saw_link = FALSE;
-
-        for (node = selection; node != NULL; node = node->next) {
-                file = NAUTILUS_FILE (node->data);
-
-                saw_link = NAUTILUS_IS_DESKTOP_ICON_FILE (file);
-
-                if (saw_link) {
-                        break;
-                }
-        }
+        return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->special_link_in_selection (view, 
selection);
+}
 
-        return saw_link;
+/* Normal view doesn't have any special link */
+static gboolean
+real_special_link_in_selection (NautilusFilesView *view,
+                                GList             *selection)
+{
+        return FALSE;
 }
 
 /* desktop_or_home_dir_in_selection
@@ -6246,7 +6232,7 @@ real_update_actions_state (NautilusFilesView *view)
 
         selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
         selection_count = g_list_length (selection);
-        selection_contains_special_link = special_link_in_selection (selection);
+        selection_contains_special_link = nautilus_files_view_special_link_in_selection (view, selection);
         selection_contains_desktop_or_home_dir = desktop_or_home_dir_in_selection (selection);
         selection_contains_recent = showing_recent_directory (view);
         selection_contains_search = nautilus_view_is_searching (NAUTILUS_VIEW (view));
@@ -7992,6 +7978,7 @@ nautilus_files_view_class_init (NautilusFilesViewClass *klass)
         klass->update_context_menus = real_update_context_menus;
         klass->update_actions_state = real_update_actions_state;
         klass->check_empty_states = real_check_empty_states;
+        klass->special_link_in_selection = real_special_link_in_selection;
 
         copied_files_atom = gdk_atom_intern ("x-special/gnome-copied-files", FALSE);
 
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index efb4dea..ccd0583 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -262,6 +262,12 @@ struct NautilusFilesViewClass {
         /* Use this to show an optional visual feedback when the directory is empty.
          * By default it shows a widget overlay on top of the view */
         void           (* check_empty_states)          (NautilusFilesView *view);
+
+        /* Use this to tell the view whether inside the selection there is some link
+         * that cannot be work with. This is used by the desktop for the trash,
+         * home and other special links. */
+        gboolean       (* special_link_in_selection)   (NautilusFilesView *view,
+                                                        GList             *selection);
 };
 
 /* GObject support */


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