[gnome-builder/wip/uajain/word-completion: 2/6] Add IdeWordCompletionItem



commit 5454445b4f517a51b7d7bc5f65b12b0ac5bf3979
Author: Umang Jain <mailumangjain gmail com>
Date:   Fri Aug 25 01:11:03 2017 +0530

    Add IdeWordCompletionItem

 libide/sourceview/ide-word-completion-item.c |  121 ++++++++++++++++++++++++++
 libide/sourceview/ide-word-completion-item.h |   61 +++++++++++++
 2 files changed, 182 insertions(+), 0 deletions(-)
---
diff --git a/libide/sourceview/ide-word-completion-item.c b/libide/sourceview/ide-word-completion-item.c
new file mode 100644
index 0000000..9e322ee
--- /dev/null
+++ b/libide/sourceview/ide-word-completion-item.c
@@ -0,0 +1,121 @@
+/* ide-word-completion-item.c
+ *
+ * Copyright (C) 2017 Umang Jain <mailumangjain gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-word-completion-item"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "sourceview/ide-word-completion-item.h"
+
+struct _IdeWordCompletionItemPrivate
+{
+  GIcon *icon;
+  gchar *word;
+  gint   offset;
+};
+
+static void ide_word_completion_item_iface_init (gpointer g_iface, gpointer iface_data);
+
+G_DEFINE_TYPE_WITH_CODE (IdeWordCompletionItem,
+                         ide_word_completion_item,
+                         IDE_TYPE_COMPLETION_ITEM,
+                         G_ADD_PRIVATE (IdeWordCompletionItem)
+                         G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROPOSAL,
+                                                ide_word_completion_item_iface_init))
+
+static gchar *
+ide_word_completion_item_get_text (GtkSourceCompletionProposal *proposal)
+{
+  return g_strdup (IDE_WORD_COMPLETION_ITEM(proposal)->priv->word);
+}
+
+static GIcon *
+ide_word_completion_item_get_gicon (GtkSourceCompletionProposal *proposal)
+{
+  return IDE_WORD_COMPLETION_ITEM(proposal)->priv->icon;
+}
+
+static void
+ide_word_completion_item_iface_init (gpointer g_iface,
+                                     gpointer iface_data)
+{
+  GtkSourceCompletionProposalIface *iface = (GtkSourceCompletionProposalIface *)g_iface;
+
+  /* Interface data getter implementations */
+  iface->get_label = ide_word_completion_item_get_text;
+  iface->get_text = ide_word_completion_item_get_text;
+  iface->get_gicon = ide_word_completion_item_get_gicon;
+}
+
+static void
+ide_word_completion_item_finalize (GObject *object)
+{
+  IdeWordCompletionItem *proposal;
+
+  proposal = IDE_WORD_COMPLETION_ITEM (object);
+  g_free (proposal->priv->word);
+  g_clear_object (&proposal->priv->icon);
+
+  G_OBJECT_CLASS (ide_word_completion_item_parent_class)->finalize (object);
+}
+
+static void
+ide_word_completion_item_class_init (IdeWordCompletionItemClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = ide_word_completion_item_finalize;
+}
+
+static void
+ide_word_completion_item_init (IdeWordCompletionItem *self)
+{
+  self->priv = ide_word_completion_item_get_instance_private (self);
+}
+
+IdeWordCompletionItem *
+ide_word_completion_item_new (const gchar *word, gint offset, GIcon *icon)
+{
+  IdeWordCompletionItem *proposal;
+  
+  g_return_val_if_fail (word != NULL, NULL);
+  
+  proposal = g_object_new (IDE_TYPE_WORD_COMPLETION_ITEM, NULL);
+
+  proposal->priv->word = g_strdup (word);
+  proposal->priv->offset = offset;
+  proposal->priv->icon = icon;
+
+  return proposal;
+}
+
+const gchar *
+ide_word_completion_item_get_word (IdeWordCompletionItem *proposal)
+{
+  g_return_val_if_fail (IDE_IS_WORD_COMPLETION_ITEM (proposal), NULL);
+  return proposal->priv->word;
+}
+
+gint
+ide_word_completion_item_get_offset (IdeWordCompletionItem *proposal)
+{
+  g_return_val_if_fail (IDE_IS_WORD_COMPLETION_ITEM (proposal), 0);
+  return proposal->priv->offset;
+}
diff --git a/libide/sourceview/ide-word-completion-item.h b/libide/sourceview/ide-word-completion-item.h
new file mode 100644
index 0000000..dcd62b7
--- /dev/null
+++ b/libide/sourceview/ide-word-completion-item.h
@@ -0,0 +1,61 @@
+/* ide-word-completion-item.h
+ *
+ * Copyright (C) 2017 Umang Jain <mailumangjain gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_WORD_COMPLETION_ITEM_H
+#define IDE_WORD_COMPLETION_ITEM_H
+
+#include <gtksourceview/gtksource.h>
+
+#include "sourceview/ide-completion-item.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_WORD_COMPLETION_ITEM                   (ide_word_completion_item_get_type ())
+#define IDE_WORD_COMPLETION_ITEM(obj)                   (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
IDE_TYPE_WORD_COMPLETION_ITEM, IdeWordCompletionItem))
+#define IDE_WORD_COMPLETION_ITEM_CONST(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
IDE_TYPE_WORD_COMPLETION_ITEM, IdeWordCompletionItem const))
+#define IDE_WORD_COMPLETION_ITEM_CLASS(klass)           (G_TYPE_CHECK_CLASS_CAST ((klass), 
IDE_TYPE_WORD_COMPLETION_ITEM, IdeWordCompletionItemClass))
+#define IDE_IS_WORD_COMPLETION_ITEM(obj)                (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
IDE_TYPE_WORD_COMPLETION_ITEM))
+#define IDE_IS_WORD_COMPLETION_ITEM_CLASS(klass)        (G_TYPE_CHECK_CLASS_TYPE ((klass), 
IDE_TYPE_WORD_COMPLETION_ITEM))
+#define IDE_WORD_COMPLETION_ITEM_GET_CLASS(obj)         (G_TYPE_INSTANCE_GET_CLASS ((obj), 
IDE_TYPE_WORD_COMPLETION_ITEM, IdeWordCompletionItemClass))
+
+typedef struct _IdeWordCompletionItem             IdeWordCompletionItem;
+typedef struct _IdeWordCompletionItemClass        IdeWordCompletionItemClass;
+typedef struct _IdeWordCompletionItemPrivate      IdeWordCompletionItemPrivate;
+
+struct _IdeWordCompletionItem
+{
+  IdeCompletionItem parent;
+
+  IdeWordCompletionItemPrivate *priv;
+};
+
+struct _IdeWordCompletionItemClass
+{
+  IdeCompletionItemClass parent_class;
+};
+
+GType                  ide_word_completion_item_get_type  (void) G_GNUC_CONST;
+IdeWordCompletionItem *ide_word_completion_item_new        (const gchar *word,
+                                                            gint         offset,
+                                                            GIcon       *icon);
+const gchar           *ide_word_completion_item_get_word   (IdeWordCompletionItem *proposal);
+gint                   ide_word_completion_item_get_offset (IdeWordCompletionItem *proposal);
+
+G_END_DECLS
+
+#endif /* IDE_WORD_COMPLETION_ITEM_H */


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