[gtk/emoji-grid: 133/136] gtk-demo: Add a sectioned view to the filebrowser demo




commit 87da22192da9677eb189334d42d9ff4fa768e003
Author: Benjamin Otte <otte redhat com>
Date:   Sat Feb 26 02:18:34 2022 +0100

    gtk-demo: Add a sectioned view to the filebrowser demo

 demos/gtk-demo/listview_filebrowser.c  | 62 +++++++++++++++++------
 demos/gtk-demo/listview_filebrowser.ui | 90 +++++++++++++++++++++++++++++++++-
 2 files changed, 135 insertions(+), 17 deletions(-)
---
diff --git a/demos/gtk-demo/listview_filebrowser.c b/demos/gtk-demo/listview_filebrowser.c
index e73ad41a0d..ce19060bbe 100644
--- a/demos/gtk-demo/listview_filebrowser.c
+++ b/demos/gtk-demo/listview_filebrowser.c
@@ -18,6 +18,8 @@ struct _FileBrowserView
   GObject parent_instance;
 
   GtkListItemFactory *factory;
+  GtkListItemFactory *section_factory;
+  GtkSorter *section_sorter;
   char *icon_name;
   char *title;
   GtkOrientation orientation;
@@ -27,8 +29,10 @@ enum {
   PROP_0,
   PROP_FACTORY,
   PROP_ICON_NAME,
-  PROP_TITLE,
   PROP_ORIENTATION,
+  PROP_SECTION_FACTORY,
+  PROP_SECTION_SORTER,
+  PROP_TITLE,
 
   N_PROPS
 };
@@ -58,14 +62,22 @@ file_browser_view_get_property (GObject    *object,
       g_value_set_string (value, self->icon_name);
       break;
 
-    case PROP_TITLE:
-      g_value_set_string (value, self->title);
-      break;
-
     case PROP_ORIENTATION:
       g_value_set_enum (value, self->orientation);
       break;
 
+    case PROP_SECTION_FACTORY:
+      g_value_set_object (value, self->section_factory);
+      break;
+
+    case PROP_SECTION_SORTER:
+      g_value_set_object (value, self->section_sorter);
+      break;
+
+    case PROP_TITLE:
+      g_value_set_string (value, self->title);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -91,15 +103,23 @@ file_browser_view_set_property (GObject      *object,
       self->icon_name = g_value_dup_string (value);
       break;
 
+    case PROP_ORIENTATION:
+      self->orientation = g_value_get_enum (value);
+      break;
+
+    case PROP_SECTION_FACTORY:
+      g_set_object (&self->section_factory, g_value_get_object (value));
+      break;
+
+    case PROP_SECTION_SORTER:
+      g_set_object (&self->section_sorter, g_value_get_object (value));
+      break;
+
     case PROP_TITLE:
       g_free (self->title);
       self->title = g_value_dup_string (value);
       break;
 
-    case PROP_ORIENTATION:
-      self->orientation = g_value_get_enum (value);
-      break;
-
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -139,12 +159,6 @@ file_browser_view_class_init (FileBrowserViewClass *klass)
                          "icon to display for selecting this view",
                          NULL,
                          G_PARAM_READWRITE);
-  properties[PROP_TITLE] =
-    g_param_spec_string ("title",
-                         "title",
-                         "title to display for selecting this view",
-                         NULL,
-                         G_PARAM_READWRITE);
   properties[PROP_ORIENTATION] =
     g_param_spec_enum ("orientation",
                        "orientation",
@@ -152,6 +166,24 @@ file_browser_view_class_init (FileBrowserViewClass *klass)
                        GTK_TYPE_ORIENTATION,
                        GTK_ORIENTATION_VERTICAL,
                        G_PARAM_READWRITE);
+  properties[PROP_SECTION_FACTORY] =
+    g_param_spec_object ("section-factory",
+                         "section factory",
+                         "factory to use for sections or NULL",
+                         GTK_TYPE_LIST_ITEM_FACTORY,
+                         G_PARAM_READWRITE);
+  properties[PROP_SECTION_SORTER] =
+    g_param_spec_object ("section-sorter",
+                         "section sorter",
+                         "sorter to split files into sections or NULL",
+                         GTK_TYPE_SORTER,
+                         G_PARAM_READWRITE);
+  properties[PROP_TITLE] =
+    g_param_spec_string ("title",
+                         "title",
+                         "title to display for selecting this view",
+                         NULL,
+                         G_PARAM_READWRITE);
 
   g_object_class_install_properties (gobject_class, N_PROPS, properties);
 }
diff --git a/demos/gtk-demo/listview_filebrowser.ui b/demos/gtk-demo/listview_filebrowser.ui
index 3fe307d702..ec3bf1e15a 100644
--- a/demos/gtk-demo/listview_filebrowser.ui
+++ b/demos/gtk-demo/listview_filebrowser.ui
@@ -91,6 +91,78 @@
         <property name="orientation">vertical</property>
       </object>
     </child>
+    <child>
+      <object class="FileBrowserView">
+        <property name="factory">
+          <object class="GtkBuilderListItemFactory">
+            <property name="bytes"><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GtkListItem">
+    <property name="child">
+      <object class="GtkBox">
+        <child>
+          <object class="GtkImage">
+            <binding name="gicon">
+              <closure type="GIcon" function="filebrowser_get_icon">
+                <lookup name="item">GtkListItem</lookup>
+              </closure>
+            </binding>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="halign">start</property>
+            <property name="hexpand">true</property>
+            <property name="width-chars">30</property>
+            <property name="ellipsize">middle</property>
+            <binding name="label">
+              <closure type="gchararray" function="filebrowser_get_display_name">
+                <lookup name="item">GtkListItem</lookup>
+              </closure>
+            </binding>
+          </object>
+        </child>
+      </object>
+    </property>
+  </template>
+</interface>
+            ]]></property>
+          </object>
+        </property>
+        <property name="section-factory">
+          <object class="GtkBuilderListItemFactory">
+            <property name="bytes"><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GtkListItem">
+    <property name="child">
+      <object class="GtkLabel">
+        <property name="xalign">0</property>
+        <binding name="label">
+          <closure type="gchararray" function="filebrowser_get_content_type">
+            <lookup name="item">GtkListItem</lookup>
+          </closure>
+        </binding>
+      </object>
+    </property>
+  </template>
+</interface>
+            ]]></property>
+          </object>
+        </property>
+        <property name="section-sorter">
+          <object class="GtkStringSorter">
+            <property name="expression">
+              <closure type="gchararray" function="filebrowser_get_content_type" swapped="true" />
+            </property>
+          </object>
+        </property>
+        <property name="icon-name">view-continuous-symbolic</property>
+        <property name="title" translatable="yes">Sections</property>
+        <property name="orientation">vertical</property>
+      </object>
+    </child>
     <child>
       <object class="FileBrowserView">
         <property name="icon-name">view-paged-symbolic</property>
@@ -167,8 +239,17 @@
   </object>
   <object class="GtkSingleSelection" id="selection_model">
     <property name="model">
-      <object class="GtkDirectoryList" id="dirlist">
-        <property 
name="attributes">standard::name,standard::display-name,standard::icon,standard::size,standard::content-type</property>
+      <object class="GtkSortListModel">
+        <binding name="section-sorter">
+          <lookup name="section-sorter" type="FileBrowserView">
+            <lookup name="selected-item">selected-view</lookup>
+          </lookup>
+        </binding>
+        <property name="model">
+          <object class="GtkDirectoryList" id="dirlist">
+            <property 
name="attributes">standard::name,standard::display-name,standard::icon,standard::size,standard::content-type</property>
+          </object>
+        </property>
       </object>
     </property>
   </object>
@@ -238,6 +319,11 @@
                 <lookup name="selected-item">selected-view</lookup>
               </lookup>
             </binding>
+            <binding name="section-factory">
+              <lookup name="section-factory" type="FileBrowserView">
+                <lookup name="selected-item">selected-view</lookup>
+              </lookup>
+            </binding>
             <binding name="orientation">
               <lookup name="orientation" type="FileBrowserView">
                 <lookup name="selected-item">selected-view</lookup>


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