[gtksourceview] Fix GtkSourceCompletionProposal virtual function prototype.



commit dae596cb918e6a25b4cd2861eec9bb70aaa09aa4
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Sun Feb 21 20:57:02 2010 +0100

    Fix GtkSourceCompletionProposal virtual function prototype.
    
    This changes get_label(), get_markup, get_text() and get_info()
    functions to return an allocated string, updates documentation
    and fixes usage of this function in other parts of gtksourceview
    library.

 .../words/gtksourcecompletionwordsproposal.c       |    4 +-
 gtksourceview/gtksourcecompletion.c                |   10 +++--
 gtksourceview/gtksourcecompletionitem.c            |   16 ++++----
 gtksourceview/gtksourcecompletionmodel.c           |    4 +-
 gtksourceview/gtksourcecompletionproposal.c        |   36 ++++++++++---------
 gtksourceview/gtksourcecompletionproposal.h        |   16 ++++----
 6 files changed, 45 insertions(+), 41 deletions(-)
---
diff --git a/gtksourceview/completion-providers/words/gtksourcecompletionwordsproposal.c b/gtksourceview/completion-providers/words/gtksourcecompletionwordsproposal.c
index 2dceccc..2455d50 100644
--- a/gtksourceview/completion-providers/words/gtksourcecompletionwordsproposal.c
+++ b/gtksourceview/completion-providers/words/gtksourcecompletionwordsproposal.c
@@ -46,10 +46,10 @@ G_DEFINE_TYPE_WITH_CODE (GtkSourceCompletionWordsProposal,
 			 G_IMPLEMENT_INTERFACE (GTK_TYPE_SOURCE_COMPLETION_PROPOSAL,
 			 			gtk_source_completion_proposal_iface_init))
 
-static const gchar *
+static gchar *
 gtk_source_completion_words_proposal_get_text (GtkSourceCompletionProposal *proposal)
 {
-	return GTK_SOURCE_COMPLETION_WORDS_PROPOSAL(proposal)->priv->word;
+	return g_strdup (GTK_SOURCE_COMPLETION_WORDS_PROPOSAL(proposal)->priv->word);
 }
 
 static void
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 82d0bd4..d124c5b 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -269,7 +269,6 @@ activate_current_proposal (GtkSourceCompletion *completion)
 	GtkSourceCompletionProposal *proposal = NULL;
 	GtkSourceCompletionProvider *provider = NULL;
 	GtkTextBuffer *buffer;
-	const gchar *text;
 	gboolean has_start;
 	GtkTextIter start;
 	
@@ -309,7 +308,7 @@ activate_current_proposal (GtkSourceCompletion *completion)
 
 	if (!activated)
 	{
-		text = gtk_source_completion_proposal_get_text (proposal);
+		gchar *text = gtk_source_completion_proposal_get_text (proposal);
 
 		if (has_start)
 		{
@@ -325,6 +324,7 @@ activate_current_proposal (GtkSourceCompletion *completion)
 					                                  text,
 					                                  -1);
 		}
+		g_free (text);
 	}
 
 	completion_end_block (completion, GTK_SOURCE_BUFFER (buffer));
@@ -925,7 +925,6 @@ update_proposal_info_real (GtkSourceCompletion         *completion,
                            GtkSourceCompletionProposal *proposal)
 {
 	GtkWidget *info_widget;
-	const gchar *text;
 	gboolean prov_update_info = FALSE;
 	GtkSourceCompletionInfo *info_window;
 	
@@ -955,13 +954,16 @@ update_proposal_info_real (GtkSourceCompletion         *completion,
 		if (info_widget == NULL)
 		{
 			gint width;
+			gchar *text;
 
 			info_widget = completion->priv->default_info;
 			text = gtk_source_completion_proposal_get_info (proposal);
 			gtk_widget_set_size_request (info_widget, -1, -1);
 			
 			gtk_label_set_markup (GTK_LABEL (info_widget), text != NULL ? text : _("No extra information available"));
-			
+
+			g_free (text);
+
 			gtk_widget_get_size_request (info_widget, &width, NULL);
 			
 			if (width > WINDOW_WIDTH)
diff --git a/gtksourceview/gtksourcecompletionitem.c b/gtksourceview/gtksourcecompletionitem.c
index 63e7256..b9de44a 100644
--- a/gtksourceview/gtksourcecompletionitem.c
+++ b/gtksourceview/gtksourcecompletionitem.c
@@ -54,22 +54,22 @@ G_DEFINE_TYPE_WITH_CODE (GtkSourceCompletionItem,
 			 G_IMPLEMENT_INTERFACE (GTK_TYPE_SOURCE_COMPLETION_PROPOSAL,
 			 			gtk_source_completion_proposal_iface_init))
 
-static const gchar *
+static gchar *
 gtk_source_completion_proposal_get_label_impl (GtkSourceCompletionProposal *self)
 {
-	return GTK_SOURCE_COMPLETION_ITEM (self)->priv->label;
+	return g_strdup (GTK_SOURCE_COMPLETION_ITEM (self)->priv->label);
 }
 
-static const gchar *
+static gchar *
 gtk_source_completion_proposal_get_markup_impl (GtkSourceCompletionProposal *self)
 {
-	return GTK_SOURCE_COMPLETION_ITEM (self)->priv->markup;
+	return g_strdup (GTK_SOURCE_COMPLETION_ITEM (self)->priv->markup);
 }
 
-static const gchar *
+static gchar *
 gtk_source_completion_proposal_get_text_impl (GtkSourceCompletionProposal *self)
 {
-	return GTK_SOURCE_COMPLETION_ITEM (self)->priv->text;
+	return g_strdup (GTK_SOURCE_COMPLETION_ITEM (self)->priv->text);
 }
 
 static GdkPixbuf *
@@ -78,10 +78,10 @@ gtk_source_completion_proposal_get_icon_impl (GtkSourceCompletionProposal *self)
 	return GTK_SOURCE_COMPLETION_ITEM (self)->priv->icon;
 }
 
-static const gchar *
+static gchar *
 gtk_source_completion_proposal_get_info_impl (GtkSourceCompletionProposal *self)
 {
-	return GTK_SOURCE_COMPLETION_ITEM (self)->priv->info;
+	return g_strdup (GTK_SOURCE_COMPLETION_ITEM (self)->priv->info);
 }
 
 static void
diff --git a/gtksourceview/gtksourcecompletionmodel.c b/gtksourceview/gtksourcecompletionmodel.c
index 1e0c3be..0b18f79 100644
--- a/gtksourceview/gtksourcecompletionmodel.c
+++ b/gtksourceview/gtksourcecompletionmodel.c
@@ -269,10 +269,10 @@ tree_model_get_value (GtkTreeModel *tree_model,
 			g_value_set_object (value, node->proposal);
 			break;
 		case GTK_SOURCE_COMPLETION_MODEL_COLUMN_LABEL:
-			g_value_set_string (value, gtk_source_completion_proposal_get_label (node->proposal));
+			g_value_take_string (value, gtk_source_completion_proposal_get_label (node->proposal));
 			break;
 		case GTK_SOURCE_COMPLETION_MODEL_COLUMN_MARKUP:
-			g_value_set_string (value, gtk_source_completion_proposal_get_markup (node->proposal));
+			g_value_take_string (value, gtk_source_completion_proposal_get_markup (node->proposal));
 			break;
 		case GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON:
 			if (node->proposal == NULL)
diff --git a/gtksourceview/gtksourcecompletionproposal.c b/gtksourceview/gtksourcecompletionproposal.c
index 796eef5..52859fb 100644
--- a/gtksourceview/gtksourcecompletionproposal.c
+++ b/gtksourceview/gtksourcecompletionproposal.c
@@ -43,19 +43,19 @@ enum
 
 static guint signals[NUM_SIGNALS] = {0,};
 
-static const gchar *
+static gchar *
 gtk_source_completion_proposal_get_label_default (GtkSourceCompletionProposal *proposal)
 {
 	return NULL;
 }
 
-static const gchar *
+static gchar *
 gtk_source_completion_proposal_get_markup_default (GtkSourceCompletionProposal *proposal)
 {
 	return NULL;
 }
 
-static const gchar *
+static gchar *
 gtk_source_completion_proposal_get_text_default (GtkSourceCompletionProposal *proposal)
 {
 	return NULL;
@@ -67,7 +67,7 @@ gtk_source_completion_proposal_get_icon_default (GtkSourceCompletionProposal *pr
 	return NULL;
 }
 
-static const gchar *
+static gchar *
 gtk_source_completion_proposal_get_info_default (GtkSourceCompletionProposal *proposal)
 {
 	return NULL;
@@ -164,11 +164,12 @@ gtk_source_completion_proposal_get_type ()
  *
  * Gets the label of @proposal. The label is shown in the list of proposals as
  * plain text. If you need any markup (such as bold or italic text), you have
- * to implement #gtk_source_completion_proposal_get_markup.
+ * to implement #gtk_source_completion_proposal_get_markup. The returned string
+ * must be freed with g_free().
  *
- * Returns: The label of @proposal.
+ * Returns: A new string containing the label of @proposal.
  */
-const gchar *
+gchar *
 gtk_source_completion_proposal_get_label (GtkSourceCompletionProposal *proposal)
 {
 	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), NULL);	
@@ -181,11 +182,12 @@ gtk_source_completion_proposal_get_label (GtkSourceCompletionProposal *proposal)
  *
  * Gets the label of @proposal with markup. The label is shown in the list of 
  * proposals and may contain markup. This will be used instead of
- * #gtk_source_completion_proposal_get_label if implemented.
+ * #gtk_source_completion_proposal_get_label if implemented. The returned string
+ * must be freed with g_free().
  *
- * Returns: The label of @proposal with markup.
+ * Returns: A new string containing the label of @proposal with markup.
  */
-const gchar *
+gchar *
 gtk_source_completion_proposal_get_markup (GtkSourceCompletionProposal *proposal)
 {
 	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), NULL);	
@@ -199,11 +201,11 @@ gtk_source_completion_proposal_get_markup (GtkSourceCompletionProposal *proposal
  * Gets the text of @proposal. The text that is inserted into
  * the text buffer when the proposal is activated by the default activation.
  * You are free to implement a custom activation handler in the provider and
- * not implement this function.
+ * not implement this function. The returned string must be freed with g_free().
  *
- * Returns: The text of @proposal.
+ * Returns: A new string containing the text of @proposal.
  */
-const gchar *
+gchar *
 gtk_source_completion_proposal_get_text (GtkSourceCompletionProposal *proposal)
 {
 	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), NULL);
@@ -231,12 +233,12 @@ gtk_source_completion_proposal_get_icon (GtkSourceCompletionProposal *proposal)
  *
  * Gets extra information associated to the proposal. This information will be
  * used to present the user with extra, detailed information about the
- * selected proposal.
+ * selected proposal. The returned string must be freed with g_free().
  *
- * Returns: The extra information of @proposal or %NULL if no extra information
- *          is associated to @proposal.
+ * Returns: A new string containing extra information of @proposal or %NULL if
+ *          no extra information is associated to @proposal.
  */
-const gchar *
+gchar *
 gtk_source_completion_proposal_get_info (GtkSourceCompletionProposal *proposal)
 {
 	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), NULL);
diff --git a/gtksourceview/gtksourcecompletionproposal.h b/gtksourceview/gtksourcecompletionproposal.h
index cead36d..5c7ba36 100644
--- a/gtksourceview/gtksourcecompletionproposal.h
+++ b/gtksourceview/gtksourcecompletionproposal.h
@@ -41,12 +41,12 @@ struct _GtkSourceCompletionProposalIface
 	GTypeInterface parent;
 	
 	/* Interface functions */
-	const gchar 	*(*get_label)	(GtkSourceCompletionProposal *proposal);
-	const gchar 	*(*get_markup)	(GtkSourceCompletionProposal *proposal);
-	const gchar 	*(*get_text)	(GtkSourceCompletionProposal *proposal);
+	gchar		*(*get_label)	(GtkSourceCompletionProposal *proposal);
+	gchar		*(*get_markup)	(GtkSourceCompletionProposal *proposal);
+	gchar		*(*get_text)	(GtkSourceCompletionProposal *proposal);
 	
 	GdkPixbuf	*(*get_icon)	(GtkSourceCompletionProposal *proposal);
-	const gchar	*(*get_info)	(GtkSourceCompletionProposal *proposal);
+	gchar		*(*get_info)	(GtkSourceCompletionProposal *proposal);
 	
 	guint		 (*hash)	(GtkSourceCompletionProposal *proposal);
 	gboolean	 (*equal)	(GtkSourceCompletionProposal *proposal,
@@ -58,12 +58,12 @@ struct _GtkSourceCompletionProposalIface
 
 GType 			 gtk_source_completion_proposal_get_type 	(void) G_GNUC_CONST;
 
-const gchar		*gtk_source_completion_proposal_get_label	(GtkSourceCompletionProposal *proposal);
-const gchar		*gtk_source_completion_proposal_get_markup	(GtkSourceCompletionProposal *proposal);
-const gchar		*gtk_source_completion_proposal_get_text	(GtkSourceCompletionProposal *proposal);
+gchar			*gtk_source_completion_proposal_get_label	(GtkSourceCompletionProposal *proposal);
+gchar			*gtk_source_completion_proposal_get_markup	(GtkSourceCompletionProposal *proposal);
+gchar			*gtk_source_completion_proposal_get_text	(GtkSourceCompletionProposal *proposal);
 
 GdkPixbuf		*gtk_source_completion_proposal_get_icon	(GtkSourceCompletionProposal *proposal);
-const gchar		*gtk_source_completion_proposal_get_info	(GtkSourceCompletionProposal *proposal);
+gchar			*gtk_source_completion_proposal_get_info	(GtkSourceCompletionProposal *proposal);
 
 void			 gtk_source_completion_proposal_changed		(GtkSourceCompletionProposal *proposal);
 



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