[gnome-builder] prefs: add GbPreferencesPage abstraction
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] prefs: add GbPreferencesPage abstraction
- Date: Mon, 13 Oct 2014 03:20:21 +0000 (UTC)
commit e9d5d7885fb82e3c7dfe113270db9a70be96b855
Author: Christian Hergert <christian hergert me>
Date: Sun Oct 12 23:19:37 2014 -0400
prefs: add GbPreferencesPage abstraction
src/gnome-builder.mk | 4 +
src/preferences/gb-preferences-page.c | 135 +++++++++++++++++++++++++++++++++
src/preferences/gb-preferences-page.h | 55 +++++++++++++
3 files changed, 194 insertions(+), 0 deletions(-)
---
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 70c53d2..f0375eb 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -79,6 +79,10 @@ libgnome_builder_la_SOURCES = \
src/navigation/gb-navigation-item.c \
src/preferences/gb-preferences-window.c \
src/preferences/gb-preferences-window.h \
+ src/preferences/gb-preferences-page.c \
+ src/preferences/gb-preferences-page.h \
+ src/preferences/gb-preferences-page-editor.c \
+ src/preferences/gb-preferences-page-editor.h \
src/sidebar/gb-sidebar.c \
src/sidebar/gb-sidebar.h \
src/snippets/gb-source-snippet-chunk.c \
diff --git a/src/preferences/gb-preferences-page.c b/src/preferences/gb-preferences-page.c
new file mode 100644
index 0000000..072712f
--- /dev/null
+++ b/src/preferences/gb-preferences-page.c
@@ -0,0 +1,135 @@
+/* gb-preferences-page.c
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * 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/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "gb-preferences-page.h"
+#include "gb-string.h"
+
+struct _GbPreferencesPagePrivate
+{
+ gchar *title;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GbPreferencesPage, gb_preferences_page,
+ GTK_TYPE_BIN)
+
+enum {
+ PROP_0,
+ PROP_TITLE,
+ LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+const gchar *
+gb_preferences_page_get_title (GbPreferencesPage *page)
+{
+ g_return_val_if_fail (GB_IS_PREFERENCES_PAGE (page), NULL);
+
+ return page->priv->title;
+}
+
+void
+gb_preferences_page_set_title (GbPreferencesPage *page,
+ const gchar *title)
+{
+ g_return_if_fail (GB_IS_PREFERENCES_PAGE (page));
+
+ if (!gb_str_equal0 (title, page->priv->title))
+ {
+ g_free (page->priv->title);
+ page->priv->title = g_strdup (title);
+ g_object_notify_by_pspec (G_OBJECT (page),
+ gParamSpecs [PROP_TITLE]);
+ }
+}
+
+static void
+gb_preferences_page_finalize (GObject *object)
+{
+ GbPreferencesPagePrivate *priv = GB_PREFERENCES_PAGE (object)->priv;
+
+ g_clear_pointer (&priv->title, g_free);
+
+ G_OBJECT_CLASS (gb_preferences_page_parent_class)->finalize (object);
+}
+
+static void
+gb_preferences_page_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GbPreferencesPage *self = GB_PREFERENCES_PAGE (object);
+
+ switch (prop_id)
+ {
+ case PROP_TITLE:
+ g_value_set_string (value, gb_preferences_page_get_title (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gb_preferences_page_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GbPreferencesPage *self = GB_PREFERENCES_PAGE (object);
+
+ switch (prop_id)
+ {
+ case PROP_TITLE:
+ gb_preferences_page_set_title (self, g_value_get_string (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gb_preferences_page_class_init (GbPreferencesPageClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gb_preferences_page_finalize;
+ object_class->get_property = gb_preferences_page_get_property;
+ object_class->set_property = gb_preferences_page_set_property;
+
+ gParamSpecs [PROP_TITLE] =
+ g_param_spec_string ("title",
+ _("Title"),
+ _("The title for the preferences page."),
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_TITLE,
+ gParamSpecs [PROP_TITLE]);
+}
+
+static void
+gb_preferences_page_init (GbPreferencesPage *self)
+{
+ self->priv = gb_preferences_page_get_instance_private (self);
+}
diff --git a/src/preferences/gb-preferences-page.h b/src/preferences/gb-preferences-page.h
new file mode 100644
index 0000000..2f1ac92
--- /dev/null
+++ b/src/preferences/gb-preferences-page.h
@@ -0,0 +1,55 @@
+/* gb-preferences-page.h
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * 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 GB_PREFERENCES_PAGE_H
+#define GB_PREFERENCES_PAGE_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_PREFERENCES_PAGE (gb_preferences_page_get_type())
+#define GB_PREFERENCES_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_PREFERENCES_PAGE,
GbPreferencesPage))
+#define GB_PREFERENCES_PAGE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_PREFERENCES_PAGE,
GbPreferencesPage const))
+#define GB_PREFERENCES_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GB_TYPE_PREFERENCES_PAGE,
GbPreferencesPageClass))
+#define GB_IS_PREFERENCES_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GB_TYPE_PREFERENCES_PAGE))
+#define GB_IS_PREFERENCES_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GB_TYPE_PREFERENCES_PAGE))
+#define GB_PREFERENCES_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GB_TYPE_PREFERENCES_PAGE,
GbPreferencesPageClass))
+
+typedef struct _GbPreferencesPage GbPreferencesPage;
+typedef struct _GbPreferencesPageClass GbPreferencesPageClass;
+typedef struct _GbPreferencesPagePrivate GbPreferencesPagePrivate;
+
+struct _GbPreferencesPage
+{
+ GtkBin parent;
+
+ /*< private >*/
+ GbPreferencesPagePrivate *priv;
+};
+
+struct _GbPreferencesPageClass
+{
+ GtkBinClass parent;
+};
+
+GType gb_preferences_page_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* GB_PREFERENCES_PAGE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]