[PATCH] Make cut icons display in light color



The attached two patches should fix bug 48948 [1].
One might argue that the color is not light enough, but it should be a
notably well-working first shot at the issue. I've expected the patch to
grow somewhat larger, nice to see that this problem was relatively easy
to tackle, so we are on the right track wrt our architecture :).

[1] http://bugzilla.gnome.org/show_bug.cgi?id=47948

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.366
diff -u -p -r1.366 nautilus-file.c
--- libnautilus-private/nautilus-file.c	2 Jun 2005 19:20:09 -0000	1.366
+++ libnautilus-private/nautilus-file.c	3 Jun 2005 15:16:41 -0000
@@ -5851,6 +5851,37 @@ nautilus_file_list_call_when_ready (GLis
 	}
 }
 
+GList *
+nautilus_file_list_from_uri_list (GList *uri_list)
+{
+	GList *ret;
+
+	ret = NULL;
+	while (uri_list != NULL) {
+		ret = g_list_prepend (ret, nautilus_file_get (uri_list->data));
+
+		uri_list = uri_list->next;
+	}
+
+	return g_list_reverse (ret);
+
+}
+
+GList *
+nautilus_file_list_to_uri_list (GList *file_list)
+{
+	GList *ret;
+
+	ret = NULL;
+	while (file_list != NULL) {
+		ret = g_list_prepend (ret, nautilus_file_get_uri (file_list->data));
+
+		file_list = file_list->next;
+	}
+
+	return g_list_reverse (ret);
+}
+
 static char *
 try_to_make_utf8 (const char *text, int *length)
 {
Index: libnautilus-private/nautilus-file.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.h,v
retrieving revision 1.105
diff -u -p -r1.105 nautilus-file.h
--- libnautilus-private/nautilus-file.h	11 Oct 2004 12:55:13 -0000	1.105
+++ libnautilus-private/nautilus-file.h	3 Jun 2005 15:16:42 -0000
@@ -340,6 +340,8 @@ void                    nautilus_file_li
 									 NautilusFileAttributes          attributes,
 									 NautilusFileListCallback        callback,
 									 gpointer                        callback_data);
+GList *                 nautilus_file_list_from_uri_list                (GList                          *uri_list);
+GList *                 nautilus_file_list_to_uri_list                  (GList                          *file_list);
 
 /* Debugging */
 void                    nautilus_file_dump                              (NautilusFile                   *file);
Index: libnautilus-private/nautilus-icon-canvas-item.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-canvas-item.c,v
retrieving revision 1.190
diff -u -p -r1.190 nautilus-icon-canvas-item.c
--- libnautilus-private/nautilus-icon-canvas-item.c	3 Jun 2005 07:48:01 -0000	1.190
+++ libnautilus-private/nautilus-icon-canvas-item.c	3 Jun 2005 15:16:43 -0000
@@ -89,12 +89,14 @@ struct NautilusIconCanvasItemDetails {
    	guint is_highlighted_for_selection : 1;
 	guint is_highlighted_as_keyboard_focus: 1;
    	guint is_highlighted_for_drop : 1;
+	guint is_highlighted_for_clipboard : 1;
 	guint show_stretch_handles : 1;
 	guint is_prelit : 1;
 
 	guint rendered_is_active : 1;
 	guint rendered_is_highlighted_for_selection : 1;
 	guint rendered_is_highlighted_for_drop : 1;
+   	guint rendered_is_highlighted_for_clipboard : 1;
 	guint rendered_is_prelit : 1;
 	guint rendered_is_focused : 1;
 	
@@ -126,7 +128,8 @@ enum {
 	PROP_ADDITIONAL_TEXT,
     	PROP_HIGHLIGHTED_FOR_SELECTION,
     	PROP_HIGHLIGHTED_AS_KEYBOARD_FOCUS,
-    	PROP_HIGHLIGHTED_FOR_DROP
+    	PROP_HIGHLIGHTED_FOR_DROP,
+	PROP_HIGHLIGHTED_FOR_CLIPBOARD
 };
 
 typedef enum {
@@ -407,7 +410,13 @@ nautilus_icon_canvas_item_set_property (
 		}
 		details->is_highlighted_for_drop = g_value_get_boolean (value);
 		break;
-		
+
+	case PROP_HIGHLIGHTED_FOR_CLIPBOARD:
+		if (!details->is_highlighted_for_clipboard == !g_value_get_boolean (value)) {
+			return;
+		}
+		details->is_highlighted_for_clipboard = g_value_get_boolean (value);
+		break;
 	default:
 		g_warning ("nautilus_icons_view_item_item_set_arg on unknown argument");
 		return;
@@ -449,6 +458,10 @@ nautilus_icon_canvas_item_get_property (
 		g_value_set_boolean (value, details->is_highlighted_for_drop);
                 break;
 
+	case PROP_HIGHLIGHTED_FOR_CLIPBOARD:
+		g_value_set_boolean (value, details->is_highlighted_for_clipboard);
+                break;
+
         default:
 		g_warning ("invalid property %d", property_id);
 		break;
@@ -1352,7 +1365,8 @@ real_map_pixbuf (NautilusIconCanvasItem 
 
 	g_object_ref (temp_pixbuf);
 
-	if (icon_item->details->is_prelit) {
+	if (icon_item->details->is_prelit
+	    || icon_item->details->is_highlighted_for_clipboard) {
 		old_pixbuf = temp_pixbuf;
 		temp_pixbuf = eel_create_spotlight_pixbuf (temp_pixbuf);
 		g_object_unref (old_pixbuf);
@@ -1424,6 +1438,7 @@ map_pixbuf (NautilusIconCanvasItem *icon
 	      && icon_item->details->rendered_is_prelit == icon_item->details->is_prelit
 	      && icon_item->details->rendered_is_highlighted_for_selection == icon_item->details->is_highlighted_for_selection
 	      && icon_item->details->rendered_is_highlighted_for_drop == icon_item->details->is_highlighted_for_drop
+	      && icon_item->details->rendered_is_highlighted_for_clipboard == icon_item->details->is_highlighted_for_clipboard
 	      && (icon_item->details->is_highlighted_for_selection && icon_item->details->rendered_is_focused == GTK_WIDGET_HAS_FOCUS (EEL_CANVAS_ITEM (icon_item)->canvas)))) {
 		if (icon_item->details->rendered_pixbuf != NULL) {
 			g_object_unref (icon_item->details->rendered_pixbuf);
@@ -1433,6 +1448,7 @@ map_pixbuf (NautilusIconCanvasItem *icon
 		icon_item->details->rendered_is_prelit = icon_item->details->is_prelit;
 		icon_item->details->rendered_is_highlighted_for_selection = icon_item->details->is_highlighted_for_selection;
 		icon_item->details->rendered_is_highlighted_for_drop = icon_item->details->is_highlighted_for_drop;
+		icon_item->details->rendered_is_highlighted_for_clipboard = icon_item->details->is_highlighted_for_clipboard;
 		icon_item->details->rendered_is_focused = GTK_WIDGET_HAS_FOCUS (EEL_CANVAS_ITEM (icon_item)->canvas);
 	}
 
@@ -2928,6 +2944,14 @@ nautilus_icon_canvas_item_class_init (Na
 		g_param_spec_boolean ("highlighted_for_drop",
 				      "highlighted for drop",
 				      "whether we are highlighted for a D&D drop",
+				      FALSE, G_PARAM_READWRITE)); 
+
+        g_object_class_install_property (
+		object_class,
+		PROP_HIGHLIGHTED_FOR_CLIPBOARD,
+		g_param_spec_boolean ("highlighted_for_clipboard",
+				      "highlighted for clipboard",
+				      "whether we are highlighted for a clipboard paste (after we have been cut)",
 				      FALSE, G_PARAM_READWRITE)); 
 
 	item_class->update = nautilus_icon_canvas_item_update;
Index: libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.387
diff -u -p -r1.387 nautilus-icon-container.c
--- libnautilus-private/nautilus-icon-container.c	3 Jun 2005 07:48:01 -0000	1.387
+++ libnautilus-private/nautilus-icon-container.c	3 Jun 2005 15:16:46 -0000
@@ -6666,6 +6666,33 @@ nautilus_icon_container_get_icon_descrip
 	}
 }
 
+/**
+ * nautilus_icon_container_set_highlighted_for_clipboard
+ * @container: An icon container widget.
+ * @data: Icon Data associated with all icons that should be highlighted.
+ *        Others will be unhighlighted.
+ **/
+void
+nautilus_icon_container_set_highlighted_for_clipboard (NautilusIconContainer *container,
+						       GList                 *clipboard_icon_data)
+{
+	GList *l;
+	NautilusIcon *icon;
+	gboolean highlighted_for_clipboard;
+
+	g_return_if_fail (NAUTILUS_IS_ICON_CONTAINER (container));
+
+	for (l = container->details->icons; l != NULL; l = l->next) {
+		icon = l->data;
+		highlighted_for_clipboard = (g_list_find (clipboard_icon_data, icon->data) != NULL);
+
+		eel_canvas_item_set (EEL_CANVAS_ITEM (icon->item),
+				     "highlighted-for-clipboard", highlighted_for_clipboard,
+				     NULL);
+	}
+
+}
+
 /* NautilusIconContainerAccessible */
 
 static NautilusIconContainerAccessiblePrivate *
Index: libnautilus-private/nautilus-icon-container.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.h,v
retrieving revision 1.86
diff -u -p -r1.86 nautilus-icon-container.h
--- libnautilus-private/nautilus-icon-container.h	2 Jun 2005 10:48:55 -0000	1.86
+++ libnautilus-private/nautilus-icon-container.h	3 Jun 2005 15:16:46 -0000
@@ -278,5 +278,7 @@ void              nautilus_icon_containe
 									 gboolean                use_drop_shadows);
 char*             nautilus_icon_container_get_icon_description          (NautilusIconContainer  *container,
                                                                          NautilusIconData       *data);
+void              nautilus_icon_container_set_highlighted_for_clipboard (NautilusIconContainer  *container,
+									 GList                  *clipboard_icon_data);
 
 #endif /* NAUTILUS_ICON_CONTAINER_H */
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.683
diff -u -p -r1.683 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	2 Jun 2005 20:15:04 -0000	1.683
+++ src/file-manager/fm-directory-view.c	3 Jun 2005 15:16:28 -0000
@@ -149,10 +149,10 @@ enum {
 enum 
 {
   PROP_0,
-  PROP_WINDOW
+  PROP_WINDOW,
+  PROP_CLIPBOARD_INFO
 };
 
-
 static guint signals[LAST_SIGNAL];
 
 static GdkAtom copied_files_atom;
@@ -210,6 +210,8 @@ struct FMDirectoryViewDetails
 
 	GList *pending_uris_selected;
 
+	FMDirectoryViewClipboardInfo *clipboard_info;
+
 	/* loading indicates whether this view has begun loading a directory.
 	 * This flag should need not be set inside subclasses. FMDirectoryView automatically
 	 * sets 'loading' to TRUE before it begins loading a directory's contents and to FALSE
@@ -1490,6 +1492,34 @@ fm_directory_view_set_parent_window (FMD
 
 	/* initialise show hidden mode */
 	fm_directory_view_init_show_hidden_files (directory_view);
+
+	g_object_notify (G_OBJECT (directory_view), "window");
+}
+
+FMDirectoryViewClipboardInfo *
+fm_directory_view_get_clipboard_info (FMDirectoryView *directory_view)
+{
+	g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (directory_view), NULL);
+
+	return directory_view->details->clipboard_info;
+}
+
+static void
+fm_directory_view_set_clipboard_info (FMDirectoryView *view,
+				      FMDirectoryViewClipboardInfo *info)
+{
+	FMDirectoryViewClipboardInfo *old_info;
+
+	g_assert (FM_IS_DIRECTORY_VIEW (view));
+
+	old_info = fm_directory_view_get_clipboard_info (view);
+	if (old_info != NULL) {
+		eel_g_list_free_deep (old_info->file_uris);
+		g_free (old_info);
+	}
+
+	view->details->clipboard_info = info;
+	g_object_notify (G_OBJECT (view), "clipboard-info");
 }
 
 static GtkWidget *
@@ -1531,20 +1561,6 @@ fm_directory_view_get_selection_uris (Na
 	return g_list_reverse (uris);
 }
 
-static GList *
-file_list_from_uri_list (GList *uri_list)
-{
-	GList *file_list, *node;
-
-	file_list = NULL;
-	for (node = uri_list; node != NULL; node = node->next) {
-		file_list = g_list_prepend
-			(file_list,
-			 nautilus_file_get (node->data));
-	}
-	return g_list_reverse (file_list);
-}
-
 static void
 fm_directory_view_set_selection_uris (NautilusView *nautilus_view,
 				      GList *selection_uris)
@@ -1558,7 +1574,7 @@ fm_directory_view_set_selection_uris (Na
 		/* If we aren't still loading, set the selection right now,
 		 * and reveal the new selection.
 		 */
-		selection = file_list_from_uri_list (selection_uris);
+		selection = nautilus_file_list_from_uri_list (selection_uris);
 		view->details->selection_change_is_due_to_shell = TRUE;
 		fm_directory_view_set_selection (view, selection);
 		view->details->selection_change_is_due_to_shell = FALSE;
@@ -2061,7 +2077,7 @@ done_loading (FMDirectoryView *view)
 		if (uris_selected != NULL) {
 			view->details->pending_uris_selected = NULL;
 			
-			selection = file_list_from_uri_list (uris_selected);
+			selection = nautilus_file_list_from_uri_list (uris_selected);
 			eel_g_list_free_deep (uris_selected);
 			
 
@@ -5182,11 +5198,6 @@ create_popup_menu (FMDirectoryView *view
 	return GTK_MENU (menu);
 }
 
-typedef struct {
-	GList *file_uris;
-	gboolean cut;
-} ClipboardInfo;
-
 static char *
 convert_file_list_to_string (GList *files,
 			     gboolean format_for_text,
@@ -5229,11 +5240,13 @@ static void
 get_clipboard_callback (GtkClipboard     *clipboard,
 			GtkSelectionData *selection_data,
 			guint             info,
-			gpointer          user_data_or_owner)
+			FMDirectoryView  *view)
 {
-	ClipboardInfo *clipboard_info = user_data_or_owner;
+	FMDirectoryViewClipboardInfo *clipboard_info;
 	char *str;
 
+	clipboard_info = fm_directory_view_get_clipboard_info (view);
+
 	str = convert_file_list_to_string (clipboard_info->file_uris,
 					   info == UTF8_STRING,
 					   clipboard_info->cut);
@@ -5250,13 +5263,9 @@ get_clipboard_callback (GtkClipboard    
 
 static void
 clear_clipboard_callback (GtkClipboard *clipboard,
-			  gpointer      user_data_or_owner)
+			  FMDirectoryView *view)
 {
-	ClipboardInfo *info = user_data_or_owner;
-	
-	eel_g_list_free_deep (info->file_uris);
-
-	g_free (info);
+	fm_directory_view_set_clipboard_info (view, NULL);
 }
 
 static GtkClipboard *
@@ -5266,20 +5275,6 @@ get_clipboard (FMDirectoryView *view)
 					      GDK_SELECTION_CLIPBOARD);
 }
 
-static GList *
-convert_file_list_to_uri_list (GList *files)
-{
-	GList *tmp = NULL;
-	
-	while (files != NULL) {
-		tmp = g_list_prepend (tmp, nautilus_file_get_uri (files->data));
-
-		files = files->next;
-	}
-
-	return g_list_reverse (tmp);
-}
-	
 static void
 copy_or_cut_files (FMDirectoryView *view,
 		   GList           *clipboard_contents,
@@ -5287,19 +5282,21 @@ copy_or_cut_files (FMDirectoryView *view
 {
 	int count;
 	char *status_string, *name;
-	ClipboardInfo *info;
+	FMDirectoryViewClipboardInfo *info;
 	
-	info = g_new0 (ClipboardInfo, 1);
-	info->file_uris = convert_file_list_to_uri_list (clipboard_contents);
+	info = g_new0 (FMDirectoryViewClipboardInfo, 1);
+	info->file_uris = nautilus_file_list_to_uri_list (clipboard_contents);
 	info->cut = cut;
 	
 	gtk_clipboard_set_with_data (get_clipboard (view),
 				     clipboard_targets, G_N_ELEMENTS (clipboard_targets),
-				     get_clipboard_callback, clear_clipboard_callback,
-				     info);
+				     (GtkClipboardGetFunc) get_clipboard_callback,
+				     (GtkClipboardClearFunc) clear_clipboard_callback,
+				     view);
 	nautilus_clipboard_monitor_emit_changed ();
-	
-	
+
+	fm_directory_view_set_clipboard_info (view, info);
+
 	count = g_list_length (clipboard_contents);
 	if (count == 1) {
 		name = nautilus_file_get_display_name (clipboard_contents->data);
@@ -8425,6 +8422,28 @@ real_get_selected_icon_locations (FMDire
 }
 
 static void
+fm_directory_view_get_property (GObject      *object,
+				unsigned int  prop_id,
+				GValue       *value,
+				GParamSpec   *pspec)
+{
+	FMDirectoryView *directory_view = FM_DIRECTORY_VIEW (object);
+
+	switch (prop_id)  {
+	case PROP_WINDOW:
+		g_value_set_object (value, directory_view->details->window);
+		break;
+	case PROP_CLIPBOARD_INFO:
+		g_value_set_pointer (value, fm_directory_view_get_clipboard_info (directory_view));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+
+static void
 fm_directory_view_set_property (GObject         *object,
 				guint            prop_id,
 				const GValue    *value,
@@ -8438,7 +8457,9 @@ fm_directory_view_set_property (GObject 
   case PROP_WINDOW:
 	  g_assert (directory_view->details->window == NULL);
 	  fm_directory_view_set_parent_window (directory_view, NAUTILUS_WINDOW_INFO (g_value_get_object (value)));
-		  
+      break;
+  case PROP_CLIPBOARD_INFO:
+	  fm_directory_view_set_clipboard_info (directory_view, (FMDirectoryViewClipboardInfo *) g_value_get_pointer (value));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -8490,6 +8511,7 @@ fm_directory_view_class_init (FMDirector
 	scrolled_window_class = GTK_SCROLLED_WINDOW_CLASS (klass);
 
 	G_OBJECT_CLASS (klass)->finalize = fm_directory_view_finalize;
+	G_OBJECT_CLASS (klass)->get_property = fm_directory_view_get_property;
 	G_OBJECT_CLASS (klass)->set_property = fm_directory_view_set_property;
 
 	GTK_OBJECT_CLASS (klass)->destroy = fm_directory_view_destroy;
@@ -8627,6 +8649,12 @@ fm_directory_view_class_init (FMDirector
 							      NAUTILUS_TYPE_WINDOW_INFO,
 							      G_PARAM_WRITABLE |
 							      G_PARAM_CONSTRUCT_ONLY));
+	g_object_class_install_property (G_OBJECT_CLASS (klass),
+					 PROP_CLIPBOARD_INFO,
+					 g_param_spec_pointer ("clipboard-info",
+						 	       "Clipboard Info",
+							       "The clipboard info associated with this directory view",
+							       G_PARAM_READWRITE));
 
 	signals[TRASH] =
 		g_signal_new ("trash",
Index: src/file-manager/fm-directory-view.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.h,v
retrieving revision 1.138
diff -u -p -r1.138 fm-directory-view.h
--- src/file-manager/fm-directory-view.h	2 Jun 2005 10:48:55 -0000	1.138
+++ src/file-manager/fm-directory-view.h	3 Jun 2005 15:16:28 -0000
@@ -50,7 +50,8 @@ typedef struct FMDirectoryViewClass FMDi
 #define FM_IS_DIRECTORY_VIEW(obj)		(GTK_CHECK_TYPE ((obj), FM_TYPE_DIRECTORY_VIEW))
 #define FM_IS_DIRECTORY_VIEW_CLASS(klass)	(GTK_CHECK_CLASS_TYPE ((klass), FM_TYPE_DIRECTORY_VIEW))
 
-typedef struct FMDirectoryViewDetails FMDirectoryViewDetails;
+typedef struct FMDirectoryViewDetails       FMDirectoryViewDetails;
+typedef struct FMDirectoryViewClipboardInfo FMDirectoryViewClipboardInfo;
 
 struct FMDirectoryView {
 	GtkScrolledWindow parent;
@@ -293,6 +294,11 @@ struct FMDirectoryViewClass {
         gboolean (* delete)                        (FMDirectoryView *view);
 };
 
+struct FMDirectoryViewClipboardInfo {
+	GList *file_uris;
+	gboolean cut;
+};
+
 /* GObject support */
 GType               fm_directory_view_get_type                         (void);
 
@@ -392,5 +398,6 @@ void                fm_directory_view_ha
 									int               y);
 void                fm_directory_view_freeze_updates                   (FMDirectoryView  *view);
 void                fm_directory_view_unfreeze_updates                 (FMDirectoryView  *view);
+FMDirectoryViewClipboardInfo *fm_directory_view_get_clipboard_info     (FMDirectoryView  *view);
 
 #endif /* FM_DIRECTORY_VIEW_H */
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.309
diff -u -p -r1.309 fm-icon-view.c
--- src/file-manager/fm-icon-view.c	2 Jun 2005 16:16:55 -0000	1.309
+++ src/file-manager/fm-icon-view.c	3 Jun 2005 15:16:29 -0000
@@ -2513,6 +2513,24 @@ icon_view_scroll_to_file (NautilusView *
 	}
 }
 
+static void
+icon_view_notify_clipboard_info (FMIconView *icon_view)
+{
+	FMDirectoryViewClipboardInfo *info;
+	GList *icon_data;
+
+	info = fm_directory_view_get_clipboard_info (FM_DIRECTORY_VIEW (icon_view));
+
+	icon_data = NULL;
+	if (info && info->cut) {
+		icon_data = nautilus_file_list_from_uri_list (info->file_uris);
+	}
+
+	nautilus_icon_container_set_highlighted_for_clipboard (
+		get_icon_container (icon_view), icon_data);
+
+	nautilus_file_list_free (icon_data);
+}
 
 static void
 fm_icon_view_class_init (FMIconViewClass *klass)
@@ -2642,6 +2660,9 @@ fm_icon_view_init (FMIconView *icon_view
 				 G_CALLBACK (icon_view_handle_url), icon_view, 0);
 	g_signal_connect_object (get_icon_container (icon_view), "handle_uri_list",
 				 G_CALLBACK (icon_view_handle_uri_list), icon_view, 0);
+
+	g_signal_connect (icon_view, "notify::clipboard-info",
+			  G_CALLBACK (icon_view_notify_clipboard_info), NULL);
 }
 
 static NautilusView *


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