[gnome-builder/wip/libide] libide: add indenter API to libide
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/libide] libide: add indenter API to libide
- Date: Wed, 18 Feb 2015 06:49:38 +0000 (UTC)
commit db2ed324e897e098eefc08cd58dcbf9d122110ed
Author: Christian Hergert <christian hergert me>
Date: Tue Feb 17 22:04:22 2015 -0800
libide: add indenter API to libide
libide/ide-indenter.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
libide/ide-indenter.h | 20 ++++++++++++++
2 files changed, 88 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-indenter.c b/libide/ide-indenter.c
index 9021e7f..e961071 100644
--- a/libide/ide-indenter.c
+++ b/libide/ide-indenter.c
@@ -29,3 +29,71 @@ static void
ide_indenter_init (IdeIndenter *self)
{
}
+
+/**
+ * ide_indenter_format:
+ * @text_view: A #GtkTextView
+ * @begin: A #GtkTextIter for the beginning region of text to replace.
+ * @end: A #GtkTextIter for the end region of text to replace.
+ * @cursor_offset: The offset in characters from @end to place the cursor.
+ * Negative values are okay.
+ * @event: The #GdkEventKey that triggered the event.
+ *
+ * This function performs an indentation for the key press activated by @event.
+ * The implementation is free to move the @begin and @end iters to swallow
+ * adjacent content. The result, a string, is the contents that will replace
+ * the content inbetween @begin and @end.
+ *
+ * @cursor_offset may be set to jump the cursor starting from @end. Negative
+ * values are allowed.
+ *
+ * Returns: (transfer full): A string containing the replacement text, or %NULL.
+ */
+gchar *
+ide_indenter_format (IdeIndenter *self,
+ GtkTextView *text_view,
+ GtkTextIter *begin,
+ GtkTextIter *end,
+ gint *cursor_offset,
+ GdkEventKey *event)
+{
+ g_return_val_if_fail (IDE_IS_INDENTER (self), NULL);
+ g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
+ g_return_val_if_fail (begin, NULL);
+ g_return_val_if_fail (end, NULL);
+ g_return_val_if_fail (cursor_offset, NULL);
+ g_return_val_if_fail (event, NULL);
+
+ if (IDE_INDENTER_GET_CLASS (self)->format)
+ return IDE_INDENTER_GET_CLASS (self)->format (self,
+ text_view,
+ begin,
+ end,
+ cursor_offset,
+ event);
+
+ return NULL;
+}
+
+/**
+ * ide_indenter_is_trigger:
+ * @self: an #IdeIndenter
+ * @event: a #GdkEventKey
+ *
+ * Determines if @event should trigger an indentation request. If %TRUE is
+ * returned then ide_indenter_format() will be called.
+ *
+ * Returns: %TRUE if @event should trigger an indentation request.
+ */
+gboolean
+ide_indenter_is_trigger (IdeIndenter *self,
+ GdkEventKey *event)
+{
+ g_return_val_if_fail (IDE_IS_INDENTER (self), FALSE);
+ g_return_val_if_fail (event, FALSE);
+
+ if (IDE_INDENTER_GET_CLASS (self)->is_trigger)
+ return IDE_INDENTER_GET_CLASS (self)->is_trigger (self, event);
+
+ return FALSE;
+}
diff --git a/libide/ide-indenter.h b/libide/ide-indenter.h
index f007591..6b7da66 100644
--- a/libide/ide-indenter.h
+++ b/libide/ide-indenter.h
@@ -19,6 +19,8 @@
#ifndef IDE_INDENTER_H
#define IDE_INDENTER_H
+#include <gtk/gtk.h>
+
#include "ide-object.h"
G_BEGIN_DECLS
@@ -30,8 +32,26 @@ G_DECLARE_DERIVABLE_TYPE (IdeIndenter, ide_indenter, IDE, INDENTER, IdeObject)
struct _IdeIndenterClass
{
IdeObjectClass parent;
+
+ gchar *(*format) (IdeIndenter *self,
+ GtkTextView *text_view,
+ GtkTextIter *begin,
+ GtkTextIter *end,
+ gint *cursor_offset,
+ GdkEventKey *event);
+ gboolean (*is_trigger) (IdeIndenter *self,
+ GdkEventKey *event);
};
+gboolean ide_indenter_is_trigger (IdeIndenter *self,
+ GdkEventKey *event);
+gchar *ide_indenter_format (IdeIndenter *self,
+ GtkTextView *text_view,
+ GtkTextIter *begin,
+ GtkTextIter *end,
+ gint *cursor_offset,
+ GdkEventKey *event);
+
G_END_DECLS
#endif /* IDE_INDENTER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]