[gtksourceview/wip/chergert/test-widget-revamp] tests: start on revamped test-widget
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/test-widget-revamp] tests: start on revamped test-widget
- Date: Sat, 19 Feb 2022 00:58:22 +0000 (UTC)
commit 6f9a8da821873bb70609963888ce14716f220d62
Author: Christian Hergert <chergert redhat com>
Date: Fri Feb 18 16:57:57 2022 -0800
tests: start on revamped test-widget
The goal here is to be more similar to how applications, and particularly
editors, are going to be rendering content (large editor space, taking
most of the window child).
Additionally, we want to be using CSD as that is more prevalent and we
need to be sure our rendering performance is good with windows which can
be, at least partially, transparent.
tests/test-widget.c | 162 +++++++++++++++-
tests/test-widget.gresource.xml | 1 +
tests/test-window.ui | 398 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 557 insertions(+), 4 deletions(-)
---
diff --git a/tests/test-widget.c b/tests/test-widget.c
index 6ae4775e..0eb3a747 100644
--- a/tests/test-widget.c
+++ b/tests/test-widget.c
@@ -22,12 +22,22 @@
#include <string.h>
#include <gtksourceview/gtksource.h>
+#define TEST_TYPE_WINDOW (test_window_get_type())
#define TEST_TYPE_WIDGET (test_widget_get_type())
#define TEST_TYPE_HOVER_PROVIDER (test_hover_provider_get_type())
+G_DECLARE_FINAL_TYPE (TestWindow, test_window, TEST, WINDOW, GtkWindow)
G_DECLARE_FINAL_TYPE (TestWidget, test_widget, TEST, WIDGET, GtkGrid)
G_DECLARE_FINAL_TYPE (TestHoverProvider, test_hover_provider, TEST, HOVER_PROVIDER, GObject)
+struct _TestWindow
+{
+ GtkWindow parent_instance;
+ GtkSourceBuffer *buffer;
+ GtkSourceView *view;
+ GtkGrid *style_grid;
+};
+
struct _TestWidget
{
GtkGrid parent_instance;
@@ -60,6 +70,7 @@ struct _TestHoverProvider
static void hover_provider_iface_init (GtkSourceHoverProviderInterface *iface);
+G_DEFINE_TYPE (TestWindow, test_window, GTK_TYPE_WINDOW)
G_DEFINE_TYPE (TestWidget, test_widget, GTK_TYPE_GRID)
G_DEFINE_TYPE_WITH_CODE (TestHoverProvider, test_hover_provider, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_HOVER_PROVIDER, hover_provider_iface_init))
@@ -1266,6 +1277,147 @@ test_hover_provider_init (TestHoverProvider *self)
{
}
+static void
+load_previews (TestWindow *self)
+{
+ GtkSourceStyleSchemeManager *manager = gtk_source_style_scheme_manager_get_default ();
+ const char * const *scheme_ids = gtk_source_style_scheme_manager_get_scheme_ids (manager);
+
+ for (guint i = 0; scheme_ids[i]; i++)
+ {
+ GtkSourceStyleScheme *scheme = gtk_source_style_scheme_manager_get_scheme (manager,
scheme_ids[i]);
+ GtkWidget *preview = gtk_source_style_scheme_preview_new (scheme);
+
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (preview), "buffer.style-scheme");
+ gtk_actionable_set_action_target (GTK_ACTIONABLE (preview), "s", scheme_ids[i]);
+ gtk_grid_attach (self->style_grid, preview, i % 2, i / 2, 1, 1);
+ }
+}
+
+static void
+set_style_scheme_cb (GSimpleAction *action,
+ GVariant *param,
+ gpointer user_data)
+{
+ TestWindow *self = user_data;
+ GtkSourceStyleSchemeManager *manager;
+ GtkSourceStyleScheme *style_scheme;
+ const char *name;
+
+ if (!g_variant_is_of_type (param, G_VARIANT_TYPE_STRING))
+ return;
+
+ name = g_variant_get_string (param, NULL);
+ manager = gtk_source_style_scheme_manager_get_default ();
+ style_scheme = gtk_source_style_scheme_manager_get_scheme (manager, name);
+ gtk_source_buffer_set_style_scheme (self->buffer, style_scheme);
+
+ for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self->style_grid));
+ child;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ GtkSourceStyleSchemePreview *preview = GTK_SOURCE_STYLE_SCHEME_PREVIEW (child);
+
+ if (style_scheme == gtk_source_style_scheme_preview_get_scheme (preview))
+ gtk_source_style_scheme_preview_set_selected (preview, TRUE);
+ else
+ gtk_source_style_scheme_preview_set_selected (preview, FALSE);
+ }
+
+ g_simple_action_set_state (action, param);
+}
+
+static void
+action_fullscreen (GtkWidget *widget,
+ const char *action_name,
+ GVariant *param)
+{
+ if (gtk_window_is_fullscreen (GTK_WINDOW (widget)))
+ gtk_window_unfullscreen (GTK_WINDOW (widget));
+ else
+ gtk_window_fullscreen (GTK_WINDOW (widget));
+}
+
+static void
+test_window_class_init (TestWindowClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/gtksourceview/tests/ui/test-window.ui");
+ gtk_widget_class_bind_template_child (widget_class, TestWindow, buffer);
+ gtk_widget_class_bind_template_child (widget_class, TestWindow, view);
+ gtk_widget_class_bind_template_child (widget_class, TestWindow, style_grid);
+
+ gtk_widget_class_install_action (widget_class, "win.fullscreen", NULL, action_fullscreen);
+
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_F11, 0, "win.fullscreen", NULL);
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_w, GDK_CONTROL_MASK, "window.close", NULL);
+}
+
+static void
+test_window_init (TestWindow *self)
+{
+ static const GActionEntry buffer_actions[] = {
+ { "style-scheme", NULL, "s", "''", set_style_scheme_cb },
+ };
+ static const char * const buffer_properties[] = {
+ "highlight-matching-brackets",
+ "highlight-syntax",
+ };
+ static const char * const view_properties[] = {
+ "auto-indent",
+ "indent-width",
+ "tab-width",
+ "insert-spaces-instead-of-tabs",
+ "enable-snippets",
+ "highlight-current-line",
+ "right-margin-position",
+ "show-line-marks",
+ "show-line-numbers",
+ "show-right-margin",
+ "smart-backspace",
+ "smart-home-end",
+ };
+ GSimpleActionGroup *group = NULL;
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ load_previews (self);
+
+ group = g_simple_action_group_new ();
+ g_action_map_add_action_entries (G_ACTION_MAP (group),
+ buffer_actions,
+ G_N_ELEMENTS (buffer_actions),
+ self);
+ gtk_widget_insert_action_group (GTK_WIDGET (self),
+ "buffer",
+ G_ACTION_GROUP (group));
+ for (guint i = 0; i < G_N_ELEMENTS (buffer_properties); i++)
+ {
+ GPropertyAction *property;
+
+ property = g_property_action_new (buffer_properties[i], self->buffer, buffer_properties[i]);
+ g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (property));
+ g_clear_object (&property);
+ }
+ g_clear_object (&group);
+
+ group = g_simple_action_group_new ();
+ gtk_widget_insert_action_group (GTK_WIDGET (self),
+ "view",
+ G_ACTION_GROUP (group));
+ for (guint i = 0; i < G_N_ELEMENTS (view_properties); i++)
+ {
+ GPropertyAction *property;
+
+ property = g_property_action_new (view_properties[i], self->view, view_properties[i]);
+ g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (property));
+ g_clear_object (&property);
+ }
+ g_clear_object (&group);
+}
+
static void
setup_search_paths (void)
{
@@ -1305,14 +1457,16 @@ main (int argc, char *argv[])
gtk_source_init ();
setup_search_paths ();
- window = gtk_window_new ();
- gtk_window_set_default_size (GTK_WINDOW (window), 900, 600);
- gtk_window_set_title (GTK_WINDOW (window), "GtkSourceView Test");
+ window = g_object_new (TEST_TYPE_WINDOW,
+ "default-width", 900,
+ "default-height", 600,
+ "title", "GtkSourceView Test Widget",
+ NULL);
g_signal_connect_swapped (window, "destroy", G_CALLBACK (g_main_loop_quit), main_loop);
test_widget = test_widget_new ();
- gtk_window_set_child (GTK_WINDOW (window), GTK_WIDGET (test_widget));
+ //gtk_window_set_child (GTK_WINDOW (window), GTK_WIDGET (test_widget));
gtk_widget_show (window);
diff --git a/tests/test-widget.gresource.xml b/tests/test-widget.gresource.xml
index 7568a08e..a08a4bef 100644
--- a/tests/test-widget.gresource.xml
+++ b/tests/test-widget.gresource.xml
@@ -2,5 +2,6 @@
<gresources>
<gresource prefix="/org/gnome/gtksourceview/tests/ui">
<file preprocess="xml-stripblanks">test-widget.ui</file>
+ <file preprocess="xml-stripblanks">test-window.ui</file>
</gresource>
</gresources>
diff --git a/tests/test-window.ui b/tests/test-window.ui
new file mode 100644
index 00000000..b570282a
--- /dev/null
+++ b/tests/test-window.ui
@@ -0,0 +1,398 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk" version="4.0"/>
+ <template class="TestWindow" parent="GtkWindow">
+ <child type="titlebar">
+ <object class="GtkHeaderBar">
+ <child type="title">
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="valign">center</property>
+ <child>
+ <object class="GtkLabel" id="title">
+ <property name="label">filename.c</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="subtitle">
+ <property name="label">document information</property>
+ <attributes>
+ <attribute name="scale" value="0.8333"/>
+ <attribute name="foreground-alpha" value="32768"/>
+ </attributes>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="start">
+ <object class="GtkMenuButton">
+ <property name="label">Style</property>
+ <property name="popover">
+ <object class="GtkPopover">
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="propagate-natural-width">true</property>
+ <property name="propagate-natural-height">true</property>
+ <property name="min-content-width">200</property>
+ <property name="max-content-height">600</property>
+ <property name="hscrollbar-policy">never</property>
+ <child>
+ <object class="GtkViewport">
+ <property name="scroll-to-focus">true</property>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="label">Style Scheme</property>
+ <property name="margin-top">6</property>
+ <property name="halign">center</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ <child>
+ <object class="GtkGrid" id="style_grid">
+ <property name="margin-top">12</property>
+ <property name="margin-bottom">12</property>
+ <property name="margin-start">12</property>
+ <property name="margin-end">12</property>
+ <property name="column-spacing">6</property>
+ <property name="row-spacing">6</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </property>
+ </object>
+ </child>
+ <child type="start">
+ <object class="GtkBox">
+ <property name="orientation">horizontal</property>
+ <style>
+ <class name="linked"/>
+ </style>
+ <child>
+ <object class="GtkButton">
+ <property name="tooltip-text">Move to previous string toggle</property>
+ <property name="icon-name">go-previous-symbolic</property>
+ <property name="action-name">win.previous-string</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="tooltip-text">Move to next string toggle</property>
+ <property name="icon-name">go-next-symbolic</property>
+ <property name="action-name">win.next-string</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="end">
+ <object class="GtkMenuButton">
+ <property name="primary">true</property>
+ <property name="icon-name">open-menu-symbolic</property>
+ <property name="menu-model">primary_menu</property>
+ </object>
+ </child>
+ <child type="end">
+ <object class="GtkMenuButton">
+ <property name="primary">true</property>
+ <property name="icon-name">document-properties-symbolic</property>
+ <property name="menu-model">properties_menu</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">horizontal</property>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="hexpand">true</property>
+ <property name="vexpand">true</property>
+ <child>
+ <object class="GtkSourceView" id="view">
+ <property name="monospace">true</property>
+ <property name="show-line-numbers">true</property>
+ <property name="left-margin">6</property>
+ <property name="top-margin">6</property>
+ <property name="buffer">buffer</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSourceMap" id="map">
+ <property name="view">view</property>
+ <property name="left-margin">6</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+ <menu id="primary_menu">
+ <section>
+ <item>
+ <attribute name="label">Open</attribute>
+ <attribute name="action">win.open</attribute>
+ <attribute name="accel"><ctrl>o</attribute>
+ </item>
+ <item>
+ <attribute name="label">Save</attribute>
+ <attribute name="action">win.save</attribute>
+ <attribute name="accel"><ctrl>s</attribute>
+ </item>
+ <item>
+ <attribute name="label">Save</attribute>
+ <attribute name="action">win.save-as</attribute>
+ <attribute name="accel"><ctrl><shift>s</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label">Print</attribute>
+ <attribute name="action">win.print</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label">Fullscreen</attribute>
+ <attribute name="action">win.fullscreen</attribute>
+ <attribute name="accel">F11</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label">Close</attribute>
+ <attribute name="action">window.close</attribute>
+ <attribute name="accel"><ctrl>w</attribute>
+ </item>
+ </section>
+ </menu>
+ <menu id="properties_menu">
+ <section>
+ <attribute name="label">Show</attribute>
+ <item>
+ <attribute name="label">Line Marks</attribute>
+ <attribute name="action">view.show-line-marks</attribute>
+ </item>
+ <item>
+ <attribute name="label">Line Numbers</attribute>
+ <attribute name="action">view.show-line-numbers</attribute>
+ </item>
+ <item>
+ <attribute name="label">Spaces</attribute>
+ <attribute name="action">view.show-spaces</attribute>
+ </item>
+ <item>
+ <attribute name="label">Overview Map</attribute>
+ <attribute name="action">view.show-map</attribute>
+ </item>
+ </section>
+ <section>
+ <attribute name="label">Behavior</attribute>
+ <item>
+ <attribute name="label">Wrap Text</attribute>
+ <attribute name="action">win.wrap-text</attribute>
+ </item>
+ <item>
+ <attribute name="label">Smart Backspace</attribute>
+ <attribute name="action">win.smart-backspace</attribute>
+ </item>
+ <submenu>
+ <attribute name="label">Smart Home & End</attribute>
+ <section>
+ <item>
+ <attribute name="label">Disabled</attribute>
+ <attribute name="action">win.smart-home-end</attribute>
+ <attribute name="target" type='s'>'disabled'</attribute>
+ </item>
+ <item>
+ <attribute name="label">Before</attribute>
+ <attribute name="action">win.smart-home-end</attribute>
+ <attribute name="target" type='s'>'before'</attribute>
+ </item>
+ <item>
+ <attribute name="label">After</attribute>
+ <attribute name="action">win.smart-home-end</attribute>
+ <attribute name="target" type='s'>'after'</attribute>
+ </item>
+ <item>
+ <attribute name="label">Always</attribute>
+ <attribute name="action">win.smart-home-end</attribute>
+ <attribute name="target" type='s'>'always'</attribute>
+ </item>
+ </section>
+ </submenu>
+ <item>
+ <attribute name="label">Vim Emulation</attribute>
+ <attribute name="action">view.vim</attribute>
+ </item>
+ <item>
+ <attribute name="label">Snippets</attribute>
+ <attribute name="action">view.enable-snippets</attribute>
+ </item>
+ <item>
+ <attribute name="label">Hover Assistants</attribute>
+ <attribute name="action">view.hoverers</attribute>
+ </item>
+ <item>
+ <attribute name="label">Completion</attribute>
+ <attribute name="action">view.completion</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label">Right Margin</attribute>
+ <attribute name="action">view.show-right-margin</attribute>
+ </item>
+ <submenu>
+ <attribute name="label">Right Margin Position</attribute>
+ <section>
+ <item>
+ <attribute name="label">72</attribute>
+ <attribute name="action">view.right-margin-position</attribute>
+ <attribute name="target" type="u">72</attribute>
+ </item>
+ <item>
+ <attribute name="label">80</attribute>
+ <attribute name="action">view.right-margin-position</attribute>
+ <attribute name="target" type="u">80</attribute>
+ </item>
+ <item>
+ <attribute name="label">100</attribute>
+ <attribute name="action">view.right-margin-position</attribute>
+ <attribute name="target" type="u">100</attribute>
+ </item>
+ <item>
+ <attribute name="label">120</attribute>
+ <attribute name="action">view.right-margin-position</attribute>
+ <attribute name="target" type="u">120</attribute>
+ </item>
+ </section>
+ </submenu>
+ </section>
+ <section>
+ <attribute name="label">Highlight</attribute>
+ <item>
+ <attribute name="label">Current Line</attribute>
+ <attribute name="action">view.highlight-current-line</attribute>
+ </item>
+ <item>
+ <attribute name="label">Matching Brackets</attribute>
+ <attribute name="action">buffer.highlight-matching-brackets</attribute>
+ </item>
+ <item>
+ <attribute name="label">Syntax</attribute>
+ <attribute name="action">buffer.highlight-syntax</attribute>
+ </item>
+ <submenu>
+ <attribute name="label">Language</attribute>
+ </submenu>
+ </section>
+ <section>
+ <attribute name="label">Indentation</attribute>
+ <item>
+ <attribute name="label">Automatic Indentation</attribute>
+ <attribute name="action">view.auto-indent</attribute>
+ </item>
+ <item>
+ <attribute name="label">Indent with Spaces</attribute>
+ <attribute name="action">view.insert-spaces-instead-of-tabs</attribute>
+ </item>
+ <submenu>
+ <attribute name="label">Tab Width</attribute>
+ <item>
+ <attribute name="label">2</attribute>
+ <attribute name="action">view.tab-width</attribute>
+ <attribute name="target" type="u">2</attribute>
+ </item>
+ <item>
+ <attribute name="label">3</attribute>
+ <attribute name="action">view.tab-width</attribute>
+ <attribute name="target" type="u">3</attribute>
+ </item>
+ <item>
+ <attribute name="label">4</attribute>
+ <attribute name="action">view.tab-width</attribute>
+ <attribute name="target" type="u">4</attribute>
+ </item>
+ <item>
+ <attribute name="label">5</attribute>
+ <attribute name="action">view.tab-width</attribute>
+ <attribute name="target" type="u">5</attribute>
+ </item>
+ <item>
+ <attribute name="label">6</attribute>
+ <attribute name="action">view.tab-width</attribute>
+ <attribute name="target" type="u">6</attribute>
+ </item>
+ <item>
+ <attribute name="label">7</attribute>
+ <attribute name="action">view.tab-width</attribute>
+ <attribute name="target" type="u">7</attribute>
+ </item>
+ <item>
+ <attribute name="label">8</attribute>
+ <attribute name="action">view.tab-width</attribute>
+ <attribute name="target" type="u">8</attribute>
+ </item>
+ </submenu>
+ <submenu>
+ <attribute name="label">Indentation Width</attribute>
+ <item>
+ <attribute name="label">Use Tab Width</attribute>
+ <attribute name="action">view.indent-width</attribute>
+ <attribute name="target" type="i">-1</attribute>
+ </item>
+ <item>
+ <attribute name="label">2</attribute>
+ <attribute name="action">view.indent-width</attribute>
+ <attribute name="target" type="i">2</attribute>
+ </item>
+ <item>
+ <attribute name="label">3</attribute>
+ <attribute name="action">view.indent-width</attribute>
+ <attribute name="target" type="i">3</attribute>
+ </item>
+ <item>
+ <attribute name="label">4</attribute>
+ <attribute name="action">view.indent-width</attribute>
+ <attribute name="target" type="i">4</attribute>
+ </item>
+ <item>
+ <attribute name="label">5</attribute>
+ <attribute name="action">view.indent-width</attribute>
+ <attribute name="target" type="i">5</attribute>
+ </item>
+ <item>
+ <attribute name="label">6</attribute>
+ <attribute name="action">view.indent-width</attribute>
+ <attribute name="target" type="i">6</attribute>
+ </item>
+ <item>
+ <attribute name="label">7</attribute>
+ <attribute name="action">view.indent-width</attribute>
+ <attribute name="target" type="i">7</attribute>
+ </item>
+ <item>
+ <attribute name="label">8</attribute>
+ <attribute name="action">view.indent-width</attribute>
+ <attribute name="target" type="i">8</attribute>
+ </item>
+ </submenu>
+ </section>
+ </menu>
+ <object class="GtkSourceBuffer" id="buffer">
+ </object>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]