[gnome-builder/tweak] GbEditorTweakWidget: add language mode filtering
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/tweak] GbEditorTweakWidget: add language mode filtering
- Date: Wed, 17 Dec 2014 04:07:43 +0000 (UTC)
commit ea0c61ffb7fd8ae045397e28aad01d990f4550d5
Author: Christian Hergert <christian hergert me>
Date: Tue Dec 16 20:07:33 2014 -0800
GbEditorTweakWidget: add language mode filtering
src/editor/gb-editor-tweak-widget.c | 91 +++++++++++++++++++++++++++++++++++
1 files changed, 91 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-editor-tweak-widget.c b/src/editor/gb-editor-tweak-widget.c
index cf6163b..d864850 100644
--- a/src/editor/gb-editor-tweak-widget.c
+++ b/src/editor/gb-editor-tweak-widget.c
@@ -19,8 +19,10 @@
#define G_LOG_DOMAIN "editor-tweak"
#include <glib/gi18n.h>
+#include <gtksourceview/gtksource.h>
#include "gb-editor-tweak-widget.h"
+#include "gb-string.h"
#include "gb-widget.h"
struct _GbEditorTweakWidgetPrivate
@@ -38,6 +40,7 @@ enum {
};
static GParamSpec *gParamSpecs [LAST_PROP];
+static GQuark gLangQuark;
GtkWidget *
gb_editor_tweak_widget_new (void)
@@ -45,6 +48,91 @@ gb_editor_tweak_widget_new (void)
return g_object_new (GB_TYPE_EDITOR_TWEAK_WIDGET, NULL);
}
+static gboolean
+gb_editor_tweak_widget_filter_func (GtkListBoxRow *row,
+ gpointer user_data)
+{
+ GtkSourceLanguage *language;
+ GtkWidget *child;
+ const gchar *needle = user_data;
+ const gchar *lang_id;
+ const gchar *lang_name;
+
+ g_return_val_if_fail (GTK_IS_LIST_BOX_ROW (row), FALSE);
+ g_return_val_if_fail (needle, FALSE);
+
+ child = gtk_bin_get_child (GTK_BIN (row));
+ language = g_object_get_qdata (G_OBJECT (child), gLangQuark);
+ lang_id = gtk_source_language_get_id (language);
+ lang_name = gtk_source_language_get_name (language);
+
+ if (strstr (lang_id, needle) || strstr (lang_name, needle))
+ return TRUE;
+
+ return FALSE;
+}
+
+static void
+gb_editor_tweak_widget_entry_changed (GbEditorTweakWidget *widget,
+ GtkEntry *entry)
+{
+ const gchar *text;
+
+ g_return_if_fail (GB_IS_EDITOR_TWEAK_WIDGET (widget));
+ g_return_if_fail (GTK_IS_ENTRY (entry));
+
+ text = gtk_entry_get_text (entry);
+
+ if (gb_str_empty0 (text))
+ gtk_list_box_set_filter_func (widget->priv->list_box, NULL, NULL, NULL);
+ else
+ gtk_list_box_set_filter_func (widget->priv->list_box,
+ gb_editor_tweak_widget_filter_func,
+ g_strdup (text),
+ g_free);
+}
+
+static void
+gb_editor_tweak_widget_constructed (GObject *object)
+{
+ GbEditorTweakWidget *widget = (GbEditorTweakWidget *)object;
+ GtkSourceLanguageManager *manager;
+ GtkSourceLanguage *lang;
+ const gchar * const *lang_ids;
+ guint i;
+
+ g_return_if_fail (GB_IS_EDITOR_TWEAK_WIDGET (widget));
+
+ G_OBJECT_CLASS (gb_editor_tweak_widget_parent_class)->constructed (object);
+
+ manager = gtk_source_language_manager_get_default ();
+ lang_ids = gtk_source_language_manager_get_language_ids (manager);
+
+ for (i = 0; lang_ids [i]; i++)
+ {
+ GtkWidget *row;
+
+ lang = gtk_source_language_manager_get_language (manager, lang_ids [i]);
+ row = g_object_new (GTK_TYPE_LABEL,
+ "label", gtk_source_language_get_name (lang),
+ "visible", TRUE,
+ "xalign", 0.0f,
+ "margin-end", 6,
+ "margin-start", 6,
+ "margin-top", 3,
+ "margin-bottom", 3,
+ NULL);
+ g_object_set_qdata (G_OBJECT (row), gLangQuark, lang);
+ gtk_list_box_insert (widget->priv->list_box, row, -1);
+ }
+
+ g_signal_connect_object (widget->priv->entry,
+ "changed",
+ G_CALLBACK (gb_editor_tweak_widget_entry_changed),
+ widget,
+ G_CONNECT_SWAPPED);
+}
+
static void
gb_editor_tweak_widget_finalize (GObject *object)
{
@@ -87,6 +175,7 @@ gb_editor_tweak_widget_class_init (GbEditorTweakWidgetClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ object_class->constructed = gb_editor_tweak_widget_constructed;
object_class->finalize = gb_editor_tweak_widget_finalize;
object_class->get_property = gb_editor_tweak_widget_get_property;
object_class->set_property = gb_editor_tweak_widget_set_property;
@@ -94,6 +183,8 @@ gb_editor_tweak_widget_class_init (GbEditorTweakWidgetClass *klass)
GB_WIDGET_CLASS_TEMPLATE (widget_class, "gb-editor-tweak-widget.ui");
GB_WIDGET_CLASS_BIND (widget_class, GbEditorTweakWidget, entry);
GB_WIDGET_CLASS_BIND (widget_class, GbEditorTweakWidget, list_box);
+
+ gLangQuark = g_quark_from_static_string ("GtkSourceLanguage");
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]