[gtksourceview/wip/chergert/snippets: 10/119] completion: modernize GtkSourceCompletionContext



commit c4b4e286f48f52a4aa23802378234dd667b7def4
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 8 16:58:52 2020 -0800

    completion: modernize GtkSourceCompletionContext
    
    Make the object final and move to G_DECLARE.

 gtksourceview/gtksourceautocleanups.h      |  1 -
 gtksourceview/gtksourcecompletioncontext.c | 69 ++++++++++++++----------------
 gtksourceview/gtksourcecompletioncontext.h | 59 +++++++------------------
 3 files changed, 47 insertions(+), 82 deletions(-)
---
diff --git a/gtksourceview/gtksourceautocleanups.h b/gtksourceview/gtksourceautocleanups.h
index 81f05d40..3a2460c6 100644
--- a/gtksourceview/gtksourceautocleanups.h
+++ b/gtksourceview/gtksourceautocleanups.h
@@ -28,7 +28,6 @@ G_BEGIN_DECLS
 
 #ifndef __GI_SCANNER__
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceCompletionContext, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceCompletionInfo, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceCompletionItem, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceFile, g_object_unref)
diff --git a/gtksourceview/gtksourcecompletioncontext.c b/gtksourceview/gtksourcecompletioncontext.c
index f3616c4f..1a843727 100644
--- a/gtksourceview/gtksourcecompletioncontext.c
+++ b/gtksourceview/gtksourcecompletioncontext.c
@@ -66,8 +66,10 @@
 #include "gtksourcecompletionprovider.h"
 #include "gtksourcecompletion.h"
 
-struct _GtkSourceCompletionContextPrivate
+struct _GtkSourceCompletionContext
 {
+       GInitiallyUnowned parent_instance;
+
        GtkSourceCompletion *completion;
 
        GtkTextMark *mark;
@@ -90,27 +92,26 @@ enum
 
 static guint context_signals[N_SIGNALS];
 
-G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceCompletionContext, gtk_source_completion_context, 
G_TYPE_INITIALLY_UNOWNED)
+G_DEFINE_TYPE (GtkSourceCompletionContext, gtk_source_completion_context, G_TYPE_INITIALLY_UNOWNED)
 
 static void
 gtk_source_completion_context_dispose (GObject *object)
 {
        GtkSourceCompletionContext *context = GTK_SOURCE_COMPLETION_CONTEXT (object);
 
-       if (context->priv->mark != NULL)
+       if (context->mark != NULL)
        {
-               GtkTextBuffer *buffer = gtk_text_mark_get_buffer (context->priv->mark);
+               GtkTextBuffer *buffer = gtk_text_mark_get_buffer (context->mark);
 
                if (buffer != NULL)
                {
-                       gtk_text_buffer_delete_mark (buffer, context->priv->mark);
+                       gtk_text_buffer_delete_mark (buffer, context->mark);
                }
 
-               g_object_unref (context->priv->mark);
-               context->priv->mark = NULL;
+               g_clear_object (&context->mark);
        }
 
-       g_clear_object (&context->priv->completion);
+       g_clear_object (&context->completion);
 
        G_OBJECT_CLASS (gtk_source_completion_context_parent_class)->dispose (object);
 }
@@ -123,27 +124,27 @@ set_iter (GtkSourceCompletionContext *context,
 
        buffer = gtk_text_iter_get_buffer (iter);
 
-       if (context->priv->mark != NULL)
+       if (context->mark != NULL)
        {
                GtkTextBuffer *old_buffer;
 
-               old_buffer = gtk_text_mark_get_buffer (context->priv->mark);
+               old_buffer = gtk_text_mark_get_buffer (context->mark);
 
                if (old_buffer != buffer)
                {
-                       g_object_unref (context->priv->mark);
-                       context->priv->mark = NULL;
+                       g_object_unref (context->mark);
+                       context->mark = NULL;
                }
        }
 
-       if (context->priv->mark == NULL)
+       if (context->mark == NULL)
        {
-               context->priv->mark = gtk_text_buffer_create_mark (buffer, NULL, iter, FALSE);
-               g_object_ref (context->priv->mark);
+               context->mark = gtk_text_buffer_create_mark (buffer, NULL, iter, FALSE);
+               g_object_ref (context->mark);
        }
        else
        {
-               gtk_text_buffer_move_mark (buffer, context->priv->mark, iter);
+               gtk_text_buffer_move_mark (buffer, context->mark, iter);
        }
 
        g_object_notify (G_OBJECT (context), "iter");
@@ -160,7 +161,7 @@ gtk_source_completion_context_set_property (GObject      *object,
        switch (prop_id)
        {
                case PROP_COMPLETION:
-                       context->priv->completion = g_value_dup_object (value);
+                       context->completion = g_value_dup_object (value);
                        break;
 
                case PROP_ITER:
@@ -168,7 +169,7 @@ gtk_source_completion_context_set_property (GObject      *object,
                        break;
 
                case PROP_ACTIVATION:
-                       context->priv->activation = g_value_get_flags (value);
+                       context->activation = g_value_get_flags (value);
                        break;
 
                default:
@@ -187,7 +188,7 @@ gtk_source_completion_context_get_property (GObject    *object,
        switch (prop_id)
        {
                case PROP_COMPLETION:
-                       g_value_set_object (value, context->priv->completion);
+                       g_value_set_object (value, context->completion);
                        break;
 
                case PROP_ITER:
@@ -202,7 +203,7 @@ gtk_source_completion_context_get_property (GObject    *object,
                        break;
 
                case PROP_ACTIVATION:
-                       g_value_set_flags (value, context->priv->activation);
+                       g_value_set_flags (value, context->activation);
                        break;
 
                default:
@@ -227,16 +228,10 @@ gtk_source_completion_context_class_init (GtkSourceCompletionContextClass *klass
         * to know when to cancel running proposal queries.
         **/
        context_signals[CANCELLED] =
-               g_signal_new ("cancelled",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                             G_STRUCT_OFFSET (GtkSourceCompletionContextClass, cancelled),
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__VOID,
-                             G_TYPE_NONE, 0);
-       g_signal_set_va_marshaller (context_signals[CANCELLED],
-                                   G_TYPE_FROM_CLASS (klass),
-                                   g_cclosure_marshal_VOID__VOIDv);
+               g_signal_new_class_handler ("cancelled",
+                                           G_TYPE_FROM_CLASS (klass),
+                                           G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                                           NULL, NULL, NULL, NULL, G_TYPE_NONE, 0);
 
        /**
         * GtkSourceCompletionContext:completion:
@@ -287,7 +282,7 @@ gtk_source_completion_context_class_init (GtkSourceCompletionContextClass *klass
 static void
 gtk_source_completion_context_init (GtkSourceCompletionContext *context)
 {
-       context->priv = gtk_source_completion_context_get_instance_private (context);
+       context = gtk_source_completion_context_get_instance_private (context);
 }
 
 /**
@@ -313,7 +308,7 @@ gtk_source_completion_context_add_proposals (GtkSourceCompletionContext  *contex
        g_return_if_fail (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
        g_return_if_fail (GTK_SOURCE_IS_COMPLETION_PROVIDER (provider));
 
-       _gtk_source_completion_add_proposals (context->priv->completion,
+       _gtk_source_completion_add_proposals (context->completion,
                                              context,
                                              provider,
                                              proposals,
@@ -340,7 +335,7 @@ gtk_source_completion_context_get_iter (GtkSourceCompletionContext *context,
 
        g_return_val_if_fail (GTK_SOURCE_IS_COMPLETION_CONTEXT (context), FALSE);
 
-       if (context->priv->mark == NULL)
+       if (context->mark == NULL)
        {
                /* This should never happen: context should be always be created
                   providing a position iter */
@@ -348,14 +343,14 @@ gtk_source_completion_context_get_iter (GtkSourceCompletionContext *context,
                return FALSE;
        }
 
-       mark_buffer = gtk_text_mark_get_buffer (context->priv->mark);
+       mark_buffer = gtk_text_mark_get_buffer (context->mark);
 
        if (mark_buffer == NULL)
        {
                return FALSE;
        }
 
-       view = gtk_source_completion_get_view (context->priv->completion);
+       view = gtk_source_completion_get_view (context->completion);
        if (view == NULL)
        {
                return FALSE;
@@ -368,7 +363,7 @@ gtk_source_completion_context_get_iter (GtkSourceCompletionContext *context,
                return FALSE;
        }
 
-       gtk_text_buffer_get_iter_at_mark (mark_buffer, iter, context->priv->mark);
+       gtk_text_buffer_get_iter_at_mark (mark_buffer, iter, context->mark);
        return TRUE;
 }
 
@@ -386,7 +381,7 @@ gtk_source_completion_context_get_activation (GtkSourceCompletionContext *contex
        g_return_val_if_fail (GTK_SOURCE_IS_COMPLETION_CONTEXT (context),
                              GTK_SOURCE_COMPLETION_ACTIVATION_NONE);
 
-       return context->priv->activation;
+       return context->activation;
 }
 
 void
diff --git a/gtksourceview/gtksourcecompletioncontext.h b/gtksourceview/gtksourcecompletioncontext.h
index 72d07eac..da04f8b1 100644
--- a/gtksourceview/gtksourcecompletioncontext.h
+++ b/gtksourceview/gtksourcecompletioncontext.h
@@ -29,15 +29,10 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_COMPLETION_CONTEXT             (gtk_source_completion_context_get_type ())
-#define GTK_SOURCE_COMPLETION_CONTEXT(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_COMPLETION_CONTEXT, GtkSourceCompletionContext))
-#define GTK_SOURCE_COMPLETION_CONTEXT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_COMPLETION_CONTEXT, GtkSourceCompletionContextClass))
-#define GTK_SOURCE_IS_COMPLETION_CONTEXT(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_COMPLETION_CONTEXT))
-#define GTK_SOURCE_IS_COMPLETION_CONTEXT_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_COMPLETION_CONTEXT))
-#define GTK_SOURCE_COMPLETION_CONTEXT_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_COMPLETION_CONTEXT, GtkSourceCompletionContextClass))
+#define GTK_SOURCE_TYPE_COMPLETION_CONTEXT (gtk_source_completion_context_get_type())
 
-typedef struct _GtkSourceCompletionContextClass                GtkSourceCompletionContextClass;
-typedef struct _GtkSourceCompletionContextPrivate      GtkSourceCompletionContextPrivate;
+GTK_SOURCE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (GtkSourceCompletionContext, gtk_source_completion_context, GTK_SOURCE, 
COMPLETION_CONTEXT, GInitiallyUnowned)
 
 /**
  * GtkSourceCompletionActivation:
@@ -51,49 +46,25 @@ typedef struct _GtkSourceCompletionContextPrivate   GtkSourceCompletionContextPriv
  */
 typedef enum _GtkSourceCompletionActivation
 {
-       GTK_SOURCE_COMPLETION_ACTIVATION_NONE = 0,
-       GTK_SOURCE_COMPLETION_ACTIVATION_INTERACTIVE = 1 << 0,
+       GTK_SOURCE_COMPLETION_ACTIVATION_NONE           = 0,
+       GTK_SOURCE_COMPLETION_ACTIVATION_INTERACTIVE    = 1 << 0,
        GTK_SOURCE_COMPLETION_ACTIVATION_USER_REQUESTED = 1 << 1
 } GtkSourceCompletionActivation;
 
-struct _GtkSourceCompletionContext {
-       GInitiallyUnowned parent;
-
-       GtkSourceCompletionContextPrivate *priv;
-};
-
-struct _GtkSourceCompletionContextClass {
-       GInitiallyUnownedClass parent_class;
-
-       void (*cancelled)       (GtkSourceCompletionContext          *context);
-
-       /* Padding for future expansion */
-       gpointer padding[10];
-};
-
 GTK_SOURCE_AVAILABLE_IN_ALL
-GType           gtk_source_completion_context_get_type (void) G_GNUC_CONST;
-
-GTK_SOURCE_AVAILABLE_IN_ALL
-void            gtk_source_completion_context_add_proposals    (GtkSourceCompletionContext   *context,
-                                                                GtkSourceCompletionProvider  *provider,
-                                                                GList                        *proposals,
-                                                                gboolean                      finished);
-
+void                           gtk_source_completion_context_add_proposals  (GtkSourceCompletionContext  
*context,
+                                                                             GtkSourceCompletionProvider 
*provider,
+                                                                             GList                       
*proposals,
+                                                                             gboolean                     
finished);
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean        gtk_source_completion_context_get_iter         (GtkSourceCompletionContext   *context,
-                                                                GtkTextIter                  *iter);
-
+gboolean                       gtk_source_completion_context_get_iter       (GtkSourceCompletionContext  
*context,
+                                                                             GtkTextIter                 
*iter);
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceCompletionActivation
-                gtk_source_completion_context_get_activation   (GtkSourceCompletionContext   *context);
-
+GtkSourceCompletionActivation  gtk_source_completion_context_get_activation (GtkSourceCompletionContext  
*context);
 G_GNUC_INTERNAL
-GtkSourceCompletionContext *
-               _gtk_source_completion_context_new              (GtkSourceCompletion          *completion,
-                                                                GtkTextIter                  *position);
-
+GtkSourceCompletionContext    *_gtk_source_completion_context_new           (GtkSourceCompletion         
*completion,
+                                                                             GtkTextIter                 
*position);
 G_GNUC_INTERNAL
-void           _gtk_source_completion_context_cancel           (GtkSourceCompletionContext   *context);
+void                           _gtk_source_completion_context_cancel        (GtkSourceCompletionContext  
*context);
 
 G_END_DECLS


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