anjuta r4563 - in trunk: . libanjuta/interfaces plugins/language-support-cpp-java plugins/sourceview



Author: jhs
Date: Sat Jan 10 18:18:41 2009
New Revision: 4563
URL: http://svn.gnome.org/viewvc/anjuta?rev=4563&view=rev

Log:
2009-01-10  Johannes Schmid  <jhs Obelix>

	* libanjuta/interfaces/libanjuta.idl:
	* plugins/sourceview/sourceview.c (on_backspace):
	Added "backspace" signal:
	#567068 â autocomplete box should vanish on backspace
	
	* plugins/language-support-cpp-java/Makefile.am:
	* plugins/language-support-cpp-java/cpp-java-assist.c
	(cpp_java_assist_destroy_completion_cache),
	(cpp_java_assist_create_scope_completion_cache),
	(cpp_java_assist_show_autocomplete),
	(cpp_java_assist_create_word_completion_cache),
	(cpp_java_assist_create_calltips), (cpp_java_assist_show_calltip),
	(cpp_java_assist_check), (on_editor_backspace),
	(cpp_java_assist_install), (cpp_java_assist_uninstall),
	(cpp_java_assist_finalize):
	#566987 â display tooltip with prototype when calling function in project
	#566693 â Code completion of symbols usually not working

Modified:
   trunk/ChangeLog
   trunk/libanjuta/interfaces/libanjuta.idl
   trunk/plugins/language-support-cpp-java/Makefile.am
   trunk/plugins/language-support-cpp-java/cpp-java-assist.c
   trunk/plugins/sourceview/sourceview.c

Modified: trunk/libanjuta/interfaces/libanjuta.idl
==============================================================================
--- trunk/libanjuta/interfaces/libanjuta.idl	(original)
+++ trunk/libanjuta/interfaces/libanjuta.idl	Sat Jan 10 18:18:41 2009
@@ -1205,6 +1205,14 @@
 	 * The newly added character is @ch which has been inserted at @position.
 	 */
 	void   ::char_added (GObject *position, gchar ch);
+
+	/**
+	 * IAnjutaEditor::backspace:
+	 * @obj: Self
+	 * 
+	 * The signal is emitted when the user presses backspace
+	 */
+	void   ::backspace ();
 	
 	/**
 	 * IAnjutaEditor::changed:

Modified: trunk/plugins/language-support-cpp-java/Makefile.am
==============================================================================
--- trunk/plugins/language-support-cpp-java/Makefile.am	(original)
+++ trunk/plugins/language-support-cpp-java/Makefile.am	Sat Jan 10 18:18:41 2009
@@ -37,7 +37,8 @@
 AM_CPPFLAGS = \
 	$(WARN_CFLAGS) \
 	$(DEPRECATED_FLAGS) \
-	$(LIBANJUTA_CFLAGS)
+	$(LIBANJUTA_CFLAGS) \
+	-DG_LOG_DOMAIN=\"language-support-cpp-java\"
 
 # Where to install the plugin
 plugindir = $(anjuta_plugin_dir)

Modified: trunk/plugins/language-support-cpp-java/cpp-java-assist.c
==============================================================================
--- trunk/plugins/language-support-cpp-java/cpp-java-assist.c	(original)
+++ trunk/plugins/language-support-cpp-java/cpp-java-assist.c	Sat Jan 10 18:18:41 2009
@@ -58,8 +58,10 @@
 	/* Last used cache */
 	gchar *search_cache;
 	gchar *scope_context_cache;
+	gchar *pre_word;
 	GCompletion *completion_cache;
 	gboolean editor_only;
+	guint word_idle;
 };
 
 static gchar*
@@ -305,7 +307,8 @@
 }
 
 static void
-cpp_java_assist_destroy_completion_cache (CppJavaAssist *assist)
+cpp_java_assist_destroy_completion_cache (CppJavaAssist *assist,
+										  gboolean cancel_idle)
 {
 	if (assist->priv->search_cache)
 	{
@@ -328,15 +331,20 @@
 		g_completion_free (assist->priv->completion_cache);
 		assist->priv->completion_cache = NULL;
 	}
+	if (assist->priv->word_idle > 0 && cancel_idle)
+	{
+		g_source_remove (assist->priv->word_idle);
+		assist->priv->word_idle = 0;
+	}
 }
 
 static void
 cpp_java_assist_create_scope_completion_cache (CppJavaAssist *assist,
 											   const gchar *scope_operator,
 											   const gchar *scope_context)
-{
+{		
 	DEBUG_PRINT ("scope context: %s", scope_context);
-	cpp_java_assist_destroy_completion_cache (assist);
+	cpp_java_assist_destroy_completion_cache (assist, TRUE);
 	if (g_str_equal (scope_operator, "::"))
 	{
 		/* Go through the possible namespace (Gnome::Glade, for example) */
@@ -413,6 +421,7 @@
 		}
 		g_strfreev(contexts);
 	}
+	
 	else if (g_str_equal (scope_operator, ".") ||
 			 g_str_equal (scope_operator, "->"))	
 	{
@@ -421,84 +430,8 @@
 	}	
 }
 
-static void
-cpp_java_assist_create_word_completion_cache (CppJavaAssist *assist,
-											  const gchar *pre_word)
-{
-	gint max_completions;
-	GCompletion *completion = NULL;
-	GList* editor_completions = NULL;
-	assist->priv->editor_only = FALSE;
-	max_completions =
-		anjuta_preferences_get_int_with_default (assist->priv->preferences,
-												 PREF_AUTOCOMPLETE_CHOICES,
-												 MAX_COMPLETIONS);
-	
-	cpp_java_assist_destroy_completion_cache (assist);
-	
-	IAnjutaIterable* iter_project = 
-		ianjuta_symbol_manager_search (assist->priv->isymbol_manager,
-									    IANJUTA_SYMBOL_TYPE_MAX,
-									    TRUE,
-										IANJUTA_SYMBOL_FIELD_SIMPLE|IANJUTA_SYMBOL_FIELD_TYPE,
-										pre_word, TRUE, TRUE, FALSE, -1, -1, NULL);
-	
-	IAnjutaIterable* iter_globals = 
-		ianjuta_symbol_manager_search (assist->priv->isymbol_manager,
-										IANJUTA_SYMBOL_TYPE_MAX,
-									    TRUE,
-										IANJUTA_SYMBOL_FIELD_SIMPLE|IANJUTA_SYMBOL_FIELD_TYPE,
-										pre_word, TRUE, TRUE, TRUE, -1, -1, NULL);
-
-	if (iter_project) 
-	{
-		completion = create_completion (assist->priv->iassist, iter_project, NULL);
-		g_object_unref (iter_project);
-	}
-	
-	if (iter_globals)
-	{
-		
-		completion = create_completion (assist->priv->iassist, iter_globals, completion);
-		g_object_unref (iter_globals);
-	}
-	
-		editor_completions = ianjuta_editor_assist_get_suggestions (assist->priv->iassist,
-																	pre_word,
-																	NULL);
-	if (editor_completions)
-	{
-		GList* tag_list = NULL;
-		GList* node;
-		for (node = editor_completions; node != NULL; node = g_list_next (node))
-		{
-			CppJavaAssistTag *tag = g_new0 (CppJavaAssistTag, 1);
-			tag->name = node->data;
-			tag->type = 0;
-			tag->is_func = FALSE;
-			if (completion && !g_list_find_custom (completion->items, tag, 
-												   completion_compare))
-				tag_list = g_list_append (tag_list, tag);
-			else
-				cpp_java_assist_tag_destroy (tag);
-		}
-		if (!completion)
-		{
-			completion = g_completion_new(completion_function);
-			assist->priv->editor_only = TRUE;
-		}
-		tag_list = g_list_sort (tag_list, completion_compare);
-		g_completion_add_items (completion, tag_list);		
-		g_list_free (editor_completions);
-	}
-	
-	assist->priv->completion_cache = completion;
-	assist->priv->search_cache = g_strdup (pre_word);
-}
-
 static gboolean
-cpp_java_assist_show_autocomplete (CppJavaAssist *assist,
-								   const gchar *pre_word)
+cpp_java_assist_show_autocomplete (CppJavaAssist *assist)
 {
 	IAnjutaIterable *position;
 	gint max_completions, length;
@@ -506,8 +439,8 @@
 
 	if (assist->priv->completion_cache == NULL) return FALSE;	
 	
-	if (pre_word)
-		g_completion_complete (assist->priv->completion_cache, pre_word, NULL);
+	if (assist->priv->pre_word)
+		g_completion_complete (assist->priv->completion_cache, assist->priv->pre_word, NULL);
 	else
 		g_completion_complete (assist->priv->completion_cache, "", NULL);
 
@@ -527,7 +460,7 @@
 	 * scope operator where there is no preword yet entered. So use the
 	 * full list because that's the full list of members of that scope.
 	 */
-	else if (!pre_word)
+	else if (!assist->priv->pre_word)
 		completion_list = assist->priv->completion_cache->items;
 		
 	else
@@ -536,8 +469,8 @@
 	length = g_list_length (completion_list);
 	if (length <= max_completions)
 	{
-		if (length > 1 || !pre_word ||
-			!g_str_equal (pre_word,
+		if (length > 1 || !assist->priv->pre_word ||
+			!g_str_equal (assist->priv->pre_word,
 						  ((CppJavaAssistTag*)completion_list->data)->name))
 		{
 			GList *node, *suggestions = NULL;
@@ -558,7 +491,7 @@
 				node = g_list_next (node);
 			}
 			suggestions = g_list_reverse (suggestions);
-			alignment = pre_word? strlen (pre_word) : 0;
+			alignment = assist->priv->pre_word? strlen (assist->priv->pre_word) : 0;
 			
 			ianjuta_editor_assist_suggest (assist->priv->iassist,
 										   suggestions,
@@ -575,6 +508,94 @@
 	return FALSE;
 }
 
+static gboolean
+cpp_java_assist_create_word_completion_cache (CppJavaAssist *assist)
+{
+	gint max_completions;
+	GCompletion *completion = NULL;
+	GList* editor_completions = NULL;
+	gboolean shown = FALSE;
+
+	max_completions =
+		anjuta_preferences_get_int_with_default (assist->priv->preferences,
+												 PREF_AUTOCOMPLETE_CHOICES,
+												 MAX_COMPLETIONS);
+	
+	cpp_java_assist_destroy_completion_cache (assist, FALSE);
+	
+	if (!assist->priv->editor_only)
+	{
+		IAnjutaIterable* iter_project = 
+			ianjuta_symbol_manager_search (assist->priv->isymbol_manager,
+										   IANJUTA_SYMBOL_TYPE_MAX,
+										   TRUE,
+										   IANJUTA_SYMBOL_FIELD_SIMPLE|IANJUTA_SYMBOL_FIELD_TYPE,
+										   assist->priv->pre_word, TRUE, FALSE, FALSE, -1, -1, NULL);
+		
+		IAnjutaIterable* iter_globals = 
+			ianjuta_symbol_manager_search (assist->priv->isymbol_manager,
+										   IANJUTA_SYMBOL_TYPE_MAX,
+										   TRUE,
+										   IANJUTA_SYMBOL_FIELD_SIMPLE|IANJUTA_SYMBOL_FIELD_TYPE,
+										   assist->priv->pre_word, TRUE, TRUE, TRUE, -1, -1, NULL);
+		
+		if (iter_project) 
+		{
+			completion = create_completion (assist->priv->iassist, iter_project, NULL);
+			g_object_unref (iter_project);
+		}
+		
+		if (iter_globals)
+		{
+			
+			completion = create_completion (assist->priv->iassist, iter_globals, completion);
+			g_object_unref (iter_globals);
+		}
+	}
+	editor_completions = ianjuta_editor_assist_get_suggestions (assist->priv->iassist,
+																assist->priv->pre_word,
+																NULL);
+	if (editor_completions)
+	{
+		GList* tag_list = NULL;
+		GList* node;
+		for (node = editor_completions; node != NULL; node = g_list_next (node))
+		{
+			CppJavaAssistTag *tag = g_new0 (CppJavaAssistTag, 1);
+			tag->name = node->data;
+			tag->type = 0;
+			tag->is_func = FALSE;
+			if (completion && !g_list_find_custom (completion->items, tag, 
+												   completion_compare))
+				tag_list = g_list_append (tag_list, tag);
+			else
+				cpp_java_assist_tag_destroy (tag);
+		}
+		if (!completion)
+		{
+			completion = g_completion_new(completion_function);
+			assist->priv->editor_only = TRUE;
+		}
+		else
+			assist->priv->editor_only = FALSE;
+
+		tag_list = g_list_sort (tag_list, completion_compare);
+		g_completion_add_items (completion, tag_list);		
+		g_list_free (editor_completions);
+	}
+	
+	assist->priv->completion_cache = completion;
+	assist->priv->search_cache = g_strdup (assist->priv->pre_word);
+	
+	shown = cpp_java_assist_show_autocomplete (assist);
+	if (!shown)
+		ianjuta_editor_assist_hide_suggestions (assist->priv->iassist,
+												NULL);
+	DEBUG_PRINT ("Show autocomplete: %d", shown);
+	
+	return FALSE;
+}
+
 static gchar*
 cpp_java_assist_get_calltip_context (CppJavaAssist *assist,
 									 IAnjutaIterable *iter,
@@ -615,28 +636,10 @@
 	return context;
 }
 
-static gboolean
-cpp_java_assist_show_calltip (CppJavaAssist *assist, gchar *call_context,
-							  gint context_offset,
-							  IAnjutaIterable *position_iter)
+static GList*
+cpp_java_assist_create_calltips (IAnjutaIterable* iter)
 {
-	GList *tips = NULL;
-	gint max_completions;
-	
-	max_completions =
-		anjuta_preferences_get_int_with_default (assist->priv->preferences,
-												 PREF_AUTOCOMPLETE_CHOICES,
-												 MAX_COMPLETIONS);
-
-	IAnjutaIterable* iter = 
-		ianjuta_symbol_manager_search (assist->priv->isymbol_manager,
-									   IANJUTA_SYMBOL_TYPE_PROTOTYPE|
-									   IANJUTA_SYMBOL_TYPE_FUNCTION|
-									   IANJUTA_SYMBOL_TYPE_METHOD|
-									   IANJUTA_SYMBOL_TYPE_MACRO_WITH_ARG,
-									   TRUE, IANJUTA_SYMBOL_FIELD_SIMPLE,
-									   call_context, FALSE, TRUE, TRUE,
-									   max_completions, -1, NULL);
+	GList* tips = NULL;
 	if (iter)
 	{
 		do
@@ -674,23 +677,61 @@
 				break;
 		}
 		while (ianjuta_iterable_next (iter, NULL));
+	}
+	return tips;
+}
+
+static gboolean
+cpp_java_assist_show_calltip (CppJavaAssist *assist, gchar *call_context,
+							  gint context_offset,
+							  IAnjutaIterable *position_iter)
+{	
+	GList *tips = NULL;
+	gint max_completions;
+	
+	max_completions =
+		anjuta_preferences_get_int_with_default (assist->priv->preferences,
+												 PREF_AUTOCOMPLETE_CHOICES,
+												 MAX_COMPLETIONS);
+	/* Search global */
+	IAnjutaIterable* iter_global = 
+		ianjuta_symbol_manager_search (assist->priv->isymbol_manager,
+									   IANJUTA_SYMBOL_TYPE_PROTOTYPE|
+									   IANJUTA_SYMBOL_TYPE_FUNCTION|
+									   IANJUTA_SYMBOL_TYPE_METHOD|
+									   IANJUTA_SYMBOL_TYPE_MACRO_WITH_ARG,
+									   TRUE, IANJUTA_SYMBOL_FIELD_SIMPLE,
+									   call_context, FALSE, TRUE, TRUE,
+									   max_completions, -1, NULL);
+	tips = cpp_java_assist_create_calltips (iter_global);
+	/* Search Project */
+	IAnjutaIterable* iter_project = 
+		ianjuta_symbol_manager_search (assist->priv->isymbol_manager,
+									   IANJUTA_SYMBOL_TYPE_PROTOTYPE|
+									   IANJUTA_SYMBOL_TYPE_FUNCTION|
+									   IANJUTA_SYMBOL_TYPE_METHOD|
+									   IANJUTA_SYMBOL_TYPE_MACRO_WITH_ARG,
+									   TRUE, IANJUTA_SYMBOL_FIELD_SIMPLE,
+									   call_context, FALSE, TRUE, FALSE,
+									   max_completions, -1, NULL);
+	tips = g_list_concat (tips, cpp_java_assist_create_calltips (iter_project));
+	g_object_unref (iter_global);
+	g_object_unref (iter_project);
+	if (tips)
+	{
+		/* Calculate calltip offset from context offset */
+		gint char_alignment =
+			get_iter_column (assist, position_iter)- context_offset;
 		
-		if (tips)
-		{
-			/* Calculate calltip offset from context offset */
-			gint char_alignment =
-				get_iter_column (assist, position_iter)- context_offset;
-			
-			if (char_alignment < 0)
-				char_alignment = context_offset;
-			
-			ianjuta_editor_assist_show_tips (assist->priv->iassist, tips,
-											 position_iter, char_alignment,
-											 NULL);
-			g_list_foreach (tips, (GFunc) g_free, NULL);
-			g_list_free (tips);
-			return TRUE;
-		}
+		if (char_alignment < 0)
+			char_alignment = context_offset;
+		
+		ianjuta_editor_assist_show_tips (assist->priv->iassist, tips,
+										 position_iter, char_alignment,
+										 NULL);
+		g_list_foreach (tips, (GFunc) g_free, NULL);
+		g_list_free (tips);
+		return TRUE;
 	}
 	return FALSE;
 }
@@ -701,13 +742,7 @@
 {
 	gboolean shown = FALSE;
 	IAnjutaEditor *editor;
-	IAnjutaIterable *iter, *iter_save;
-	IAnjutaEditorAttribute attribute;
-	gchar *pre_word = NULL, *scope_operator = NULL;
-	GTimer* timer = g_timer_new ();
-	
-	//DEBUG_PRINT ("Autocomplete enable is: %d", autocomplete);
-	//DEBUG_PRINT ("Calltips enable is: %d", calltips);
+	IAnjutaIterable *iter, *iter_save;	
 	
 	if (!autocomplete && !calltips)
 		return FALSE; /* Nothing to do */
@@ -717,71 +752,31 @@
 	iter = ianjuta_editor_get_position (editor, NULL);
 	ianjuta_iterable_previous (iter, NULL);
 	iter_save = ianjuta_iterable_clone (iter, NULL);
-		
-	attribute = ianjuta_editor_cell_get_attribute (IANJUTA_EDITOR_CELL (iter),
-												   NULL);
-	/*
-	if (attribute == IANJUTA_EDITOR_COMMENT ||
-		attribute == IANJUTA_EDITOR_STRING);
-	{
-		g_object_unref (iter);
-		g_object_unref (iter_save);
-		return FALSE;
-	}
-	*/
-	
-	DEBUG_PRINT ("assist init: %f", g_timer_elapsed (timer, NULL));
 	
 	if (autocomplete)
 	{
-		pre_word = cpp_java_assist_get_pre_word (editor, iter);
-		DEBUG_PRINT ("assist pre word: %f", g_timer_elapsed (timer, NULL));
+		gboolean shown = FALSE;
+		g_free (assist->priv->pre_word);
+		assist->priv->pre_word = cpp_java_assist_get_pre_word (editor, iter);
+		DEBUG_PRINT ("Pre word: %s", assist->priv->pre_word);
 		
-		scope_operator = cpp_java_assist_get_scope_operator (editor, iter);
-		DEBUG_PRINT ("assist scope operator: %f", g_timer_elapsed (timer, NULL));
-		
-		DEBUG_PRINT ("Pre word: %s", pre_word);
-		DEBUG_PRINT ("Scope op: %s", scope_operator);
-		
-		if (scope_operator)
-		{
-			gchar *scope_context = NULL;
-			scope_context = cpp_java_assist_get_scope_context (editor,
-															   scope_operator,
-															   iter);
-			
-			DEBUG_PRINT ("Scope context: %s", scope_context);
-			
-			if (scope_context)
-			{
-				if (!assist->priv->scope_context_cache ||
-					strcmp (scope_context,
-							assist->priv->scope_context_cache) != 0)
-				{
-					cpp_java_assist_create_scope_completion_cache (assist,
-																   scope_operator,
-																   scope_context);
-				}
-				shown = cpp_java_assist_show_autocomplete (assist, pre_word);
-			}
-			g_free (scope_context);
-		}
-		else if (pre_word && strlen (pre_word) > 3)
+		if (assist->priv->pre_word && strlen (assist->priv->pre_word) > 3)
 		{
 			if (!assist->priv->search_cache ||
-				!g_str_has_prefix (pre_word,
-						 assist->priv->search_cache) || assist->priv->editor_only)
+				!g_str_has_prefix (assist->priv->pre_word, assist->priv->search_cache))
 			{
-				cpp_java_assist_create_word_completion_cache (assist, pre_word);
+				g_idle_add_full (G_PRIORITY_LOW,
+								 (GSourceFunc) cpp_java_assist_create_word_completion_cache,
+								 assist,
+								 NULL);
+				DEBUG_PRINT ("Idle source added");
 			}
-			shown = cpp_java_assist_show_autocomplete (assist, pre_word);
 		}
+		shown = cpp_java_assist_show_autocomplete (assist);
 		if (!shown)
-		{
 			ianjuta_editor_assist_hide_suggestions (assist->priv->iassist,
 													NULL);
-		}
-		DEBUG_PRINT ("assist autocomplete: %f", g_timer_elapsed (timer, NULL));
+		DEBUG_PRINT ("Show autocomplete: %d", shown);
 	}
 	if (calltips)
 	{
@@ -790,7 +785,6 @@
 			gint offset;
 			gchar *call_context =
 				cpp_java_assist_get_calltip_context (assist, iter, &offset);
-			DEBUG_PRINT ("get calltip context: %f", g_timer_elapsed (timer, NULL));
 			if (call_context)
 			{
 				shown = cpp_java_assist_show_calltip (assist, call_context,
@@ -802,14 +796,10 @@
 			}
 			g_free (call_context);
 		}
-		DEBUG_PRINT ("assist calltip: %f", g_timer_elapsed (timer, NULL));
 	}
 	
 	g_object_unref (iter);
 	g_object_unref (iter_save);
-	g_free (pre_word);
-	g_free (scope_operator);
-	g_timer_destroy (timer);
 	
 	return shown;
 }
@@ -831,6 +821,12 @@
 }
 
 static void
+on_editor_backspace (IAnjutaEditor* editor, CppJavaAssist* assist)
+{
+	on_editor_char_added (editor, NULL, '\b', assist);
+}
+
+static void
 on_assist_chosen (IAnjutaEditorAssist* iassist, gint selection,
 				  CppJavaAssist* assist)
 {
@@ -916,6 +912,8 @@
 	assist->priv->iassist = iassist;
 	g_signal_connect (iassist, "char-added",
 					  G_CALLBACK (on_editor_char_added), assist);
+	g_signal_connect (iassist, "backspace",
+					  G_CALLBACK (on_editor_backspace), assist);
 	g_signal_connect (iassist, "assist-chosen",
 					  G_CALLBACK(on_assist_chosen), assist);
 }
@@ -929,6 +927,10 @@
 	g_signal_handlers_disconnect_by_func (assist->priv->iassist,
 										  G_CALLBACK (on_editor_char_added),
 										  assist);
+ g_signal_handlers_disconnect_by_func (assist->priv->iassist,
+
+  G_CALLBACK (on_editor_backspace), assist);
+
 	assist->priv->iassist = NULL;
 }
 
@@ -943,7 +945,7 @@
 {
 	CppJavaAssist *assist = CPP_JAVA_ASSIST (object);
 	cpp_java_assist_uninstall (assist);
-	cpp_java_assist_destroy_completion_cache (assist);
+	cpp_java_assist_destroy_completion_cache (assist, TRUE);
 	g_free (assist->priv);
 	G_OBJECT_CLASS (cpp_java_assist_parent_class)->finalize (object);
 }

Modified: trunk/plugins/sourceview/sourceview.c
==============================================================================
--- trunk/plugins/sourceview/sourceview.c	(original)
+++ trunk/plugins/sourceview/sourceview.c	Sat Jan 10 18:18:41 2009
@@ -274,6 +274,7 @@
 static void on_backspace (GtkTextView* view,
 						  Sourceview* sv)
 {
+	g_signal_emit_by_name(G_OBJECT(sv), "backspace");
 	g_signal_emit_by_name(G_OBJECT(sv), "update_ui");
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]