[gnome-builder/wip/libide-merge] add "keybindings" preferences page



commit e9e7b0eb21bb85ac126639dfd0a495bd3d58da2e
Author: Christian Hergert <christian hergert me>
Date:   Sun Mar 22 15:32:49 2015 -0700

    add "keybindings" preferences page
    
    having one item for emacs/vim and no way to reselect default was pretty
    bad. we still need a way to view keybindings and what not.

 data/ui/gb-preferences-page-emacs.ui              |   85 -----------
 data/ui/gb-preferences-page-keybindings.ui        |  160 +++++++++++++++++++++
 data/ui/gb-preferences-page-vim.ui                |   84 -----------
 data/ui/gb-preferences-window.ui                  |   15 +--
 src/gnome-builder.mk                              |    6 +-
 src/preferences/gb-preferences-page-emacs.c       |   99 -------------
 src/preferences/gb-preferences-page-emacs.h       |   55 -------
 src/preferences/gb-preferences-page-keybindings.c |  109 ++++++++++++++
 src/preferences/gb-preferences-page-keybindings.h |   33 +++++
 src/preferences/gb-preferences-page-vim.c         |  101 -------------
 src/preferences/gb-preferences-page-vim.h         |   55 -------
 src/preferences/gb-preferences-page.h             |    2 +
 src/preferences/gb-preferences-window.c           |   20 +--
 src/resources/gnome-builder.gresource.xml         |    3 +-
 14 files changed, 315 insertions(+), 512 deletions(-)
---
diff --git a/data/ui/gb-preferences-page-keybindings.ui b/data/ui/gb-preferences-page-keybindings.ui
new file mode 100644
index 0000000..f28530a
--- /dev/null
+++ b/data/ui/gb-preferences-page-keybindings.ui
@@ -0,0 +1,160 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.8 -->
+  <template class="GbPreferencesPageKeybindings" parent="GbPreferencesPage">
+    <child>
+      <object class="GtkBox">
+        <property name="visible">true</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkBox" id="box1">
+            <property name="visible">true</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <object class="GtkRadioButton" id="default_container">
+                <property name="action-name">settings.keybindings</property>
+                <property name="action-target">'default'</property>
+                <property name="visible">true</property>
+                <child>
+                  <object class="GtkBox" id="box3">
+                    <property name="visible">true</property>
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <object class="GtkLabel" id="label1">
+                        <property name="visible">true</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">&lt;b&gt;Builder&lt;/b&gt;</property>
+                        <property name="use-markup">true</property>
+                        <property name="margin-start">6</property>
+                        <property name="margin-top">6</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="label2">
+                        <property name="visible">true</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">The default keybindings for 
Builder.</property>
+                        <property name="margin-start">6</property>
+                        <property name="margin-bottom">6</property>
+                        <style>
+                          <class name="dim-label"/>
+                        </style>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">false</property>
+                <property name="fill">true</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkRadioButton" id="vim_container">
+                <property name="group">default_container</property>
+                <property name="action-name">settings.keybindings</property>
+                <property name="action-target">'vim'</property>
+                <property name="visible">true</property>
+                <child>
+                  <object class="GtkBox" id="box2">
+                    <property name="visible">true</property>
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <object class="GtkLabel" id="label3">
+                        <property name="visible">true</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">&lt;b&gt;Vim Emulation&lt;/b&gt;</property>
+                        <property name="use-markup">true</property>
+                        <property name="margin-start">6</property>
+                        <property name="margin-top">6</property>
+                      </object>
+                      <packing>
+                        <property name="expand">false</property>
+                        <property name="fill">true</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel">
+                        <property name="visible">true</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Emulates keybindings from the Vim text 
editor.</property>
+                        <property name="margin-start">6</property>
+                        <property name="margin-bottom">6</property>
+                        <style>
+                          <class name="dim-label"/>
+                        </style>
+                      </object>
+                      <packing>
+                        <property name="expand">false</property>
+                        <property name="fill">true</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">false</property>
+                <property name="fill">true</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkRadioButton" id="emacs_container">
+                <property name="group">default_container</property>
+                <property name="action-name">settings.keybindings</property>
+                <property name="action-target">'emacs'</property>
+                <property name="visible">true</property>
+                <child>
+                  <object class="GtkBox" id="box4">
+                    <property name="visible">true</property>
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <object class="GtkLabel" id="label5">
+                        <property name="visible">true</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">&lt;b&gt;Emacs 
Emulation&lt;/b&gt;</property>
+                        <property name="use-markup">true</property>
+                        <property name="margin-start">6</property>
+                        <property name="margin-top">6</property>
+                      </object>
+                      <packing>
+                        <property name="expand">false</property>
+                        <property name="fill">true</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="label6">
+                        <property name="visible">true</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Emulates keybindings from the Emacs text 
editor.</property>
+                        <property name="margin-start">6</property>
+                        <property name="margin-bottom">6</property>
+                        <style>
+                          <class name="dim-label"/>
+                        </style>
+                      </object>
+                      <packing>
+                        <property name="expand">false</property>
+                        <property name="fill">true</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">false</property>
+                <property name="fill">true</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/data/ui/gb-preferences-window.ui b/data/ui/gb-preferences-window.ui
index a9fcdfc..91e8623 100644
--- a/data/ui/gb-preferences-window.ui
+++ b/data/ui/gb-preferences-window.ui
@@ -133,21 +133,12 @@
               </packing>
             </child>
             <child>
-              <object class="GbPreferencesPageVim" id="vim_page">
+              <object class="GbPreferencesPageKeybindings" id="keybindings_page">
                 <property name="visible">True</property>
               </object>
               <packing>
-                <property name="name">vim</property>
-                <property name="title" translatable="yes">Vim</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GbPreferencesPageEmacs" id="emacs_page">
-                <property name="visible">True</property>
-              </object>
-              <packing>
-                <property name="name">emacs</property>
-                <property name="title" translatable="yes">Emacs</property>
+                <property name="name">keybindings</property>
+                <property name="title" translatable="yes">Keybindings</property>
               </packing>
             </child>
           </object>
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index a4eef43..8db1d58 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -73,14 +73,12 @@ libgnome_builder_la_SOURCES = \
        src/nautilus/nautilus-floating-bar.h \
        src/preferences/gb-preferences-page-editor.c \
        src/preferences/gb-preferences-page-editor.h \
-       src/preferences/gb-preferences-page-emacs.c \
-       src/preferences/gb-preferences-page-emacs.h \
        src/preferences/gb-preferences-page-git.c \
        src/preferences/gb-preferences-page-git.h \
+       src/preferences/gb-preferences-page-keybindings.c \
+       src/preferences/gb-preferences-page-keybindings.h \
        src/preferences/gb-preferences-page-language.c \
        src/preferences/gb-preferences-page-language.h \
-       src/preferences/gb-preferences-page-vim.c \
-       src/preferences/gb-preferences-page-vim.h \
        src/preferences/gb-preferences-page.c \
        src/preferences/gb-preferences-page.h \
        src/preferences/gb-preferences-window.c \
diff --git a/src/preferences/gb-preferences-page-keybindings.c 
b/src/preferences/gb-preferences-page-keybindings.c
new file mode 100644
index 0000000..589c188
--- /dev/null
+++ b/src/preferences/gb-preferences-page-keybindings.c
@@ -0,0 +1,109 @@
+/* gb-preferences-page-keybindings.h
+ *
+ * Copyright (C) 2015 Carlos Soriano <csoriano gnome org>
+ * Copyright (C) 2015 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/>.
+ */
+
+#define G_LOG_DOMAIN "gb-preferences-page-keybindings"
+
+#include <glib/gi18n.h>
+
+#include "gb-preferences-page-keybindings.h"
+#include "gb-widget.h"
+
+struct _GbPreferencesPageKeybindings
+{
+  GbPreferencesPage      parent_instance;
+
+  GSettings             *editor_settings;
+
+  /* Template widgets used for filtering */
+  GtkWidget             *default_container;
+  GtkWidget             *emacs_container;
+  GtkWidget             *vim_container;
+};
+
+G_DEFINE_TYPE (GbPreferencesPageKeybindings,
+               gb_preferences_page_keybindings,
+               GB_TYPE_PREFERENCES_PAGE)
+
+static void
+gb_preferences_page_keybindings_constructed (GObject *object)
+{
+  GbPreferencesPageKeybindings *self = (GbPreferencesPageKeybindings *)object;
+  GSimpleActionGroup *group;
+  GAction *action;
+
+  g_return_if_fail (GB_IS_PREFERENCES_PAGE_KEYBINDINGS (self));
+
+  self->editor_settings = g_settings_new ("org.gnome.builder.editor");
+
+  group = g_simple_action_group_new ();
+
+  action = g_settings_create_action (self->editor_settings, "keybindings");
+  g_action_map_add_action (G_ACTION_MAP (group), action);
+  g_clear_object (&action);
+
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "settings", G_ACTION_GROUP (group));
+  g_clear_object (&group);
+}
+
+static void
+gb_preferences_page_keybindings_finalize (GObject *object)
+{
+  GbPreferencesPageKeybindings *self = (GbPreferencesPageKeybindings *)object;
+
+  g_clear_object (&self->editor_settings);
+
+  G_OBJECT_CLASS (gb_preferences_page_keybindings_parent_class)->finalize (object);
+}
+
+static void
+gb_preferences_page_keybindings_class_init (GbPreferencesPageKeybindingsClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = gb_preferences_page_keybindings_finalize;
+  object_class->constructed = gb_preferences_page_keybindings_constructed;
+
+  GB_WIDGET_CLASS_TEMPLATE (widget_class, "gb-preferences-page-keybindings.ui");
+  GB_WIDGET_CLASS_BIND (widget_class, GbPreferencesPageKeybindings, vim_container);
+  GB_WIDGET_CLASS_BIND (widget_class, GbPreferencesPageKeybindings, emacs_container);
+  GB_WIDGET_CLASS_BIND (widget_class, GbPreferencesPageKeybindings, default_container);
+}
+
+static void
+gb_preferences_page_keybindings_init (GbPreferencesPageKeybindings *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  /* To translators: This is a list of keywords for the preferences page */
+  gb_preferences_page_set_keywords_for_widget (GB_PREFERENCES_PAGE (self),
+                                               _("default keybindings"),
+                                               self->default_container,
+                                               NULL);
+  /* To translators: This is a list of keywords for the preferences page */
+  gb_preferences_page_set_keywords_for_widget (GB_PREFERENCES_PAGE (self),
+                                               _("emacs keybindings modal"),
+                                               self->emacs_container,
+                                               NULL);
+  /* To translators: This is a list of keywords for the preferences page */
+  gb_preferences_page_set_keywords_for_widget (GB_PREFERENCES_PAGE (self),
+                                               _("vim keybindings modal"),
+                                               self->vim_container,
+                                               NULL);
+}
diff --git a/src/preferences/gb-preferences-page-keybindings.h 
b/src/preferences/gb-preferences-page-keybindings.h
new file mode 100644
index 0000000..c2abb3a
--- /dev/null
+++ b/src/preferences/gb-preferences-page-keybindings.h
@@ -0,0 +1,33 @@
+/* gb-preferences-page-vim.h
+ *
+ * Copyright (C) 2015 Carlos Soriano <csoriano gnome org>
+ *
+ * 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_KEYBINDINGS_H
+#define GB_PREFERENCES_PAGE_KEYBINDINGS_H
+
+#include "gb-preferences-page.h"
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_PREFERENCES_PAGE_KEYBINDINGS (gb_preferences_page_keybindings_get_type())
+
+G_DECLARE_FINAL_TYPE (GbPreferencesPageKeybindings, gb_preferences_page_keybindings,
+                      GB, PREFERENCES_PAGE_KEYBINDINGS, GbPreferencesPage)
+
+G_END_DECLS
+
+#endif /* GB_PREFERENCES_PAGE_KEYBINDINGS_H */
diff --git a/src/preferences/gb-preferences-page.h b/src/preferences/gb-preferences-page.h
index 875f86d..f51404c 100644
--- a/src/preferences/gb-preferences-page.h
+++ b/src/preferences/gb-preferences-page.h
@@ -35,6 +35,8 @@ typedef struct _GbPreferencesPage        GbPreferencesPage;
 typedef struct _GbPreferencesPageClass   GbPreferencesPageClass;
 typedef struct _GbPreferencesPagePrivate GbPreferencesPagePrivate;
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GbPreferencesPage, g_object_unref)
+
 struct _GbPreferencesPage
 {
   GtkBin parent;
diff --git a/src/preferences/gb-preferences-window.c b/src/preferences/gb-preferences-window.c
index a79e58b..326261e 100644
--- a/src/preferences/gb-preferences-window.c
+++ b/src/preferences/gb-preferences-window.c
@@ -16,19 +16,12 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/*
- * TODO: We will probably have to split all the preferences stuff out into
- *       child widgets just to keep things under control.
- *       Feel free to do that if you beat me to it.
- */
-
 #include <glib/gi18n.h>
 
 #include "gb-preferences-page-editor.h"
-#include "gb-preferences-page-emacs.h"
 #include "gb-preferences-page-git.h"
+#include "gb-preferences-page-keybindings.h"
 #include "gb-preferences-page-language.h"
-#include "gb-preferences-page-vim.h"
 #include "gb-preferences-page.h"
 #include "gb-preferences-window.h"
 #include "gb-widget.h"
@@ -65,11 +58,9 @@ gb_preferences_window_notify_search_mode (GbPreferencesWindow *window,
 {
   g_return_if_fail (GB_IS_PREFERENCES_WINDOW (window));
 
-  if (!gtk_search_bar_get_search_mode (search_bar) &&
-      window->priv->return_to_page)
+  if (!gtk_search_bar_get_search_mode (search_bar) && window->priv->return_to_page)
     {
-      gtk_stack_set_visible_child (window->priv->stack,
-                                   window->priv->return_to_page);
+      gtk_stack_set_visible_child (window->priv->stack, window->priv->return_to_page);
       window->priv->return_to_page = NULL;
     }
 }
@@ -334,11 +325,10 @@ gb_preferences_window_class_init (GbPreferencesWindowClass *klass)
   GB_WIDGET_CLASS_BIND_PRIVATE (widget_class, GbPreferencesWindow, search_entry);
   GB_WIDGET_CLASS_BIND_PRIVATE (widget_class, GbPreferencesWindow, stack);
 
-  g_type_ensure (GB_TYPE_PREFERENCES_PAGE_GIT);
   g_type_ensure (GB_TYPE_PREFERENCES_PAGE_EDITOR);
+  g_type_ensure (GB_TYPE_PREFERENCES_PAGE_GIT);
+  g_type_ensure (GB_TYPE_PREFERENCES_PAGE_KEYBINDINGS);
   g_type_ensure (GB_TYPE_PREFERENCES_PAGE_LANGUAGE);
-  g_type_ensure (GB_TYPE_PREFERENCES_PAGE_VIM);
-  g_type_ensure (GB_TYPE_PREFERENCES_PAGE_EMACS);
 }
 
 static void
diff --git a/src/resources/gnome-builder.gresource.xml b/src/resources/gnome-builder.gresource.xml
index 9ab351f..fdf97c2 100644
--- a/src/resources/gnome-builder.gresource.xml
+++ b/src/resources/gnome-builder.gresource.xml
@@ -32,10 +32,9 @@
     <file alias="ui/gb-editor-workspace.ui">../../data/ui/gb-editor-workspace.ui</file>
     <file alias="ui/gb-html-view.ui">../../data/ui/gb-html-view.ui</file>
     <file alias="ui/gb-preferences-page-editor.ui">../../data/ui/gb-preferences-page-editor.ui</file>
-    <file alias="ui/gb-preferences-page-emacs.ui">../../data/ui/gb-preferences-page-emacs.ui</file>
     <file alias="ui/gb-preferences-page-git.ui">../../data/ui/gb-preferences-page-git.ui</file>
+    <file 
alias="ui/gb-preferences-page-keybindings.ui">../../data/ui/gb-preferences-page-keybindings.ui</file>
     <file alias="ui/gb-preferences-page-language.ui">../../data/ui/gb-preferences-page-language.ui</file>
-    <file alias="ui/gb-preferences-page-vim.ui">../../data/ui/gb-preferences-page-vim.ui</file>
     <file alias="ui/gb-preferences-window.ui">../../data/ui/gb-preferences-window.ui</file>
     <file alias="ui/gb-search-box.ui">../../data/ui/gb-search-box.ui</file>
     <file alias="ui/gb-search-display-group.ui">../../data/ui/gb-search-display-group.ui</file>


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