[gnome-text-editor] statusbar: move statusbar to window level widget



commit 7cedf234d175ac41dcaf466865f2c302c643450d
Author: Christian Hergert <chergert redhat com>
Date:   Mon Dec 6 18:03:44 2021 -0800

    statusbar: move statusbar to window level widget
    
    We don't need this to be within the page. Instead make it window level and
    try to clean it up a bit.

 src/editor-page-private.h              |   3 -
 src/editor-page-vim.c                  |   9 +-
 src/editor-page.c                      |   3 -
 src/editor-page.ui                     |  23 ---
 src/editor-preferences-dialog.c        |  10 +-
 src/editor-statusbar-private.h         |  50 ++++++
 src/editor-statusbar.c                 | 314 +++++++++++++++++++++++++++++++++
 src/editor-statusbar.ui                |  82 +++++++++
 src/editor-window-private.h            |   8 +-
 src/editor-window.c                    |  31 +++-
 src/editor-window.ui                   |   5 +
 src/meson.build                        |   1 +
 src/org.gnome.TextEditor.gresource.xml |   1 +
 13 files changed, 492 insertions(+), 48 deletions(-)
---
diff --git a/src/editor-page-private.h b/src/editor-page-private.h
index 1692ce6..8bca924 100644
--- a/src/editor-page-private.h
+++ b/src/editor-page-private.h
@@ -57,9 +57,6 @@ struct _EditorPage
   EditorSearchBar         *search_bar;
   GtkInfoBar              *changed_infobar;
   GtkInfoBar              *infobar;
-  GtkLabel                *vim_command;
-  GtkLabel                *vim_command_bar;
-  GtkBox                  *statusbar;
   GtkEventController      *vim;
 
   guint                    close_requested : 1;
diff --git a/src/editor-page-vim.c b/src/editor-page-vim.c
index 4c2f531..f37269c 100644
--- a/src/editor-page-vim.c
+++ b/src/editor-page-vim.c
@@ -133,11 +133,8 @@ on_keybindings_changed_cb (EditorPage *self,
     {
       if (self->vim == NULL)
         {
-          GtkIMContext *im_context;
+          GtkIMContext *im_context = gtk_source_vim_im_context_new ();
 
-          im_context = gtk_source_vim_im_context_new ();
-          g_object_bind_property (im_context, "command-bar-text", self->vim_command_bar, "label", 0);
-          g_object_bind_property (im_context, "command-text", self->vim_command, "label", 0);
           g_signal_connect_object (im_context,
                                    "write",
                                    G_CALLBACK (on_vim_write_cb),
@@ -159,16 +156,12 @@ on_keybindings_changed_cb (EditorPage *self,
           gtk_event_controller_set_propagation_phase (self->vim, GTK_PHASE_CAPTURE);
           gtk_event_controller_key_set_im_context (GTK_EVENT_CONTROLLER_KEY (self->vim), im_context);
           gtk_widget_add_controller (GTK_WIDGET (self->view), self->vim);
-
-          gtk_widget_show (GTK_WIDGET (self->statusbar));
         }
     }
   else
     {
       if (self->vim)
         {
-          gtk_label_set_label (self->vim_command_bar, NULL);
-          gtk_widget_hide (GTK_WIDGET (self->statusbar));
           gtk_widget_remove_controller (GTK_WIDGET (self->view), self->vim);
           self->vim = NULL;
         }
diff --git a/src/editor-page.c b/src/editor-page.c
index a339aac..1e2b19b 100644
--- a/src/editor-page.c
+++ b/src/editor-page.c
@@ -752,10 +752,7 @@ editor_page_class_init (EditorPageClass *klass)
   gtk_widget_class_bind_template_child (widget_class, EditorPage, scroller);
   gtk_widget_class_bind_template_child (widget_class, EditorPage, search_bar);
   gtk_widget_class_bind_template_child (widget_class, EditorPage, search_revealer);
-  gtk_widget_class_bind_template_child (widget_class, EditorPage, statusbar);
   gtk_widget_class_bind_template_child (widget_class, EditorPage, view);
-  gtk_widget_class_bind_template_child (widget_class, EditorPage, vim_command_bar);
-  gtk_widget_class_bind_template_child (widget_class, EditorPage, vim_command);
   gtk_widget_class_bind_template_callback (widget_class, get_child_position_cb);
   gtk_widget_class_bind_template_callback (widget_class, goto_line_entry_activate_cb);
   gtk_widget_class_bind_template_callback (widget_class, font_scale_changed_cb);
diff --git a/src/editor-page.ui b/src/editor-page.ui
index 74c2fbd..2d84701 100644
--- a/src/editor-page.ui
+++ b/src/editor-page.ui
@@ -146,29 +146,6 @@
             </child>
           </object>
         </child>
-        <child>
-          <object class="GtkBox" id="statusbar">
-            <property name="valign">end</property>
-            <property name="hexpand">true</property>
-            <property name="vexpand">false</property>
-            <property name="visible">false</property>
-            <property name="spacing">12</property>
-            <style>
-              <class name="statusbar"/>
-            </style>
-            <child>
-              <object class="GtkLabel" id="vim_command_bar">
-                <property name="hexpand">true</property>
-                <property name="xalign">0</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkLabel" id="vim_command">
-                <property name="xalign">1</property>
-              </object>
-            </child>
-          </object>
-        </child>
       </object>
     </child>
   </template>
diff --git a/src/editor-preferences-dialog.c b/src/editor-preferences-dialog.c
index b95660e..74bffda 100644
--- a/src/editor-preferences-dialog.c
+++ b/src/editor-preferences-dialog.c
@@ -25,10 +25,14 @@
 
 #include "editor-page.h"
 #include "editor-preferences-dialog-private.h"
+#include "editor-preferences-font.h"
+#include "editor-preferences-radio.h"
+#include "editor-preferences-spin.h"
+#include "editor-preferences-switch.h"
 #include "editor-recoloring-private.h"
 #include "editor-session.h"
-#include "editor-window.h"
 #include "editor-utils-private.h"
+#include "editor-window.h"
 
 struct _EditorPreferencesDialog
 {
@@ -292,6 +296,10 @@ editor_preferences_dialog_class_init (EditorPreferencesDialogClass *klass)
   gtk_widget_class_bind_template_child (widget_class, EditorPreferencesDialog, scheme_group);
   gtk_widget_class_bind_template_child (widget_class, EditorPreferencesDialog, source_view);
   gtk_widget_class_bind_template_child (widget_class, EditorPreferencesDialog, use_custom_font);
+
+  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-statusbar-private.h b/src/editor-statusbar-private.h
new file mode 100644
index 0000000..34f1575
--- /dev/null
+++ b/src/editor-statusbar-private.h
@@ -0,0 +1,50 @@
+/* editor-statusbar-private.h
+ *
+ * Copyright 2021 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#include "editor-page.h"
+
+G_BEGIN_DECLS
+
+#define EDITOR_TYPE_STATUSBAR (editor_statusbar_get_type())
+
+G_DECLARE_FINAL_TYPE (EditorStatusbar, editor_statusbar, EDITOR, STATUSBAR, GtkWidget)
+
+GtkWidget  *editor_statusbar_new                  (void);
+void        editor_statusbar_bind_page            (EditorStatusbar *self,
+                                                   EditorPage      *page);
+void        editor_statusbar_set_selection_count  (EditorStatusbar *self,
+                                                   guint            selection_lines);
+void        editor_statusbar_set_position         (EditorStatusbar *self,
+                                                   guint            line,
+                                                   guint            line_offset);
+const char *editor_statusbar_get_command_text     (EditorStatusbar *self);
+void        editor_statusbar_set_command_text     (EditorStatusbar *self,
+                                                   const char      *command_text);
+const char *editor_statusbar_get_command_bar_text (EditorStatusbar *self);
+void        editor_statusbar_set_command_bar_text (EditorStatusbar *self,
+                                                   const char      *command_bar_text);
+void        editor_statusbar_set_overwrite        (EditorStatusbar *self,
+                                                   gboolean         overwrite);
+
+G_END_DECLS
diff --git a/src/editor-statusbar.c b/src/editor-statusbar.c
new file mode 100644
index 0000000..4719eae
--- /dev/null
+++ b/src/editor-statusbar.c
@@ -0,0 +1,314 @@
+/* editor-statusbar.c
+ *
+ * Copyright 2021 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "config.h"
+
+#include "editor-binding-group.h"
+#include "editor-page-private.h"
+#include "editor-signal-group.h"
+#include "editor-statusbar-private.h"
+
+struct _EditorStatusbar
+{
+  GtkWidget           parent_instance;
+
+  EditorBindingGroup *page_bindings;
+  EditorSignalGroup  *document_signals;
+  EditorBindingGroup *vim_bindings;
+
+  GtkWidget          *box;
+  GtkLabel           *command_bar_text;
+  GtkLabel           *command_text;
+  GtkLabel           *selection_count;
+  GtkLabel           *position;
+  GtkLabel           *mode;
+};
+
+G_DEFINE_FINAL_TYPE (EditorStatusbar, editor_statusbar, GTK_TYPE_WIDGET)
+
+enum {
+  PROP_0,
+  PROP_COMMAND_TEXT,
+  PROP_COMMAND_BAR_TEXT,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+GtkWidget *
+editor_statusbar_new (void)
+{
+  return g_object_new (EDITOR_TYPE_STATUSBAR, NULL);
+}
+
+static void
+editor_statusbar_cursor_moved_cb (EditorStatusbar *self,
+                                  EditorDocument  *document)
+{
+  GtkTextIter begin, end;
+  char str[32];
+  int val = 0;
+
+  g_assert (EDITOR_IS_STATUSBAR (self));
+  g_assert (EDITOR_IS_DOCUMENT (document));
+
+  if (gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (document), &begin, &end))
+    {
+      gtk_text_iter_order (&begin, &end);
+
+      if (gtk_text_iter_get_line (&begin) != gtk_text_iter_get_line (&end))
+        val = (int)gtk_text_iter_get_line (&end) - (int)gtk_text_iter_get_line (&begin);
+      else
+        val = (int)gtk_text_iter_get_line_offset (&end) - (int)gtk_text_iter_get_line_offset (&begin);
+    }
+
+  if (val == 0)
+    str[0] = 0;
+  else
+    g_snprintf (str, sizeof str, "%d", val);
+
+  gtk_label_set_label (self->selection_count, str);
+}
+
+static void
+editor_statusbar_dispose (GObject *object)
+{
+  EditorStatusbar *self = (EditorStatusbar *)object;
+
+  g_clear_object (&self->page_bindings);
+  g_clear_object (&self->vim_bindings);
+  g_clear_pointer (&self->box, gtk_widget_unparent);
+
+  G_OBJECT_CLASS (editor_statusbar_parent_class)->dispose (object);
+}
+
+static void
+editor_statusbar_get_property (GObject    *object,
+                               guint       prop_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  EditorStatusbar *self = EDITOR_STATUSBAR (object);
+
+  switch (prop_id)
+    {
+    case PROP_COMMAND_BAR_TEXT:
+      g_value_set_string (value, editor_statusbar_get_command_bar_text (self));
+      break;
+
+    case PROP_COMMAND_TEXT:
+      g_value_set_string (value, editor_statusbar_get_command_text (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+editor_statusbar_set_property (GObject      *object,
+                               guint         prop_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
+{
+  EditorStatusbar *self = EDITOR_STATUSBAR (object);
+
+  switch (prop_id)
+    {
+    case PROP_COMMAND_BAR_TEXT:
+      editor_statusbar_set_command_bar_text (self, g_value_get_string (value));
+      break;
+
+    case PROP_COMMAND_TEXT:
+      editor_statusbar_set_command_text (self, g_value_get_string (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+editor_statusbar_class_init (EditorStatusbarClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->dispose = editor_statusbar_dispose;
+  object_class->get_property = editor_statusbar_get_property;
+  object_class->set_property = editor_statusbar_set_property;
+
+  properties [PROP_COMMAND_BAR_TEXT] =
+    g_param_spec_string ("command-bar-text",
+                         "Command Bar Text",
+                         "Command Bar Text",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_COMMAND_TEXT] =
+    g_param_spec_string ("command-text",
+                         "Command Text",
+                         "Command Text",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
+  gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/TextEditor/ui/editor-statusbar.ui");
+  gtk_widget_class_bind_template_child (widget_class, EditorStatusbar, box);
+  gtk_widget_class_bind_template_child (widget_class, EditorStatusbar, command_bar_text);
+  gtk_widget_class_bind_template_child (widget_class, EditorStatusbar, command_text);
+  gtk_widget_class_bind_template_child (widget_class, EditorStatusbar, mode);
+  gtk_widget_class_bind_template_child (widget_class, EditorStatusbar, position);
+  gtk_widget_class_bind_template_child (widget_class, EditorStatusbar, selection_count);
+}
+
+static void
+editor_statusbar_init (EditorStatusbar *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  self->vim_bindings = editor_binding_group_new ();
+  editor_binding_group_bind (self->vim_bindings, "command-bar-text",
+                             self, "command-bar-text",
+                             G_BINDING_SYNC_CREATE);
+  editor_binding_group_bind (self->vim_bindings, "command-text",
+                             self, "command-text",
+                             G_BINDING_SYNC_CREATE);
+
+  self->page_bindings = editor_binding_group_new ();
+  editor_binding_group_bind (self->page_bindings, "position-label",
+                             self->position, "label",
+                             G_BINDING_SYNC_CREATE);
+
+  self->document_signals = editor_signal_group_new (EDITOR_TYPE_DOCUMENT);
+  editor_signal_group_connect_object (self->document_signals,
+                                      "cursor-moved",
+                                      G_CALLBACK (editor_statusbar_cursor_moved_cb),
+                                      self,
+                                      G_CONNECT_SWAPPED);
+}
+
+const char *
+editor_statusbar_get_command_bar_text (EditorStatusbar *self)
+{
+  g_return_val_if_fail (EDITOR_IS_STATUSBAR (self), NULL);
+
+  return gtk_label_get_label (self->command_bar_text);
+}
+
+const char *
+editor_statusbar_get_command_text (EditorStatusbar *self)
+{
+  g_return_val_if_fail (EDITOR_IS_STATUSBAR (self), NULL);
+
+  return gtk_label_get_label (self->command_text);
+}
+
+void
+editor_statusbar_set_command_bar_text (EditorStatusbar *self,
+                                       const char      *command_bar_text)
+{
+  g_return_if_fail (EDITOR_IS_STATUSBAR (self));
+
+  gtk_label_set_label (self->command_bar_text, command_bar_text);
+  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_COMMAND_BAR_TEXT]);
+}
+
+void
+editor_statusbar_set_command_text (EditorStatusbar *self,
+                                   const char      *command_text)
+{
+  g_return_if_fail (EDITOR_IS_STATUSBAR (self));
+
+  gtk_label_set_label (self->command_text, command_text);
+  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_COMMAND_TEXT]);
+}
+
+void
+editor_statusbar_set_selection_count (EditorStatusbar *self,
+                                      guint            selection_count)
+{
+  char str[12];
+
+  g_return_if_fail (EDITOR_IS_STATUSBAR (self));
+
+  if (selection_count)
+    g_snprintf (str, sizeof str, "%u", selection_count);
+  else
+    str[0] = 0;
+
+  gtk_label_set_label (self->selection_count, str);
+}
+
+void
+editor_statusbar_set_position (EditorStatusbar *self,
+                               guint            line,
+                               guint            line_offset)
+{
+  char str[32];
+
+  g_return_if_fail (EDITOR_IS_STATUSBAR (self));
+
+  g_snprintf (str, sizeof str, "%u,%u", line, line_offset);
+  gtk_label_set_label (self->position, str);
+}
+
+void
+editor_statusbar_set_overwrite (EditorStatusbar *self,
+                                gboolean         overwrite)
+{
+  g_return_if_fail (EDITOR_IS_STATUSBAR (self));
+
+  if (overwrite)
+    gtk_label_set_label (self->mode, "OVR");
+  else
+    gtk_label_set_label (self->mode, NULL);
+}
+
+void
+editor_statusbar_bind_page (EditorStatusbar *self,
+                            EditorPage      *page)
+{
+  GtkIMContext *vim = NULL;
+  EditorDocument *document = NULL;
+
+  g_return_if_fail (EDITOR_IS_STATUSBAR (self));
+
+  gtk_label_set_label (self->command_bar_text, NULL);
+  gtk_label_set_label (self->command_text, NULL);
+  gtk_label_set_label (self->mode, NULL);
+  gtk_label_set_label (self->position, NULL);
+  gtk_label_set_label (self->selection_count, NULL);
+
+  if (page != NULL)
+    {
+      vim = gtk_event_controller_key_get_im_context (GTK_EVENT_CONTROLLER_KEY (page->vim));
+      document = page->document;
+    }
+
+  editor_binding_group_set_source (self->page_bindings, page);
+  editor_binding_group_set_source (self->vim_bindings, vim);
+  editor_signal_group_set_target (self->document_signals, document);
+
+  if (document != NULL)
+    editor_statusbar_cursor_moved_cb (self, document);
+}
diff --git a/src/editor-statusbar.ui b/src/editor-statusbar.ui
new file mode 100644
index 0000000..f9240f9
--- /dev/null
+++ b/src/editor-statusbar.ui
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk" version="4.0"/>
+  <template class="EditorStatusbar" parent="GtkWidget">
+    <property name="height-request">24</property>
+    <child>
+      <object class="GtkBox" id="box">
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkSeparator">
+            <property name="orientation">horizontal</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="orientation">horizontal</property>
+            <property name="margin-top">3</property>
+            <property name="margin-bottom">3</property>
+            <property name="margin-start">12</property>
+            <property name="margin-end">12</property>
+            <child>
+              <object class="GtkLabel" id="command_bar_text">
+                <property name="hexpand">true</property>
+                <property name="valign">center</property>
+                <property name="xalign">0</property>
+                <attributes>
+                  <attribute name="family" value="Monospace"/>
+                </attributes>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="command_text">
+                <property name="width-chars">6</property>
+                <property name="max-width-chars">6</property>
+                <property name="valign">center</property>
+                <property name="xalign">0</property>
+                <attributes>
+                  <attribute name="family" value="Monospace"/>
+                  <attribute name="font-features" value="tnum"/>
+                </attributes>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="selection_count">
+                <property name="width-chars">4</property>
+                <property name="max-width-chars">4</property>
+                <property name="valign">center</property>
+                <property name="xalign">0</property>
+                <attributes>
+                  <attribute name="family" value="Monospace"/>
+                  <attribute name="font-features" value="tnum"/>
+                </attributes>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="mode">
+                <property name="width-chars">3</property>
+                <property name="max-width-chars">3</property>
+                <property name="valign">center</property>
+                <attributes>
+                  <attribute name="family" value="Monospace"/>
+                </attributes>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="position">
+                <property name="width-chars">12</property>
+                <property name="max-width-chars">12</property>
+                <property name="valign">center</property>
+                <property name="xalign">0</property>
+                <attributes>
+                  <attribute name="family" value="Monospace"/>
+                  <attribute name="font-features" value="tnum"/>
+                </attributes>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/editor-window-private.h b/src/editor-window-private.h
index 58dd24a..886f8b8 100644
--- a/src/editor-window-private.h
+++ b/src/editor-window-private.h
@@ -22,12 +22,13 @@
 
 #include <adwaita.h>
 
-#include "editor-window.h"
+#include "editor-binding-group.h"
 #include "editor-open-popover-private.h"
-#include "editor-position-label-private.h"
 #include "editor-page-private.h"
+#include "editor-position-label-private.h"
 #include "editor-signal-group.h"
-#include "editor-binding-group.h"
+#include "editor-statusbar-private.h"
+#include "editor-window.h"
 
 G_BEGIN_DECLS
 
@@ -53,6 +54,7 @@ struct _EditorWindow
   GtkMenuButton        *export_menu;
   GtkWidget            *zoom_label;
   GMenu                *options_menu_model;
+  EditorStatusbar      *statusbar;
 
   /* Borrowed References */
   EditorPage           *visible_page;
diff --git a/src/editor-window.c b/src/editor-window.c
index fa9e201..806ea45 100644
--- a/src/editor-window.c
+++ b/src/editor-window.c
@@ -27,10 +27,6 @@
 #include "editor-application.h"
 #include "editor-document.h"
 #include "editor-open-popover-private.h"
-#include "editor-preferences-font.h"
-#include "editor-preferences-radio.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"
@@ -47,6 +43,21 @@ enum {
 
 static GParamSpec *properties[N_PROPS];
 
+static void
+update_keybindings_cb (EditorWindow *self,
+                       const char   *key,
+                       GSettings    *settings)
+{
+  g_autofree char *keybindings = NULL;
+
+  g_assert (EDITOR_IS_WINDOW (self));
+  g_assert (G_IS_SETTINGS (settings));
+
+  /* Show the statusbar if we have vim keybindings enabled */
+  keybindings = g_settings_get_string (settings, "keybindings");
+  gtk_widget_set_visible (GTK_WIDGET (self->statusbar), g_strcmp0 (keybindings, "vim") == 0);
+}
+
 static void
 update_subtitle_visibility_cb (EditorWindow *self)
 {
@@ -195,6 +206,7 @@ editor_window_notify_selected_page_cb (EditorWindow *self,
 
   editor_binding_group_set_source (self->page_bindings, page);
   editor_signal_group_set_target (self->page_signals, page);
+  editor_statusbar_bind_page (self->statusbar, page);
 
   _editor_window_actions_update (self, page);
 
@@ -743,6 +755,7 @@ editor_window_class_init (EditorWindowClass *klass)
   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, statusbar);
   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);
@@ -782,9 +795,7 @@ 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);
+  g_type_ensure (EDITOR_TYPE_STATUSBAR);
 }
 
 static void
@@ -806,6 +817,12 @@ editor_window_init (EditorWindow *self)
                            G_CALLBACK (update_subtitle_visibility_cb),
                            self,
                            G_CONNECT_SWAPPED);
+  g_signal_connect_object (self->settings,
+                           "changed::keybindings",
+                           G_CALLBACK (update_keybindings_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+  update_keybindings_cb (self, NULL, self->settings);
 
   g_signal_connect_swapped (adw_tab_view_get_pages (self->tab_view),
                             "items-changed",
diff --git a/src/editor-window.ui b/src/editor-window.ui
index bc0418f..3211e7e 100644
--- a/src/editor-window.ui
+++ b/src/editor-window.ui
@@ -162,6 +162,11 @@ Or, press Ctrl+W to close the window.</property>
             </child>
           </object>
         </child>
+        <child>
+          <object class="EditorStatusbar" id="statusbar">
+            <property name="visible">false</property>
+          </object>
+        </child>
       </object>
     </child>
   </template>
diff --git a/src/meson.build b/src/meson.build
index c7e8181..851fd3e 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -42,6 +42,7 @@ editor_sources = [
   'editor-spell-language-info.c',
   'editor-spell-menu.c',
   'editor-spell-provider.c',
+  'editor-statusbar.c',
   'editor-text-buffer-spell-adapter.c',
   'editor-theme-selector.c',
   'editor-utils.c',
diff --git a/src/org.gnome.TextEditor.gresource.xml b/src/org.gnome.TextEditor.gresource.xml
index 77590dd..991d2f2 100644
--- a/src/org.gnome.TextEditor.gresource.xml
+++ b/src/org.gnome.TextEditor.gresource.xml
@@ -11,6 +11,7 @@
     <file preprocess="xml-stripblanks">editor-search-bar.ui</file>
     <file preprocess="xml-stripblanks">editor-search-entry.ui</file>
     <file preprocess="xml-stripblanks">editor-sidebar-row.ui</file>
+    <file preprocess="xml-stripblanks">editor-statusbar.ui</file>
     <file preprocess="xml-stripblanks">editor-theme-selector.ui</file>
     <file preprocess="xml-stripblanks">editor-window.ui</file>
     <file preprocess="xml-stripblanks">help-overlay.ui</file>


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