[evince/wip/gpoo/gtk4-preparation-ev-progress-message-area: 2/2] shell: Use composite template for the progress message area




commit 5f629a76f315b7d1c8741160be4eeca1584b8780
Author: Germán Poo-Caamaño <gpoo gnome org>
Date:   Sat Mar 26 00:17:39 2022 -0300

    shell: Use composite template for the progress message area
    
    Co-authored-by: Qiu Wenbo <qiuwenbo kylinos com cn>

 shell/ev-progress-message-area.c      | 32 +++++++-------------------------
 shell/evince-progress-message-area.ui | 28 ++++++++++++++++++++++++++++
 shell/evince.gresource.xml            |  1 +
 shell/meson.build                     |  1 +
 4 files changed, 37 insertions(+), 25 deletions(-)
---
diff --git a/shell/ev-progress-message-area.c b/shell/ev-progress-message-area.c
index 16cfa48a0..fd7b7aa2e 100644
--- a/shell/ev-progress-message-area.c
+++ b/shell/ev-progress-message-area.c
@@ -52,10 +52,15 @@ static void
 ev_progress_message_area_class_init (EvProgressMessageAreaClass *class)
 {
        GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
 
        gobject_class->set_property = ev_progress_message_area_set_property;
        gobject_class->get_property = ev_progress_message_area_get_property;
 
+       gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/evince/ui/progress-message-area.ui");
+       gtk_widget_class_bind_template_child_private (widget_class, EvProgressMessageArea, label);
+       gtk_widget_class_bind_template_child_private (widget_class, EvProgressMessageArea, progress_bar);
+
        g_object_class_install_property (gobject_class,
                                         PROP_STATUS,
                                         g_param_spec_string ("status",
@@ -77,31 +82,7 @@ ev_progress_message_area_class_init (EvProgressMessageAreaClass *class)
 static void
 ev_progress_message_area_init (EvProgressMessageArea *area)
 {
-       GtkWidget *contents;
-       GtkWidget *vbox;
-       EvProgressMessageAreaPrivate *priv;
-
-       priv = ev_progress_message_area_get_instance_private (area);
-
-       contents = _ev_message_area_get_main_box (EV_MESSAGE_AREA (area));
-       
-       vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-       
-       priv->label = gtk_label_new (NULL);
-       gtk_label_set_use_markup (GTK_LABEL (priv->label), TRUE);
-       gtk_label_set_ellipsize (GTK_LABEL (priv->label),
-                                PANGO_ELLIPSIZE_END);
-       g_object_set (G_OBJECT (priv->label), "xalign", 0., "yalign", 0.5, NULL);
-       gtk_box_pack_start (GTK_BOX (vbox), priv->label, TRUE, TRUE, 0);
-       gtk_widget_show (priv->label);
-
-       priv->progress_bar = gtk_progress_bar_new ();
-       gtk_widget_set_size_request (priv->progress_bar, -1, 15);
-       gtk_box_pack_start (GTK_BOX (vbox), priv->progress_bar, TRUE, FALSE, 0);
-       gtk_widget_show (priv->progress_bar);
-
-       gtk_box_pack_start (GTK_BOX (contents), vbox, TRUE, TRUE, 0);
-       gtk_widget_show (vbox);
+       gtk_widget_init_template (GTK_WIDGET (area));
 }
 
 static void
@@ -163,6 +144,7 @@ ev_progress_message_area_new (const gchar *icon_name,
                               "message-type", GTK_MESSAGE_OTHER,
                               "text", text,
                               NULL);
+
        if (first_button_text) {
                va_list args;
 
diff --git a/shell/evince-progress-message-area.ui b/shell/evince-progress-message-area.ui
new file mode 100644
index 000000000..211b5d1c6
--- /dev/null
+++ b/shell/evince-progress-message-area.ui
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="EvProgressMessageArea" parent="EvMessageArea">
+    <child internal-child="main_box">
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkLabel" id="label">
+            <property name="use-markup">True</property>
+            <property name="ellipsize">3</property>
+            <property name="xalign">0.0</property>
+            <property name="yalign">0.5</property>
+            <property name="valign">fill</property>
+            <property name="vexpand">False</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkProgressBar" id="progress_bar">
+            <property name="width-request">-1</property>
+            <property name="height-request">15</property>
+            <property name="vexpand">False</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/shell/evince.gresource.xml b/shell/evince.gresource.xml
index d8eb58deb..f0ec07af8 100644
--- a/shell/evince.gresource.xml
+++ b/shell/evince.gresource.xml
@@ -23,6 +23,7 @@
     <file alias="gtk/menus.ui" compressed="true" preprocess="xml-stripblanks">evince-menus.ui</file>
     <file alias="ui/message-area.ui" compressed="true" 
preprocess="xml-stripblanks">evince-message-area.ui</file>
     <file alias="ui/password-view.ui" compressed="true" 
preprocess="xml-stripblanks">evince-password-view.ui</file>
+    <file alias="ui/progress-message-area.ui" compressed="true" 
preprocess="xml-stripblanks">evince-progress-message-area.ui</file>
     <file alias="ui/properties-fonts.ui" compressed="true" 
preprocess="xml-stripblanks">evince-properties-fonts.ui</file>
     <file alias="ui/zoom-action.ui" compressed="true" 
preprocess="xml-stripblanks">evince-zoom-action.ui</file>
   </gresource>
diff --git a/shell/meson.build b/shell/meson.build
index f25793f1d..06a7a53b3 100644
--- a/shell/meson.build
+++ b/shell/meson.build
@@ -39,6 +39,7 @@ resource_data = files(
   'evince-message-area.ui',
   'evince-password-view.ui',
   'evince-properties-fonts.ui',
+  'evince-progress-message-area.ui',
   'evince-zoom-action.ui',
   'help-overlay.ui',
 )


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