[nautilus/gnome-2-32: 105/283] Implement transparent icons for cut files in tree view.



commit 28fc6a0b30d66d1f17ddc726dce3c13bb216ead9
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu May 20 11:34:54 2010 +0200

    Implement transparent icons for cut files in tree view.

 src/file-manager/fm-tree-model.c |   82 ++++++++++++++++++++++--
 src/file-manager/fm-tree-model.h |    2 +
 src/file-manager/fm-tree-view.c  |  127 +++++++++++++++-----------------------
 3 files changed, 126 insertions(+), 85 deletions(-)
---
diff --git a/src/file-manager/fm-tree-model.c b/src/file-manager/fm-tree-model.c
index c058bc1..7804d97 100644
--- a/src/file-manager/fm-tree-model.c
+++ b/src/file-manager/fm-tree-model.c
@@ -100,6 +100,8 @@ struct FMTreeModelDetails {
 	gboolean show_hidden_files;
 	gboolean show_backup_files;
 	gboolean show_only_directories;
+
+	GList *highlighted_files;
 };
 
 struct FMTreeModelRoot {
@@ -260,20 +262,37 @@ get_menu_icon (GIcon *icon)
 }
 
 static GdkPixbuf *
-get_menu_icon_for_file (NautilusFile *file,
+get_menu_icon_for_file (TreeNode *node,
+                        NautilusFile *file,
 			NautilusFileIconFlags flags)
 {
 	NautilusIconInfo *info;
-	GdkPixbuf *pixbuf;
+	GdkPixbuf *pixbuf, *retval;
+	gboolean highlight;
 	int size;
+	FMTreeModel *model;
 
 	size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);
-	
+
 	info = nautilus_file_get_icon (file, size, flags);
-	pixbuf = nautilus_icon_info_get_pixbuf_nodefault_at_size (info, size);
+	retval = nautilus_icon_info_get_pixbuf_nodefault_at_size (info, size);
+	model = node->root->model;
+
+	highlight = (g_list_find_custom (model->details->highlighted_files,
+	                                 file, (GCompareFunc) nautilus_file_compare_location) != NULL);
+
+	if (highlight) {
+		pixbuf = eel_gdk_pixbuf_render (retval, 1, 255, 255, 0, 0);
+
+		if (pixbuf != NULL) {
+			g_object_unref (retval);
+			retval = pixbuf;
+		}
+	}
+
 	g_object_unref (info);
-	
-	return pixbuf;
+
+	return retval;
 }
 
 static GdkPixbuf *
@@ -283,7 +302,7 @@ tree_node_get_pixbuf (TreeNode *node,
 	if (node->parent == NULL) {
 		return get_menu_icon (node->icon);
 	}
-	return get_menu_icon_for_file (node->file, flags);
+	return get_menu_icon_for_file (node, node->file, flags);
 }
 
 static gboolean
@@ -1816,6 +1835,51 @@ fm_tree_model_file_get_iter (FMTreeModel *model,
 }
 
 static void
+do_update_node (NautilusFile *file,
+                  FMTreeModel *model)
+{
+	TreeNode *root, *node = NULL;
+
+	for (root = model->details->root_node; root != NULL; root = root->next) {
+		node = get_node_from_file (root->root, file);
+
+		if (node != NULL) {
+			break;
+		}
+	}
+
+	if (node == NULL) {
+		return;
+	}
+
+	update_node (model, node);
+}
+
+void
+fm_tree_model_set_highlight_for_files (FMTreeModel *model,
+                                       GList *files)
+{
+	GList *old_files;
+
+	if (model->details->highlighted_files != NULL) {
+		old_files = model->details->highlighted_files;
+		model->details->highlighted_files = NULL;
+
+		g_list_foreach (old_files,
+		                (GFunc) do_update_node, model);
+
+		nautilus_file_list_free (old_files);
+	}
+
+	if (files != NULL) {
+		model->details->highlighted_files = 
+			nautilus_file_list_copy (files);
+		g_list_foreach (model->details->highlighted_files,
+		                (GFunc) do_update_node, model);
+	}
+}
+
+static void
 fm_tree_model_init (FMTreeModel *model)
 {
 	model->details = g_new0 (FMTreeModelDetails, 1);
@@ -1846,6 +1910,10 @@ fm_tree_model_finalize (GObject *object)
 		g_source_remove (model->details->monitoring_update_idle_id);
 	}
 
+	if (model->details->highlighted_files != NULL) {
+		nautilus_file_list_free (model->details->highlighted_files);
+	}
+
 	g_free (model->details);
 
 	G_OBJECT_CLASS (fm_tree_model_parent_class)->finalize (object);
diff --git a/src/file-manager/fm-tree-model.h b/src/file-manager/fm-tree-model.h
index 909d299..092ff90 100644
--- a/src/file-manager/fm-tree-model.h
+++ b/src/file-manager/fm-tree-model.h
@@ -95,5 +95,7 @@ gboolean           fm_tree_model_file_get_iter             (FMTreeModel *model,
 GMount *         fm_tree_model_get_mount_for_root_node_file        
                                                            (FMTreeModel  *model, 
                                                             NautilusFile *file);
+void             fm_tree_model_set_highlight_for_files    (FMTreeModel *model,
+                                                            GList *files);
 
 #endif /* FM_TREE_MODEL_H */
diff --git a/src/file-manager/fm-tree-view.c b/src/file-manager/fm-tree-view.c
index de9523d..fc63502 100644
--- a/src/file-manager/fm-tree-view.c
+++ b/src/file-manager/fm-tree-view.c
@@ -86,7 +86,8 @@ struct FMTreeViewDetails {
 	gboolean selecting;
 
 	guint show_selection_idle_id;
-	
+	gulong clipboard_handler_id;
+
 	GtkWidget *popup;
 	GtkWidget *popup_open;
 	GtkWidget *popup_open_in_new_window;
@@ -133,6 +134,19 @@ G_DEFINE_TYPE_WITH_CODE (FMTreeViewProvider, fm_tree_view_provider, G_TYPE_OBJEC
 			 G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SIDEBAR_PROVIDER,
 						sidebar_provider_iface_init));
 
+static void
+notify_clipboard_info (NautilusClipboardMonitor *monitor,
+                       NautilusClipboardInfo *info,
+                       FMTreeView *view)
+{
+	if (info != NULL && info->cut) {
+		fm_tree_model_set_highlight_for_files (view->details->child_model, info->files);
+	} else {
+		fm_tree_model_set_highlight_for_files (view->details->child_model, NULL);
+	}
+}
+
+
 static gboolean
 show_iter_for_file (FMTreeView *view, NautilusFile *file, GtkTreeIter *iter)
 {
@@ -188,6 +202,18 @@ show_iter_for_file (FMTreeView *view, NautilusFile *file, GtkTreeIter *iter)
 	return FALSE;
 }
 
+static void
+refresh_highlight (FMTreeView *view)
+{
+	NautilusClipboardMonitor *monitor;
+	NautilusClipboardInfo *info;
+
+	monitor = nautilus_clipboard_monitor_get ();
+	info = nautilus_clipboard_monitor_get_clipboard_info (monitor);
+
+	notify_clipboard_info (monitor, info, view);
+}
+
 static gboolean
 show_selection_idle_callback (gpointer callback_data)
 {
@@ -232,6 +258,7 @@ show_selection_idle_callback (gpointer callback_data)
 	gtk_tree_path_free (sort_path);
 
 	nautilus_file_unref (file);
+	refresh_highlight (view);	
 
 	return FALSE;
 }
@@ -858,88 +885,19 @@ fm_tree_view_create_folder_cb (GtkWidget *menu_item,
 	g_free (parent_uri);
 }
 
-typedef struct {
-        char *file_uri;
-	gboolean cut;
-} ClipboardInfo;
-
-static void
-get_clipboard_callback (GtkClipboard	 *clipboard,
-			GtkSelectionData *selection_data,
-			guint		  info_,
-			gpointer	  user_data)
-{
-	ClipboardInfo *info = user_data;
-
-
-        if (gtk_targets_include_uri (&selection_data->target, 1)) {
-                char *uris[2];
-
-                uris[0] = info->file_uri;
-                uris[1] = NULL;
-                gtk_selection_data_set_uris (selection_data, uris);
-        } else if (gtk_targets_include_text (&selection_data->target, 1)) {
-                GFile *file;
-                char *str;
-
-                file = g_file_new_for_uri (info->file_uri);
-                str = g_file_get_parse_name (file);
-                g_object_unref (file);
-
-                if (str) {
-                        gtk_selection_data_set_text (selection_data, str, strlen (str));
-                        g_free (str);
-                } else {
-                        gtk_selection_data_set_text (selection_data,
-                                                    info->file_uri, strlen (info->file_uri));
-                }
-        } else if (selection_data->target == copied_files_atom) {
-                char *str;
-
-                str = g_strdup_printf ("%s\n%s",
-                                       info->cut ? "cut" : "copy",
-                                       info->file_uri);
-                gtk_selection_data_set (selection_data, copied_files_atom,
-                                        8, str, strlen (str));
-                g_free (str);
-        }
-}
-
-static void
-clear_clipboard_callback (GtkClipboard *clipboard,
-			  gpointer	user_data)
-{
-	ClipboardInfo *info = user_data;
-
-        g_free (info->file_uri);
-	g_slice_free (ClipboardInfo, info);
-}
-
-static ClipboardInfo *
-convert_file_to_uri (NautilusFile *file,
-		     gboolean cut)
-{
-        ClipboardInfo *info;
-
-        info = g_slice_new (ClipboardInfo);
-        info->cut = cut;
-	info->file_uri = nautilus_file_get_uri (file);
-
-        return info;
-}
-
 static void
 copy_or_cut_files (FMTreeView *view,
 		   gboolean cut)
 {
 	char *status_string, *name;
-        ClipboardInfo *info;
+	NautilusClipboardInfo info;
         GtkTargetList *target_list;
         GtkTargetEntry *targets;
         int n_targets;
 
-	info = convert_file_to_uri (view->details->popup_file, cut);
-	
+	info.cut = cut;
+	info.files = g_list_prepend (NULL, view->details->popup_file);
+
         target_list = gtk_target_list_new (NULL, 0);
         gtk_target_list_add (target_list, copied_files_atom, 0, 0);
         gtk_target_list_add_uri_targets (target_list, 0);
@@ -950,12 +908,14 @@ copy_or_cut_files (FMTreeView *view,
 
 	gtk_clipboard_set_with_data (nautilus_clipboard_get (GTK_WIDGET (view->details->tree_widget)),
 				     targets, n_targets,
-				     get_clipboard_callback, clear_clipboard_callback,
-				     info);
+				     nautilus_get_clipboard_callback, nautilus_clear_clipboard_callback,
+				     NULL);
         gtk_target_table_free (targets, n_targets);
 
-	nautilus_clipboard_monitor_emit_changed ();
-	
+	nautilus_clipboard_monitor_set_clipboard_info (nautilus_clipboard_monitor_get (),
+	                                               &info);
+	g_list_free (info.files);
+
 	name = nautilus_file_get_display_name (view->details->popup_file);
 	if (cut) {
 		status_string = g_strdup_printf (_("\"%s\" will be moved "
@@ -1541,6 +1501,11 @@ fm_tree_view_init (FMTreeView *view)
 						  filtering_changed_callback, view, G_OBJECT (view));
 	
 	view->details->popup_file = NULL;
+
+	view->details->clipboard_handler_id = 
+		g_signal_connect (nautilus_clipboard_monitor_get (),
+		                  "clipboard_info",
+		                  G_CALLBACK (notify_clipboard_info), view);
 }
 
 static void
@@ -1565,6 +1530,12 @@ fm_tree_view_dispose (GObject *object)
 		view->details->show_selection_idle_id = 0;
 	}
 
+	if (view->details->clipboard_handler_id != 0) {
+		g_signal_handler_disconnect (nautilus_clipboard_monitor_get (),
+		                             view->details->clipboard_handler_id);
+		view->details->clipboard_handler_id = 0;
+	}
+
 	cancel_activation (view);
 
 	if (view->details->popup != NULL) {



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