[anjuta] language-support-cpp: bgo#633341 - Code completion should close parentheses
- From: Johannes Schmid <jhs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] language-support-cpp: bgo#633341 - Code completion should close parentheses
- Date: Wed, 4 Jan 2012 17:58:45 +0000 (UTC)
commit 10e4fd276167a2af7a6ed330e49d4b609933e281
Author: Peter Hoffmann <p_hoffmann rocketmail com>
Date: Wed Jan 4 18:43:27 2012 +0100
language-support-cpp: bgo#633341 - Code completion should close parentheses
.../anjuta-language-cpp-java.ui | 17 +++
.../language-support-cpp-java/cpp-java-assist.c | 125 ++++++++++++++++++++
.../org.gnome.anjuta.cpp.gschema.xml.in | 5 +-
plugins/language-support-cpp-java/plugin.c | 3 +
4 files changed, 149 insertions(+), 1 deletions(-)
---
diff --git a/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui b/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui
index 8f48f3d..ba18ea8 100644
--- a/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui
+++ b/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui
@@ -424,6 +424,23 @@
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="preferences_toggle:bool:1:1:cpp-completion-closebrace-after-func">
+ <property name="label" translatable="yes">Add ')' after function call autocompletion</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="border_width">5</property>
+ <property name="use_action_appearance">False</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/plugins/language-support-cpp-java/cpp-java-assist.c b/plugins/language-support-cpp-java/cpp-java-assist.c
index 967402f..4e72329 100644
--- a/plugins/language-support-cpp-java/cpp-java-assist.c
+++ b/plugins/language-support-cpp-java/cpp-java-assist.c
@@ -42,6 +42,7 @@
#define PREF_AUTOCOMPLETE_ENABLE "cpp-completion-enable"
#define PREF_AUTOCOMPLETE_SPACE_AFTER_FUNC "cpp-completion-space-after-func"
#define PREF_AUTOCOMPLETE_BRACE_AFTER_FUNC "cpp-completion-brace-after-func"
+#define PREF_AUTOCOMPLETE_CLOSEBRACE_AFTER_FUNC "cpp-completion-closebrace-after-func"
#define PREF_CALLTIP_ENABLE "cpp-calltip-enable"
#define BRACE_SEARCH_LIMIT 500
@@ -98,6 +99,11 @@ struct _CppJavaAssistPriv {
/* Member autocompletion */
IAnjutaSymbolQuery *query_members;
+
+ /* Sync query */
+ IAnjutaSymbolQuery *sync_query_file;
+ IAnjutaSymbolQuery *sync_query_system;
+ IAnjutaSymbolQuery *sync_query_project;
};
typedef struct
@@ -1204,6 +1210,7 @@ cpp_java_assist_activate (IAnjutaProvider* self, IAnjutaIterable* iter, gpointer
IAnjutaEditor *te;
gboolean add_space_after_func = FALSE;
gboolean add_brace_after_func = FALSE;
+ gboolean add_closebrace_after_func = FALSE;
g_return_if_fail (prop_data != NULL);
@@ -1217,6 +1224,9 @@ cpp_java_assist_activate (IAnjutaProvider* self, IAnjutaIterable* iter, gpointer
add_brace_after_func =
g_settings_get_boolean (assist->priv->settings,
PREF_AUTOCOMPLETE_BRACE_AFTER_FUNC);
+ add_closebrace_after_func =
+ g_settings_get_boolean (assist->priv->settings,
+ PREF_AUTOCOMPLETE_CLOSEBRACE_AFTER_FUNC);
if (!cpp_java_assist_find_next_brace (assist, iter))
{
@@ -1242,6 +1252,57 @@ cpp_java_assist_activate (IAnjutaProvider* self, IAnjutaIterable* iter, gpointer
{
ianjuta_editor_insert (te, iter, assistance->str, -1, NULL);
}
+
+ if (add_brace_after_func && add_closebrace_after_func)
+ {
+ IAnjutaIterable *pos = ianjuta_iterable_clone (iter, NULL);
+
+ ianjuta_iterable_set_position (pos,
+ ianjuta_iterable_get_position (assist->priv->start_iter, NULL)
+ + strlen (assistance->str),
+ NULL);
+ ianjuta_editor_insert (te, pos, ")", -1, NULL);
+ ianjuta_editor_goto_position (te, pos, NULL);
+
+ ianjuta_iterable_previous (pos, NULL);
+ gchar *context = cpp_java_assist_get_calltip_context (assist, pos);
+ g_object_unref (pos);
+ IAnjutaIterable *symbol = NULL;
+ if (IANJUTA_IS_FILE (assist->priv->iassist))
+ {
+ GFile *file = ianjuta_file_get_file (IANJUTA_FILE (assist->priv->iassist), NULL);
+ if (file != NULL)
+ {
+ symbol =
+ ianjuta_symbol_query_search_file (assist->priv->sync_query_file,
+ context, file, NULL);
+ g_object_unref (file);
+ }
+ }
+ if (!symbol)
+ {
+ symbol =
+ ianjuta_symbol_query_search (assist->priv->sync_query_project, context, NULL);
+ }
+ if (!symbol)
+ {
+ symbol =
+ ianjuta_symbol_query_search (assist->priv->sync_query_system, context, NULL);
+ }
+ const gchar* signature =
+ ianjuta_symbol_get_string (IANJUTA_SYMBOL(symbol),
+ IANJUTA_SYMBOL_FIELD_SIGNATURE, NULL);
+ if (!g_strcmp0 (signature, "(void)") || !g_strcmp0 (signature, "()"))
+ {
+ pos = ianjuta_editor_get_position (te, NULL);
+ ianjuta_iterable_next (pos, NULL);
+ ianjuta_editor_goto_position (te, pos, NULL);
+ }
+ g_object_unref (symbol);
+ g_object_unref (pos);
+ g_free (context);
+ }
+
ianjuta_document_end_undo_action (IANJUTA_DOCUMENT (te), NULL);
/* Show calltip if we completed function */
@@ -1380,6 +1441,18 @@ cpp_java_assist_finalize (GObject *object)
g_object_unref (priv->query_members);
priv->query_members = NULL;
+ if (priv->sync_query_file)
+ g_object_unref (priv->sync_query_file);
+ priv->sync_query_file = NULL;
+
+ if (priv->sync_query_system)
+ g_object_unref (priv->sync_query_system);
+ priv->sync_query_system = NULL;
+
+ if (priv->sync_query_project)
+ g_object_unref (priv->sync_query_project);
+ priv->sync_query_project = NULL;
+
engine_parser_deinit ();
g_free (assist->priv);
@@ -1547,6 +1620,58 @@ cpp_java_assist_new (IAnjutaEditor *ieditor,
ianjuta_symbol_query_set_fields (assist->priv->query_members,
G_N_ELEMENTS (ac_fields),
ac_fields, NULL);
+
+ /* Create sync queries */
+ /* Sync query in file */
+ assist->priv->sync_query_file =
+ ianjuta_symbol_manager_create_query (isymbol_manager,
+ IANJUTA_SYMBOL_QUERY_SEARCH_FILE,
+ IANJUTA_SYMBOL_QUERY_DB_PROJECT,
+ NULL);
+ ianjuta_symbol_query_set_fields (assist->priv->sync_query_file,
+ G_N_ELEMENTS (calltip_fields),
+ calltip_fields, NULL);
+ ianjuta_symbol_query_set_filters (assist->priv->sync_query_file,
+ IANJUTA_SYMBOL_TYPE_PROTOTYPE |
+ IANJUTA_SYMBOL_TYPE_FUNCTION |
+ IANJUTA_SYMBOL_TYPE_METHOD |
+ IANJUTA_SYMBOL_TYPE_MACRO_WITH_ARG,
+ TRUE, NULL);
+ ianjuta_symbol_query_set_file_scope (assist->priv->sync_query_file,
+ IANJUTA_SYMBOL_QUERY_SEARCH_FS_PRIVATE, NULL);
+ /* Sync query in project */
+ assist->priv->sync_query_project =
+ ianjuta_symbol_manager_create_query (isymbol_manager,
+ IANJUTA_SYMBOL_QUERY_SEARCH,
+ IANJUTA_SYMBOL_QUERY_DB_PROJECT,
+ NULL);
+ ianjuta_symbol_query_set_fields (assist->priv->sync_query_project,
+ G_N_ELEMENTS (calltip_fields),
+ calltip_fields, NULL);
+ ianjuta_symbol_query_set_filters (assist->priv->sync_query_project,
+ IANJUTA_SYMBOL_TYPE_PROTOTYPE |
+ IANJUTA_SYMBOL_TYPE_METHOD |
+ IANJUTA_SYMBOL_TYPE_MACRO_WITH_ARG,
+ TRUE, NULL);
+ ianjuta_symbol_query_set_file_scope (assist->priv->sync_query_project,
+ IANJUTA_SYMBOL_QUERY_SEARCH_FS_PUBLIC, NULL);
+ /* Sync query in system */
+ assist->priv->sync_query_system =
+ ianjuta_symbol_manager_create_query (isymbol_manager,
+ IANJUTA_SYMBOL_QUERY_SEARCH,
+ IANJUTA_SYMBOL_QUERY_DB_SYSTEM,
+ NULL);
+ ianjuta_symbol_query_set_fields (assist->priv->sync_query_system,
+ G_N_ELEMENTS (calltip_fields),
+ calltip_fields, NULL);
+ ianjuta_symbol_query_set_filters (assist->priv->sync_query_system,
+ IANJUTA_SYMBOL_TYPE_PROTOTYPE |
+ IANJUTA_SYMBOL_TYPE_METHOD |
+ IANJUTA_SYMBOL_TYPE_MACRO_WITH_ARG,
+ TRUE, NULL);
+ ianjuta_symbol_query_set_file_scope (assist->priv->sync_query_system,
+ IANJUTA_SYMBOL_QUERY_SEARCH_FS_PUBLIC, NULL);
+
/* Install support */
cpp_java_assist_install (assist, ieditor);
diff --git a/plugins/language-support-cpp-java/org.gnome.anjuta.cpp.gschema.xml.in b/plugins/language-support-cpp-java/org.gnome.anjuta.cpp.gschema.xml.in
index 77671ff..9d87419 100644
--- a/plugins/language-support-cpp-java/org.gnome.anjuta.cpp.gschema.xml.in
+++ b/plugins/language-support-cpp-java/org.gnome.anjuta.cpp.gschema.xml.in
@@ -36,6 +36,9 @@
<key name="cpp-completion-brace-after-func" type="b">
<default>true</default>
</key>
+ <key name="cpp-completion-closebrace-after-func" type="b">
+ <default>true</default>
+ </key>
<key name="cpp-brace-autocompletion" type="b">
<default>false</default>
</key>
@@ -52,4 +55,4 @@
<default>true</default>
</key>
</schema>
-</schemalist>
\ No newline at end of file
+</schemalist>
diff --git a/plugins/language-support-cpp-java/plugin.c b/plugins/language-support-cpp-java/plugin.c
index afaa2d5..a14b063 100644
--- a/plugins/language-support-cpp-java/plugin.c
+++ b/plugins/language-support-cpp-java/plugin.c
@@ -1342,6 +1342,7 @@ cpp_java_plugin_class_init (GObjectClass *klass)
#define PREF_WIDGET_SPACE "preferences_toggle:bool:1:1:cpp-completion-space-after-func"
#define PREF_WIDGET_BRACE "preferences_toggle:bool:1:1:cpp-completion-brace-after-func"
+#define PREF_WIDGET_CLOSEBRACE "preferences_toggle:bool:1:1:cpp-completion-closebrace-after-func"
#define PREF_WIDGET_AUTO "preferences_toggle:bool:1:1:cpp-completion-enable"
#define PREF_WIDGET_PACKAGES "preferences_toggle:bool:1:1:cpp-load-project-packages"
#define PREF_WIDGET_PKG_CONFIG "pkg_config_chooser1"
@@ -1357,6 +1358,8 @@ on_autocompletion_toggled (GtkToggleButton* button,
gtk_widget_set_sensitive (widget, sensitive);
widget = GTK_WIDGET (gtk_builder_get_object (plugin->bxml, PREF_WIDGET_BRACE));
gtk_widget_set_sensitive (widget, sensitive);
+ widget = GTK_WIDGET (gtk_builder_get_object (plugin->bxml, PREF_WIDGET_CLOSEBRACE));
+ gtk_widget_set_sensitive (widget, sensitive);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]