[gnome-builder] libide/tweaks: add simple caption item type



commit 1bb031f29a2f573f60ef3dd12722abf70d1fd66b
Author: Christian Hergert <chergert redhat com>
Date:   Mon Aug 22 12:59:56 2022 -0700

    libide/tweaks: add simple caption item type

 src/libide/tweaks/ide-tweaks-caption.c | 153 +++++++++++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-caption.h |  40 +++++++++
 src/libide/tweaks/ide-tweaks-init.c    |   1 +
 src/libide/tweaks/libide-tweaks.h      |   1 +
 src/libide/tweaks/meson.build          |   2 +
 5 files changed, 197 insertions(+)
---
diff --git a/src/libide/tweaks/ide-tweaks-caption.c b/src/libide/tweaks/ide-tweaks-caption.c
new file mode 100644
index 000000000..a303dfdbc
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-caption.c
@@ -0,0 +1,153 @@
+/* ide-tweaks-caption.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-tweaks-caption"
+
+#include "config.h"
+
+#include "ide-tweaks-caption.h"
+
+struct _IdeTweaksCaption
+{
+  IdeTweaksWidget parent_instance;
+  char *text;
+};
+
+enum {
+  PROP_0,
+  PROP_TEXT,
+  N_PROPS
+};
+
+G_DEFINE_FINAL_TYPE (IdeTweaksCaption, ide_tweaks_caption, IDE_TYPE_TWEAKS_WIDGET)
+
+static GParamSpec *properties [N_PROPS];
+
+static GtkWidget *
+ide_tweaks_caption_create_for_item (IdeTweaksWidget *widget,
+                                    IdeTweaksItem   *item)
+{
+  g_assert (IDE_IS_TWEAKS_CAPTION (widget));
+  g_assert (IDE_IS_TWEAKS_CAPTION (item));
+
+  return g_object_new (GTK_TYPE_LABEL,
+                       "css-classes", IDE_STRV_INIT ("caption", "dim-label"),
+                       "label", IDE_TWEAKS_CAPTION (item)->text,
+                       "use-markup", TRUE,
+                       "xalign", .0f,
+                       "wrap", TRUE,
+                       NULL);
+}
+
+static void
+ide_tweaks_caption_dispose (GObject *object)
+{
+  IdeTweaksCaption *self = (IdeTweaksCaption *)object;
+
+  g_clear_pointer (&self->text, g_free);
+
+  G_OBJECT_CLASS (ide_tweaks_caption_parent_class)->dispose (object);
+}
+
+static void
+ide_tweaks_caption_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  IdeTweaksCaption *self = IDE_TWEAKS_CAPTION (object);
+
+  switch (prop_id)
+    {
+    case PROP_TEXT:
+      g_value_set_string (value, ide_tweaks_caption_get_text (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_caption_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  IdeTweaksCaption *self = IDE_TWEAKS_CAPTION (object);
+
+  switch (prop_id)
+    {
+    case PROP_TEXT:
+      ide_tweaks_caption_set_text (self, g_value_get_string (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_caption_class_init (IdeTweaksCaptionClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  IdeTweaksWidgetClass *widget_class = IDE_TWEAKS_WIDGET_CLASS (klass);
+
+  object_class->dispose = ide_tweaks_caption_dispose;
+  object_class->get_property = ide_tweaks_caption_get_property;
+  object_class->set_property = ide_tweaks_caption_set_property;
+
+  widget_class->create_for_item = ide_tweaks_caption_create_for_item;
+
+  properties [PROP_TEXT] =
+    g_param_spec_string ("text", NULL, NULL, NULL,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY |G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+ide_tweaks_caption_init (IdeTweaksCaption *self)
+{
+}
+
+IdeTweaksCaption *
+ide_tweaks_caption_new (void)
+{
+  return g_object_new (IDE_TYPE_TWEAKS_CAPTION, NULL);
+}
+
+const char *
+ide_tweaks_caption_get_text (IdeTweaksCaption *self)
+{
+  g_return_val_if_fail (IDE_IS_TWEAKS_CAPTION (self), NULL);
+
+  return self->text;
+}
+
+void
+ide_tweaks_caption_set_text (IdeTweaksCaption *self,
+                             const char       *text)
+{
+  g_return_if_fail (IDE_IS_TWEAKS_CAPTION (self));
+
+  if (ide_set_string (&self->text, text))
+    g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TEXT]);
+}
diff --git a/src/libide/tweaks/ide-tweaks-caption.h b/src/libide/tweaks/ide-tweaks-caption.h
new file mode 100644
index 000000000..cabbe1580
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-caption.h
@@ -0,0 +1,40 @@
+/* ide-tweaks-caption.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include "ide-tweaks-widget.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_TWEAKS_CAPTION (ide_tweaks_caption_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeTweaksCaption, ide_tweaks_caption, IDE, TWEAKS_CAPTION, IdeTweaksWidget)
+
+IDE_AVAILABLE_IN_ALL
+IdeTweaksCaption *ide_tweaks_caption_new      (void);
+IDE_AVAILABLE_IN_ALL
+const char       *ide_tweaks_caption_get_text (IdeTweaksCaption *self);
+IDE_AVAILABLE_IN_ALL
+void              ide_tweaks_caption_set_text (IdeTweaksCaption *self,
+                                               const char       *text);
+
+G_END_DECLS
diff --git a/src/libide/tweaks/ide-tweaks-init.c b/src/libide/tweaks/ide-tweaks-init.c
index 3f85b0ce9..67c98bd6b 100644
--- a/src/libide/tweaks/ide-tweaks-init.c
+++ b/src/libide/tweaks/ide-tweaks-init.c
@@ -34,6 +34,7 @@ _ide_tweaks_init (void)
 
   g_type_ensure (IDE_TYPE_TWEAKS);
   g_type_ensure (IDE_TYPE_TWEAKS_ADDIN);
+  g_type_ensure (IDE_TYPE_TWEAKS_CAPTION);
   g_type_ensure (IDE_TYPE_TWEAKS_CHOICE);
   g_type_ensure (IDE_TYPE_TWEAKS_COMBO);
   g_type_ensure (IDE_TYPE_TWEAKS_DIRECTORY);
diff --git a/src/libide/tweaks/libide-tweaks.h b/src/libide/tweaks/libide-tweaks.h
index 04f9a8e7c..10d866a76 100644
--- a/src/libide/tweaks/libide-tweaks.h
+++ b/src/libide/tweaks/libide-tweaks.h
@@ -23,6 +23,7 @@
 #define IDE_TWEAKS_INSIDE
 # include "ide-tweaks.h"
 # include "ide-tweaks-addin.h"
+# include "ide-tweaks-caption.h"
 # include "ide-tweaks-choice.h"
 # include "ide-tweaks-combo.h"
 # include "ide-tweaks-directory.h"
diff --git a/src/libide/tweaks/meson.build b/src/libide/tweaks/meson.build
index 1198e4e6c..2b6dcad8b 100644
--- a/src/libide/tweaks/meson.build
+++ b/src/libide/tweaks/meson.build
@@ -10,6 +10,7 @@ libide_tweaks_public_headers = [
   'libide-tweaks.h',
   'ide-tweaks.h',
   'ide-tweaks-addin.h',
+  'ide-tweaks-caption.h',
   'ide-tweaks-choice.h',
   'ide-tweaks-combo.h',
   'ide-tweaks-directory.h',
@@ -37,6 +38,7 @@ install_headers(libide_tweaks_public_headers, subdir: libide_tweaks_header_subdi
 libide_tweaks_public_sources = [
   'ide-tweaks.c',
   'ide-tweaks-addin.c',
+  'ide-tweaks-caption.c',
   'ide-tweaks-choice.c',
   'ide-tweaks-combo.c',
   'ide-tweaks-directory.c',


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