All pastes #28219 Raw Edit

Unnamed

public text v1 · immutable
#28219 ·published 2005-11-10 13:24 UTC
rendered paste body
Index: gedit-document.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-document.c,v
retrieving revision 1.111.2.50
diff -u -p -r1.111.2.50 gedit-document.c
--- gedit-document.c	6 Nov 2005 11:56:14 -0000	1.111.2.50
+++ gedit-document.c	10 Nov 2005 13:19:43 -0000
@@ -84,6 +84,7 @@ struct _GeditDocumentPrivate
 	gint	     language_set_by_user : 1;
 	gint         is_saving_as : 1;
 	gint         has_selection : 1;
+	gint         stop_cursor_moved_emission : 1;
 
 	gchar	    *uri;
 	gint 	     untitled_number;
@@ -130,6 +131,7 @@ enum {
 };
 
 enum {
+	CURSOR_MOVED,
 	LOADING,
 	LOADED,
 	SAVING,
@@ -289,6 +291,17 @@ gedit_document_get_property (GObject    
 }
 
 static void
+emit_cursor_moved (GeditDocument *doc)
+{
+	if (!doc->priv->stop_cursor_moved_emission)
+	{
+		g_signal_emit (doc,
+			       document_signals[CURSOR_MOVED],
+			       0);
+	}
+}
+
+static void
 gedit_document_mark_set (GtkTextBuffer     *buffer,
                          const GtkTextIter *iter,
                          GtkTextMark       *mark)
@@ -315,6 +328,19 @@ gedit_document_mark_set (GtkTextBuffer  
 			g_object_notify (G_OBJECT (doc), "has-selection");
 		}
 	}
+
+	if (mark == gtk_text_buffer_get_insert (buffer))
+	{
+		emit_cursor_moved (doc);
+	}
+}
+
+static void
+gedit_document_changed (GtkTextBuffer *buffer)
+{
+	emit_cursor_moved (GEDIT_DOCUMENT (buffer));
+
+	GTK_TEXT_BUFFER_CLASS (gedit_document_parent_class)->changed (buffer);
 }
 
 static void 
@@ -327,6 +353,7 @@ gedit_document_class_init (GeditDocument
 	object_class->get_property = gedit_document_get_property;
 
 	buf_class->mark_set = gedit_document_mark_set;
+	buf_class->changed = gedit_document_changed;
 
 	g_object_class_install_property (object_class, PROP_URI,
 					 g_param_spec_string ("uri",
@@ -360,7 +387,7 @@ gedit_document_class_init (GeditDocument
 					 		     G_PARAM_READABLE));
 
 	/* This has been properly moved in GtkTextBuffer in gtk 2.10, so when
-	 * we switch to 2.10 we can remove it along with gedit_document_mark_set
+	 * we switch to 2.10 we can remove it and part of with gedit_document_mark_set.
 	 */
 	g_object_class_install_property (object_class, PROP_HAS_SELECTION,
 					 g_param_spec_boolean ("has-selection",
@@ -368,6 +395,15 @@ gedit_document_class_init (GeditDocument
 					 		       "Wheter the document has selected text",
 					 		       FALSE,
 					 		       G_PARAM_READABLE));
+	document_signals[CURSOR_MOVED] =
+   		g_signal_new ("cursor-moved",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (GeditDocumentClass, cursor_moved),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE,
+			      0);
 
 	document_signals[LOADING] =
    		g_signal_new ("loading",
@@ -603,6 +639,9 @@ gedit_document_init (GeditDocument *doc)
 
 	doc->priv->readonly = FALSE;
 
+	doc->priv->has_selection = FALSE;
+	doc->priv->stop_cursor_moved_emission = FALSE;
+
 	doc->priv->last_save_was_manually = TRUE;
 	doc->priv->language_set_by_user = FALSE;
 
@@ -1408,7 +1447,13 @@ gedit_document_replace_all (GeditDocumen
 	}
 	
 	replace_text_len = strlen (replace_text);
-	
+
+	/* disable cursor_moved emission until the end of the
+	 * replace_all so that we don't spend all the time
+	 * updating the position in the statusbar
+	 */
+	doc->priv->stop_cursor_moved_emission = FALSE;
+
 	gtk_text_buffer_begin_user_action (buffer);
 	
 	do
@@ -1453,6 +1498,12 @@ gedit_document_replace_all (GeditDocumen
 	} while (found);
 
 	gtk_text_buffer_end_user_action (buffer);
+
+	/* re-enable cursor_moved emission and notify
+	 * the current position 
+	 */
+	doc->priv->stop_cursor_moved_emission = TRUE;
+	emit_cursor_moved (doc);
 
 	g_free (search_text);
 	g_free (replace_text);	
Index: gedit-document.h
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-document.h,v
retrieving revision 1.41.2.24
diff -u -p -r1.41.2.24 gedit-document.h
--- gedit-document.h	6 Nov 2005 11:56:14 -0000	1.41.2.24
+++ gedit-document.h	10 Nov 2005 13:19:43 -0000
@@ -86,6 +86,8 @@ struct _GeditDocumentClass
 
 	/* Signals */ // CHECK: ancora da rivedere
 
+	void (* cursor_moved)		(GeditDocument    *document);
+
 	/* Document load */
 	void (* loading)		(GeditDocument    *document,
 					 GnomeVFSFileSize  size,
Index: gedit-window.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/Attic/gedit-window.c,v
retrieving revision 1.4.2.106
diff -u -p -r1.4.2.106 gedit-window.c
--- gedit-window.c	6 Nov 2005 11:56:14 -0000	1.4.2.106
+++ gedit-window.c	10 Nov 2005 13:20:02 -0000
@@ -1312,19 +1312,6 @@ update_cursor_position_statusbar (GtkTex
 }
 
 static void
-cursor_moved (GtkTextBuffer     *buffer,
-	      const GtkTextIter *new_location,
-	      GtkTextMark       *mark,
-	      GeditWindow       *window)
-{
-	if (buffer != GTK_TEXT_BUFFER (gedit_window_get_active_document (window)))
-		return;
-			  
-	if (mark == gtk_text_buffer_get_insert (buffer))
-		update_cursor_position_statusbar (buffer, window);
-}
-
-static void
 update_overwrite_mode_statusbar (GtkTextView *view, 
 				 GeditWindow *window)
 {
@@ -1949,19 +1936,14 @@ notebook_tab_added (GeditNotebook *noteb
 			 "notify::name",
 			  G_CALLBACK (sync_name), 
 			  window);
-			  
 	g_signal_connect (tab, 
 			 "notify::state",
 			  G_CALLBACK (sync_state), 
 			  window);
-			  
-	g_signal_connect (doc, 
-			  "changed",
-			  G_CALLBACK (update_cursor_position_statusbar),
-			  window);
+
 	g_signal_connect (doc,
-			  "mark_set",/* cursor moved */
-			  G_CALLBACK (cursor_moved),
+			  "cursor-moved",
+			  G_CALLBACK (update_cursor_position_statusbar),
 			  window);			  
 	g_signal_connect (doc,
 			  "can-undo",
@@ -2049,9 +2031,6 @@ notebook_tab_removed (GeditNotebook *not
 	g_signal_handlers_disconnect_by_func (doc,
 					      G_CALLBACK (update_cursor_position_statusbar), 
 					      window);
-	g_signal_handlers_disconnect_by_func (doc,
-					      G_CALLBACK (cursor_moved), 
-					      window);					      
 	g_signal_handlers_disconnect_by_func (doc, 
 					      G_CALLBACK (can_undo),
 					      window);
@@ -2639,6 +2618,7 @@ gedit_window_close_tab (GeditWindow *win
 				   tab);
 }
 
+// CHECK: these should be priv? pbor.
 void
 gedit_window_close_all_tabs (GeditWindow *window)
 {