[gnome-builder/wip/language-settings: 1/2] prefs: add a language settings page.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/language-settings: 1/2] prefs: add a language settings page.
- Date: Tue, 14 Oct 2014 20:49:22 +0000 (UTC)
commit 39a391be2dacd49643c0562d03b60c0f94513f2f
Author: Christian Hergert <christian hergert me>
Date: Mon Oct 13 22:38:46 2014 -0400
prefs: add a language settings page.
src/gnome-builder.mk | 2 +
src/preferences/gb-preferences-page-language.c | 191 ++++++++++++++++++++++
src/preferences/gb-preferences-page-language.h | 55 ++++++
src/preferences/gb-preferences-window.c | 2 +
src/resources/gnome-builder.gresource.xml | 1 +
src/resources/ui/gb-preferences-page-language.ui | 36 ++++
src/resources/ui/gb-preferences-window.ui | 9 +
7 files changed, 296 insertions(+), 0 deletions(-)
---
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index c6c83a6..11e4f07 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -85,6 +85,8 @@ libgnome_builder_la_SOURCES = \
src/preferences/gb-preferences-page-editor.h \
src/preferences/gb-preferences-page-git.c \
src/preferences/gb-preferences-page-git.h \
+ src/preferences/gb-preferences-page-language.c \
+ src/preferences/gb-preferences-page-language.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-language.c b/src/preferences/gb-preferences-page-language.c
new file mode 100644
index 0000000..444cf64
--- /dev/null
+++ b/src/preferences/gb-preferences-page-language.c
@@ -0,0 +1,191 @@
+/* gb-preferences-page-language.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 <gtksourceview/gtksource.h>
+#include <string.h>
+
+#include "gb-preferences-page-language.h"
+#include "gb-string.h"
+
+struct _GbPreferencesPageLanguagePrivate
+{
+ GtkListBox *language_list_box;
+ GtkSearchEntry *search_entry;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GbPreferencesPageLanguage,
+ gb_preferences_page_language,
+ GB_TYPE_PREFERENCES_PAGE)
+
+GtkWidget *
+make_language_row (GtkSourceLanguage *language)
+{
+ GtkListBoxRow *row;
+ GtkBox *box;
+ GtkLabel *label;
+ const gchar *name;
+
+ box = g_object_new (GTK_TYPE_BOX,
+ "orientation", GTK_ORIENTATION_HORIZONTAL,
+ "spacing", 6,
+ "visible", TRUE,
+ NULL);
+
+ name = gtk_source_language_get_name (language);
+
+ label = g_object_new (GTK_TYPE_LABEL,
+ "hexpand", TRUE,
+ "visible", TRUE,
+ "ypad", 6,
+ "xpad", 6,
+ "xalign", 0.0f,
+ "label", name,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (label));
+
+ row = g_object_new (GTK_TYPE_LIST_BOX_ROW,
+ "visible", TRUE,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (row), GTK_WIDGET (box));
+
+ g_object_set_data (G_OBJECT (row), "GTK_SOURCE_LANGUAGE", language);
+
+ return GTK_WIDGET (row);
+}
+
+static void
+item_header_func (GtkListBoxRow *row,
+ GtkListBoxRow *before,
+ gpointer user_data)
+{
+ g_return_if_fail (GTK_IS_LIST_BOX_ROW (row));
+
+ if (before)
+ {
+ GtkWidget *sep;
+
+ sep = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_list_box_row_set_header (row, sep);
+ gtk_widget_show (sep);
+ }
+}
+
+static gboolean
+item_filter_func (GtkListBoxRow *row,
+ gpointer user_data)
+{
+ GtkEntry *entry = user_data;
+ GtkSourceLanguage *lang;
+ const gchar *text;
+
+ g_return_val_if_fail (GTK_IS_LIST_BOX_ROW (row), FALSE);
+ g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
+
+ text = gtk_entry_get_text (entry);
+
+ if (gb_str_empty0 (text))
+ return TRUE;
+
+ lang = g_object_get_data (G_OBJECT (row), "GTK_SOURCE_LANGUAGE");
+ g_assert (lang);
+
+ if (strstr (gtk_source_language_get_id (lang), text) ||
+ strstr (gtk_source_language_get_name (lang), text))
+ return TRUE;
+
+ return FALSE;
+}
+
+static void
+search_entry_changed (GtkEntry *entry,
+ GtkListBox *list_box)
+{
+ g_return_if_fail (GTK_IS_LIST_BOX (list_box));
+
+ gtk_list_box_invalidate_filter (list_box);
+}
+
+static void
+gb_preferences_page_language_constructed (GObject *object)
+{
+ GtkSourceLanguageManager *manager;
+ GbPreferencesPageLanguage *page = (GbPreferencesPageLanguage *)object;
+ const gchar * const *lang_ids;
+ guint i;
+
+ gtk_list_box_set_header_func (page->priv->language_list_box,
+ item_header_func, NULL, NULL);
+ gtk_list_box_set_filter_func (page->priv->language_list_box,
+ item_filter_func, page->priv->search_entry,
+ NULL);
+
+ g_signal_connect (page->priv->search_entry,
+ "changed",
+ G_CALLBACK (search_entry_changed),
+ page->priv->language_list_box);
+
+ manager = gtk_source_language_manager_get_default ();
+ lang_ids = gtk_source_language_manager_get_language_ids (manager);
+
+ for (i = 0; lang_ids [i]; i++)
+ {
+ GtkSourceLanguage *lang;
+ GtkWidget *widget;
+
+ lang = gtk_source_language_manager_get_language (manager, lang_ids [i]);
+ widget = make_language_row (lang);
+
+ gtk_container_add (GTK_CONTAINER (page->priv->language_list_box), widget);
+ }
+
+ G_OBJECT_CLASS (gb_preferences_page_language_parent_class)->constructed (object);
+}
+
+static void
+gb_preferences_page_language_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (gb_preferences_page_language_parent_class)->finalize (object);
+}
+
+static void
+gb_preferences_page_language_class_init (GbPreferencesPageLanguageClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->constructed = gb_preferences_page_language_constructed;
+ object_class->finalize = gb_preferences_page_language_finalize;
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/builder/ui/gb-preferences-page-language.ui");
+
+ gtk_widget_class_bind_template_child_private (widget_class,
+ GbPreferencesPageLanguage,
+ language_list_box);
+ gtk_widget_class_bind_template_child_private (widget_class,
+ GbPreferencesPageLanguage,
+ search_entry);
+}
+
+static void
+gb_preferences_page_language_init (GbPreferencesPageLanguage *self)
+{
+ self->priv = gb_preferences_page_language_get_instance_private (self);
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/src/preferences/gb-preferences-page-language.h b/src/preferences/gb-preferences-page-language.h
new file mode 100644
index 0000000..e39fe9b
--- /dev/null
+++ b/src/preferences/gb-preferences-page-language.h
@@ -0,0 +1,55 @@
+/* gb-preferences-page-language.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_LANGUAGE_H
+#define GB_PREFERENCES_PAGE_LANGUAGE_H
+
+#include "gb-preferences-page.h"
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_PREFERENCES_PAGE_LANGUAGE (gb_preferences_page_language_get_type())
+#define GB_PREFERENCES_PAGE_LANGUAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GB_TYPE_PREFERENCES_PAGE_LANGUAGE, GbPreferencesPageLanguage))
+#define GB_PREFERENCES_PAGE_LANGUAGE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GB_TYPE_PREFERENCES_PAGE_LANGUAGE, GbPreferencesPageLanguage const))
+#define GB_PREFERENCES_PAGE_LANGUAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GB_TYPE_PREFERENCES_PAGE_LANGUAGE, GbPreferencesPageLanguageClass))
+#define GB_IS_PREFERENCES_PAGE_LANGUAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GB_TYPE_PREFERENCES_PAGE_LANGUAGE))
+#define GB_IS_PREFERENCES_PAGE_LANGUAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GB_TYPE_PREFERENCES_PAGE_LANGUAGE))
+#define GB_PREFERENCES_PAGE_LANGUAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GB_TYPE_PREFERENCES_PAGE_LANGUAGE, GbPreferencesPageLanguageClass))
+
+typedef struct _GbPreferencesPageLanguage GbPreferencesPageLanguage;
+typedef struct _GbPreferencesPageLanguageClass GbPreferencesPageLanguageClass;
+typedef struct _GbPreferencesPageLanguagePrivate GbPreferencesPageLanguagePrivate;
+
+struct _GbPreferencesPageLanguage
+{
+ GbPreferencesPage parent;
+
+ /*< private >*/
+ GbPreferencesPageLanguagePrivate *priv;
+};
+
+struct _GbPreferencesPageLanguageClass
+{
+ GbPreferencesPageClass parent;
+};
+
+GType gb_preferences_page_language_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* GB_PREFERENCES_PAGE_LANGUAGE_H */
diff --git a/src/preferences/gb-preferences-window.c b/src/preferences/gb-preferences-window.c
index 37e1077..49e9295 100644
--- a/src/preferences/gb-preferences-window.c
+++ b/src/preferences/gb-preferences-window.c
@@ -26,6 +26,7 @@
#include "gb-preferences-page-editor.h"
#include "gb-preferences-page-git.h"
+#include "gb-preferences-page-language.h"
#include "gb-preferences-window.h"
#include "gb-sidebar.h"
@@ -138,6 +139,7 @@ gb_preferences_window_class_init (GbPreferencesWindowClass *klass)
g_type_ensure (GB_TYPE_PREFERENCES_PAGE_GIT);
g_type_ensure (GB_TYPE_PREFERENCES_PAGE_EDITOR);
+ g_type_ensure (GB_TYPE_PREFERENCES_PAGE_LANGUAGE);
g_type_ensure (GB_TYPE_SIDEBAR);
}
diff --git a/src/resources/gnome-builder.gresource.xml b/src/resources/gnome-builder.gresource.xml
index 837afb9..6d244be 100644
--- a/src/resources/gnome-builder.gresource.xml
+++ b/src/resources/gnome-builder.gresource.xml
@@ -23,6 +23,7 @@
<file>ui/gb-preferences-window.ui</file>
<file>ui/gb-preferences-page-editor.ui</file>
<file>ui/gb-preferences-page-git.ui</file>
+ <file>ui/gb-preferences-page-language.ui</file>
<file>ui/gb-tab-label.ui</file>
<file>ui/gb-workbench.ui</file>
</gresource>
diff --git a/src/resources/ui/gb-preferences-page-language.ui
b/src/resources/ui/gb-preferences-page-language.ui
new file mode 100644
index 0000000..0a746f3
--- /dev/null
+++ b/src/resources/ui/gb-preferences-page-language.ui
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.8 -->
+ <template class="GbPreferencesPageLanguage" parent="GbPreferencesPage">
+ <property name="can-focus">False</property>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+ <property name="visible">True</property>
+ <property name="border-width">6</property>
+ <property name="spacing">2</property>
+ <property name="can-focus">False</property>
+ <child>
+ <object class="GtkSearchEntry" id="search_entry">
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="visible">True</property>
+ <property name="shadow-type">GTK_SHADOW_IN</property>
+ <property name="can-focus">False</property>
+ <child>
+ <object class="GtkListBox" id="language_list_box">
+ <property name="visible">True</property>
+ <property name="expand">True</property>
+ <property name="can-focus">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/resources/ui/gb-preferences-window.ui b/src/resources/ui/gb-preferences-window.ui
index 893830c..4ce9a4b 100644
--- a/src/resources/ui/gb-preferences-window.ui
+++ b/src/resources/ui/gb-preferences-window.ui
@@ -123,6 +123,15 @@
<property name="title" translatable="yes">Git</property>
</packing>
</child>
+ <child>
+ <object class="GbPreferencesPageLanguage" id="language_page">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="name">language</property>
+ <property name="title" translatable="yes">Language Settings</property>
+ </packing>
+ </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]