[evince/wip/gpoo/gtk4-preparation: 2/2] shell: Use composite template for EvZoomView




commit 77cb623ec2c0c90d285978c086bccfc44ad1d7bf
Author: Qiu Wenbo <qiuwenbo kylinos com cn>
Date:   Thu Nov 18 09:38:42 2021 +0800

    shell: Use composite template for EvZoomView
    
    * Minimize the changes proposed by Qiu Wenbo for porting to Gtk4

 shell/ev-toolbar.c          |  1 -
 shell/ev-zoom-action.c      | 47 ++++++++++++++++++---------------------------
 shell/evince-zoom-action.ui | 17 ++++++++++++++++
 shell/evince.gresource.xml  |  1 +
 shell/meson.build           |  1 +
 5 files changed, 38 insertions(+), 29 deletions(-)
---
diff --git a/shell/ev-toolbar.c b/shell/ev-toolbar.c
index 75306a76e..e934bad59 100644
--- a/shell/ev-toolbar.c
+++ b/shell/ev-toolbar.c
@@ -253,7 +253,6 @@ ev_toolbar_constructed (GObject *object)
         vbox = ev_zoom_action_new (ev_window_get_document_model (priv->window),
                                    G_MENU (gtk_builder_get_object (builder, "zoom-menu")));
         priv->zoom_action = vbox;
-        gtk_widget_set_tooltip_text (vbox, _("Select or set the zoom level of the document"));
         atk_object_set_name (gtk_widget_get_accessible (vbox), _("Set zoom level"));
         g_signal_connect (vbox, "activated",
                           G_CALLBACK (zoom_selector_activated),
diff --git a/shell/ev-zoom-action.c b/shell/ev-zoom-action.c
index 65c9fa1c3..3c59e1466 100644
--- a/shell/ev-zoom-action.c
+++ b/shell/ev-zoom-action.c
@@ -198,6 +198,7 @@ max_zoom_changed_cb (EvDocumentModel *model,
         ev_zoom_action_populate_free_zoom_section (zoom_action);
 }
 
+
 static void
 entry_activated_cb (GtkEntry     *entry,
                     EvZoomAction *zoom_action)
@@ -260,7 +261,8 @@ get_popup (EvZoomAction *zoom_action)
                 return priv->popup;
 
         priv->popup = GTK_POPOVER (gtk_popover_new_from_model (GTK_WIDGET (zoom_action),
-                                                                            G_MENU_MODEL (priv->menu)));
+                                                               G_MENU_MODEL (priv->menu)));
+
         g_signal_connect (priv->popup, "closed",
                           G_CALLBACK (popup_menu_closed),
                           zoom_action);
@@ -336,17 +338,6 @@ setup_initial_entry_size (EvZoomAction *zoom_action)
         ev_zoom_action_set_width_chars (zoom_action, width);
 }
 
-static void
-ev_zoom_action_get_preferred_width (GtkWidget *widget,
-                                    gint      *minimum_width,
-                                    gint      *natural_width)
-{
-        *minimum_width = *natural_width = 0;
-
-        GTK_WIDGET_CLASS (ev_zoom_action_parent_class)->get_preferred_width (widget, minimum_width, 
natural_width);
-        *natural_width = *minimum_width;
-}
-
 static void
 ev_zoom_action_constructed (GObject *object)
 {
@@ -392,7 +383,11 @@ ev_zoom_action_class_init (EvZoomActionClass *klass)
         object_class->constructed = ev_zoom_action_constructed;
         object_class->set_property = ev_zoom_action_set_property;
 
-        widget_class->get_preferred_width = ev_zoom_action_get_preferred_width;
+        gtk_widget_class_set_template_from_resource (widget_class,
+                        "/org/gnome/evince/ui/zoom-action.ui");
+        gtk_widget_class_bind_template_child_private (widget_class,
+                                                      EvZoomAction,
+                                                      entry);
 
         g_object_class_install_property (object_class,
                                          PROP_DOCUMENT_MODEL,
@@ -403,7 +398,6 @@ ev_zoom_action_class_init (EvZoomActionClass *klass)
                                                               G_PARAM_WRITABLE |
                                                               G_PARAM_CONSTRUCT_ONLY |
                                                               G_PARAM_STATIC_STRINGS));
-
         g_object_class_install_property (object_class,
                                          PROP_MENU,
                                          g_param_spec_object ("menu",
@@ -428,16 +422,7 @@ ev_zoom_action_init (EvZoomAction *zoom_action)
 {
         EvZoomActionPrivate *priv = GET_PRIVATE (zoom_action);
 
-        gtk_orientable_set_orientation (GTK_ORIENTABLE (zoom_action), GTK_ORIENTATION_VERTICAL);
-
-        priv->entry = gtk_entry_new ();
-        gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->entry),
-                                           GTK_ENTRY_ICON_SECONDARY,
-                                           "pan-down-symbolic");
-        gtk_style_context_add_class (gtk_widget_get_style_context (priv->entry), "tnum");
-        gtk_box_pack_start (GTK_BOX (zoom_action), priv->entry, TRUE, FALSE, 0);
-        g_object_set (priv->entry, "xalign", 1.0, NULL);
-        gtk_widget_show (priv->entry);
+        gtk_widget_init_template (GTK_WIDGET (zoom_action));
 
         g_signal_connect (priv->entry, "icon-press",
                           G_CALLBACK (entry_icon_press_callback),
@@ -445,6 +430,7 @@ ev_zoom_action_init (EvZoomAction *zoom_action)
         g_signal_connect (priv->entry, "activate",
                           G_CALLBACK (entry_activated_cb),
                           zoom_action);
+
         g_signal_connect_swapped (priv->entry, "focus-out-event",
                                   G_CALLBACK (focus_out_cb),
                                   zoom_action);
@@ -454,13 +440,18 @@ GtkWidget *
 ev_zoom_action_new (EvDocumentModel *model,
                     GMenu           *menu)
 {
+        GtkWidget *retval;
+
         g_return_val_if_fail (EV_IS_DOCUMENT_MODEL (model), NULL);
         g_return_val_if_fail (G_IS_MENU (menu), NULL);
 
-        return GTK_WIDGET (g_object_new (EV_TYPE_ZOOM_ACTION,
-                                         "document-model", model,
-                                         "menu", menu,
-                                         NULL));
+        retval = GTK_WIDGET (g_object_new (EV_TYPE_ZOOM_ACTION,
+                                           "document-model", model,
+                                           "menu", menu,
+                                           NULL));
+        gtk_widget_show_all (retval);
+
+        return retval;
 }
 
 gboolean
diff --git a/shell/evince-zoom-action.ui b/shell/evince-zoom-action.ui
new file mode 100644
index 000000000..eed1c48f6
--- /dev/null
+++ b/shell/evince-zoom-action.ui
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="EvZoomAction" parent="GtkBox">
+    <property name="orientation">vertical</property>
+    <property name="tooltip-text" translatable="yes">Select or set the zoom level of the document</property>
+    <child>
+      <object class="GtkEntry" id="entry">
+        <style>
+          <class name="tnum" />
+        </style>
+        <property name="secondary-icon-name">pan-down-symbolic</property>
+        <property name="xalign">1.0</property>
+        <property name="max-width-chars">0</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/shell/evince.gresource.xml b/shell/evince.gresource.xml
index 1e29d72ae..3e98fe3cb 100644
--- a/shell/evince.gresource.xml
+++ b/shell/evince.gresource.xml
@@ -22,5 +22,6 @@
     <file alias="ui/thumbnail-frame.png" compressed="true">thumbnail-frame.png</file>
     <file alias="gtk/menus.ui" compressed="true" preprocess="xml-stripblanks">evince-menus.ui</file>
     <file alias="ui/password-view.ui" compressed="true" 
preprocess="xml-stripblanks">evince-password-view.ui</file>
+    <file alias="ui/zoom-action.ui" compressed="true" 
preprocess="xml-stripblanks">evince-zoom-action.ui</file>
   </gresource>
 </gresources>
diff --git a/shell/meson.build b/shell/meson.build
index 18d1a8aaf..bfcbe807c 100644
--- a/shell/meson.build
+++ b/shell/meson.build
@@ -37,6 +37,7 @@ resource_data = files(
   '../data/thumbnail-frame.png',
   'evince-menus.ui',
   'evince-password-view.ui',
+  'evince-zoom-action.ui',
   'help-overlay.ui',
 )
 


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