Commit 50490f49 authored by Johannes Schmid's avatar Johannes Schmid Committed by Johannes Schmid

Added ianjuta_editor_assist_tip_shown() to determine if a calltip is

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

svn path=/trunk/; revision=4888
parent 8223ddc7
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
2009-03-21 Massimo Cora' <mcora@svn.gnome.org>
* plugins/class-inheritance/class-inherit.c
......@@ -1944,6 +1944,15 @@ interface IAnjutaEditor
*/
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
......
......@@ -60,6 +60,8 @@ struct _CppJavaAssistPriv {
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 @@ cpp_java_assist_tag_destroy (CppJavaAssistTag *tag)
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 @@ static GCompletion*
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 @@ cpp_java_assist_create_word_completion_cache (CppJavaAssist *assist)
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 @@ cpp_java_assist_get_calltip_context (CppJavaAssist *assist,
&& 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 @@ cpp_java_assist_create_calltips (IAnjutaIterable* iter)
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 @@ cpp_java_assist_show_calltip (CppJavaAssist *assist, gchar *call_context,
}
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 @@ cpp_java_assist_show_calltip (CppJavaAssist *assist, gchar *call_context,
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 @@ cpp_java_assist_check (CppJavaAssist *assist, gboolean autocomplete,
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 @@ on_editor_char_added (IAnjutaEditor *editor, IAnjutaIterable *insert_pos,
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 @@ on_assist_chosen (IAnjutaEditorAssist* iassist, gint selection,
/* 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 @@ cpp_java_assist_finalize (GObject *object)
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);
}
......
......@@ -65,8 +65,8 @@ GType cpp_java_assist_get_type (void) G_GNUC_CONST;
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
......
......@@ -1884,7 +1884,7 @@ on_auto_complete (GtkAction *action, gpointer data)
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[] = {
......
......@@ -3106,11 +3106,17 @@ static void
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 @@ iassist_show_tips (IAnjutaEditorAssist *iassist, GList* tips,
DEBUG_PRINT ("Number of calltips found %d\n", tips_count);
calltip = g_string_sized_new (256);
tip = tips;
while (tip)
{
......@@ -3129,31 +3134,29 @@ iassist_show_tips (IAnjutaEditorAssist *iassist, GList* tips,
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 @@ iassist_cancel_tips (IAnjutaEditorAssist *iassist, GError **err)
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 @@ iassist_iface_init(IAnjutaEditorAssistIface* iface)
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 */
......
......@@ -109,28 +109,21 @@ assist_tip_set_tips (AssistTip* tip, GList* tips)
/* 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 @@ assist_tip_get_coordinates(GtkWidget* view, int offset, int* x, int* y, GtkWidge
}
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);
}
......
......@@ -56,7 +56,7 @@ struct _AssistTip
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
......
......@@ -2084,16 +2084,10 @@ iassist_show_tips (IAnjutaEditorAssist *iassist, GList* tips, IAnjutaIterable* i
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));
SourceviewCell* cell = SOURCEVIEW_CELL (ipos);
GtkTextIter* iter = sourceview_cell_get_iter(cell);
tip_position = gtk_text_iter_get_offset (&iter) - char_alignment;
if (tips == NULL)
return;
g_return_if_fail (tips != NULL);
if (!sv->priv->assist_tip)
{
......@@ -2103,13 +2097,13 @@ iassist_show_tips (IAnjutaEditorAssist *iassist, GList* tips, IAnjutaIterable* i
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 @@ iassist_cancel_tips (IAnjutaEditorAssist* iassist, GError** err)
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 @@ iassist_iface_init(IAnjutaEditorAssistIface* iface)
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment