[gnome-builder] libide/tweaks: implement basic item matching
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/tweaks: implement basic item matching
- Date: Tue, 23 Aug 2022 04:07:54 +0000 (UTC)
commit a949a3f05d6aff36969d67754faed4fbf8b57388
Author: Christian Hergert <chergert redhat com>
Date: Mon Aug 22 20:39:29 2022 -0700
libide/tweaks: implement basic item matching
src/libide/tweaks/ide-tweaks-item.c | 34 ++++++++++++++++++++++++++++++++++
src/libide/tweaks/ide-tweaks-item.h | 12 +++++++++---
src/libide/tweaks/ide-tweaks-page.c | 11 +++++++++++
3 files changed, 54 insertions(+), 3 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-item.c b/src/libide/tweaks/ide-tweaks-item.c
index 7399063e7..9f7a9ca14 100644
--- a/src/libide/tweaks/ide-tweaks-item.c
+++ b/src/libide/tweaks/ide-tweaks-item.c
@@ -140,6 +140,27 @@ ide_tweaks_item_real_copy (IdeTweaksItem *self)
return IDE_TWEAKS_ITEM (copy);
}
+static gboolean
+ide_tweaks_item_real_match (IdeTweaksItem *self,
+ IdePatternSpec *spec)
+{
+ IdeTweaksItemPrivate *priv = ide_tweaks_item_get_instance_private (self);
+
+ g_assert (IDE_IS_TWEAKS_ITEM (self));
+ g_assert (spec != NULL);
+
+ if (priv->keywords != NULL)
+ {
+ for (guint i = 0; priv->keywords[i]; i++)
+ {
+ if (ide_pattern_spec_match (spec, priv->keywords[i]))
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
static void
ide_tweaks_item_dispose (GObject *object)
{
@@ -219,6 +240,7 @@ ide_tweaks_item_class_init (IdeTweaksItemClass *klass)
object_class->set_property = ide_tweaks_item_set_property;
klass->copy = ide_tweaks_item_real_copy;
+ klass->match = ide_tweaks_item_real_match;
properties[PROP_ID] =
g_param_spec_string ("id", NULL, NULL,
@@ -787,3 +809,15 @@ ide_tweaks_item_get_root (IdeTweaksItem *self)
return parent;
}
+
+gboolean
+ide_tweaks_item_match (IdeTweaksItem *self,
+ IdePatternSpec *spec)
+{
+ g_return_val_if_fail (IDE_IS_TWEAKS_ITEM (self), FALSE);
+
+ if (spec == NULL)
+ return TRUE;
+
+ return IDE_TWEAKS_ITEM_GET_CLASS (self)->match (self, spec);
+}
diff --git a/src/libide/tweaks/ide-tweaks-item.h b/src/libide/tweaks/ide-tweaks-item.h
index ccdd028e1..906187002 100644
--- a/src/libide/tweaks/ide-tweaks-item.h
+++ b/src/libide/tweaks/ide-tweaks-item.h
@@ -25,6 +25,7 @@
#endif
#include <libide-core.h>
+#include <libide-search.h>
G_BEGIN_DECLS
@@ -57,9 +58,11 @@ struct _IdeTweaksItemClass
{
GObjectClass parent_class;
- gboolean (*accepts) (IdeTweaksItem *self,
- IdeTweaksItem *child);
- IdeTweaksItem *(*copy) (IdeTweaksItem *self);
+ gboolean (*accepts) (IdeTweaksItem *self,
+ IdeTweaksItem *child);
+ IdeTweaksItem *(*copy) (IdeTweaksItem *self);
+ gboolean (*match) (IdeTweaksItem *self,
+ IdePatternSpec *spec);
};
IDE_AVAILABLE_IN_ALL
@@ -72,6 +75,9 @@ IDE_AVAILABLE_IN_ALL
void ide_tweaks_item_set_keywords (IdeTweaksItem *self,
const char * const *keywords);
IDE_AVAILABLE_IN_ALL
+gboolean ide_tweaks_item_match (IdeTweaksItem *self,
+ IdePatternSpec *spec);
+IDE_AVAILABLE_IN_ALL
gboolean ide_tweaks_item_is_ancestor (IdeTweaksItem *self,
IdeTweaksItem *ancestor);
IDE_AVAILABLE_IN_ALL
diff --git a/src/libide/tweaks/ide-tweaks-page.c b/src/libide/tweaks/ide-tweaks-page.c
index 176081789..91026cd63 100644
--- a/src/libide/tweaks/ide-tweaks-page.c
+++ b/src/libide/tweaks/ide-tweaks-page.c
@@ -68,6 +68,16 @@ ide_tweaks_page_accepts (IdeTweaksItem *item,
IDE_IS_TWEAKS_SECTION (child);
}
+static gboolean
+ide_tweaks_page_match (IdeTweaksItem *item,
+ IdePatternSpec *spec)
+{
+ IdeTweaksPage *self = IDE_TWEAKS_PAGE (item);
+
+ return ide_pattern_spec_match (spec, self->title) ||
+ IDE_TWEAKS_ITEM_CLASS (ide_tweaks_page_parent_class)->match (item, spec);
+}
+
static void
ide_tweaks_page_dispose (GObject *object)
{
@@ -152,6 +162,7 @@ ide_tweaks_page_class_init (IdeTweaksPageClass *klass)
object_class->set_property = ide_tweaks_page_set_property;
item_class->accepts = ide_tweaks_page_accepts;
+ item_class->match = ide_tweaks_page_match;
properties [PROP_HAS_SUBPAGE] =
g_param_spec_boolean ("has-subpage", NULL, NULL,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]