[gtksourceview/wip/marks-sequence] MarksSequence: continue the implementation
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/marks-sequence] MarksSequence: continue the implementation
- Date: Sun, 8 Sep 2013 21:09:02 +0000 (UTC)
commit 078b223d5142f03499c47ad925bbe61deea940f6
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Sep 8 22:22:00 2013 +0200
MarksSequence: continue the implementation
gtksourceview/gtksourcemarkssequence.c | 171 ++++++++++++++++++++++++++++++++
gtksourceview/gtksourcemarkssequence.h | 32 ++++--
2 files changed, 193 insertions(+), 10 deletions(-)
---
diff --git a/gtksourceview/gtksourcemarkssequence.c b/gtksourceview/gtksourcemarkssequence.c
index 2046f85..76d85dd 100644
--- a/gtksourceview/gtksourcemarkssequence.c
+++ b/gtksourceview/gtksourcemarkssequence.c
@@ -320,3 +320,174 @@ _gtk_source_marks_sequence_prev (GtkSourceMarksSequence *seq,
return g_sequence_get (seq_iter);
}
+
+/* Moves @iter forward to the next position where there is at least one mark.
+ * Returns %TRUE if @iter was moved.
+ */
+gboolean
+_gtk_source_marks_sequence_forward_iter (GtkSourceMarksSequence *seq,
+ GtkTextIter *iter)
+{
+ GtkTextMark *mark;
+ GSequenceIter *seq_iter;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), FALSE);
+ g_return_val_if_fail (iter != NULL, FALSE);
+ g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == seq->priv->buffer, FALSE);
+
+ mark = gtk_text_buffer_create_mark (seq->priv->buffer,
+ NULL,
+ iter,
+ TRUE);
+
+ seq_iter = g_sequence_search (seq->priv->seq,
+ mark,
+ (GCompareDataFunc)compare_marks,
+ NULL);
+
+ gtk_text_buffer_delete_mark (seq->priv->buffer, mark);
+
+ while (!g_sequence_iter_is_end (seq_iter))
+ {
+ GtkTextMark *cur_mark = g_sequence_get (seq_iter);
+ GtkTextIter cur_iter;
+
+ gtk_text_buffer_get_iter_at_mark (seq->priv->buffer, &cur_iter, cur_mark);
+
+ if (gtk_text_iter_compare (iter, &cur_iter) < 0)
+ {
+ *iter = cur_iter;
+ return TRUE;
+ }
+
+ seq_iter = g_sequence_iter_next (seq_iter);
+ }
+
+ return FALSE;
+}
+
+/* Moves @iter backward to the previous position where there is at least one
+ * mark. Returns %TRUE if @iter was moved.
+ */
+gboolean
+_gtk_source_marks_sequence_backward_iter (GtkSourceMarksSequence *seq,
+ GtkTextIter *iter)
+{
+ GtkTextMark *mark;
+ GSequenceIter *seq_iter;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), FALSE);
+ g_return_val_if_fail (iter != NULL, FALSE);
+ g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == seq->priv->buffer, FALSE);
+
+ mark = gtk_text_buffer_create_mark (seq->priv->buffer,
+ NULL,
+ iter,
+ TRUE);
+
+ seq_iter = g_sequence_search (seq->priv->seq,
+ mark,
+ (GCompareDataFunc)compare_marks,
+ NULL);
+
+ gtk_text_buffer_delete_mark (seq->priv->buffer, mark);
+
+ if (g_sequence_iter_is_end (seq_iter))
+ {
+ seq_iter = g_sequence_iter_prev (seq_iter);
+ }
+
+ if (g_sequence_iter_is_end (seq_iter))
+ {
+ /* The sequence is empty. */
+ return FALSE;
+ }
+
+ while (TRUE)
+ {
+ GtkTextMark *cur_mark;
+ GtkTextIter cur_iter;
+
+ cur_mark = g_sequence_get (seq_iter);
+
+ gtk_text_buffer_get_iter_at_mark (seq->priv->buffer, &cur_iter, cur_mark);
+
+ if (gtk_text_iter_compare (&cur_iter, iter) < 0)
+ {
+ *iter = cur_iter;
+ return TRUE;
+ }
+
+ if (g_sequence_iter_is_begin (seq_iter))
+ {
+ break;
+ }
+
+ seq_iter = g_sequence_iter_prev (seq_iter);
+ }
+
+ return FALSE;
+}
+
+GSList *
+_gtk_source_marks_sequence_get_marks_at_iter (GtkSourceMarksSequence *seq,
+ const GtkTextIter *iter)
+{
+ GtkTextMark *mark;
+ GSequenceIter *seq_iter;
+ GSList *ret = NULL;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), NULL);
+ g_return_val_if_fail (iter != NULL, NULL);
+ g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == seq->priv->buffer, NULL);
+
+ mark = gtk_text_buffer_create_mark (seq->priv->buffer,
+ NULL,
+ iter,
+ TRUE);
+
+ seq_iter = g_sequence_lookup (seq->priv->seq,
+ mark,
+ (GCompareDataFunc)compare_marks,
+ NULL);
+
+
+ if (seq_iter == NULL)
+ {
+ goto out;
+ }
+
+ /* Go to the first mark at @iter. */
+ while (!g_sequence_iter_is_begin (seq_iter))
+ {
+ GSequenceIter *prev_seq_iter;
+ GtkTextMark *prev_mark;
+
+ prev_seq_iter = g_sequence_iter_prev (seq_iter);
+ prev_mark = g_sequence_get (prev_seq_iter);
+
+ if (compare_marks (mark, prev_mark) != 0)
+ {
+ break;
+ }
+
+ seq_iter = prev_seq_iter;
+ }
+
+ while (!g_sequence_iter_is_end (seq_iter))
+ {
+ GtkTextMark *cur_mark = g_sequence_get (seq_iter);
+
+ if (compare_marks (mark, cur_mark) != 0)
+ {
+ break;
+ }
+
+ ret = g_slist_prepend (ret, cur_mark);
+ seq_iter = g_sequence_iter_next (seq_iter);
+ }
+
+out:
+ gtk_text_buffer_delete_mark (seq->priv->buffer, mark);
+ return ret;
+}
diff --git a/gtksourceview/gtksourcemarkssequence.h b/gtksourceview/gtksourcemarkssequence.h
index 5bed4b0..f304e15 100644
--- a/gtksourceview/gtksourcemarkssequence.h
+++ b/gtksourceview/gtksourcemarkssequence.h
@@ -50,26 +50,38 @@ struct _GtkSourceMarksSequenceClass
};
G_GNUC_INTERNAL
-GType _gtk_source_marks_sequence_get_type (void) G_GNUC_CONST;
+GType _gtk_source_marks_sequence_get_type (void) G_GNUC_CONST;
G_GNUC_INTERNAL
-GtkSourceMarksSequence *_gtk_source_marks_sequence_new (GtkTextBuffer *buffer);
+GtkSourceMarksSequence *_gtk_source_marks_sequence_new (GtkTextBuffer *buffer);
G_GNUC_INTERNAL
-void _gtk_source_marks_sequence_add (GtkSourceMarksSequence *seq,
- GtkTextMark *mark);
+void _gtk_source_marks_sequence_add (GtkSourceMarksSequence *seq,
+ GtkTextMark *mark);
G_GNUC_INTERNAL
-void _gtk_source_marks_sequence_remove (GtkSourceMarksSequence *seq,
- GtkTextMark *mark);
+void _gtk_source_marks_sequence_remove (GtkSourceMarksSequence *seq,
+ GtkTextMark *mark);
G_GNUC_INTERNAL
-GtkTextMark *_gtk_source_marks_sequence_next (GtkSourceMarksSequence *seq,
- GtkTextMark *mark);
+GtkTextMark *_gtk_source_marks_sequence_next (GtkSourceMarksSequence *seq,
+ GtkTextMark *mark);
G_GNUC_INTERNAL
-GtkTextMark *_gtk_source_marks_sequence_prev (GtkSourceMarksSequence *seq,
- GtkTextMark *mark);
+GtkTextMark *_gtk_source_marks_sequence_prev (GtkSourceMarksSequence *seq,
+ GtkTextMark *mark);
+
+G_GNUC_INTERNAL
+gboolean _gtk_source_marks_sequence_forward_iter (GtkSourceMarksSequence *seq,
+ GtkTextIter *iter);
+
+G_GNUC_INTERNAL
+gboolean _gtk_source_marks_sequence_backward_iter (GtkSourceMarksSequence *seq,
+ GtkTextIter *iter);
+
+G_GNUC_INTERNAL
+GSList *_gtk_source_marks_sequence_get_marks_at_iter (GtkSourceMarksSequence *seq,
+ const GtkTextIter *iter);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]