[anjuta/gtksourcecompletion: 2/3] Remove Proposal interface and use an struct instead.



commit e4c780cfed2ae3382f33f9d25916c3f594f9a9e0
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sun May 17 20:57:04 2009 +0200

    Remove Proposal interface and use an struct instead.
---
 libanjuta/interfaces/libanjuta.idl      |   44 +++---------
 plugins/sourceview/Makefile.am          |    6 ++-
 plugins/sourceview/anjuta-view.c        |   26 +-------
 plugins/sourceview/anjuta-view.h        |    2 +-
 plugins/sourceview/assist-tip.c         |  115 ++++---------------------------
 plugins/sourceview/assist-tip.h         |   10 +--
 plugins/sourceview/sourceview-private.h |    4 +-
 plugins/sourceview/sourceview.c         |   68 +++++-------------
 8 files changed, 57 insertions(+), 218 deletions(-)

diff --git a/libanjuta/interfaces/libanjuta.idl b/libanjuta/interfaces/libanjuta.idl
index 6001193..b69deed 100644
--- a/libanjuta/interfaces/libanjuta.idl
+++ b/libanjuta/interfaces/libanjuta.idl
@@ -1872,32 +1872,25 @@ interface IAnjutaEditor
 		void fix ();
 	}
 	
-	interface IAnjutaEditorAssistProposal
-	{
-		const gchar *get_label ();
-		
-		const gchar *get_markup ();
-		
-		const gchar *get_text ();
-		
-		GdkPixbuf *get_icon ();
-		
-		const gchar *get_info ();
-	}
-	
 	interface IAnjutaEditorAssistProvider
 	{
-		#include <libanjuta/interfaces/ianjuta-editor-assist-proposal.h>
+		struct Proposal
+		{
+			gchar *label;
+			gchar *text;
+			GdkPixbuf *pixbuf;
+			gchar *info;
+		}
 		
 		const gchar *get_name ();
 		
 		GdkPixbuf *get_icon ();
 		
-		List<IAnjutaEditorAssistProposal *> get_proposals (IAnjutaIterable *position);
+		List<AnjutaEditorAssistProviderProposal *> get_proposals (IAnjutaIterable *position);
 		
-		GtkWidget *get_info_widget (IAnjutaEditorAssistProposal *proposal);
+		GtkWidget *get_info_widget (IAnjutaEditorAssistProviderProposal *proposal);
 		
-		void update_info (IAnjutaEditorAssistProposal *proposal, GtkWidget *info);
+		void update_info (IAnjutaEditorAssistProviderProposal *proposal, GtkWidget *info);
 	}
 	
 	/**
@@ -1986,23 +1979,6 @@ interface IAnjutaEditor
 		 * Returns: whether a tooltip is crrently shown		
 		 */
 		gboolean tip_shown();
-		
-		/**
-		 * ianjuta_editor_assist_get_suggestions:
-		 * @obj: Self
-		 * @context: The context for the suggestions.
-		 * @err: Error propagation and reporting
-		 *
-		 * Usually the editor might have some suggestions to make
-		 * for a context. For example in a simple word completion context.
-		 * The list of suggestion returned is allocated dynamically. The whole
-		 * list, including the the strings should be freed when done.
-		 * If the editor has no suggestions to make, it returns NULL.
-		 * 
-		 * Returns: A list of dynamically allocated strings for the given context or NULL
-		 * if there is nothing to suggest.
-		 */
-		List<const gchar*> get_suggestions (const gchar *context);
 	}
 	
 	/**
diff --git a/plugins/sourceview/Makefile.am b/plugins/sourceview/Makefile.am
index e4ccfc6..0e6c62b 100644
--- a/plugins/sourceview/Makefile.am
+++ b/plugins/sourceview/Makefile.am
@@ -64,7 +64,11 @@ libanjuta_sourceview_la_SOURCES = \
 	sourceview-print.h \
 	sourceview-print.c \
 	sourceview-io.h \
-	sourceview-io.c
+	sourceview-io.c \
+	completion-provider.h \
+	completion-provider.c \
+	assist-tip.h \
+	assist-tip.c
 
 libanjuta_sourceview_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 
diff --git a/plugins/sourceview/anjuta-view.c b/plugins/sourceview/anjuta-view.c
index 2806d00..ccfd741 100644
--- a/plugins/sourceview/anjuta-view.c
+++ b/plugins/sourceview/anjuta-view.c
@@ -49,6 +49,7 @@
 #include "sourceview.h"
 #include "sourceview-private.h"
 #include "anjuta-marshal.h"
+#include <gtksourceview/gtksourcecompletioninfo.h>
 
 #define ANJUTA_VIEW_SCROLL_MARGIN 0.02
 
@@ -344,17 +345,11 @@ static gint
 anjuta_view_focus_out (GtkWidget *widget, GdkEventFocus *event)
 {
 	AnjutaView *view = ANJUTA_VIEW (widget);
-	AssistWindow* assist_win = view->priv->sv->priv->assist_win;
 	AssistTip* assist_tip = view->priv->sv->priv->assist_tip;
 	
-	if (assist_win)
-		gtk_widget_destroy(GTK_WIDGET(assist_win));
-	
 	if (assist_tip)
 		gtk_widget_destroy(GTK_WIDGET(assist_tip));
 	
-	gtk_widget_queue_draw (widget);
-	
 	
 	(* GTK_WIDGET_CLASS (anjuta_view_parent_class)->focus_out_event) (widget, event);
 	
@@ -578,22 +573,9 @@ anjuta_view_expose (GtkWidget      *widget,
 static gboolean
 anjuta_view_key_press_event		(GtkWidget *widget, GdkEventKey       *event)
 {
-	GtkTextBuffer *buffer;
 	AnjutaView* view = ANJUTA_VIEW(widget);
-	AssistWindow* assist_win;
 	AssistTip* assist_tip;
 	
-	buffer  = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-	
-	assist_win = view->priv->sv->priv->assist_win;
-	if (assist_win)
-	{
-		if (assist_window_filter_keypress(assist_win, event->keyval))
-		{
-			DEBUG_PRINT("key filtered: %d", event->keyval);
-			return TRUE;
-		}
-	}
 	assist_tip = view->priv->sv->priv->assist_tip;
 	if (assist_tip)
 	{
@@ -618,11 +600,7 @@ anjuta_view_button_press_event	(GtkWidget *widget, GdkEventButton *event)
 	
   /* If we have a calltip shown - hide it */
   AssistTip* assist_tip = view->priv->sv->priv->assist_tip;
-  AssistWindow* assist_win = view->priv->sv->priv->assist_win;
-  if (assist_win)
-  {
-    gtk_widget_destroy (GTK_WIDGET (assist_win));
-  }
+  
 	if (assist_tip)
 	{
     gtk_widget_destroy (GTK_WIDGET (assist_tip));
diff --git a/plugins/sourceview/anjuta-view.h b/plugins/sourceview/anjuta-view.h
index 4bbafb0..42735c7 100644
--- a/plugins/sourceview/anjuta-view.h
+++ b/plugins/sourceview/anjuta-view.h
@@ -78,7 +78,7 @@ struct _AnjutaViewClass
 								 gchar character);
 };
 
-/*
+/*e
  * Public methods
  */
 GType		 anjuta_view_get_type     	(void) G_GNUC_CONST;
diff --git a/plugins/sourceview/assist-tip.c b/plugins/sourceview/assist-tip.c
index 903989e..a0f12e9 100644
--- a/plugins/sourceview/assist-tip.c
+++ b/plugins/sourceview/assist-tip.c
@@ -29,33 +29,18 @@
 
 #include <string.h>
 
-G_DEFINE_TYPE (AssistTip, assist_tip, GTK_TYPE_WINDOW);
-
-enum
-{
-	COLUMN_TIP,
-	N_COLUMNS
-};
+G_DEFINE_TYPE (AssistTip, assist_tip, GTK_TYPE_SOURCE_COMPLETION_INFO);
 
 static void
-assist_tip_init (AssistTip *object)
+assist_tip_init (AssistTip *tip)
 {
 	GtkWidget* alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
-	GtkWidget* window = GTK_WIDGET(object);
 	
-	gtk_widget_set_name (GTK_WIDGET(object), "gtk-tooltip");
-	gtk_widget_set_app_paintable (GTK_WIDGET(object), TRUE);
-	
-	gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
-							   window->style->ythickness,
-							   window->style->ythickness,
-							   window->style->xthickness,
-							   window->style->xthickness);
-	object->label = gtk_label_new ("");
-	gtk_widget_show (object->label);
+	tip->label = gtk_label_new ("");
+	gtk_widget_show (tip->label);
 	
-	gtk_container_add (GTK_CONTAINER(alignment), object->label);
-	gtk_container_add (GTK_CONTAINER(object), alignment);
+	gtk_container_add (GTK_CONTAINER (alignment), tip->label);
+	gtk_container_add (GTK_CONTAINER (tip), alignment);
 
 	gtk_widget_show (alignment);
 }
@@ -81,6 +66,8 @@ assist_tip_set_tips (AssistTip* tip, GList* tips)
 	gchar* text = NULL;
 	gchar* tip_text;
 	
+	g_return_if_fail (ASSIST_IS_TIP (tip));
+	
 	if (tips == NULL)
 		return;
 	
@@ -98,92 +85,20 @@ assist_tip_set_tips (AssistTip* tip, GList* tips)
 		g_free(text);
 		text = new_text;
 	}
+	
 	tip_text = g_markup_printf_escaped ("<tt>%s</tt>", text);
-	gtk_label_set_markup(GTK_LABEL(tip->label), tip_text);
+	gtk_label_set_markup (GTK_LABEL (tip->label), tip_text);
 	gtk_widget_show (tip->label);
-	g_free(text);
-	g_free(tip_text);
-	/* Make the window as small as possible */
-	gtk_window_resize (GTK_WINDOW (tip), 1, 1);
-}
-
-/* Return a tuple containing the (x, y) position of the cursor + 1 line */
-static void
-assist_tip_get_coordinates(GtkWidget* view, int* x, int* y, GtkTextIter* iter, GtkWidget* entry)
-{
-	int xor, yor;
-	/* We need Rectangles because if we step to the next line
-	the x position is lost */
-	GtkRequisition entry_req;
-	GdkRectangle rect;
-	gint view_width;
-	gint width_left;
-	GdkWindow* window;
-	
-	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, 
-		rect.x, rect.y, x, y);
-	
-	gdk_window_get_origin(window, &xor, &yor);
-	*x = *x + xor;
-	*y = *y + yor;
-	
-
-	/* Compute entry width/height */
-	gtk_widget_size_request(entry, &entry_req);
-	
-	/* ensure that the tip is inside the text_view */
-	gdk_drawable_get_size (GDK_DRAWABLE(window), &view_width, NULL);
-	width_left = (xor + view_width) - (*x + entry_req.width);
-	DEBUG_PRINT ("width_left: %d", width_left);
-	if (width_left < 0)
-	{
-		*x += width_left;
-	}
-	
-	*y -= (entry_req.height + 5);
-}
-
-void
-assist_tip_move(AssistTip* assist_tip, GtkTextView* text_view, GtkTextIter* iter)
-{
-	int x,y;
-	assist_tip_get_coordinates(GTK_WIDGET(text_view), &x, &y, iter, assist_tip->label);	
-	gtk_window_move(GTK_WINDOW(assist_tip), x, y);
-
-}
-
-gint assist_tip_get_position (AssistTip* tip)
-{	
-	return tip->position;
+	g_free (text);
+	g_free (tip_text);
 }
 
-GtkWidget*
+AssistTip *
 assist_tip_new (GtkTextView* view, GList* tips)
 {
-	GtkTextBuffer* buffer;
-	GtkTextIter iter;
-	GtkTextMark* mark;
-	AssistTip* assist_tip;
-	GObject* object = 
-		g_object_new (ASSIST_TYPE_TIP, 
-					  "type", GTK_WINDOW_POPUP,
-					  "type_hint", GDK_WINDOW_TYPE_HINT_TOOLTIP,
-					  NULL);
-	
-	
-	assist_tip = ASSIST_TIP (object);
+	AssistTip* assist_tip = g_object_new (ASSIST_TYPE_TIP, NULL);
 	
 	assist_tip_set_tips (assist_tip, tips);
 	
-	buffer = gtk_text_view_get_buffer (view);
-	mark = gtk_text_buffer_get_insert (buffer);
-	gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
-	assist_tip->position = gtk_text_iter_get_offset (&iter);
-	
-	/* Position is off by one for '(' brace */
-	assist_tip->position--;
-										
-	return GTK_WIDGET(object);
+	return assist_tip;
 }
diff --git a/plugins/sourceview/assist-tip.h b/plugins/sourceview/assist-tip.h
index 4e89854..7dde7bd 100644
--- a/plugins/sourceview/assist-tip.h
+++ b/plugins/sourceview/assist-tip.h
@@ -27,6 +27,7 @@
 
 #include <glib-object.h>
 #include <gtk/gtk.h>
+#include <gtksourceview/gtksourcecompletioninfo.h>
 
 G_BEGIN_DECLS
 
@@ -42,22 +43,19 @@ typedef struct _AssistTip AssistTip;
 
 struct _AssistTipClass
 {
-	GtkWindowClass parent_class;
+	GtkSourceCompletionInfoClass parent_class;
 };
 
 struct _AssistTip
 {
-	GtkWindow parent_instance;
+	GtkSourceCompletionInfo parent_instance;
 	
 	GtkWidget* label;
-	gint position;
 };
 
 GType assist_tip_get_type (void) G_GNUC_CONST;
-GtkWidget* assist_tip_new (GtkTextView* view, GList* tips);
+AssistTip* 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, GtkTextIter* iter);
-gint assist_tip_get_position (AssistTip* tip);
 
 G_END_DECLS
 
diff --git a/plugins/sourceview/sourceview-private.h b/plugins/sourceview/sourceview-private.h
index 84d7763..d5b50f2 100644
--- a/plugins/sourceview/sourceview-private.h
+++ b/plugins/sourceview/sourceview-private.h
@@ -21,7 +21,7 @@
 
 #include "sourceview-cell.h"
 #include "sourceview-io.h"
-#include <gtksourceview/gtksourcecompletioninfo.h>
+#include "assist-tip.h"
 
 #include <libanjuta/anjuta-plugin.h>
 #include <glib.h>
@@ -67,7 +67,7 @@ struct SourceviewPrivate {
 	GSList* idle_sources;
 	
 	/* Assist */
-	GtkSourceCompletionInfo* assist_tip;
+	AssistTip* assist_tip;
 	
 	/* Hover */
 	gchar* tooltip;
diff --git a/plugins/sourceview/sourceview.c b/plugins/sourceview/sourceview.c
index f9a866b..599aad6 100644
--- a/plugins/sourceview/sourceview.c
+++ b/plugins/sourceview/sourceview.c
@@ -60,6 +60,7 @@
 #include "sourceview-print.h"
 #include "sourceview-cell.h"
 #include "plugin.h"
+#include "completion-provider.h"
 		 
 #define FORWARD 	0
 #define BACKWARD 	1
@@ -223,16 +224,6 @@ sourceview_set_message_area (Sourceview* sv,  GtkWidget *message_area)
 
 /* Callbacks */
 
-static void 
-on_assist_cancel(AssistWindow* assist_win, Sourceview* sv)
-{
-	GtkSourceCompletion *completion;
-	
-	completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (sv->view));
-	
-	gtk_source_completion_hide (completion);
-}
-
 static void on_insert_text (GtkTextBuffer* buffer, 
 							GtkTextIter* location,
 							char* text,
@@ -2007,44 +1998,23 @@ iassist_get_suggestions (IAnjutaEditorAssist *iassist, const gchar *context, GEr
 }
 
 static void
-iassist_suggest (IAnjutaEditorAssist *iassist, GList* choices, IAnjutaIterable* ipos,
+iassist_suggest (IAnjutaEditorAssist *iassist, GList* providers, IAnjutaIterable* ipos,
 				 int char_alignment, GError **err)
 {
-	Sourceview* sv = ANJUTA_SOURCEVIEW(iassist);
+	Sourceview* sv = ANJUTA_SOURCEVIEW (iassist);
+	GtkSourceCompletion *completion;
+	GList *real_providers = NULL, *l;
 	
-	if (choices == NULL)
-	{
-		if (sv->priv->assist_win)
-			gtk_widget_destroy(GTK_WIDGET(sv->priv->assist_win));
-	}
-	else
+	completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (sv->priv->view));
+	
+	for (l = providers; l != NULL; l = g_list_next (l))
 	{
-		if (!sv->priv->assist_win)
-		{
-			sv->priv->assist_win = assist_window_new(GTK_TEXT_VIEW(sv->priv->view), NULL,
-													 ianjuta_iterable_get_position (ipos, NULL));
-			g_object_weak_ref (G_OBJECT(sv->priv->assist_win),
-			                   (GWeakNotify)on_assist_window_destroyed, sv);
-			g_signal_connect(G_OBJECT(sv->priv->assist_win), "chosen", 
-								 G_CALLBACK(on_assist_chosen), sv);
-			g_signal_connect(G_OBJECT(sv->priv->assist_win), "cancel", 
-								 G_CALLBACK(on_assist_cancel), sv);
-		}
-		assist_window_update(sv->priv->assist_win, choices);
-		gtk_widget_show(GTK_WIDGET(sv->priv->assist_win));
-		if (char_alignment > 0)
-		{
-			/* Calculate offset */
-			GtkTextIter cursor;
-			GtkTextBuffer* buffer = GTK_TEXT_BUFFER (sv->priv->document);
-			gtk_text_buffer_get_iter_at_mark (buffer,
-											  &cursor,
-											  gtk_text_buffer_get_insert(buffer));
-			
-			gint offset = gtk_text_iter_get_offset (&cursor);
-			assist_window_move(sv->priv->assist_win, offset - char_alignment);
-		}
+		CompletionProvider *cp = completion_provider_new (l->data);
+		
+		real_providers = g_list_append (real_providers, cp);
 	}
+	
+	gtk_source_completion_show (completion, real_providers, NULL, NULL);
 }
 
 static void
@@ -2053,7 +2023,7 @@ iassist_hide_suggestions (IAnjutaEditorAssist* iassist, GError** err)
 	Sourceview* sv = ANJUTA_SOURCEVIEW(iassist);
 	GtkSourceCompletion *completion;
 	
-	completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (sv->view));
+	completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (sv->priv->view));
 	
 	gtk_source_completion_hide (completion);
 }
@@ -2073,16 +2043,15 @@ iassist_show_tips (IAnjutaEditorAssist *iassist, GList* tips, IAnjutaIterable* i
 		sv->priv->assist_tip = 
 			ASSIST_TIP (assist_tip_new (GTK_TEXT_VIEW (sv->priv->view), tips));
 		
-		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), iter);
+		gtk_source_completion_info_move_to_iter (GTK_SOURCE_COMPLETION_INFO (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), iter);
+		gtk_source_completion_info_move_to_iter (GTK_SOURCE_COMPLETION_INFO (sv->priv->assist_tip),
+												 GTK_TEXT_VIEW (sv->priv->view), iter);
 	}
 }
 
@@ -2106,7 +2075,6 @@ iassist_iface_init(IAnjutaEditorAssistIface* iface)
 {
 	iface->suggest = iassist_suggest;
 	iface->hide_suggestions = iassist_hide_suggestions;
-	iface->get_suggestions = iassist_get_suggestions;
 	iface->show_tips = iassist_show_tips;
 	iface->cancel_tips = iassist_cancel_tips;
 	iface->tip_shown = iassist_tip_shown;



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