[gtksourceview] Changed "bracket-matched" signal.
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Changed "bracket-matched" signal.
- Date: Sun, 31 Oct 2010 21:01:29 +0000 (UTC)
commit d23f442b5b67e54364dd7ac724a4f58444446a5e
Author: Krzesimir Nowak <qdlacz gmail com>
Date: Sun Oct 31 21:17:33 2010 +0100
Changed "bracket-matched" signal.
Now this signal's 'state' parameter is a value instead of a pointer,
so it is consistent with what documentation says and what is passed
to g_signal_new(). Also, this signal is not emitted if previous and
current char are nonbrackets. Added a function checking this to
C and python test-widget.
gtksourceview/gtksourcebuffer.c | 23 ++++++++++++++++-------
gtksourceview/gtksourcebuffer.h | 2 +-
tests/test-widget.c | 26 ++++++++++++++++++++++++++
tests/test-widget.py | 10 ++++++++++
4 files changed, 53 insertions(+), 8 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 4b00d80..e88aebd 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -362,7 +362,8 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
* @state: state of bracket matching
*
* Sets @iter to a valid iterator pointing to the matching bracket
- * if @state is #GTK_SOURCE_BRACKET_MATCH_FOUND.
+ * if @state is #GTK_SOURCE_BRACKET_MATCH_FOUND. Otherwise @iter is
+ * meaningless.
*
* Since: 2.12
*/
@@ -788,6 +789,7 @@ gtk_source_buffer_move_cursor (GtkTextBuffer *buffer,
GtkSourceBuffer *source_buffer;
GtkTextIter start, end;
gunichar cursor_char;
+ GtkSourceBracketMatchType previous_state;
g_return_if_fail (GTK_IS_SOURCE_BUFFER (buffer));
g_return_if_fail (iter != NULL);
@@ -821,16 +823,23 @@ gtk_source_buffer_move_cursor (GtkTextBuffer *buffer,
return;
start = *iter;
+ previous_state = source_buffer->priv->bracket_match;
if (!gtk_source_buffer_find_bracket_match_with_limit (source_buffer,
&start,
&source_buffer->priv->bracket_match,
MAX_CHARS_BEFORE_FINDING_A_MATCH))
{
- g_signal_emit (source_buffer,
- buffer_signals[BRACKET_MATCHED],
- 0,
- NULL,
- &source_buffer->priv->bracket_match);
+ /* don't emit the signal at all if chars at previous and current
+ positions are nonbrackets. */
+ if (previous_state != GTK_SOURCE_BRACKET_MATCH_NONE ||
+ source_buffer->priv->bracket_match != GTK_SOURCE_BRACKET_MATCH_NONE)
+ {
+ g_signal_emit (source_buffer,
+ buffer_signals[BRACKET_MATCHED],
+ 0,
+ &end,
+ source_buffer->priv->bracket_match);
+ }
}
else
{
@@ -838,7 +847,7 @@ gtk_source_buffer_move_cursor (GtkTextBuffer *buffer,
buffer_signals[BRACKET_MATCHED],
0,
&start,
- &source_buffer->priv->bracket_match);
+ source_buffer->priv->bracket_match);
/* allow_bracket_match will allow the bracket match tag to be
applied to the buffer. See apply_tag_real for more
diff --git a/gtksourceview/gtksourcebuffer.h b/gtksourceview/gtksourcebuffer.h
index 5b19a32..95c5788 100644
--- a/gtksourceview/gtksourcebuffer.h
+++ b/gtksourceview/gtksourcebuffer.h
@@ -77,7 +77,7 @@ struct _GtkSourceBufferClass
void (*bracket_matched) (GtkSourceBuffer *buffer,
GtkTextIter *iter,
- GtkSourceBracketMatchType *state);
+ GtkSourceBracketMatchType state);
/* Padding for future expansion */
void (*_gtk_source_reserved1) (void);
diff --git a/tests/test-widget.c b/tests/test-widget.c
index 0b0d93f..a1aa05f 100644
--- a/tests/test-widget.c
+++ b/tests/test-widget.c
@@ -36,6 +36,7 @@
#include <gtksourceview/gtksourcestyleschememanager.h>
#include <gtksourceview/gtksourceprintcompositor.h>
#include <gtksourceview/gtksourceiter.h>
+#include <gtksourceview/gtksourceview-typebuiltins.h>
#ifdef TEST_XML_MEM
#include <libxml/xmlreader.h>
#endif
@@ -1246,6 +1247,30 @@ line_mark_activated (GtkSourceGutter *gutter,
g_slist_free (mark_list);
}
+static void
+bracket_matched (GtkSourceBuffer *buffer G_GNUC_UNUSED,
+ GtkTextIter *iter,
+ GtkSourceBracketMatchType state,
+ gpointer *data G_GNUC_UNUSED)
+{
+ GEnumClass *eclass;
+ GEnumValue *evalue;
+
+ g_return_if_fail (iter != NULL);
+
+ eclass = G_ENUM_CLASS (g_type_class_ref (GTK_TYPE_SOURCE_BRACKET_MATCH_TYPE));
+ evalue = g_enum_get_value (eclass, state);
+
+ g_print ("Bracket match state: '%s'\n", evalue->value_nick);
+
+ if (state == GTK_SOURCE_BRACKET_MATCH_FOUND)
+ {
+ g_print ("Matched bracket: '%c' at row: %"G_GINT32_FORMAT", col: %"G_GINT32_FORMAT"\n",
+ gtk_text_iter_get_char (iter),
+ gtk_text_iter_get_line (iter) + 1,
+ gtk_text_iter_get_line_offset (iter) + 1);
+ }
+}
/* Window creation functions -------------------------------------------------------- */
@@ -1324,6 +1349,7 @@ create_view_window (GtkSourceBuffer *buffer, GtkSourceView *from)
g_signal_connect (buffer, "changed", G_CALLBACK (update_cursor_position), view);
g_signal_connect (view, "line-mark-activated", G_CALLBACK (line_mark_activated), view);
g_signal_connect (window, "delete-event", (GCallback) window_deleted_cb, view);
+ g_signal_connect (buffer, "bracket-matched", G_CALLBACK (bracket_matched), 0);
/* action group and UI manager */
action_group = gtk_action_group_new ("ViewActions");
diff --git a/tests/test-widget.py b/tests/test-widget.py
index 2fc1862..255e43e 100644
--- a/tests/test-widget.py
+++ b/tests/test-widget.py
@@ -170,6 +170,7 @@ class Window(Gtk.Window):
self._buf.connect("mark-set", self.move_cursor_cb, None)
self._view.connect("line-mark-activated", self.line_mark_activated, None)
+ self._buffer.connect("bracket-matched", self.bracket_matched, None);
def insert_menu(self):
action_group = Gtk.ActionGroup()
@@ -506,6 +507,15 @@ class Window(Gtk.Window):
else:
self._buf.create_source_mark(None, mark_type, place)
+ def bracket_matched(self, place, state, user_data):
+ # FIXME: figure out how to obtain the nick from the enum value
+ # print "Bracket match state: '%s'\n" % nick
+ if state == GtkSource.BracketMatchType.FOUND:
+ bracket = place.get_char()
+ row = place.get_line() + 1
+ col = place.get_line_offset() + 1
+ print "Matched bracket: '%c' at row: %i, col: %i\n" % bracket % row % col
+
def open_file(self, filename):
if os.path.isabs(filename):
path = filename
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]