[gtksourceview/wip/renovate-test-widget: 2/2] test-widget: composite widget template



commit cc9c643f43af7562fc232432afdb51450f36ce1c
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Mar 9 15:19:07 2014 +0100

    test-widget: composite widget template
    
    Replaces the menu with a sidebar, like in test-completion.
    It removes lots of warnings due to deprecated functions (GtkStock,
    GtkUIManager, etc.).

 tests/Makefile.am               |   10 +-
 tests/test-widget.c             |  129 ++++++++++----
 tests/test-widget.gresource.xml |    6 +
 tests/test-widget.ui            |  382 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 492 insertions(+), 35 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8d0a4e6..94dd3f3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -14,7 +14,8 @@ noinst_PROGRAMS = $(TEST_PROGS) $(UNIT_TEST_PROGS)
 
 BUILT_SOURCES =                                \
        test-completion-resources.c     \
-       test-search-resources.c
+       test-search-resources.c         \
+       test-widget-resources.c
 
 test-completion-resources.c: test-completion.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) 
--generate-dependencies $(srcdir)/test-completion.gresource.xml)
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
$(srcdir)/test-completion.gresource.xml
@@ -22,6 +23,9 @@ test-completion-resources.c: test-completion.gresource.xml $(shell $(GLIB_COMPIL
 test-search-resources.c: test-search.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies 
$(srcdir)/test-search.gresource.xml)
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
$(srcdir)/test-search.gresource.xml
 
+test-widget-resources.c: test-widget.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies 
$(srcdir)/test-widget.gresource.xml)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
$(srcdir)/test-widget.gresource.xml
+
 TEST_PROGS = test-completion
 test_completion_SOURCES =              \
        test-completion.c               \
@@ -49,7 +53,9 @@ test_search_performances_LDADD =                              \
        $(TESTS_LIBS)
 
 TEST_PROGS += test-widget
-test_widget_SOURCES = test-widget.c
+test_widget_SOURCES =          \
+       test-widget.c           \
+       test-widget-resources.c
 test_widget_LDADD =                    \
        $(top_builddir)/gtksourceview/libgtksourceview-3.0.la \
        $(DEP_LIBS)                     \
diff --git a/tests/test-widget.c b/tests/test-widget.c
index 319fd5b..b2f8410 100644
--- a/tests/test-widget.c
+++ b/tests/test-widget.c
@@ -4,6 +4,7 @@
  *
  * Copyright (C) 2001 - Mikael Hermansson <tyan linux se>
  * Copyright (C) 2003 - Gustavo Giráldez <gustavo giraldez gmx net>
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -25,6 +26,38 @@
 #include <gio/gio.h>
 #include <gtksourceview/gtksource.h>
 
+#define TEST_TYPE_WIDGET             (test_widget_get_type ())
+#define TEST_WIDGET(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_WIDGET, TestWidget))
+#define TEST_WIDGET_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_WIDGET, TestWidgetClass))
+#define TEST_IS_WIDGET(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_WIDGET))
+#define TEST_IS_WIDGET_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_TYPE_WIDGET))
+#define TEST_WIDGET_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_WIDGET, TestWidgetClass))
+
+typedef struct _TestWidget         TestWidget;
+typedef struct _TestWidgetClass    TestWidgetClass;
+typedef struct _TestWidgetPrivate  TestWidgetPrivate;
+
+struct _TestWidget
+{
+       GtkGrid parent;
+
+       TestWidgetPrivate *priv;
+};
+
+struct _TestWidgetClass
+{
+       GtkGridClass parent_class;
+};
+
+struct _TestWidgetPrivate
+{
+       GtkSourceView *source_view;
+};
+
+GType test_widget_get_type (void);
+
+G_DEFINE_TYPE_WITH_PRIVATE (TestWidget, test_widget, GTK_TYPE_GRID)
+
 static GtkSourceStyleScheme *style_scheme = NULL;
 
 #define MARK_TYPE_1      "one"
@@ -1346,19 +1379,60 @@ create_main_window (GtkSourceBuffer *buffer)
        return window;
 }
 
+/* Class init, finalize, etc. */
+
+static void
+test_widget_finalize (GObject *object)
+{
+
+       G_OBJECT_CLASS (test_widget_parent_class)->finalize (object);
+}
+
+static void
+test_widget_class_init (TestWidgetClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+       object_class->finalize = test_widget_finalize;
+
+       gtk_widget_class_set_template_from_resource (widget_class,
+                                                    "/org/gnome/gtksourceview/tests/ui/test-widget.ui");
+
+       gtk_widget_class_bind_template_child_private (widget_class, TestWidget, source_view);
+}
+
+static void
+test_widget_init (TestWidget *self)
+{
+       GtkSourceBuffer *source_buffer;
+
+       self->priv = test_widget_get_instance_private (self);
+
+       gtk_widget_init_template (GTK_WIDGET (self));
+
+       source_buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW 
(self->priv->source_view)));
+       open_file (source_buffer, TOP_SRCDIR "/gtksourceview/gtksourcebuffer.c");
+}
+
+static TestWidget *
+test_widget_new (void)
+{
+       return g_object_new (test_widget_get_type (), NULL);
+}
+
 /* Program entry point */
 
 int
 main (int argc, char *argv[])
 {
+       GtkSourceLanguageManager *language_manager;
+       GtkSourceStyleSchemeManager *style_scheme_manager;
        GtkWidget *window;
-       GtkSourceLanguageManager *lm;
-       GtkSourceStyleSchemeManager *sm;
-       GtkSourceBuffer *buffer;
+       TestWidget *test_widget;
 
-       gboolean no_syntax = FALSE;
        gchar *builtin_lang_dirs[] = {TOP_SRCDIR "/data/language-specs", NULL};
-       gchar *builtin_sm_dirs[] = {TOP_SRCDIR "/data/styles", NULL};
+       gchar *builtin_styles_dirs[] = {TOP_SRCDIR "/data/styles", NULL};
        gchar **dirs;
        const gchar * const * schemes;
        gboolean use_default_paths = FALSE;
@@ -1367,7 +1441,6 @@ main (int argc, char *argv[])
        GOptionContext *context;
 
        GOptionEntry entries[] = {
-         { "no-syntax", 'n', 0, G_OPTION_ARG_NONE, &no_syntax, "Disable syntax highlighting", NULL},
          { "style-scheme", 's', 0, G_OPTION_ARG_STRING, &style_scheme_id, "Style scheme name to use", 
"SCHEME"},
          { "default-paths", 'd', 0, G_OPTION_ARG_NONE, &use_default_paths, "Use default search paths", NULL},
          { NULL }
@@ -1378,29 +1451,32 @@ main (int argc, char *argv[])
        g_option_context_add_group (context, gtk_get_option_group (TRUE));
        g_option_context_parse (context, &argc, &argv, NULL);
 
+       gtk_init (&argc, &argv);
+
        /* we do not use defaults so we don't need to install the library */
        dirs = use_default_paths ? NULL : builtin_lang_dirs;
-       lm = gtk_source_language_manager_get_default ();
-       gtk_source_language_manager_set_search_path (lm, dirs);
+       language_manager = gtk_source_language_manager_get_default ();
+       gtk_source_language_manager_set_search_path (language_manager, dirs);
 
-       dirs = use_default_paths ? NULL : builtin_sm_dirs;
+       dirs = use_default_paths ? NULL : builtin_styles_dirs;
 
-       sm = gtk_source_style_scheme_manager_get_default ();
-       gtk_source_style_scheme_manager_set_search_path (sm, dirs);
+       style_scheme_manager = gtk_source_style_scheme_manager_get_default ();
+       gtk_source_style_scheme_manager_set_search_path (style_scheme_manager, dirs);
 
        if (!use_default_paths)
        {
-               gtk_source_style_scheme_manager_append_search_path (sm, TOP_SRCDIR "/tests/test-scheme.xml");
+               gtk_source_style_scheme_manager_append_search_path (style_scheme_manager,
+                                                                   TOP_SRCDIR "/tests/test-scheme.xml");
        }
 
-       schemes = gtk_source_style_scheme_manager_get_scheme_ids (sm);
+       schemes = gtk_source_style_scheme_manager_get_scheme_ids (style_scheme_manager);
        g_print ("Available style schemes:\n");
        while (*schemes != NULL)
        {
                const gchar* const *authors;
                gchar *authors_str = NULL;
 
-               style_scheme = gtk_source_style_scheme_manager_get_scheme (sm, *schemes);
+               style_scheme = gtk_source_style_scheme_manager_get_scheme (style_scheme_manager, *schemes);
 
                authors = gtk_source_style_scheme_get_authors (style_scheme);
                if (authors != NULL)
@@ -1426,38 +1502,25 @@ main (int argc, char *argv[])
 
        if (style_scheme_id != NULL)
        {
-               style_scheme = gtk_source_style_scheme_manager_get_scheme (sm, style_scheme_id);
+               style_scheme = gtk_source_style_scheme_manager_get_scheme (style_scheme_manager, 
style_scheme_id);
        }
        else
        {
                style_scheme = NULL;
        }
 
-       /* create buffer */
-       buffer = gtk_source_buffer_new (NULL);
+       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+       gtk_window_set_default_size (GTK_WINDOW (window), 700, 500);
 
-       gtk_source_buffer_set_highlight_syntax (buffer, !no_syntax);
+       g_signal_connect (window, "destroy", gtk_main_quit, NULL);
 
-       if (argc > 1)
-       {
-               open_file (buffer, argv [1]);
-       }
-       else
-       {
-               open_file (buffer, TOP_SRCDIR "/gtksourceview/gtksourcebuffer.c");
-       }
+       test_widget = test_widget_new ();
+       gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (test_widget));
 
-       /* create first window */
-       window = create_main_window (buffer);
-       gtk_window_set_default_size (GTK_WINDOW (window), 500, 500);
        gtk_widget_show (window);
 
-       /* ... and action! */
        gtk_main ();
 
-       /* cleanup */
-       g_object_unref (buffer);
-
        g_free (style_scheme_id);
 
        return 0;
diff --git a/tests/test-widget.gresource.xml b/tests/test-widget.gresource.xml
new file mode 100644
index 0000000..7568a08
--- /dev/null
+++ b/tests/test-widget.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/gtksourceview/tests/ui">
+    <file preprocess="xml-stripblanks">test-widget.ui</file>
+  </gresource>
+</gresources>
diff --git a/tests/test-widget.ui b/tests/test-widget.ui
new file mode 100644
index 0000000..ff74dc7
--- /dev/null
+++ b/tests/test-widget.ui
@@ -0,0 +1,382 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.0 -->
+<interface>
+  <requires lib="gtk+" version="3.10"/>
+  <requires lib="gtksourceview" version="3.0"/>
+  <object class="GtkAdjustment" id="adjustment_tab_width">
+    <property name="upper">16</property>
+    <property name="value">8</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <template class="TestWidget" parent="GtkGrid">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="border_width">6</property>
+    <property name="column_spacing">4</property>
+    <child>
+      <object class="GtkScrolledWindow" id="scrolledwindow1">
+        <property name="width_request">400</property>
+        <property name="height_request">400</property>
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="shadow_type">in</property>
+        <child>
+          <object class="GtkSourceView" id="source_view">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <property name="left_margin">2</property>
+            <property name="right_margin">2</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkGrid" id="grid2">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="row_spacing">2</property>
+        <child>
+          <object class="GtkButton" id="open">
+            <property name="label">Open File</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton" id="print">
+            <property name="label">Print</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="xalign">0</property>
+            <property name="label">General options</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">2</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid3">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkCheckButton" id="highlight_syntax">
+                <property name="label">Highlight syntax</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="highlight_matching_bracket">
+                <property name="label">Highlight matching bracket</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="show_line_numbers">
+                <property name="label">Show line numbers</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="show_line_marks">
+                <property name="label">Show line marks</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">3</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="show_right_margin">
+                <property name="label">Show right margin</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">4</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="highlight_current_line">
+                <property name="label">Highlight current line</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">5</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="draw_spaces">
+                <property name="label">Draw spaces</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">6</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="wrap_lines">
+                <property name="label">Wrap lines</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">7</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">3</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="xalign">0</property>
+            <property name="label">Indentation</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">4</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid4">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkCheckButton" id="auto_indent">
+                <property name="label">Auto indent</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="indent_spaces">
+                <property name="label">Insert spaces instead of tabs</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkGrid" id="grid5">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="column_spacing">4</property>
+                <child>
+                  <object class="GtkLabel" id="label3">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label">Tab width:</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkSpinButton" id="tab_width">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="adjustment">adjustment_tab_width</property>
+                    <property name="value">8</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">0</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkGrid" id="grid6">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="column_spacing">4</property>
+                <child>
+                  <object class="GtkSpinButton" id="indent_width">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="adjustment">adjustment_tab_width</property>
+                    <property name="value">8</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">0</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label4">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label">Indent width:</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">3</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">5</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+  </template>
+</interface>


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