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



Author: jhs
Date: Tue Mar 24 16:32:36 2009
New Revision: 4888
URL: http://svn.gnome.org/viewvc/anjuta?rev=4888&view=rev

Log:
2009-03-24  Johannes Schmid  <jhs gnome org>

	* libanjuta/interfaces/libanjuta.idl:
	Added ianjuta_editor_assist_tip_shown() to determine if a calltip is
	currently active.

	* plugins/language-support-cpp-java/cpp-java-assist.c
	(cpp_java_assist_get_calltip_context),
	(cpp_java_assist_show_calltip), (cpp_java_assist_check),
	(on_editor_char_added), (on_assist_chosen),
	(cpp_java_assist_finalize):

	* plugins/language-support-cpp-java/cpp-java-assist.h:
	* plugins/language-support-cpp-java/plugin.c (on_auto_complete):
	- Avoid jumping tooltips
	- Fix #574802 â show calltips makes the editing lag
	- Fixed backspace problems

	* plugins/scintilla/text_editor.c (iassist_show_tips),
	(iassist_tip_shown), (iassist_iface_init):
	Implemented changed calltip behaviour

	* plugins/sourceview/assist-tip.c (assist_tip_get_coordinates),
	(assist_tip_move):
	* plugins/sourceview/assist-tip.h:
	* plugins/sourceview/sourceview.c (iassist_show_tips),
	(iassist_tip_shown), (iassist_iface_init):
	Implemented changed calltip behaviour

Modified:
   trunk/ChangeLog
   trunk/libanjuta/interfaces/libanjuta.idl
   trunk/plugins/language-support-cpp-java/cpp-java-assist.c
   trunk/plugins/language-support-cpp-java/cpp-java-assist.h
   trunk/plugins/language-support-cpp-java/plugin.c
   trunk/plugins/scintilla/text_editor.c
   trunk/plugins/sourceview/assist-tip.c
   trunk/plugins/sourceview/assist-tip.h
   trunk/plugins/sourceview/sourceview.c

Modified: trunk/libanjuta/interfaces/libanjuta.idl
==============================================================================
--- trunk/libanjuta/interfaces/libanjuta.idl	(original)
+++ trunk/libanjuta/interfaces/libanjuta.idl	Tue Mar 24 16:32:36 2009
@@ -1945,6 +1945,15 @@
 		void cancel_tips ();
 		
 		/**
+		 * ianjuta_editor_assist_tip_shown:
+		 * @obj: Self
+		 * @err: Error propagation and reporting
+		 * 
+		 * Returns: whether a tooltip is crrently shown		
+		 */
+		gboolean tip_shown();
+		
+		/**
 		 * ianjuta_editor_assist_get_suggestions:
 		 * @obj: Self
 		 * @context: The context for the suggestions.

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	Tue Mar 24 16:32:36 2009
@@ -60,6 +60,8 @@
 	gchar *search_cache;
 	gchar *scope_context_cache;
 	gchar *pre_word;
+	gchar *calltip_context;
+	
 	GCompletion *completion_cache;
 	gboolean editor_only;
 	guint word_idle;
@@ -92,31 +94,6 @@
 	g_free (tag);
 }
 
-static gint
-get_iter_column (CppJavaAssist *assist, IAnjutaIterable *iter)
-{
-	gchar ch;
-	gint offset = 0;
-	gint tabsize =
-		ianjuta_editor_get_tabsize (IANJUTA_EDITOR (assist->priv->iassist),
-									NULL);
-	ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (iter),
-									   0, NULL);
-	
-	while (ch != '\n')
-	{
-		if (!ianjuta_iterable_previous (iter, NULL))
-			break;
-		if (ch == '\t')
-			offset += tabsize - 1;
-		offset++;
-		ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (iter),
-										   0, NULL);
-	}
-	//DEBUG_PRINT ("Iter column: %d", offset);
-	return offset;
-}
-
 static gboolean
 is_scope_context_character (gchar ch)
 {
@@ -151,7 +128,7 @@
 create_completion (IAnjutaEditorAssist* iassist, IAnjutaIterable* iter,
 				   GCompletion* mergeable)
 {	
-	GCompletion *completion;
+	GCompletion *completion;	
 	
 	if (mergeable == NULL)
 		completion = g_completion_new (completion_function);
@@ -629,11 +606,10 @@
 
 static gchar*
 cpp_java_assist_get_calltip_context (CppJavaAssist *assist,
-									 IAnjutaIterable *iter,
-									 gint *context_offset)
+                                     IAnjutaIterable *iter)
 {
 	gchar ch;
-	gchar *context = NULL;
+	gchar *context = NULL;	
 	
 	ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (iter), 0, NULL);
 	if (ch == ')')
@@ -655,14 +631,11 @@
 		&& g_ascii_isspace (ianjuta_editor_cell_get_char
 								(IANJUTA_EDITOR_CELL (iter), 0, NULL)));
 
-	
 	context = cpp_java_assist_get_scope_context
 		(IANJUTA_EDITOR (assist->priv->iassist), "(", iter);
-	
-	if (context_offset)
-	{
-		*context_offset = get_iter_column (assist, iter);
-	}
+
+	/* Point iter to the first character of the scope to align calltip correctly */
+	ianjuta_iterable_next (iter, NULL);
 	
 	return context;
 }
@@ -714,7 +687,6 @@
 
 static gboolean
 cpp_java_assist_show_calltip (CppJavaAssist *assist, gchar *call_context,
-							  gint context_offset,
 							  IAnjutaIterable *position_iter)
 {	
 	GList *tips = NULL;
@@ -782,16 +754,9 @@
 	}
 	
 	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,
+										 position_iter, 0,
 										 NULL);
 		g_list_foreach (tips, (GFunc) g_free, NULL);
 		g_list_free (tips);
@@ -800,40 +765,41 @@
 	return FALSE;
 }
 
-gboolean
+void
 cpp_java_assist_check (CppJavaAssist *assist, gboolean autocomplete,
-					   gboolean calltips)
+					   gboolean calltips, gboolean backspace)
 {
-	gboolean shown = FALSE;
 	IAnjutaEditor *editor;
-	IAnjutaIterable *iter, *iter_save;	
+	IAnjutaIterable *iter;
 	
 	if (!autocomplete && !calltips)
-		return FALSE; /* Nothing to do */
+		return; /* Nothing to do */
 	
 	editor = IANJUTA_EDITOR (assist->priv->iassist);
 	
 	iter = ianjuta_editor_get_position (editor, NULL);
 	ianjuta_iterable_previous (iter, NULL);
-	iter_save = ianjuta_iterable_clone (iter, NULL);
-	
+
 	if (autocomplete)
 	{
 		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);
-		
+
 		if (assist->priv->pre_word && strlen (assist->priv->pre_word) > 3)
 		{
 			if (!assist->priv->search_cache ||
-				!g_str_has_prefix (assist->priv->pre_word, assist->priv->search_cache))
+			    !g_str_has_prefix (assist->priv->pre_word, assist->priv->search_cache))
 			{
-				g_idle_add_full (G_PRIORITY_LOW,
-								 (GSourceFunc) cpp_java_assist_create_word_completion_cache,
-								 assist,
-								 NULL);
-				DEBUG_PRINT ("Idle source added");
+				if (!backspace)
+				{
+					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);
 		}
@@ -841,33 +807,42 @@
 			shown = FALSE;
 		if (!shown)
 			ianjuta_editor_assist_hide_suggestions (assist->priv->iassist,
-													NULL);
+			                                        NULL);
 		DEBUG_PRINT ("Show autocomplete: %d", shown);
 	}
 	if (calltips)
 	{
-		if (!shown)
+		gchar *call_context =
+			cpp_java_assist_get_calltip_context (assist, iter);
+		if (call_context)
 		{
-			gint offset;
-			gchar *call_context =
-				cpp_java_assist_get_calltip_context (assist, iter, &offset);
-			if (call_context)
+			if (ianjuta_editor_assist_tip_shown (IANJUTA_EDITOR_ASSIST (editor), NULL))
 			{
-				shown = cpp_java_assist_show_calltip (assist, call_context,
-													  offset, iter_save);
+				if (!g_str_equal (call_context, assist->priv->calltip_context))
+				{
+					cpp_java_assist_show_calltip (assist, call_context,
+					                              iter);
+					g_free (assist->priv->calltip_context);
+					assist->priv->calltip_context = g_strdup(call_context);
+				}
 			}
 			else
 			{
-				ianjuta_editor_assist_cancel_tips (assist->priv->iassist, NULL);
+				cpp_java_assist_show_calltip (assist, call_context,
+				                              iter);
+				g_free (assist->priv->calltip_context);
+				assist->priv->calltip_context = g_strdup(call_context);
 			}
-			g_free (call_context);
 		}
+		else
+		{
+			ianjuta_editor_assist_cancel_tips (assist->priv->iassist, NULL);
+			g_free (assist->priv->calltip_context);
+			assist->priv->calltip_context = NULL;
+		}
+		g_free (call_context);
 	}
-	
-	g_object_unref (iter);
-	g_object_unref (iter_save);
-	
-	return shown;
+	g_object_unref (iter);	
 }
 
 static void
@@ -883,7 +858,7 @@
 		anjuta_preferences_get_bool_with_default (assist->priv->preferences,
 												 PREF_CALLTIP_ENABLE,
 												 TRUE);
-	cpp_java_assist_check (assist, enable_complete, enable_calltips);
+	cpp_java_assist_check (assist, enable_complete, enable_calltips, ch == '\b');
 }
 
 static void
@@ -965,7 +940,7 @@
 	
 	/* Show calltip if we completed function */
 	if (add_brace_after_func)
-		cpp_java_assist_check (assist, FALSE, TRUE);
+		cpp_java_assist_check (assist, FALSE, TRUE, FALSE);
 	
 	g_string_free (assistance, TRUE);
 }
@@ -1012,6 +987,11 @@
 	CppJavaAssist *assist = CPP_JAVA_ASSIST (object);
 	cpp_java_assist_uninstall (assist);
 	cpp_java_assist_destroy_completion_cache (assist, TRUE);
+	if (assist->priv->calltip_context)
+	{
+		g_free (assist->priv->calltip_context);
+		assist->priv->calltip_context = NULL;
+	}
 	g_free (assist->priv);
 	G_OBJECT_CLASS (cpp_java_assist_parent_class)->finalize (object);
 }

Modified: trunk/plugins/language-support-cpp-java/cpp-java-assist.h
==============================================================================
--- trunk/plugins/language-support-cpp-java/cpp-java-assist.h	(original)
+++ trunk/plugins/language-support-cpp-java/cpp-java-assist.h	Tue Mar 24 16:32:36 2009
@@ -65,8 +65,8 @@
 CppJavaAssist *cpp_java_assist_new (IAnjutaEditorAssist *assist,
 									IAnjutaSymbolManager *isymbol_manager,
 									AnjutaPreferences *preferences);
-gboolean cpp_java_assist_check (CppJavaAssist *assist, gboolean autocomplete,
-								gboolean calltips);
+void cpp_java_assist_check (CppJavaAssist *assist, gboolean autocomplete,
+								gboolean calltips, gboolean backspace);
 
 G_END_DECLS
 

Modified: trunk/plugins/language-support-cpp-java/plugin.c
==============================================================================
--- trunk/plugins/language-support-cpp-java/plugin.c	(original)
+++ trunk/plugins/language-support-cpp-java/plugin.c	Tue Mar 24 16:32:36 2009
@@ -1884,7 +1884,7 @@
 	CppJavaPlugin *lang_plugin;
 	lang_plugin = ANJUTA_PLUGIN_CPP_JAVA (data);
 	if (lang_plugin->assist)
-		cpp_java_assist_check (lang_plugin->assist, TRUE, TRUE);
+		cpp_java_assist_check (lang_plugin->assist, TRUE, TRUE, FALSE);
 }
 
 static GtkActionEntry actions[] = {

Modified: trunk/plugins/scintilla/text_editor.c
==============================================================================
--- trunk/plugins/scintilla/text_editor.c	(original)
+++ trunk/plugins/scintilla/text_editor.c	Tue Mar 24 16:32:36 2009
@@ -3106,11 +3106,17 @@
 iassist_show_tips (IAnjutaEditorAssist *iassist, GList* tips,
 				   IAnjutaIterable *position, gint char_alignment, GError **err)
 {
-	gint lineno, cur_pos, cur_col, real_pos, real_col;
 	GString *calltip;
 	GList *tip;
 	gint tips_count;
 	TextEditor *te = TEXT_EDITOR (iassist);
+	TextEditorCell *cell = TEXT_EDITOR_CELL (position);
+	gint column;
+	gint pos;
+	gint calltip_pos;
+	gint line;
+	gint calltip_lines = 0;
+	int i;
 	
 	g_return_if_fail (IS_TEXT_EDITOR (te));
 	g_return_if_fail (tips != NULL);
@@ -3120,7 +3126,6 @@
 	DEBUG_PRINT ("Number of calltips found %d\n", tips_count);
 	
 	calltip = g_string_sized_new (256);
-
 	tip = tips;
 	while (tip)
 	{
@@ -3129,31 +3134,29 @@
 		g_string_append (calltip, (gchar*) tip->data);
 		tip = g_list_next (tip);
 	}
-/*	
-	if (tips_count > 1)
+	for (i = 0; calltip->str[i] != '\0'; i++)
 	{
-		g_string_prepend_c (calltip, '\001');
-		g_string_append_c (calltip, '\002');
+		if (calltip->str[i] == '\n')
+			calltip_lines++;
 	}
-*/
 	/* Calculate real calltip position */
-	cur_pos = scintilla_send_message (SCINTILLA (te->scintilla),
-									 SCI_GETCURRENTPOS, 0, 0);
-	lineno = scintilla_send_message (SCINTILLA (te->scintilla),
-									 SCI_LINEFROMPOSITION, cur_pos, 0);
-	cur_col = scintilla_send_message (SCINTILLA (te->scintilla),
-									 SCI_GETCOLUMN, cur_pos, 0);
-	real_col = cur_col - char_alignment;
-	if (real_col < 0)
-		real_col = 0;
-	real_pos = scintilla_send_message (SCINTILLA (te->scintilla),
-									   SCI_FINDCOLUMN, lineno, real_col);
+	pos = text_editor_cell_get_position (cell);
+	column = scintilla_send_message (SCINTILLA (te->scintilla),
+	                                 SCI_GETCOLUMN,
+	                                 pos, 0);
+	line = scintilla_send_message (SCINTILLA (te->scintilla),
+	                               SCI_LINEFROMPOSITION,
+	                               pos, 0);
+	/* Align calltip above function call */
+	line -= (calltip_lines + 3);
+	calltip_pos = scintilla_send_message (SCINTILLA(te->scintilla),
+	                                      SCI_POSITIONFROMLINE, line, 0) + column;
+	
 	scintilla_send_message (SCINTILLA (te->scintilla),
 							SCI_CALLTIPSHOW,
-							real_pos,
+							calltip_pos,
 							(uptr_t) calltip->str);
 	g_string_free (calltip, TRUE);
-	/* ContinueCallTip_new(); */
 }
 
 static void
@@ -3163,6 +3166,14 @@
 	scintilla_send_message (SCINTILLA (te->scintilla), SCI_CALLTIPCANCEL, 0, 0);
 }
 
+static gboolean
+iassist_tip_shown (IAnjutaEditorAssist* iassist, GError **err)
+{
+	TextEditor *te = TEXT_EDITOR (iassist);
+	return scintilla_send_message (SCINTILLA (te->scintilla),
+	                                          SCI_CALLTIPACTIVE, 0, 0);
+}
+
 static void
 iassist_hide_suggestions (IAnjutaEditorAssist *iassist, GError **err)
 {
@@ -3180,6 +3191,7 @@
 	iface->hide_suggestions = iassist_hide_suggestions;
 	iface->show_tips = iassist_show_tips;
 	iface->cancel_tips = iassist_cancel_tips;
+	iface->tip_shown = iassist_tip_shown;
 }
 
 /* IAnutaEditorFolds implementation */

Modified: trunk/plugins/sourceview/assist-tip.c
==============================================================================
--- trunk/plugins/sourceview/assist-tip.c	(original)
+++ trunk/plugins/sourceview/assist-tip.c	Tue Mar 24 16:32:36 2009
@@ -109,28 +109,21 @@
 
 /* Return a tuple containing the (x, y) position of the cursor + 1 line */
 static void
-assist_tip_get_coordinates(GtkWidget* view, int offset, int* x, int* y, GtkWidget* entry)
+assist_tip_get_coordinates(GtkWidget* view, int* x, int* y, GtkTextIter* iter, GtkWidget* entry)
 {
 	int xor, yor;
-	/* We need to Rectangles because if we step to the next line
+	/* We need Rectangles because if we step to the next line
 	the x position is lost */
 	GtkRequisition entry_req;
-	GdkRectangle rectx;
-	GdkRectangle recty;
+	GdkRectangle rect;
 	gint view_width;
 	gint width_left;
 	GdkWindow* window;
-	GtkTextIter iter;
-	GtkTextBuffer* buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
-	
-	gtk_text_buffer_get_iter_at_offset(buffer, &iter, 
-									   offset); 
-	gtk_text_view_get_iter_location(GTK_TEXT_VIEW(view), &iter, &rectx);
 	
-	gtk_text_view_get_iter_location(GTK_TEXT_VIEW(view), &iter, &recty);
+	gtk_text_view_get_iter_location(GTK_TEXT_VIEW(view), iter, &rect);
 	window = gtk_text_view_get_window(GTK_TEXT_VIEW(view), GTK_TEXT_WINDOW_TEXT);
 	gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(view), GTK_TEXT_WINDOW_TEXT, 
-		rectx.x + rectx.width, recty.y, x, y);
+		rect.x, rect.y, x, y);
 	
 	gdk_window_get_origin(window, &xor, &yor);
 	*x = *x + xor;
@@ -153,10 +146,10 @@
 }
 
 void
-assist_tip_move(AssistTip* assist_tip, GtkTextView* text_view, int offset)
+assist_tip_move(AssistTip* assist_tip, GtkTextView* text_view, GtkTextIter* iter)
 {
 	int x,y;
-	assist_tip_get_coordinates(GTK_WIDGET(text_view), offset, &x, &y, assist_tip->label);	
+	assist_tip_get_coordinates(GTK_WIDGET(text_view), &x, &y, iter, assist_tip->label);	
 	gtk_window_move(GTK_WINDOW(assist_tip), x, y);
 
 }

Modified: trunk/plugins/sourceview/assist-tip.h
==============================================================================
--- trunk/plugins/sourceview/assist-tip.h	(original)
+++ trunk/plugins/sourceview/assist-tip.h	Tue Mar 24 16:32:36 2009
@@ -56,7 +56,7 @@
 GType assist_tip_get_type (void) G_GNUC_CONST;
 GtkWidget* assist_tip_new (GtkTextView* view, GList* tips);
 void assist_tip_set_tips (AssistTip* tip, GList* tips);
-void assist_tip_move(AssistTip* assist_tip, GtkTextView* text_view, int offset);
+void assist_tip_move(AssistTip* assist_tip, GtkTextView* text_view, GtkTextIter* iter);
 gint assist_tip_get_position (AssistTip* tip);
 
 G_END_DECLS

Modified: trunk/plugins/sourceview/sourceview.c
==============================================================================
--- trunk/plugins/sourceview/sourceview.c	(original)
+++ trunk/plugins/sourceview/sourceview.c	Tue Mar 24 16:32:36 2009
@@ -2084,16 +2084,10 @@
 				   gint char_alignment, GError **err)
 {
 	Sourceview* sv = ANJUTA_SOURCEVIEW(iassist);
-	GtkTextBuffer* buffer = GTK_TEXT_BUFFER (sv->priv->document);
-	GtkTextIter iter;
-	gint tip_position;
-	gtk_text_buffer_get_iter_at_mark (buffer, &iter,
-									  gtk_text_buffer_get_insert (buffer));
-	
-	tip_position = gtk_text_iter_get_offset (&iter) - char_alignment;
+	SourceviewCell* cell = SOURCEVIEW_CELL (ipos);
+	GtkTextIter* iter = sourceview_cell_get_iter(cell);
 	
-	if (tips == NULL)
-		return;
+	g_return_if_fail (tips != NULL);
 	
 	if (!sv->priv->assist_tip)
 	{
@@ -2103,13 +2097,13 @@
 		g_object_weak_ref (G_OBJECT(sv->priv->assist_tip),
 		                   (GWeakNotify) on_assist_tip_destroyed,
 		                   sv);
-		assist_tip_move (sv->priv->assist_tip, GTK_TEXT_VIEW (sv->priv->view), tip_position);
+		assist_tip_move (sv->priv->assist_tip, GTK_TEXT_VIEW (sv->priv->view), iter);
 		gtk_widget_show (GTK_WIDGET (sv->priv->assist_tip));
 	}
 	else
 	{
 		assist_tip_set_tips (sv->priv->assist_tip, tips);
-		assist_tip_move (sv->priv->assist_tip, GTK_TEXT_VIEW (sv->priv->view), tip_position);
+		assist_tip_move (sv->priv->assist_tip, GTK_TEXT_VIEW (sv->priv->view), iter);
 	}
 }
 
@@ -2121,6 +2115,13 @@
 		gtk_widget_destroy (GTK_WIDGET (sv->priv->assist_tip));
 }
 
+static gboolean
+iassist_tip_shown (IAnjutaEditorAssist* iassist, GError** err)
+{
+	Sourceview* sv = ANJUTA_SOURCEVIEW(iassist);
+	return (sv->priv->assist_tip != NULL);
+}
+
 static void
 iassist_iface_init(IAnjutaEditorAssistIface* iface)
 {
@@ -2129,6 +2130,7 @@
 	iface->get_suggestions = iassist_get_suggestions;
 	iface->show_tips = iassist_show_tips;
 	iface->cancel_tips = iassist_cancel_tips;
+	iface->tip_shown = iassist_tip_shown;
 }
 
 static gboolean



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