[gnome-dictionary/wip/ui-redesign: 2/4] app: Use widget templates and a header bar



commit dea54b1fd5c4bc606f137bac3a72e3fb67bb8b0f
Author: Juan R. GarcĂ­a Blanco <juanrgar gmail com>
Date:   Thu Apr 2 17:04:12 2015 +0200

    app: Use widget templates and a header bar
    
    Migrate to current GNOME applications style: use a template widget
    for GdictWindow, add a header bar and a menu button.
    See https://bugzilla.gnome.org/show_bug.cgi?id=334866

 src/gdict-app-window.ui |   39 +++++++++++++++++++++++++++++++++++++++
 src/gdict-app.c         |    2 --
 src/gdict-window.c      |   39 ++++++++++++++++++++-------------------
 src/gdict-window.h      |    1 +
 src/gdict.gresource.xml |    1 +
 5 files changed, 61 insertions(+), 21 deletions(-)
---
diff --git a/src/gdict-app-window.ui b/src/gdict-app-window.ui
new file mode 100644
index 0000000..382fa76
--- /dev/null
+++ b/src/gdict-app-window.ui
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <template class="GdictWindow" parent="GtkApplicationWindow">
+    <property name="can_focus">False</property>
+    <property name="show_menubar">False</property>
+    <child>
+      <object class="GtkBox" id="main_box">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
+    <child type="titlebar">
+      <object class="GtkHeaderBar" id="header_bar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="show_close_button">True</property>
+        <child>
+          <placeholder/>
+        </child>
+        <child type="title">
+          <object class="GtkEntry" id="entry">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="max_width_chars">3</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/gdict-app.c b/src/gdict-app.c
index 89f4659..2484e67 100644
--- a/src/gdict-app.c
+++ b/src/gdict-app.c
@@ -331,8 +331,6 @@ gdict_app_startup (GApplication *application)
 
   gtk_builder_add_from_resource (builder, "/org/gnome/Dictionary/gdict-app-menus.ui", NULL);
 
-  gtk_application_set_menubar (GTK_APPLICATION (application),
-                               G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
   gtk_application_set_app_menu (GTK_APPLICATION (application),
                                 G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
   gtk_application_set_accels_for_action (GTK_APPLICATION (application), "win.lookup", lookup_accels);
diff --git a/src/gdict-window.c b/src/gdict-window.c
index fb81726..1eb6283 100644
--- a/src/gdict-window.c
+++ b/src/gdict-window.c
@@ -1560,7 +1560,7 @@ gdict_window_constructor (GType                  type,
 {
   GObject *object;
   GdictWindow *window;
-  GtkWidget *hbox;
+  GtkBuilder *builder;
   GtkWidget *handle;
   GtkWidget *frame1, *frame2;
   GtkWidget *vbox;
@@ -1577,32 +1577,27 @@ gdict_window_constructor (GType                  type,
   /* recover the state */
   gdict_window_load_state (window);
 
-  window->main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-  gtk_container_add (GTK_CONTAINER (window), window->main_box);
-  gtk_widget_show (window->main_box);
-  
   /* build menus */
   g_action_map_add_action_entries (G_ACTION_MAP (window),
                                    entries, G_N_ELEMENTS (entries),
                                    window);
   gdict_window_ensure_menu_state (window);
 
+  button = gtk_menu_button_new ();
+  builder = gtk_builder_new ();
+  gtk_builder_add_from_resource (builder, "/org/gnome/Dictionary/gdict-app-menus.ui", NULL);
+  gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button),
+                                  G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
+  g_object_unref (builder);
+  gtk_menu_button_set_direction (GTK_MENU_BUTTON (button), GTK_ARROW_NONE);
+  gtk_header_bar_pack_end (GTK_HEADER_BAR (window->header_bar), button);
+  gtk_widget_show (button);
+
   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
   gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
   gtk_container_add (GTK_CONTAINER (window->main_box), vbox);
   gtk_widget_show (vbox);
   
-  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
-  gtk_widget_show (hbox);
-  
-  button = gtk_button_new_with_mnemonic (_("Look _up"));
-  g_signal_connect_swapped (button, "clicked",
-                            G_CALLBACK (lookup_word),
-                            window);
-  gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
-  gtk_widget_show (button);
-
   window->completion_model = gtk_list_store_new (COMPLETION_N_COLUMNS,
                                                 G_TYPE_STRING);
   
@@ -1613,7 +1608,6 @@ gdict_window_constructor (GType                  type,
   gtk_entry_completion_set_text_column (window->completion,
                                        COMPLETION_TEXT_COLUMN);
   
-  window->entry = gtk_entry_new ();
   if (window->word)
     gtk_entry_set_text (GTK_ENTRY (window->entry), window->word);
   
@@ -1622,8 +1616,6 @@ gdict_window_constructor (GType                  type,
   g_signal_connect_swapped (window->entry, "activate",
                             G_CALLBACK (lookup_word),
                             window);
-  gtk_box_pack_start (GTK_BOX (hbox), window->entry, TRUE, TRUE, 0);
-  gtk_widget_show (window->entry);
 
   handle = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
   gtk_box_pack_start (GTK_BOX (vbox), handle, TRUE, TRUE, 0);
@@ -1826,6 +1818,13 @@ gdict_window_class_init (GdictWindowClass *klass)
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
+  gtk_widget_class_set_template_from_resource (widget_class,
+                                               "/org/gnome/Dictionary/gdict-app-window.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, GdictWindow, header_bar);
+  gtk_widget_class_bind_template_child (widget_class, GdictWindow, entry);
+  gtk_widget_class_bind_template_child (widget_class, GdictWindow, main_box);
+
   gdict_window_properties[PROP_ACTION] =
     g_param_spec_enum ("action",
                        "Action",
@@ -1946,6 +1945,8 @@ gdict_window_init (GdictWindow *window)
   
   window->window_id = (gulong) time (NULL);
 
+  gtk_widget_init_template (GTK_WIDGET (window));
+
   /* we need to create the chooser widgets for the sidebar before
    * we set the construction properties
    */
diff --git a/src/gdict-window.h b/src/gdict-window.h
index 1190765..38d9ca9 100644
--- a/src/gdict-window.h
+++ b/src/gdict-window.h
@@ -48,6 +48,7 @@ struct _GdictWindow
 {
   GtkApplicationWindow parent_instance;
   
+  GtkWidget *header_bar;
   GtkWidget *main_box;
   GtkWidget *entry;
   
diff --git a/src/gdict.gresource.xml b/src/gdict.gresource.xml
index 2a9c788..59a12f3 100644
--- a/src/gdict.gresource.xml
+++ b/src/gdict.gresource.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/Dictionary">
     <file preprocess="xml-stripblanks">gdict-app-menus.ui</file>
+    <file preprocess="xml-stripblanks">gdict-app-window.ui</file>
     <file preprocess="xml-stripblanks">gdict-pref-dialog.ui</file>
     <file preprocess="xml-stripblanks">gdict-source-dialog.ui</file>
   </gresource>


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