[gnome-text-editor] window: implement preferences as sidepanel in window



commit 6fd8d4b47f39a7bd7689c54f544ce26384d1ff57
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 29 17:20:22 2021 -0700

    window: implement preferences as sidepanel in window
    
    This does the first part of things to allow selecting an alternate
    style-scheme by moving the preferences into the window for live and
    direct application/preview.
    
    Related #79

 src/editor-window-actions.c |  32 +++++++++
 src/editor-window-private.h |   1 +
 src/editor-window.c         |   9 ++-
 src/editor-window.ui        | 164 +++++++++++++++++++++++++++++++++++++-------
 src/menus.ui                |   2 +-
 5 files changed, 183 insertions(+), 25 deletions(-)
---
diff --git a/src/editor-window-actions.c b/src/editor-window-actions.c
index fcf1343..6e58c4f 100644
--- a/src/editor-window-actions.c
+++ b/src/editor-window-actions.c
@@ -548,6 +548,30 @@ editor_window_actions_focus_neighbor_cb (GtkWidget  *widget,
     adw_tab_view_select_next_page (self->tab_view);
 }
 
+static void
+editor_window_actions_show_preferences_cb (GtkWidget  *widget,
+                                           const char *action_name,
+                                           GVariant   *param)
+{
+  EditorWindow *self = (EditorWindow *)widget;
+
+  g_assert (EDITOR_IS_WINDOW (self));
+
+  gtk_revealer_set_reveal_child (self->preferences_revealer, TRUE);
+}
+
+static void
+editor_window_actions_hide_preferences_cb (GtkWidget  *widget,
+                                           const char *action_name,
+                                           GVariant   *param)
+{
+  EditorWindow *self = (EditorWindow *)widget;
+
+  g_assert (EDITOR_IS_WINDOW (self));
+
+  gtk_revealer_set_reveal_child (self->preferences_revealer, FALSE);
+}
+
 void
 _editor_window_class_actions_init (EditorWindowClass *klass)
 {
@@ -637,6 +661,14 @@ _editor_window_class_actions_init (EditorWindowClass *klass)
                                    "page.begin-replace",
                                    NULL,
                                    editor_window_actions_begin_replace_cb);
+  gtk_widget_class_install_action (widget_class,
+                                   "win.hide-preferences",
+                                   NULL,
+                                   editor_window_actions_hide_preferences_cb);
+  gtk_widget_class_install_action (widget_class,
+                                   "win.show-preferences",
+                                   NULL,
+                                   editor_window_actions_show_preferences_cb);
 }
 
 void
diff --git a/src/editor-window-private.h b/src/editor-window-private.h
index 5b3a995..375e206 100644
--- a/src/editor-window-private.h
+++ b/src/editor-window-private.h
@@ -51,6 +51,7 @@ struct _EditorWindow
   GtkMenuButton        *primary_menu;
   GtkMenuButton        *options_menu;
   GtkMenuButton        *export_menu;
+  GtkRevealer          *preferences_revealer;
 
   /* Borrowed References */
   EditorPage           *visible_page;
diff --git a/src/editor-window.c b/src/editor-window.c
index 1af7f31..7012878 100644
--- a/src/editor-window.c
+++ b/src/editor-window.c
@@ -27,6 +27,9 @@
 #include "editor-application.h"
 #include "editor-document.h"
 #include "editor-open-popover-private.h"
+#include "editor-preferences-font.h"
+#include "editor-preferences-spin.h"
+#include "editor-preferences-switch.h"
 #include "editor-save-changes-dialog-private.h"
 #include "editor-session-private.h"
 #include "editor-theme-selector-private.h"
@@ -406,12 +409,13 @@ editor_window_class_init (EditorWindowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, pages);
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, position_box);
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, position_label);
+  gtk_widget_class_bind_template_child (widget_class, EditorWindow, preferences_revealer);
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, primary_menu);
+  gtk_widget_class_bind_template_child (widget_class, EditorWindow, stack);
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, subtitle);
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, tab_bar);
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, tab_view);
   gtk_widget_class_bind_template_child (widget_class, EditorWindow, title);
-  gtk_widget_class_bind_template_child (widget_class, EditorWindow, stack);
 
   gtk_widget_class_add_binding_action (widget_class, GDK_KEY_w, GDK_CONTROL_MASK, 
"win.close-page-or-window", NULL);
   gtk_widget_class_add_binding_action (widget_class, GDK_KEY_o, GDK_CONTROL_MASK, "win.open", NULL);
@@ -440,6 +444,9 @@ editor_window_class_init (EditorWindowClass *klass)
 
   g_type_ensure (EDITOR_TYPE_OPEN_POPOVER);
   g_type_ensure (EDITOR_TYPE_POSITION_LABEL);
+  g_type_ensure (EDITOR_TYPE_PREFERENCES_FONT);
+  g_type_ensure (EDITOR_TYPE_PREFERENCES_SPIN);
+  g_type_ensure (EDITOR_TYPE_PREFERENCES_SWITCH);
 }
 
 static void
diff --git a/src/editor-window.ui b/src/editor-window.ui
index 1149fd0..8444c18 100644
--- a/src/editor-window.ui
+++ b/src/editor-window.ui
@@ -111,40 +111,158 @@
           </object>
         </child>
         <child>
-          <object class="GtkStack" id="stack">
-            <style>
-              <class name="view"/>
-            </style>
+          <object class="GtkBox">
+            <property name="orientation">horizontal</property>
             <child>
-              <object class="GtkBox" id="pages">
-                <property name="orientation">vertical</property>
+              <object class="GtkStack" id="stack">
+                <property name="hexpand">true</property>
+                <style>
+                  <class name="view"/>
+                </style>
                 <child>
-                  <object class="AdwTabBar" id="tab_bar">
-                    <property name="view">tab_view</property>
+                  <object class="GtkBox" id="pages">
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <object class="AdwTabBar" id="tab_bar">
+                        <property name="view">tab_view</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="AdwTabView" id="tab_view">
+                        <property name="hexpand">true</property>
+                        <property name="vexpand">true</property>
+                      </object>
+                    </child>
                   </object>
                 </child>
                 <child>
-                  <object class="AdwTabView" id="tab_view">
-                    <property name="hexpand">true</property>
-                    <property name="vexpand">true</property>
-                  </object>
-                </child>
-              </object>
-            </child>
-            <child>
-              <object class="AdwStatusPage" id="empty">
-                <property name="icon-name">text-editor-symbolic</property>
-                <property name="title" translatable="yes">Start or Open a Document</property>
-                <property name="child">
-                  <object class="GtkLabel">
-                    <property name="label" translatable="yes">• Use the open button
+                  <object class="AdwStatusPage" id="empty">
+                    <property name="icon-name">text-editor-symbolic</property>
+                    <property name="title" translatable="yes">Start or Open a Document</property>
+                    <property name="child">
+                      <object class="GtkLabel">
+                        <property name="label" translatable="yes">• Use the open button
 • Press the new tab button
 • Press Ctrl+N to start a new document
 • Press Ctrl+O to browse for a document
 
 Or, press Ctrl+W to close the window.</property>
+                      </object>
+                    </property>
                   </object>
-                </property>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkRevealer" id="preferences_revealer">
+                <property name="transition-type">slide-left</property>
+                <child>
+                  <object class="GtkBox">
+                    <property name="orientation">horizontal</property>
+                    <child>
+                      <object class="GtkSeparator">
+                        <property name="orientation">vertical</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkScrolledWindow">
+                        <property name="propagate-natural-width">true</property>
+                        <property name="propagate-natural-height">true</property>
+                        <property name="hscrollbar-policy">never</property>
+                        <child>
+                          <object class="GtkBox">
+                            <property name="orientation">vertical</property>
+                            <property name="width-request">300</property>
+                            <property name="margin-start">12</property>
+                            <property name="margin-end">12</property>
+                            <property name="margin-top">12</property>
+                            <property name="margin-bottom">12</property>
+                            <child>
+                              <object class="GtkCenterBox">
+                                <property name="orientation">horizontal</property>
+                                <child type="center">
+                                  <object class="GtkLabel">
+                                    <property name="label" translatable="yes">Preferences</property>
+                                    <property name="xalign">.5</property>
+                                    <attributes>
+                                      <attribute name="weight" value="bold"/>
+                                    </attributes>
+                                  </object>
+                                </child>
+                                <child type="end">
+                                  <object class="GtkButton">
+                                    <property name="icon-name">window-close-symbolic</property>
+                                    <property name="action-name">win.hide-preferences</property>
+                                    <style>
+                                      <class name="image-button"/>
+                                      <class name="circular"/>
+                                      <class name="flat"/>
+                                    </style>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="AdwPreferencesGroup">
+                                <property name="title" translatable="yes">Font</property>
+                                <property name="margin-top">12</property>
+                                <child>
+                                  <object class="EditorPreferencesSwitch" id="use_system_font">
+                                    <property name="title" translatable="yes">Use System Font</property>
+                                    <property name="schema-key">use-system-font</property>
+                                  </object>
+                                </child>
+                                <child>
+                                  <object class="EditorPreferencesFont" id="custom_font">
+                                    <property name="title" translatable="yes">Custom Font</property>
+                                    <property name="schema-key">custom-font</property>
+                                    <property name="sensitive" bind-source="use_system_font" 
bind-property="active" bind-flags="sync-create|invert-boolean"/>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="AdwPreferencesGroup">
+                                <property name="title" translatable="yes">Right Margin</property>
+                                <property name="margin-top">24</property>
+                                <child>
+                                  <object class="EditorPreferencesSpin" id="right_margin">
+                                    <property name="title" translatable="yes">Margin Position</property>
+                                    <property name="schema-key">right-margin-position</property>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="AdwPreferencesGroup">
+                                <property name="title" translatable="yes">Appearance</property>
+                                <property name="margin-top">24</property>
+                                <child>
+                                  <object class="EditorPreferencesSwitch" id="grid">
+                                    <property name="title" translatable="yes">Display Grid Pattern</property>
+                                    <property name="schema-key">show-grid</property>
+                                  </object>
+                                </child>
+                                <child>
+                                  <object class="EditorPreferencesSwitch" id="highlight_current_line">
+                                    <property name="title" translatable="yes">Highlight Current 
Line</property>
+                                    <property name="schema-key">highlight-current-line</property>
+                                  </object>
+                                </child>
+                                <child>
+                                  <object class="EditorPreferencesSwitch" id="map">
+                                    <property name="title" translatable="yes">Display Overview Map</property>
+                                    <property name="schema-key">show-map</property>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
               </object>
             </child>
           </object>
diff --git a/src/menus.ui b/src/menus.ui
index 2fc7ff4..7046efc 100644
--- a/src/menus.ui
+++ b/src/menus.ui
@@ -56,7 +56,7 @@
     <section>
       <item>
         <attribute name="label" translatable="yes">_Preferences</attribute>
-        <attribute name="action">app.preferences</attribute>
+        <attribute name="action">win.show-preferences</attribute>
       </item>
       <item>
         <attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>


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