[gnome-builder] prefs: add GbPreferencesPageGit.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] prefs: add GbPreferencesPageGit.
- Date: Mon, 13 Oct 2014 15:40:18 +0000 (UTC)
commit c62152d731fe5a374109d13270bfc93e80e0564c
Author: Christian Hergert <christian hergert me>
Date: Mon Oct 13 11:39:27 2014 -0400
prefs: add GbPreferencesPageGit.
src/gnome-builder.mk | 2 +
src/preferences/gb-preferences-page-git.c | 122 +++++++++++++++++++++++++++
src/preferences/gb-preferences-page-git.h | 55 ++++++++++++
src/resources/ui/gb-preferences-page-git.ui | 68 +++++++++++++++
src/resources/ui/gb-preferences-window.ui | 63 ++------------
5 files changed, 256 insertions(+), 54 deletions(-)
---
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index f0375eb..c6c83a6 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -83,6 +83,8 @@ libgnome_builder_la_SOURCES = \
src/preferences/gb-preferences-page.h \
src/preferences/gb-preferences-page-editor.c \
src/preferences/gb-preferences-page-editor.h \
+ src/preferences/gb-preferences-page-git.c \
+ src/preferences/gb-preferences-page-git.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-git.c b/src/preferences/gb-preferences-page-git.c
new file mode 100644
index 0000000..16b2a34
--- /dev/null
+++ b/src/preferences/gb-preferences-page-git.c
@@ -0,0 +1,122 @@
+/* gb-preferences-page-git.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 <libgit2-glib/ggit.h>
+
+#include "gb-preferences-page-git.h"
+
+struct _GbPreferencesPageGitPrivate
+{
+ GgitConfig *config;
+
+ GtkEntry *git_author_name_entry;
+ GtkEntry *git_author_email_entry;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GbPreferencesPageGit, gb_preferences_page_git,
+ GTK_TYPE_BIN)
+
+static void
+on_author_name_changed (GtkEntry *entry,
+ GbPreferencesPageGit *git)
+{
+ g_return_if_fail (GB_IS_PREFERENCES_PAGE_GIT (git));
+ g_return_if_fail (GTK_IS_ENTRY (entry));
+
+ ggit_config_set_string (git->priv->config, "user.name",
+ gtk_entry_get_text (entry), NULL);
+}
+
+static void
+on_author_email_changed (GtkEntry *entry,
+ GbPreferencesPageGit *git)
+{
+ g_return_if_fail (GB_IS_PREFERENCES_PAGE_GIT (git));
+ g_return_if_fail (GTK_IS_ENTRY (entry));
+
+ ggit_config_set_string (git->priv->config, "user.email",
+ gtk_entry_get_text (entry), NULL);
+}
+
+static void
+gb_preferences_page_git_constructed (GObject *object)
+{
+ GbPreferencesPageGitPrivate *priv;
+ GbPreferencesPageGit *git = (GbPreferencesPageGit *)object;
+ const gchar *value;
+
+ g_return_if_fail (GB_IS_PREFERENCES_PAGE_GIT (git));
+
+ priv = git->priv;
+
+ /* set current values from git */
+ value = ggit_config_get_string (priv->config, "user.name", NULL);
+ if (value)
+ gtk_entry_set_text (priv->git_author_name_entry, value);
+ value = ggit_config_get_string (priv->config, "user.email", NULL);
+ if (value)
+ gtk_entry_set_text (priv->git_author_email_entry, value);
+
+ /* connect to changed signals to update values */
+ g_signal_connect (priv->git_author_name_entry,
+ "changed",
+ G_CALLBACK (on_author_name_changed),
+ git);
+ g_signal_connect (priv->git_author_email_entry,
+ "changed",
+ G_CALLBACK (on_author_email_changed),
+ git);
+
+ G_OBJECT_CLASS (gb_preferences_page_git_parent_class)->constructed (object);
+}
+
+static void
+gb_preferences_page_git_finalize (GObject *object)
+{
+ GbPreferencesPageGitPrivate *priv = GB_PREFERENCES_PAGE_GIT (object)->priv;
+
+ g_clear_object (&priv->config);
+
+ G_OBJECT_CLASS (gb_preferences_page_git_parent_class)->finalize (object);
+}
+
+static void
+gb_preferences_page_git_class_init (GbPreferencesPageGitClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->constructed = gb_preferences_page_git_constructed;
+ object_class->finalize = gb_preferences_page_git_finalize;
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/builder/ui/gb-preferences-page-git.ui");
+
+ gtk_widget_class_bind_template_child_private (widget_class, GbPreferencesPageGit, git_author_name_entry);
+ gtk_widget_class_bind_template_child_private (widget_class, GbPreferencesPageGit, git_author_email_entry);
+}
+
+static void
+gb_preferences_page_git_init (GbPreferencesPageGit *self)
+{
+ self->priv = gb_preferences_page_git_get_instance_private (self);
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ self->priv->config = ggit_config_new_default (NULL);
+}
diff --git a/src/preferences/gb-preferences-page-git.h b/src/preferences/gb-preferences-page-git.h
new file mode 100644
index 0000000..2026cc3
--- /dev/null
+++ b/src/preferences/gb-preferences-page-git.h
@@ -0,0 +1,55 @@
+/* gb-preferences-page-git.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_GIT_H
+#define GB_PREFERENCES_PAGE_GIT_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_PREFERENCES_PAGE_GIT (gb_preferences_page_git_get_type())
+#define GB_PREFERENCES_PAGE_GIT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GB_TYPE_PREFERENCES_PAGE_GIT, GbPreferencesPageGit))
+#define GB_PREFERENCES_PAGE_GIT_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GB_TYPE_PREFERENCES_PAGE_GIT, GbPreferencesPageGit const))
+#define GB_PREFERENCES_PAGE_GIT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GB_TYPE_PREFERENCES_PAGE_GIT, GbPreferencesPageGitClass))
+#define GB_IS_PREFERENCES_PAGE_GIT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GB_TYPE_PREFERENCES_PAGE_GIT))
+#define GB_IS_PREFERENCES_PAGE_GIT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GB_TYPE_PREFERENCES_PAGE_GIT))
+#define GB_PREFERENCES_PAGE_GIT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GB_TYPE_PREFERENCES_PAGE_GIT, GbPreferencesPageGitClass))
+
+typedef struct _GbPreferencesPageGit GbPreferencesPageGit;
+typedef struct _GbPreferencesPageGitClass GbPreferencesPageGitClass;
+typedef struct _GbPreferencesPageGitPrivate GbPreferencesPageGitPrivate;
+
+struct _GbPreferencesPageGit
+{
+ GtkBin parent;
+
+ /*< private >*/
+ GbPreferencesPageGitPrivate *priv;
+};
+
+struct _GbPreferencesPageGitClass
+{
+ GtkBinClass parent;
+};
+
+GType gb_preferences_page_git_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* GB_PREFERENCES_PAGE_GIT_H */
diff --git a/src/resources/ui/gb-preferences-page-git.ui b/src/resources/ui/gb-preferences-page-git.ui
new file mode 100644
index 0000000..90aa502
--- /dev/null
+++ b/src/resources/ui/gb-preferences-page-git.ui
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.8 -->
+ <template class="GbPreferencesPageGit" parent="GtkBin">
+ <child>
+ <object class="GtkGrid">
+ <property name="visible">True</property>
+ <property name="row-spacing">6</property>
+ <property name="column-spacing">12</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="halign">start</property>
+ <property name="hexpand">False</property>
+ <property name="label" translatable="Yes">Author Name</property>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="width">1</property>
+ <property name="top-attach">0</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="git_author_name_entry">
+ <property name="visible">True</property>
+ <property name="hexpand">True</property>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="width">1</property>
+ <property name="top-attach">0</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="Yes">Author Email</property>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="width">1</property>
+ <property name="top-attach">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="git_author_email_entry">
+ <property name="visible">True</property>
+ <property name="hexpand">True</property>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="width">1</property>
+ <property name="top-attach">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="name">git</property>
+ <property name="title" translatable="yes">Git</property>
+ </packing>
+ </child>
+ </template>
+</interface>
diff --git a/src/resources/ui/gb-preferences-window.ui b/src/resources/ui/gb-preferences-window.ui
index 2d7ec35..893830c 100644
--- a/src/resources/ui/gb-preferences-window.ui
+++ b/src/resources/ui/gb-preferences-window.ui
@@ -103,8 +103,8 @@
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="expand">True</property>
+ <property name="visible-child">editor_page</property>
<property name="transition-type">GTK_STACK_TRANSITION_TYPE_CROSSFADE</property>
- <property name="visible_child">editor_grid</property>
<child>
<object class="GbPreferencesPageEditor" id="editor_page">
<property name="visible">True</property>
@@ -115,60 +115,8 @@
</packing>
</child>
<child>
- <object class="GtkGrid" id="git_grid">
+ <object class="GbPreferencesPageGit" id="git_page">
<property name="visible">True</property>
- <property name="row-spacing">6</property>
- <property name="column-spacing">12</property>
- <child>
- <object class="GtkLabel" id="git_author_name_label">
- <property name="visible">True</property>
- <property name="halign">start</property>
- <property name="label" translatable="Yes">Author Name</property>
- </object>
- <packing>
- <property name="left-attach">0</property>
- <property name="width">1</property>
- <property name="top-attach">0</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="git_author_name_entry">
- <property name="visible">True</property>
- <property name="hexpand">True</property>
- </object>
- <packing>
- <property name="left-attach">1</property>
- <property name="width">1</property>
- <property name="top-attach">0</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="git_author_email_label">
- <property name="visible">True</property>
- <property name="halign">start</property>
- <property name="label" translatable="Yes">Author Email</property>
- </object>
- <packing>
- <property name="left-attach">0</property>
- <property name="width">1</property>
- <property name="top-attach">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="git_author_email_entry">
- <property name="visible">True</property>
- <property name="hexpand">True</property>
- </object>
- <packing>
- <property name="left-attach">1</property>
- <property name="width">1</property>
- <property name="top-attach">1</property>
- <property name="height">1</property>
- </packing>
- </child>
</object>
<packing>
<property name="name">git</property>
@@ -180,4 +128,11 @@
</object>
</child>
</template>
+ <object class="GtkSizeGroup">
+ <property name="mode">GTK_SIZE_GROUP_HORIZONTAL</property>
+ <widgets>
+ <widget name="left_header_bar"/>
+ <widget name="sidebar"/>
+ </widgets>
+ </object>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]