[libadwaita/wip/exalm/demo-cleanups: 11/20] demo: Split tab view page into a separate class




commit ffdc77708be670fdd3e228c7129b75e35b5dc877
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Thu Dec 9 18:24:41 2021 +0500

    demo: Split tab view page into a separate class

 demo/adw-demo-window.c                             | 15 ++------
 demo/adw-demo-window.ui                            | 17 +--------
 demo/adwaita-demo.gresources.xml                   |  3 +-
 demo/meson.build                                   |  3 +-
 demo/pages/tab-view/adw-demo-page-tab-view.c       | 40 ++++++++++++++++++++++
 demo/pages/tab-view/adw-demo-page-tab-view.h       | 11 ++++++
 demo/pages/tab-view/adw-demo-page-tab-view.ui      | 24 +++++++++++++
 .../tab-view}/adw-tab-view-demo-window.c           |  2 +-
 .../tab-view}/adw-tab-view-demo-window.h           |  0
 .../tab-view}/adw-tab-view-demo-window.ui          |  0
 10 files changed, 83 insertions(+), 32 deletions(-)
---
diff --git a/demo/adw-demo-window.c b/demo/adw-demo-window.c
index 6d6604db..71e38d48 100644
--- a/demo/adw-demo-window.c
+++ b/demo/adw-demo-window.c
@@ -7,10 +7,10 @@
 #include "pages/flap/adw-demo-page-flap.h"
 #include "pages/leaflet/adw-demo-page-leaflet.h"
 #include "pages/lists/adw-demo-page-lists.h"
+#include "pages/tab-view/adw-demo-page-tab-view.h"
 #include "pages/view-switcher/adw-demo-page-view-switcher.h"
 #include "pages/welcome/adw-demo-page-welcome.h"
 #include "adw-style-demo-window.h"
-#include "adw-tab-view-demo-window.h"
 
 struct _AdwDemoWindow
 {
@@ -162,17 +162,6 @@ adw_demo_window_new (GtkApplication *application)
   return g_object_new (ADW_TYPE_DEMO_WINDOW, "application", application, NULL);
 }
 
-static void
-tab_view_demo_clicked_cb (GtkButton     *btn,
-                          AdwDemoWindow *self)
-{
-  AdwTabViewDemoWindow *window = adw_tab_view_demo_window_new ();
-
-  adw_tab_view_demo_window_prepopulate (window);
-
-  gtk_window_present (GTK_WINDOW (window));
-}
-
 static AdwAnimation *
 get_current_animation (AdwDemoWindow *self)
 {
@@ -523,7 +512,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, tab_view_demo_clicked_cb);
   gtk_widget_class_bind_template_callback (widget_class, style_classes_demo_clicked_cb);
   gtk_widget_class_bind_template_callback (widget_class, add_toast_cb);
   gtk_widget_class_bind_template_callback (widget_class, add_toast_with_button_cb);
@@ -627,6 +615,7 @@ adw_demo_window_init (AdwDemoWindow *self)
   g_type_ensure (ADW_TYPE_DEMO_PAGE_FLAP);
   g_type_ensure (ADW_TYPE_DEMO_PAGE_LEAFLET);
   g_type_ensure (ADW_TYPE_DEMO_PAGE_LISTS);
+  g_type_ensure (ADW_TYPE_DEMO_PAGE_TAB_VIEW);
   g_type_ensure (ADW_TYPE_DEMO_PAGE_VIEW_SWITCHER);
   g_type_ensure (ADW_TYPE_DEMO_PAGE_WELCOME);
 
diff --git a/demo/adw-demo-window.ui b/demo/adw-demo-window.ui
index 74df32e3..6851e3df 100644
--- a/demo/adw-demo-window.ui
+++ b/demo/adw-demo-window.ui
@@ -189,24 +189,9 @@
                         </child>
                         <child>
                           <object class="GtkStackPage">
-                            <property name="name">tab-view</property>
                             <property name="title" translatable="yes">Tab View</property>
                             <property name="child">
-                              <object class="AdwStatusPage">
-                                <property name="icon-name">widget-tab-view-symbolic</property>
-                                <property name="title" translatable="yes">Tab View</property>
-                                <property name="description" translatable="yes">A modern tab 
widget.</property>
-                                <property name="child">
-                                  <object class="GtkButton">
-                                    <property name="label" translatable="yes">Run the Demo</property>
-                                    <property name="halign">center</property>
-                                    <signal name="clicked" handler="tab_view_demo_clicked_cb" swapped="no"/>
-                                    <style>
-                                      <class name="pill"/>
-                                    </style>
-                                  </object>
-                                </property>
-                              </object>
+                              <object class="AdwDemoPageTabView"/>
                             </property>
                           </object>
                         </child>
diff --git a/demo/adwaita-demo.gresources.xml b/demo/adwaita-demo.gresources.xml
index 6450b442..ebce2f10 100644
--- a/demo/adwaita-demo.gresources.xml
+++ b/demo/adwaita-demo.gresources.xml
@@ -48,12 +48,13 @@
     <file preprocess="xml-stripblanks">pages/flap/adw-flap-demo-window.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/tab-view/adw-demo-page-tab-view.ui</file>
+    <file preprocess="xml-stripblanks">pages/tab-view/adw-tab-view-demo-window.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-style-demo-window.ui</file>
-    <file preprocess="xml-stripblanks">adw-tab-view-demo-window.ui</file>
   </gresource>
 </gresources>
diff --git a/demo/meson.build b/demo/meson.build
index 3f6e1bcd..e4901611 100644
--- a/demo/meson.build
+++ b/demo/meson.build
@@ -19,6 +19,8 @@ adwaita_demo_sources = [
   'pages/flap/adw-flap-demo-window.c',
   'pages/leaflet/adw-demo-page-leaflet.c',
   'pages/lists/adw-demo-page-lists.c',
+  'pages/tab-view/adw-demo-page-tab-view.c',
+  'pages/tab-view/adw-tab-view-demo-window.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',
@@ -27,7 +29,6 @@ adwaita_demo_sources = [
   'adw-demo-preferences-window.c',
   'adw-demo-window.c',
   'adw-style-demo-window.c',
-  'adw-tab-view-demo-window.c',
   libadwaita_generated_headers,
 ]
 
diff --git a/demo/pages/tab-view/adw-demo-page-tab-view.c b/demo/pages/tab-view/adw-demo-page-tab-view.c
new file mode 100644
index 00000000..7778f750
--- /dev/null
+++ b/demo/pages/tab-view/adw-demo-page-tab-view.c
@@ -0,0 +1,40 @@
+#include "adw-demo-page-tab-view.h"
+
+#include <glib/gi18n.h>
+
+#include "adw-tab-view-demo-window.h"
+
+struct _AdwDemoPageTabView
+{
+  AdwBin parent_instance;
+};
+
+G_DEFINE_TYPE (AdwDemoPageTabView, adw_demo_page_tab_view, ADW_TYPE_BIN)
+
+static void
+demo_run_cb (AdwDemoPageTabView *self)
+{
+  AdwTabViewDemoWindow *window = adw_tab_view_demo_window_new ();
+  GtkRoot *root = gtk_widget_get_root (GTK_WIDGET (self));
+
+  adw_tab_view_demo_window_prepopulate (window);
+
+  gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (root));
+  gtk_window_present (GTK_WINDOW (window));
+}
+
+static void
+adw_demo_page_tab_view_class_init (AdwDemoPageTabViewClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Adwaita1/Demo/ui/pages/tab-view/adw-demo-page-tab-view.ui");
+
+  gtk_widget_class_install_action (widget_class, "demo.run", NULL, (GtkWidgetActionActivateFunc) 
demo_run_cb);
+}
+
+static void
+adw_demo_page_tab_view_init (AdwDemoPageTabView *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/demo/pages/tab-view/adw-demo-page-tab-view.h b/demo/pages/tab-view/adw-demo-page-tab-view.h
new file mode 100644
index 00000000..965de020
--- /dev/null
+++ b/demo/pages/tab-view/adw-demo-page-tab-view.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include <adwaita.h>
+
+G_BEGIN_DECLS
+
+#define ADW_TYPE_DEMO_PAGE_TAB_VIEW (adw_demo_page_tab_view_get_type())
+
+G_DECLARE_FINAL_TYPE (AdwDemoPageTabView, adw_demo_page_tab_view, ADW, DEMO_PAGE_TAB_VIEW, AdwBin)
+
+G_END_DECLS
diff --git a/demo/pages/tab-view/adw-demo-page-tab-view.ui b/demo/pages/tab-view/adw-demo-page-tab-view.ui
new file mode 100644
index 00000000..7304dda0
--- /dev/null
+++ b/demo/pages/tab-view/adw-demo-page-tab-view.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="AdwDemoPageTabView" parent="AdwBin">
+    <property name="child">
+      <object class="AdwStatusPage">
+        <property name="icon-name">widget-tab-view-symbolic</property>
+        <property name="title" translatable="yes">Tab View</property>
+        <property name="description" translatable="yes">A modern tab widget.</property>
+        <property name="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>
+        </property>
+      </object>
+    </property>
+  </template>
+</interface>
diff --git a/demo/adw-tab-view-demo-window.c b/demo/pages/tab-view/adw-tab-view-demo-window.c
similarity index 99%
rename from demo/adw-tab-view-demo-window.c
rename to demo/pages/tab-view/adw-tab-view-demo-window.c
index 3830a114..cda44c92 100644
--- a/demo/adw-tab-view-demo-window.c
+++ b/demo/pages/tab-view/adw-tab-view-demo-window.c
@@ -479,7 +479,7 @@ adw_tab_view_demo_window_class_init (AdwTabViewDemoWindowClass *klass)
 
   object_class->dispose = adw_tab_view_demo_window_dispose;
 
-  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Adwaita1/Demo/ui/adw-tab-view-demo-window.ui");
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Adwaita1/Demo/ui/pages/tab-view/adw-tab-view-demo-window.ui");
   gtk_widget_class_bind_template_child (widget_class, AdwTabViewDemoWindow, view);
   gtk_widget_class_bind_template_child (widget_class, AdwTabViewDemoWindow, tab_bar);
   gtk_widget_class_bind_template_callback (widget_class, page_detached_cb);
diff --git a/demo/adw-tab-view-demo-window.h b/demo/pages/tab-view/adw-tab-view-demo-window.h
similarity index 100%
rename from demo/adw-tab-view-demo-window.h
rename to demo/pages/tab-view/adw-tab-view-demo-window.h
diff --git a/demo/adw-tab-view-demo-window.ui b/demo/pages/tab-view/adw-tab-view-demo-window.ui
similarity index 100%
rename from demo/adw-tab-view-demo-window.ui
rename to demo/pages/tab-view/adw-tab-view-demo-window.ui


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