[PATCH] Manage note sidepane by nautilus-clipboard



After applying this patch, the note sidepane will be managed by
NautilusClipboard. NautilusClipboard used to be only usable for
GtkEditables. I've modified it to also take GtkTextViews. One may ask
him or herself why GtkTextView can't be turned into a GtkEditable, but
there are in fact design hurdles [1].
I don't know whether you like the way the callbacks are organized. We
could also provide two completely separated codepaths with two setup
functions, and separate callbacks for each type - but I think that the
API structure of GtkTextView and GtkEditable is too similar to be split
apart.
Note that after fixing this issue we can also commit the patch for [2],
with updates that are probably necessary.

[1]
http://mail.gnome.org/archives/gtk-devel-list/2000-October/msg00241.html
[2] http://bugzilla.gnome.org/show_bug.cgi?id=95112

-- 
Christian Neumair <chris gnome-de org>
? src/gmon.out
? src/nautilus-toolbars-model.c
? src/nautilus-toolbars-model.h
Index: libnautilus-private/nautilus-clipboard.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-clipboard.c,v
retrieving revision 1.4
diff -u -r1.4 nautilus-clipboard.c
--- libnautilus-private/nautilus-clipboard.c	12 May 2005 19:20:43 -0000	1.4
+++ libnautilus-private/nautilus-clipboard.c	21 May 2005 13:12:41 -0000
@@ -38,6 +38,7 @@
 #include <gtk/gtkmain.h>
 #include <gtk/gtksignal.h>
 #include <gtk/gtktext.h>
+#include <gtk/gtktextview.h>
 #include <string.h>
 
 typedef void (* EditableFunction) (GtkEditable *editable);
@@ -52,28 +53,60 @@
 action_cut_callback (GtkAction *action,
 		     gpointer callback_data)
 {
-	gtk_editable_cut_clipboard (GTK_EDITABLE (callback_data));
+	g_return_if_fail (callback_data != NULL);
+
+	if (GTK_IS_EDITABLE (callback_data)) {
+		gtk_editable_cut_clipboard (GTK_EDITABLE (callback_data));
+	} else if (GTK_IS_TEXT_VIEW (callback_data)) {
+		g_signal_emit_by_name (callback_data, "cut-clipboard");
+	} else {
+		g_assert_not_reached ();
+	}
 }
 
 static void
 action_copy_callback (GtkAction *action,
 		      gpointer callback_data)
 {
-	gtk_editable_copy_clipboard (GTK_EDITABLE (callback_data));
+	g_return_if_fail (callback_data != NULL);
+
+	if (GTK_IS_EDITABLE (callback_data)) {
+		gtk_editable_copy_clipboard (GTK_EDITABLE (callback_data));
+	} else if (GTK_IS_TEXT_VIEW (callback_data)) {
+		g_signal_emit_by_name (callback_data, "copy-clipboard");
+	} else {
+		g_assert_not_reached ();
+	}
 }
 
 static void
 action_paste_callback (GtkAction *action,
 		       gpointer callback_data)
 {
-	gtk_editable_paste_clipboard (GTK_EDITABLE (callback_data));
+	g_return_if_fail (callback_data != NULL);
+
+	if (GTK_IS_EDITABLE (callback_data)) {
+		gtk_editable_paste_clipboard (GTK_EDITABLE (callback_data));
+	} else if (GTK_IS_TEXT_VIEW (callback_data)) {
+		g_signal_emit_by_name (callback_data, "paste-clipboard");
+	} else {
+		g_assert_not_reached ();
+	}
 }
 
 static void
-select_all (GtkEditable *editable)
-{	
-	gtk_editable_set_position (editable, -1);
-	gtk_editable_select_region (editable, 0, -1);
+select_all (GtkWidget *widget)
+{
+	g_return_if_fail (widget != NULL);
+
+	if (GTK_IS_EDITABLE (widget)) {
+		gtk_editable_set_position (GTK_EDITABLE (widget), -1);
+		gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
+	} else if (GTK_IS_TEXT_VIEW (widget)) {
+		g_signal_emit_by_name (widget, "select-all", TRUE);
+	} else {
+		g_assert_not_reached ();
+	}
 }
 
 
@@ -87,23 +120,23 @@
 static gboolean
 select_all_idle_callback (gpointer callback_data)
 {
-	GtkEditable *editable;
+	GtkWidget *widget;
 	GSource *source;
 
-	editable = GTK_EDITABLE (callback_data);
+	widget = GTK_WIDGET (callback_data);
 
-	source = g_object_get_data (G_OBJECT (editable), 
+	source = g_object_get_data (G_OBJECT (widget), 
 				    "clipboard-select-all-source");
 
-	g_object_weak_unref (G_OBJECT (editable), 
+	g_object_weak_unref (G_OBJECT (widget), 
 			     idle_source_destroy_callback,
 			     source);
 	
-	g_object_set_data (G_OBJECT (editable), 
+	g_object_set_data (G_OBJECT (widget), 
 			   "clipboard-select-all-source",
 			   NULL);
 
-	select_all (editable);
+	select_all (widget);
 
 	return FALSE;
 }
@@ -113,24 +146,24 @@
 			    gpointer callback_data)
 {
 	GSource *source;
-	GtkEditable *editable;
+	GtkWidget *widget;
 
-	editable = GTK_EDITABLE (callback_data);
+	widget = GTK_WIDGET (callback_data);
 
-	if (g_object_get_data (G_OBJECT (editable), 
+	if (g_object_get_data (G_OBJECT (widget), 
 			       "clipboard-select-all-source")) {
 		return;
 	}
 
 	source = g_idle_source_new ();
-	g_source_set_callback (source, select_all_idle_callback, editable, NULL);
-	g_object_weak_ref (G_OBJECT (editable),
+	g_source_set_callback (source, select_all_idle_callback, widget, NULL);
+	g_object_weak_ref (G_OBJECT (widget),
 			   idle_source_destroy_callback,
 			   source);
 	g_source_attach (source, NULL);
 	g_source_unref (source);
 
-	g_object_set_data (G_OBJECT (editable),
+	g_object_set_data (G_OBJECT (widget),
 			   "clipboard-select-all-source", 
 			   source);
 }
@@ -202,7 +235,7 @@
 typedef struct {
 	GtkUIManager *ui_manager;
 	GtkActionGroup *action_group;
-	gboolean editable_shares_selection_changes;
+	gboolean shares_selection_changes;
 } TargetCallbackData;
 
 static gboolean
@@ -229,7 +262,7 @@
 
 	g_assert (target_data != NULL);
 	
-	add_selection_callback = target_data->editable_shares_selection_changes;
+	add_selection_callback = target_data->shares_selection_changes;
 
 	gtk_ui_manager_insert_action_group (target_data->ui_manager,
 					    target_data->action_group, 0);
@@ -269,7 +302,7 @@
 					      G_CALLBACK (owner_change_callback),
 					      target_data);
 	
-	selection_callback_was_added = target_data->editable_shares_selection_changes;
+	selection_callback_was_added = target_data->shares_selection_changes;
 
 	if (selection_callback_was_added) {
 		g_signal_handlers_disconnect_matched (widget_as_object,
@@ -305,15 +338,24 @@
 			    gpointer callback_data)
 {
 	TargetCallbackData *target_data;
-	GtkEditable *editable;
+	GtkTextBuffer *buffer;
+	gboolean has_selection;
 	int start, end;
 
 	target_data = (TargetCallbackData *) callback_data;
 	g_assert (target_data != NULL);
 
-	editable = GTK_EDITABLE (widget);
+	if (GTK_IS_EDITABLE (widget)) {
+		has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (widget), &start, &end) && start != end;
+	} else if (GTK_IS_TEXT_VIEW (widget)) {
+		buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
+		has_selection = gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL);
+	} else {
+		g_assert_not_reached ();
+		return;
+	}
 
-	if (gtk_editable_get_selection_bounds (editable, &start, &end) && start != end) {
+	if (has_selection) {
 		set_clipboard_menu_items_sensitive (target_data->action_group);
 	} else {
 		set_clipboard_menu_items_insensitive (target_data->action_group);
@@ -374,7 +416,7 @@
 };
 
 static TargetCallbackData *
-initialize_clipboard_component_with_callback_data (GtkEditable *target,
+initialize_clipboard_component_with_callback_data (GtkWidget *target,
 						   GtkUIManager *ui_manager,
 						   gboolean shares_selection_changes)
 {
@@ -394,19 +436,19 @@
 	target_data = g_new (TargetCallbackData, 1);
 	target_data->ui_manager = ui_manager;
 	target_data->action_group = action_group;
-	target_data->editable_shares_selection_changes = shares_selection_changes;
+	target_data->shares_selection_changes = shares_selection_changes;
 	
 	return target_data;
 }
 
 void
-nautilus_clipboard_set_up_editable (GtkEditable *target,
-				    GtkUIManager *ui_manager,
-				    gboolean shares_selection_changes)
+nautilus_clipboard_set_up_text_widget (GtkWidget *target,
+				       GtkUIManager *ui_manager,
+				       gboolean shares_selection_changes)
 {
 	TargetCallbackData *target_data;
 	
-	g_return_if_fail (GTK_IS_EDITABLE (target));
+	g_return_if_fail (GTK_IS_EDITABLE (target) || GTK_IS_TEXT_VIEW (target));
 	g_return_if_fail (ui_manager != NULL);
 
 	target_data = initialize_clipboard_component_with_callback_data
@@ -426,5 +468,5 @@
 	/* Call the focus changed callback once to merge if the window is
 	 * already in focus.
 	 */
-	focus_changed_callback (GTK_WIDGET (target), NULL, target_data);
+	focus_changed_callback (target, NULL, target_data);
 }
Index: libnautilus-private/nautilus-clipboard.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-clipboard.h,v
retrieving revision 1.2
diff -u -r1.2 nautilus-clipboard.h
--- libnautilus-private/nautilus-clipboard.h	22 Nov 2004 15:24:35 -0000	1.2
+++ libnautilus-private/nautilus-clipboard.h	21 May 2005 13:12:41 -0000
@@ -29,17 +29,17 @@
 #include <gtk/gtkeditable.h>
 #include <gtk/gtkuimanager.h>
 
-/* This makes this editable put clipboard commands into the passed UI
- * manager when the editable is in focus. Callers in Nautilus
- * normally get the UI manager from
+/* This makes this editable or text view widget put clipboard commands
+ * into the passed UI manager when the editable/text view widget is in
+ * focus. Callers in Nautilus normally get the UI manager from
  * nautilus_window_get_ui_manager. */
 /* The shares selection changes argument should be set to true if the
- * editable is a widget that uses the signal "selection_changed" to
+ * target is a widget that uses the signal "selection_changed" to
  * tell others about text selection changes.  The NautilusEntry widget
  * is currently the only widget in nautilus that shares selection
  * changes.  */
-void nautilus_clipboard_set_up_editable            (GtkEditable        *target,
-						    GtkUIManager       *ui_manager,
-						    gboolean            shares_selection_changes);
+void nautilus_clipboard_set_up_text_widget (GtkWidget          *target,
+					    GtkUIManager       *ui_manager,
+					    gboolean            shares_selection_changes);
 
 #endif /* NAUTILUS_CLIPBOARD_H */
Index: src/nautilus-location-bar.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-location-bar.c,v
retrieving revision 1.106
diff -u -r1.106 nautilus-location-bar.c
--- src/nautilus-location-bar.c	17 May 2005 13:27:36 -0000	1.106
+++ src/nautilus-location-bar.c	21 May 2005 13:12:41 -0000
@@ -466,8 +466,8 @@
 	location_bar = NAUTILUS_LOCATION_BAR (bar);
 
 	/* Clipboard */
-	nautilus_clipboard_set_up_editable
-		(GTK_EDITABLE (location_bar->details->entry),
+	nautilus_clipboard_set_up_text_widget
+		(GTK_WIDGET (location_bar->details->entry),
 		 nautilus_window_get_ui_manager (NAUTILUS_WINDOW (window)),
 		 TRUE);
 
Index: src/nautilus-navigation-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-navigation-window.c,v
retrieving revision 1.430
diff -u -r1.430 nautilus-navigation-window.c
--- src/nautilus-navigation-window.c	19 Apr 2005 12:01:16 -0000	1.430
+++ src/nautilus-navigation-window.c	21 May 2005 13:12:42 -0000
Index: src/nautilus-notes-viewer.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-notes-viewer.c,v
retrieving revision 1.5
diff -u -r1.5 nautilus-notes-viewer.c
--- src/nautilus-notes-viewer.c	17 May 2005 14:17:57 -0000	1.5
+++ src/nautilus-notes-viewer.c	21 May 2005 13:12:42 -0000
@@ -431,13 +431,10 @@
         notes_load_metainfo (sidebar);
 
         /* handle selections */
-#ifdef GNOME2_CONVERSION_COMPLETE
-        /* note_text_field is a text-view, not a GtkEditable */
-	nautilus_clipboard_set_up_editable
-                (GTK_EDITABLE (sidebar->details->note_text_field),
+	nautilus_clipboard_set_up_text_widget
+                (sidebar->details->note_text_field,
 		 nautilus_window_info_get_ui_manager (window),
 		 FALSE);
-#endif
 }
 
 static NautilusSidebar *
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.306
diff -u -r1.306 fm-icon-view.c
--- src/file-manager/fm-icon-view.c	19 Apr 2005 12:01:17 -0000	1.306
+++ src/file-manager/fm-icon-view.c	21 May 2005 13:12:44 -0000
@@ -1929,8 +1929,8 @@
 	FMDirectoryView *directory_view;
 
 	directory_view = FM_DIRECTORY_VIEW (callback_data);
-	nautilus_clipboard_set_up_editable
-		(GTK_EDITABLE (widget),
+	nautilus_clipboard_set_up_text_widget
+		(widget,
 		 fm_directory_view_get_ui_manager (directory_view),
 		 FALSE);
 }
Index: src/file-manager/fm-list-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-view.c,v
retrieving revision 1.242
diff -u -r1.242 fm-list-view.c
--- src/file-manager/fm-list-view.c	3 May 2005 01:00:50 -0000	1.242
+++ src/file-manager/fm-list-view.c	21 May 2005 13:12:45 -0000
@@ -1972,8 +2076,8 @@
 	
 	gtk_tree_path_free (path);
 
-	nautilus_clipboard_set_up_editable
-		(GTK_EDITABLE (entry),
+	nautilus_clipboard_set_up_text_widget
+		(GTK_WIDGET (entry),
 		 fm_directory_view_get_ui_manager (view),
 		 FALSE);
 }


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