[anjuta] libanjuta: Add IAnjutaIndenter interface
- From: Johannes Schmid <jhs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] libanjuta: Add IAnjutaIndenter interface
- Date: Sun, 13 Feb 2011 20:19:28 +0000 (UTC)
commit 24df909884cbbaa50294e04828c026b48d4945df
Author: Johannes Schmid <jhs gnome org>
Date: Sun Feb 13 20:33:47 2011 +0100
libanjuta: Add IAnjutaIndenter interface
libanjuta/interfaces/libanjuta.idl | 32 +++++++++++++++++
.../cpp-java-indentation.c | 36 ++++++++++++-------
.../cpp-java-indentation.h | 4 ++-
plugins/language-support-cpp-java/plugin.c | 23 ++++++++++++-
4 files changed, 80 insertions(+), 15 deletions(-)
---
diff --git a/libanjuta/interfaces/libanjuta.idl b/libanjuta/interfaces/libanjuta.idl
index 07f8a0e..6e59672 100644
--- a/libanjuta/interfaces/libanjuta.idl
+++ b/libanjuta/interfaces/libanjuta.idl
@@ -6450,3 +6450,35 @@ typedef gint Id;
*/
GList* get_languages ();
}
+
+/**
+ * SECTION:ianjuta-indenter
+ * @title: IAnjutaIndenter
+ * @short_description: Interface for automatic indentation
+ * @see_also:
+ * @stability: Unstable
+ * @include: libanjuta/interfaces/ianjuta-indenter.h
+ *
+ */
+
+interface IAnjutaIndenter
+{
+ #include <libanjuta/interfaces/ianjuta-iterable.h>
+
+ /**
+ * ianjuta_indenter_indent
+ * @obj: Self
+ * @start: Start of the area to indent
+ * @end: End of the area to indent
+ * @error: Error propagation
+ *
+ * Indent the area between @start and @end according to the indentation rules
+ * of the programming language. Usually implemented by language support plugins.
+ * Only one indenter can be loaded at a time.
+ * Note: Indenters always affect full lines, so start and end will be moved
+ * according to the next line start/end.
+ */
+ void indent (IAnjutaIterable* start, IAnjutaIterable* end);
+}
+
+
diff --git a/plugins/language-support-cpp-java/cpp-java-indentation.c b/plugins/language-support-cpp-java/cpp-java-indentation.c
index 6408972..ec9141d 100644
--- a/plugins/language-support-cpp-java/cpp-java-indentation.c
+++ b/plugins/language-support-cpp-java/cpp-java-indentation.c
@@ -1305,7 +1305,9 @@ cpp_indentation (IAnjutaEditor *editor,
void
cpp_auto_indentation (IAnjutaEditor *editor,
- CppJavaPlugin *lang_plugin)
+ CppJavaPlugin *lang_plugin,
+ IAnjutaIterable *start,
+ IAnjutaIterable *end)
{
gint line_start, line_end;
gint insert_line;
@@ -1314,22 +1316,30 @@ cpp_auto_indentation (IAnjutaEditor *editor,
has_selection = ianjuta_editor_selection_has_selection
(IANJUTA_EDITOR_SELECTION (editor), NULL);
- if (has_selection)
+ if (start == NULL || end == NULL)
{
- IAnjutaIterable *sel_start, *sel_end;
- sel_start = ianjuta_editor_selection_get_start (IANJUTA_EDITOR_SELECTION (editor),
- NULL);
- sel_end = ianjuta_editor_selection_get_end (IANJUTA_EDITOR_SELECTION (editor),
- NULL);
- line_start = ianjuta_editor_get_line_from_position (editor, sel_start, NULL);
- line_end = ianjuta_editor_get_line_from_position (editor, sel_end, NULL);
- g_object_unref (sel_start);
- g_object_unref (sel_end);
+ if (has_selection)
+ {
+ IAnjutaIterable *sel_start, *sel_end;
+ sel_start = ianjuta_editor_selection_get_start (IANJUTA_EDITOR_SELECTION (editor),
+ NULL);
+ sel_end = ianjuta_editor_selection_get_end (IANJUTA_EDITOR_SELECTION (editor),
+ NULL);
+ line_start = ianjuta_editor_get_line_from_position (editor, sel_start, NULL);
+ line_end = ianjuta_editor_get_line_from_position (editor, sel_end, NULL);
+ g_object_unref (sel_start);
+ g_object_unref (sel_end);
+ }
+ else
+ {
+ line_start = ianjuta_editor_get_lineno (IANJUTA_EDITOR(editor), NULL);
+ line_end = line_start;
+ }
}
else
{
- line_start = ianjuta_editor_get_lineno (IANJUTA_EDITOR(editor), NULL);
- line_end = line_start;
+ line_start = ianjuta_editor_get_line_from_position (editor, start, NULL);
+ line_end = ianjuta_editor_get_line_from_position (editor, end, NULL);
}
ianjuta_document_begin_undo_action (IANJUTA_DOCUMENT(editor), NULL);
diff --git a/plugins/language-support-cpp-java/cpp-java-indentation.h b/plugins/language-support-cpp-java/cpp-java-indentation.h
index b68d16f..54727ee 100644
--- a/plugins/language-support-cpp-java/cpp-java-indentation.h
+++ b/plugins/language-support-cpp-java/cpp-java-indentation.h
@@ -28,7 +28,9 @@ cpp_indentation (IAnjutaEditor *editor,
void
cpp_auto_indentation (IAnjutaEditor *editor,
- CppJavaPlugin *plugin);
+ CppJavaPlugin *plugin,
+ IAnjutaIterable *start,
+ IAnjutaIterable *end);
void
java_indentation (IAnjutaEditor *editor,
diff --git a/plugins/language-support-cpp-java/plugin.c b/plugins/language-support-cpp-java/plugin.c
index cd01287..7b7f9c7 100644
--- a/plugins/language-support-cpp-java/plugin.c
+++ b/plugins/language-support-cpp-java/plugin.c
@@ -38,6 +38,7 @@
#include <libanjuta/interfaces/ianjuta-preferences.h>
#include <libanjuta/interfaces/ianjuta-symbol.h>
#include <libanjuta/interfaces/ianjuta-language.h>
+#include <libanjuta/interfaces/ianjuta-indenter.h>
#include "plugin.h"
#include "cpp-java-utils.h"
@@ -782,7 +783,7 @@ on_auto_indent (GtkAction *action, gpointer data)
lang_plugin = ANJUTA_PLUGIN_CPP_JAVA (data);
editor = IANJUTA_EDITOR (lang_plugin->current_editor);
- cpp_auto_indentation (editor, lang_plugin);
+ cpp_auto_indentation (editor, lang_plugin, NULL, NULL);
}
/* Automatic comments */
@@ -1234,8 +1235,28 @@ ipreferences_iface_init (IAnjutaPreferencesIface* iface)
iface->unmerge = ipreferences_unmerge;
}
+static void
+iindenter_indent (IAnjutaIndenter* indenter,
+ IAnjutaIterable* start,
+ IAnjutaIterable* end,
+ GError** e)
+{
+ CppJavaPlugin* plugin = ANJUTA_PLUGIN_CPP_JAVA (indenter);
+
+ cpp_auto_indentation (IANJUTA_EDITOR (plugin->current_editor),
+ plugin,
+ start, end);
+}
+
+static void
+iindenter_iface_init (IAnjutaIndenterIface* iface)
+{
+ iface->indent = iindenter_indent;
+}
+
ANJUTA_PLUGIN_BEGIN (CppJavaPlugin, cpp_java_plugin);
ANJUTA_PLUGIN_ADD_INTERFACE(ipreferences, IANJUTA_TYPE_PREFERENCES);
+ANJUTA_PLUGIN_ADD_INTERFACE(iindenter, IANJUTA_TYPE_INDENTER);
ANJUTA_PLUGIN_END;
ANJUTA_SIMPLE_PLUGIN (CppJavaPlugin, cpp_java_plugin);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]