[libadwaita/wip/exalm/demo-cleanups: 8/21] demo: Split view switcher page into a separate class




commit 324754d7e60e41c38a0076fc3c65618cd9a8eabb
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Thu Dec 9 16:24:03 2021 +0500

    demo: Split view switcher page into a separate class

 demo/adw-demo-window.c                             | 14 ++------
 demo/adw-demo-window.ui                            | 17 +---------
 demo/adwaita-demo.gresources.xml                   |  3 +-
 demo/meson.build                                   |  3 +-
 .../view-switcher/adw-demo-page-view-switcher.c    | 38 ++++++++++++++++++++++
 .../view-switcher/adw-demo-page-view-switcher.h    | 11 +++++++
 .../view-switcher/adw-demo-page-view-switcher.ui   | 24 ++++++++++++++
 .../view-switcher}/adw-view-switcher-demo-window.c |  2 +-
 .../view-switcher}/adw-view-switcher-demo-window.h |  0
 .../adw-view-switcher-demo-window.ui               |  0
 10 files changed, 81 insertions(+), 31 deletions(-)
---
diff --git a/demo/adw-demo-window.c b/demo/adw-demo-window.c
index cecc194b..eb4fbeeb 100644
--- a/demo/adw-demo-window.c
+++ b/demo/adw-demo-window.c
@@ -4,11 +4,11 @@
 #include "pages/clamp/adw-demo-page-clamp.h"
 #include "pages/leaflet/adw-demo-page-leaflet.h"
 #include "pages/lists/adw-demo-page-lists.h"
+#include "pages/view-switcher/adw-demo-page-view-switcher.h"
 #include "pages/welcome/adw-demo-page-welcome.h"
 #include "adw-flap-demo-window.h"
 #include "adw-style-demo-window.h"
 #include "adw-tab-view-demo-window.h"
-#include "adw-view-switcher-demo-window.h"
 
 struct _AdwDemoWindow
 {
@@ -163,16 +163,6 @@ leaflet_next_page_cb (AdwDemoWindow *self)
   adw_leaflet_navigate (self->subpage_leaflet, ADW_NAVIGATION_DIRECTION_FORWARD);
 }
 
-static void
-view_switcher_demo_clicked_cb (GtkButton     *btn,
-                               AdwDemoWindow *self)
-{
-  AdwViewSwitcherDemoWindow *window = adw_view_switcher_demo_window_new ();
-
-  gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (self));
-  gtk_window_present (GTK_WINDOW (window));
-}
-
 static char *
 carousel_orientation_name (AdwEnumListItem *item,
                            gpointer         user_data)
@@ -791,7 +781,6 @@ adw_demo_window_class_init (AdwDemoWindowClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, leaflet_next_page_cb);
   gtk_widget_class_bind_template_callback (widget_class, get_color_scheme_icon_name);
   gtk_widget_class_bind_template_callback (widget_class, color_scheme_button_clicked_cb);
-  gtk_widget_class_bind_template_callback (widget_class, view_switcher_demo_clicked_cb);
   gtk_widget_class_bind_template_callback (widget_class, notify_carousel_orientation_cb);
   gtk_widget_class_bind_template_callback (widget_class, notify_carousel_indicators_cb);
   gtk_widget_class_bind_template_callback (widget_class, carousel_indicators_name);
@@ -926,6 +915,7 @@ adw_demo_window_init (AdwDemoWindow *self)
   g_type_ensure (ADW_TYPE_DEMO_PAGE_CLAMP);
   g_type_ensure (ADW_TYPE_DEMO_PAGE_LEAFLET);
   g_type_ensure (ADW_TYPE_DEMO_PAGE_LISTS);
+  g_type_ensure (ADW_TYPE_DEMO_PAGE_VIEW_SWITCHER);
   g_type_ensure (ADW_TYPE_DEMO_PAGE_WELCOME);
 
   gtk_widget_init_template (GTK_WIDGET (self));
diff --git a/demo/adw-demo-window.ui b/demo/adw-demo-window.ui
index 30103f8f..786de7bd 100644
--- a/demo/adw-demo-window.ui
+++ b/demo/adw-demo-window.ui
@@ -157,24 +157,9 @@
                         </child>
                         <child>
                           <object class="GtkStackPage">
-                            <property name="name">view-switcher</property>
                             <property name="title" translatable="yes">View Switcher</property>
                             <property name="child">
-                              <object class="AdwStatusPage">
-                                <property name="icon-name">widget-view-switcher-symbolic</property>
-                                <property name="title" translatable="yes">View Switcher</property>
-                                <property name="description" translatable="yes">Widgets to switch the 
window's view.</property>
-                                <child>
-                                  <object class="GtkButton">
-                                    <property name="label" translatable="yes">Run the Demo</property>
-                                    <property name="halign">center</property>
-                                    <signal name="clicked" handler="view_switcher_demo_clicked_cb" 
swapped="no"/>
-                                    <style>
-                                      <class name="pill"/>
-                                    </style>
-                                  </object>
-                                </child>
-                              </object>
+                              <object class="AdwDemoPageViewSwitcher"/>
                             </property>
                           </object>
                         </child>
diff --git a/demo/adwaita-demo.gresources.xml b/demo/adwaita-demo.gresources.xml
index d73e1f1c..8cdbd16c 100644
--- a/demo/adwaita-demo.gresources.xml
+++ b/demo/adwaita-demo.gresources.xml
@@ -44,12 +44,13 @@
     <file preprocess="xml-stripblanks">pages/clamp/adw-demo-page-clamp.ui</file>
     <file preprocess="xml-stripblanks">pages/leaflet/adw-demo-page-leaflet.ui</file>
     <file preprocess="xml-stripblanks">pages/lists/adw-demo-page-lists.ui</file>
+    <file preprocess="xml-stripblanks">pages/view-switcher/adw-demo-page-view-switcher.ui</file>
+    <file preprocess="xml-stripblanks">pages/view-switcher/adw-view-switcher-demo-window.ui</file>
     <file preprocess="xml-stripblanks">pages/welcome/adw-demo-page-welcome.ui</file>
     <file preprocess="xml-stripblanks">adw-demo-preferences-window.ui</file>
     <file preprocess="xml-stripblanks">adw-demo-window.ui</file>
     <file preprocess="xml-stripblanks">adw-flap-demo-window.ui</file>
     <file preprocess="xml-stripblanks">adw-style-demo-window.ui</file>
     <file preprocess="xml-stripblanks">adw-tab-view-demo-window.ui</file>
-    <file preprocess="xml-stripblanks">adw-view-switcher-demo-window.ui</file>
   </gresource>
 </gresources>
diff --git a/demo/meson.build b/demo/meson.build
index 659c3f38..3d51fbfe 100644
--- a/demo/meson.build
+++ b/demo/meson.build
@@ -15,6 +15,8 @@ adwaita_demo_sources = [
   'pages/clamp/adw-demo-page-clamp.c',
   'pages/leaflet/adw-demo-page-leaflet.c',
   'pages/lists/adw-demo-page-lists.c',
+  'pages/view-switcher/adw-demo-page-view-switcher.c',
+  'pages/view-switcher/adw-view-switcher-demo-window.c',
   'pages/welcome/adw-demo-page-welcome.c',
 
   'adwaita-demo.c',
@@ -23,7 +25,6 @@ adwaita_demo_sources = [
   'adw-flap-demo-window.c',
   'adw-style-demo-window.c',
   'adw-tab-view-demo-window.c',
-  'adw-view-switcher-demo-window.c',
   libadwaita_generated_headers,
 ]
 
diff --git a/demo/pages/view-switcher/adw-demo-page-view-switcher.c 
b/demo/pages/view-switcher/adw-demo-page-view-switcher.c
new file mode 100644
index 00000000..1e15e8e2
--- /dev/null
+++ b/demo/pages/view-switcher/adw-demo-page-view-switcher.c
@@ -0,0 +1,38 @@
+#include "adw-demo-page-view-switcher.h"
+
+#include <glib/gi18n.h>
+
+#include "adw-view-switcher-demo-window.h"
+
+struct _AdwDemoPageViewSwitcher
+{
+  AdwBin parent_instance;
+};
+
+G_DEFINE_TYPE (AdwDemoPageViewSwitcher, adw_demo_page_view_switcher, ADW_TYPE_BIN)
+
+static void
+demo_run_cb (AdwDemoPageViewSwitcher *self)
+{
+  AdwViewSwitcherDemoWindow *window = adw_view_switcher_demo_window_new ();
+  GtkRoot *root = gtk_widget_get_root (GTK_WIDGET (self));
+
+  gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (root));
+  gtk_window_present (GTK_WINDOW (window));
+}
+
+static void
+adw_demo_page_view_switcher_class_init (AdwDemoPageViewSwitcherClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Adwaita1/Demo/ui/pages/view-switcher/adw-demo-page-view-switcher.ui");
+
+  gtk_widget_class_install_action (widget_class, "demo.run", NULL, (GtkWidgetActionActivateFunc) 
demo_run_cb);
+}
+
+static void
+adw_demo_page_view_switcher_init (AdwDemoPageViewSwitcher *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/demo/pages/view-switcher/adw-demo-page-view-switcher.h 
b/demo/pages/view-switcher/adw-demo-page-view-switcher.h
new file mode 100644
index 00000000..1660e99c
--- /dev/null
+++ b/demo/pages/view-switcher/adw-demo-page-view-switcher.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include <adwaita.h>
+
+G_BEGIN_DECLS
+
+#define ADW_TYPE_DEMO_PAGE_VIEW_SWITCHER (adw_demo_page_view_switcher_get_type())
+
+G_DECLARE_FINAL_TYPE (AdwDemoPageViewSwitcher, adw_demo_page_view_switcher, ADW, DEMO_PAGE_VIEW_SWITCHER, 
AdwBin)
+
+G_END_DECLS
diff --git a/demo/pages/view-switcher/adw-demo-page-view-switcher.ui 
b/demo/pages/view-switcher/adw-demo-page-view-switcher.ui
new file mode 100644
index 00000000..0721d51d
--- /dev/null
+++ b/demo/pages/view-switcher/adw-demo-page-view-switcher.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk" version="4.0"/>
+  <requires lib="libadwaita" version="1.0"/>
+  <template class="AdwDemoPageViewSwitcher" parent="AdwBin">
+    <property name="child">
+      <object class="AdwStatusPage">
+        <property name="icon-name">widget-view-switcher-symbolic</property>
+        <property name="title" translatable="yes">View Switcher</property>
+        <property name="description" translatable="yes">Widgets to switch the window's view.</property>
+        <child>
+          <object class="GtkButton">
+            <property name="label" translatable="yes">Run the Demo</property>
+            <property name="halign">center</property>
+            <property name="action-name">demo.run</property>
+            <style>
+              <class name="pill"/>
+            </style>
+          </object>
+        </child>
+      </object>
+    </property>
+  </template>
+</interface>
diff --git a/demo/adw-view-switcher-demo-window.c b/demo/pages/view-switcher/adw-view-switcher-demo-window.c
similarity index 89%
rename from demo/adw-view-switcher-demo-window.c
rename to demo/pages/view-switcher/adw-view-switcher-demo-window.c
index 9637d52e..1832647e 100644
--- a/demo/adw-view-switcher-demo-window.c
+++ b/demo/pages/view-switcher/adw-view-switcher-demo-window.c
@@ -14,7 +14,7 @@ adw_view_switcher_demo_window_class_init (AdwViewSwitcherDemoWindowClass *klass)
 {
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
-  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Adwaita1/Demo/ui/adw-view-switcher-demo-window.ui");
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Adwaita1/Demo/ui/pages/view-switcher/adw-view-switcher-demo-window.ui");
 }
 
 static void
diff --git a/demo/adw-view-switcher-demo-window.h b/demo/pages/view-switcher/adw-view-switcher-demo-window.h
similarity index 100%
rename from demo/adw-view-switcher-demo-window.h
rename to demo/pages/view-switcher/adw-view-switcher-demo-window.h
diff --git a/demo/adw-view-switcher-demo-window.ui b/demo/pages/view-switcher/adw-view-switcher-demo-window.ui
similarity index 100%
rename from demo/adw-view-switcher-demo-window.ui
rename to demo/pages/view-switcher/adw-view-switcher-demo-window.ui


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