gtksourceview r1990 - in trunk: . gtksourceview tests



Author: muntyan
Date: Sun Aug  3 02:52:01 2008
New Revision: 1990
URL: http://svn.gnome.org/viewvc/gtksourceview?rev=1990&view=rev

Log:
2008-08-02  Yevgen Muntyan  <muntyan tamu edu>

	Bug 329883 - evaluate bracket matching as soon as it's turned on.
	* gtksourceview/gtksourcebuffer.c
	(gtk_source_buffer_set_highlight_matching_brackets):
	update matching bracket immediately.
	* tests/test-widget.c: added a menu item for highlighting matching
	brackets.



Modified:
   trunk/ChangeLog
   trunk/gtksourceview/gtksourcebuffer.c
   trunk/tests/test-widget.c

Modified: trunk/gtksourceview/gtksourcebuffer.c
==============================================================================
--- trunk/gtksourceview/gtksourcebuffer.c	(original)
+++ trunk/gtksourceview/gtksourcebuffer.c	Sun Aug  3 02:52:01 2008
@@ -98,7 +98,7 @@
 
 	GtkSourceUndoManager  *undo_manager;
 };
-	
+
 G_DEFINE_TYPE (GtkSourceBuffer, gtk_source_buffer, GTK_TYPE_TEXT_BUFFER)
 
 static guint 	 buffer_signals[LAST_SIGNAL];
@@ -153,7 +153,7 @@
 	 * that will cause problems (a loop). */
 	tb_class->delete_range  = gtk_source_buffer_real_delete_range;
 	tb_class->insert_text 	= gtk_source_buffer_real_insert_text;
-	
+
 	tb_class->mark_set	= gtk_source_buffer_real_mark_set;
 	tb_class->mark_deleted	= gtk_source_buffer_real_mark_deleted;
 
@@ -258,7 +258,7 @@
 	 * GtkSourceBuffer::source-mark-updated
 	 * @buffer: the buffer that received the signal
 	 *
-	 * The ::source_mark_updated signal is emitted each time 
+	 * The ::source_mark_updated signal is emitted each time
 	 * a mark is added to, moved or removed from the @buffer.
 	 **/
 	buffer_signals[SOURCE_MARK_UPDATED] =
@@ -1048,7 +1048,15 @@
 
 	if (highlight != buffer->priv->highlight_brackets)
 	{
+		GtkTextIter iter;
+		GtkTextMark *mark;
+
 		buffer->priv->highlight_brackets = highlight;
+
+		mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (buffer));
+		gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), &iter, mark);
+		gtk_source_buffer_move_cursor (GTK_TEXT_BUFFER (buffer), &iter, mark);
+
 		g_object_notify (G_OBJECT (buffer), "highlight-matching-brackets");
 	}
 }
@@ -1079,7 +1087,7 @@
  * is %TRUE, the text will be highlighted according to the syntax
  * patterns specified in the language set with
  * gtk_source_buffer_set_language(). If @highlight is %FALSE, syntax highlighting
- * is disabled and all the GtkTextTag objects that have been added by the 
+ * is disabled and all the GtkTextTag objects that have been added by the
  * syntax highlighting engine are removed from the buffer.
  **/
 void
@@ -1102,12 +1110,12 @@
  * @buffer: a #GtkSourceBuffer.
  * @language: a #GtkSourceLanguage to set, or %NULL.
  *
- * Associate a #GtkSourceLanguage with the source buffer. If @language is 
+ * Associate a #GtkSourceLanguage with the source buffer. If @language is
  * not-%NULL and syntax highlighting is enabled (see gtk_source_buffer_set_highlight_syntax()),
  * the syntax patterns defined in @language will be used to highlight the text
- * contained in the buffer. If @language is %NULL, the text contained in the 
+ * contained in the buffer. If @language is %NULL, the text contained in the
  * buffer is not highlighted.
- * 
+ *
  * The buffer holds a reference to @language.
  **/
 void
@@ -1157,7 +1165,7 @@
  * gtk_source_buffer_get_language:
  * @buffer: a #GtkSourceBuffer.
  *
- * Returns the #GtkSourceLanguage associated with the buffer, 
+ * Returns the #GtkSourceLanguage associated with the buffer,
  * see gtk_source_buffer_set_language().  The returned object should not be
  * unreferenced by the user.
  *
@@ -1398,7 +1406,7 @@
 	GTK_TEXT_BUFFER_CLASS (gtk_source_buffer_parent_class)->mark_set (buffer, location, mark);
 }
 
-static void 	 
+static void
 gtk_source_buffer_real_mark_deleted (GtkTextBuffer *buffer,
 				     GtkTextMark *mark)
 {
@@ -1733,7 +1741,7 @@
 
 	res = gtk_source_buffer_get_source_marks_at_iter (buffer,
 							  &iter,
-							  category); 
+							  category);
 
 	while (gtk_source_buffer_forward_iter_to_source_mark (buffer,
 							      &iter,
@@ -1788,7 +1796,7 @@
 
 	list = gtk_source_buffer_get_source_marks_at_iter (buffer,
 							   &iter,
-							   category); 
+							   category);
 
 	while (gtk_source_buffer_forward_iter_to_source_mark (buffer,
 							      &iter,

Modified: trunk/tests/test-widget.c
==============================================================================
--- trunk/tests/test-widget.c	(original)
+++ trunk/tests/test-widget.c	Sun Aug  3 02:52:01 2008
@@ -74,6 +74,8 @@
 						  gpointer         user_data);
 static void       margin_toggled_cb              (GtkAction       *action,
 						  gpointer         user_data);
+static void       hl_bracket_toggled_cb          (GtkAction       *action,
+						  gpointer         user_data);
 static void       hl_line_toggled_cb             (GtkAction       *action,
 						  gpointer         user_data);
 static void       wrap_lines_toggled_cb          (GtkAction       *action,
@@ -117,6 +119,9 @@
 };
 
 static GtkToggleActionEntry toggle_entries[] = {
+	{ "HlBracket", NULL, "Highlight Matching _Bracket", NULL,
+	  "Toggle highlighting of matching bracket",
+	  G_CALLBACK (hl_bracket_toggled_cb), FALSE },
 	{ "ShowNumbers", NULL, "Show _Line Numbers", NULL,
 	  "Toggle visibility of line numbers in the left margin",
 	  G_CALLBACK (numbers_toggled_cb), FALSE },
@@ -179,6 +184,7 @@
 "    <menu action=\"ViewMenu\">"
 "      <menuitem action=\"NewView\"/>"
 "      <separator/>"
+"      <menuitem action=\"HlBracket\"/>"
 "      <menuitem action=\"ShowNumbers\"/>"
 "      <menuitem action=\"ShowMarks\"/>"
 "      <menuitem action=\"ShowMargin\"/>"
@@ -575,6 +581,17 @@
 }
 
 static void
+hl_bracket_toggled_cb (GtkAction *action, gpointer user_data)
+{
+	GtkTextBuffer *buffer;
+	g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_IS_SOURCE_VIEW (user_data));
+	buffer = gtk_text_view_get_buffer (user_data);
+	gtk_source_buffer_set_highlight_matching_brackets (
+		GTK_SOURCE_BUFFER (buffer),
+		gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+}
+
+static void
 hl_line_toggled_cb (GtkAction *action, gpointer user_data)
 {
 	g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_IS_SOURCE_VIEW (user_data));
@@ -1379,6 +1396,9 @@
 	/* retrieve the view action group at position 0 in the list */
 	action_group = g_list_nth_data (groups, 0);
 
+	action = gtk_action_group_get_action (action_group, "HlBracket");
+	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
+
 	action = gtk_action_group_get_action (action_group, "ShowNumbers");
 	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
 



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