[gnome-builder] terminal: allow specifying terminal scrollback



commit 778917f8513722c602166abcc7f02929fcbd06ea
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jan 15 12:03:14 2021 -0800

    terminal: allow specifying terminal scrollback

 .../org.gnome.builder.terminal.gschema.xml         |   7 ++
 src/libide/terminal/ide-terminal.c                 |  31 ++++++
 .../terminal/gbp-terminal-preferences-addin.c      | 105 +++++++++++++++++++++
 .../terminal/gbp-terminal-preferences-addin.h      |  31 ++++++
 src/plugins/terminal/meson.build                   |   1 +
 src/plugins/terminal/terminal-plugin.c             |   4 +
 6 files changed, 179 insertions(+)
---
diff --git a/data/gsettings/org.gnome.builder.terminal.gschema.xml 
b/data/gsettings/org.gnome.builder.terminal.gschema.xml
index fbf7978ae..690ffe722 100644
--- a/data/gsettings/org.gnome.builder.terminal.gschema.xml
+++ b/data/gsettings/org.gnome.builder.terminal.gschema.xml
@@ -6,5 +6,12 @@
     <key name="font-name" type="s">
       <default>"Monospace 11"</default>
     </key>
+    <key name="limit-scrollback" type="b">
+      <default>true</default>
+    </key>
+    <key name="scrollback-lines" type="u">
+      <range min="0" max="999999999"/>
+      <default>10000</default>
+    </key>
   </schema>
 </schemalist>
diff --git a/src/libide/terminal/ide-terminal.c b/src/libide/terminal/ide-terminal.c
index 53c6c18f8..0e400eeee 100644
--- a/src/libide/terminal/ide-terminal.c
+++ b/src/libide/terminal/ide-terminal.c
@@ -428,6 +428,26 @@ ide_terminal_size_allocate (GtkWidget     *widget,
   vte_terminal_set_size (VTE_TERMINAL (self), columns, rows);
 }
 
+static void
+update_scrollback_cb (IdeTerminal *self,
+                      const char  *key,
+                      GSettings   *settings)
+{
+  gboolean limit_scrollback;
+  guint scrollback_lines;
+
+  g_assert (IDE_IS_TERMINAL (self));
+  g_assert (G_IS_SETTINGS (settings));
+
+  limit_scrollback = g_settings_get_boolean (settings, "limit-scrollback");
+  scrollback_lines = g_settings_get_uint (settings, "scrollback-lines");
+
+  if (limit_scrollback)
+    vte_terminal_set_scrollback_lines (VTE_TERMINAL (self), scrollback_lines);
+  else
+    vte_terminal_set_scrollback_lines (VTE_TERMINAL (self), -1);
+}
+
 static void
 ide_terminal_destroy (GtkWidget *widget)
 {
@@ -554,12 +574,23 @@ ide_terminal_init (IdeTerminal *self)
 
   priv->settings = g_settings_new ("org.gnome.builder.terminal");
   g_settings_bind (priv->settings, "allow-bold", self, "allow-bold", G_SETTINGS_BIND_GET);
+  g_signal_connect_object (priv->settings,
+                           "changed::limit-scrollback",
+                           G_CALLBACK (update_scrollback_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+  g_signal_connect_object (priv->settings,
+                           "changed::scrollback-lines",
+                           G_CALLBACK (update_scrollback_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
   g_signal_connect_object (priv->settings,
                            "changed::font-name",
                            G_CALLBACK (ide_terminal_font_changed),
                            self,
                            G_CONNECT_SWAPPED);
   ide_terminal_font_changed (self, NULL, priv->settings);
+  update_scrollback_cb (self, "scrollback-lines", priv->settings);
 
   style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
   gtk_style_context_add_class (style_context, "terminal");
diff --git a/src/plugins/terminal/gbp-terminal-preferences-addin.c 
b/src/plugins/terminal/gbp-terminal-preferences-addin.c
new file mode 100644
index 000000000..9dc863cae
--- /dev/null
+++ b/src/plugins/terminal/gbp-terminal-preferences-addin.c
@@ -0,0 +1,105 @@
+/* gbp-terminal-preferences-addin.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
+ */
+
+#define G_LOG_DOMAIN "gbp-terminal-preferences-addin"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include "gbp-terminal-preferences-addin.h"
+
+struct _GbpTerminalPreferencesAddin
+{
+  GObject parent_instance;
+  guint limit_id;
+  guint lines_id;
+};
+
+static void
+gbp_terminal_preferences_addin_load (IdePreferencesAddin *addin,
+                                     DzlPreferences      *preferences)
+{
+  GbpTerminalPreferencesAddin *self = (GbpTerminalPreferencesAddin *)addin;
+
+  g_assert (GBP_IS_TERMINAL_PREFERENCES_ADDIN (self));
+  g_assert (DZL_IS_PREFERENCES (preferences));
+
+  dzl_preferences_add_page (preferences, "terminal", _("Terminal"), 100);
+  dzl_preferences_add_list_group (preferences, "terminal", "scrollback", _("Scrollback"), 
GTK_SELECTION_NONE, 10);
+
+  self->limit_id = dzl_preferences_add_switch (preferences,
+                                               "terminal",
+                                               "scrollback",
+                                               "org.gnome.builder.terminal",
+                                               "limit-scrollback",
+                                               NULL,
+                                               NULL,
+                                               _("Limit Scrollback"),
+                                               _("When enabled terminal scrollback will be limited to the 
number of lines specified below"),
+                                               /* translators: the following are keywords the user can 
search for in no particular order */
+                                               _("scrollback limit"),
+                                               10);
+  self->lines_id = dzl_preferences_add_spin_button (preferences,
+                                                    "terminal",
+                                                    "scrollback",
+                                                    "org.gnome.builder.terminal",
+                                                    "scrollback-lines",
+                                                    NULL,
+                                                    _("Scrollback Lines"),
+                                                    _("The number of lines to keep available for scrolling"),
+                                                    /* translators: the following are keywords the user can 
search for in no particular order */
+                                                    _("scrollback lines"),
+                                                    20);
+}
+
+static void
+gbp_terminal_preferences_addin_unload (IdePreferencesAddin *addin,
+                                       DzlPreferences      *preferences)
+{
+  GbpTerminalPreferencesAddin *self = (GbpTerminalPreferencesAddin *)addin;
+
+  g_assert (GBP_IS_TERMINAL_PREFERENCES_ADDIN (self));
+  g_assert (DZL_IS_PREFERENCES (preferences));
+
+  dzl_preferences_remove_id (preferences, self->limit_id);
+  dzl_preferences_remove_id (preferences, self->lines_id);
+}
+
+static void
+preferences_addin_iface_Init (IdePreferencesAddinInterface *iface)
+{
+  iface->load = gbp_terminal_preferences_addin_load;
+  iface->unload = gbp_terminal_preferences_addin_unload;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpTerminalPreferencesAddin, gbp_terminal_preferences_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_PREFERENCES_ADDIN,
+                                                preferences_addin_iface_Init))
+
+static void
+gbp_terminal_preferences_addin_class_init (GbpTerminalPreferencesAddinClass *klass)
+{
+}
+
+static void
+gbp_terminal_preferences_addin_init (GbpTerminalPreferencesAddin *self)
+{
+}
diff --git a/src/plugins/terminal/gbp-terminal-preferences-addin.h 
b/src/plugins/terminal/gbp-terminal-preferences-addin.h
new file mode 100644
index 000000000..ed0658ee6
--- /dev/null
+++ b/src/plugins/terminal/gbp-terminal-preferences-addin.h
@@ -0,0 +1,31 @@
+/* gbp-terminal-preferences-addin.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 <libide-gui.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_TERMINAL_PREFERENCES_ADDIN (gbp_terminal_preferences_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpTerminalPreferencesAddin, gbp_terminal_preferences_addin, GBP, 
TERMINAL_PREFERENCES_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/terminal/meson.build b/src/plugins/terminal/meson.build
index 1c9dbc7e2..5c1514330 100644
--- a/src/plugins/terminal/meson.build
+++ b/src/plugins/terminal/meson.build
@@ -1,5 +1,6 @@
 plugins_sources += files([
   'gbp-terminal-application-addin.c',
+  'gbp-terminal-preferences-addin.c',
   'gbp-terminal-workspace-addin.c',
   'terminal-plugin.c',
 ])
diff --git a/src/plugins/terminal/terminal-plugin.c b/src/plugins/terminal/terminal-plugin.c
index 06a97dc19..c0f05e747 100644
--- a/src/plugins/terminal/terminal-plugin.c
+++ b/src/plugins/terminal/terminal-plugin.c
@@ -27,6 +27,7 @@
 #include <libide-terminal.h>
 
 #include "gbp-terminal-application-addin.h"
+#include "gbp-terminal-preferences-addin.h"
 #include "gbp-terminal-workspace-addin.h"
 
 _IDE_EXTERN void
@@ -35,6 +36,9 @@ _gbp_terminal_register_types (PeasObjectModule *module)
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_APPLICATION_ADDIN,
                                               GBP_TYPE_TERMINAL_APPLICATION_ADDIN);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_PREFERENCES_ADDIN,
+                                              GBP_TYPE_TERMINAL_PREFERENCES_ADDIN);
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_WORKSPACE_ADDIN,
                                               GBP_TYPE_TERMINAL_WORKSPACE_ADDIN);


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