[Glade-devel] [patch, glade3] clipboard_paste does not need to change the editor widget

paolo borelli pborelli@katamail.com
16 May 2003 15:04:50 +0200


--=-4mLhF5XK+3fhq8fiGAnj
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi!

The attached patch is a small cleanup in glade-clipboard which I saw
while trying to understand how selection works. clipboard_paste does not
need to explicitly change which widget is in the editor, as it is
handled by the signal handler connected to the "selection_changed"
signal. I also moved gpw->active_placeholder = NULL in the signal
handler. Some minor coding style cleanups along the way.
Note also the FIXME comment I added in the clipboard_paste function: do
you agree with it? If not delete it...


ciao
	paolo

--=-4mLhF5XK+3fhq8fiGAnj
Content-Disposition: attachment; filename=clipboard.patch
Content-Type: text/x-patch; name=clipboard.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

Only in glade3: aclocal.m4
Only in glade3: autom4te.cache
diff -upr gnome2/glade3/ChangeLog glade3/ChangeLog
--- gnome2/glade3/ChangeLog	2003-05-15 09:32:17.000000000 +0200
+++ glade3/ChangeLog	2003-05-16 11:43:11.000000000 +0200
@@ -1,3 +1,11 @@
+2003-05-16  Paolo Borelli  <pborelli@katamail.com>
+
+	* src/glade-clipboard.c: no need to call glade_editor_select_widget,
+	as it is already called when the selection_changed signal is
+	emitted. Move gpw->active_placeholder = NULL in the signal handler
+	in glade-project-window.c.
+	* src/glade-project-window.c: see above.
+
 2003-05-14  Joaquin Cuenca Abela  <e98cuenc@yahoo.com>
 
 	* src/glade-project-window.[ch]: Make the undo/redo toolbar items
diff -upr gnome2/glade3/src/glade-clipboard.c glade3/src/glade-clipboard.c
--- gnome2/glade3/src/glade-clipboard.c	2003-05-02 09:08:42.000000000 +0200
+++ glade3/src/glade-clipboard.c	2003-05-16 11:31:38.000000000 +0200
@@ -22,9 +22,6 @@
  * USA.
  */
 
-#include <glib.h>
-#include <gtk/gtk.h>
-
 #include "glade.h"
 #include "glade-clipboard-view.h"
 #include "glade-clipboard.h"
@@ -34,16 +31,15 @@
 #include "glade-placeholder.h"
 #include "glade-project.h"
 #include "glade-packing.h"
-#include "glade-editor.h"
 
 static void
-glade_clipboard_class_init (GladeClipboardClass * klass)
+glade_clipboard_class_init (GladeClipboardClass *klass)
 {
 
 }
 
 static void
-glade_clipboard_init (GladeClipboard * clipboard)
+glade_clipboard_init (GladeClipboard *clipboard)
 {
 	clipboard->widgets = NULL;
 	clipboard->view = NULL;
@@ -105,7 +101,7 @@ glade_clipboard_new ()
  * Cut/Copy commands.
  **/
 static void
-glade_clipboard_add (GladeClipboard * clipboard, GladeWidget * widget)
+glade_clipboard_add (GladeClipboard *clipboard, GladeWidget *widget)
 {
 	/*
 	 * Add the GladeWidget to the list of children. And set the
@@ -129,7 +125,7 @@ glade_clipboard_add (GladeClipboard * cl
  * Remove a GladeWidget from the Clipboard
  **/
 static void
-glade_clipboard_remove (GladeClipboard * clipboard, GladeWidget * widget)
+glade_clipboard_remove (GladeClipboard *clipboard, GladeWidget *widget)
 {
 	clipboard->widgets = g_list_remove (clipboard->widgets, widget);
 	clipboard->curr = NULL;
@@ -149,7 +145,7 @@ glade_clipboard_remove (GladeClipboard *
  * Cut a GladeWidget onto the Clipboard. 
  **/
 GladePlaceholder *
-glade_clipboard_cut (GladeClipboard * clipboard, GladeWidget * widget)
+glade_clipboard_cut (GladeClipboard *clipboard, GladeWidget *widget)
 {
 	GladePlaceholder *placeholder = NULL;
 
@@ -180,7 +176,7 @@ glade_clipboard_cut (GladeClipboard * cl
  * Copy a GladeWidget onto the Clipboard. 
  **/
 void
-glade_clipboard_copy (GladeClipboard * clipboard, GladeWidget * widget)
+glade_clipboard_copy (GladeClipboard *clipboard, GladeWidget *widget)
 {
 	GladeWidget *copy;
 
@@ -200,19 +196,25 @@ glade_clipboard_copy (GladeClipboard * c
  * Paste a GladeWidget from the Clipboard.
  **/
 void
-glade_clipboard_paste (GladeClipboard * clipboard,
-		       GladePlaceholder * placeholder)
+glade_clipboard_paste (GladeClipboard *clipboard,
+		       GladePlaceholder *placeholder)
 {
-	GladeProjectWindow *gpw;
 	GladeWidget *widget;
 	GladeWidget *parent;
 	GladeProject *project;
 
 	g_return_if_fail (GLADE_IS_CLIPBOARD (clipboard));
 
-	gpw = glade_project_window_get ();
 	widget = clipboard->curr;
+
+	/*
+	 * FIXME: I think that GladePlaceholder should have a pointer
+	 * to the project it belongs to, as GladeWidget does. This way
+	 * the clipboard can be independent from glade-project-window.
+	 * 	Paolo.
+	 */
 	project = glade_project_window_get_project ();
+
 	parent = glade_placeholder_get_parent (placeholder);
 
 	if (!widget)
@@ -243,8 +245,7 @@ glade_clipboard_paste (GladeClipboard * 
 		glade_widget_set_default_packing_options (widget);
 	}
 
-	glade_widget_select (widget);
-	glade_editor_select_widget (gpw->editor, widget);
+	glade_project_selection_set (widget, TRUE);
 
 	/*
 	 * This damned 'if' statement caused a 1 month delay.
@@ -252,8 +253,6 @@ glade_clipboard_paste (GladeClipboard * 
 	if (GTK_IS_WIDGET (widget->widget))
 		gtk_widget_show_all (GTK_WIDGET (widget->widget));
 
-	gpw->active_placeholder = NULL;
-
 	/*
 	 * Finally remove widget from clipboard.
 	 */
diff -upr gnome2/glade3/src/glade-project-window.c glade3/src/glade-project-window.c
--- gnome2/glade3/src/glade-project-window.c	2003-05-15 09:32:23.000000000 +0200
+++ glade3/src/glade-project-window.c	2003-05-16 11:31:42.000000000 +0200
@@ -1022,6 +1022,7 @@ glade_project_window_selection_changed_c
 		if (num == 1) {
 			glade_editor_select_widget (gpw->editor, list->data);
 			gpw->active_widget = list->data;
+			gpw->active_placeholder = NULL;
 		} else {
 			glade_editor_select_widget (gpw->editor, NULL);
 		}

--=-4mLhF5XK+3fhq8fiGAnj--