[gnome-clocks] Use a ui file also for the main window structure



commit 0b167a1c30655e338635e2faacd75d816a53e668
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Mar 3 12:38:28 2013 +0100

    Use a ui file also for the main window structure

 Makefile.am                    |    1 +
 src/alarm.vala                 |    6 +----
 src/gnome-clocks.gresource.xml |    1 +
 src/widgets.vala               |    5 ----
 src/window.ui                  |   48 ++++++++++++++++++++++++++++++++++++++++
 src/window.vala                |   28 ++++++++---------------
 src/world.vala                 |    6 +----
 7 files changed, 62 insertions(+), 33 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 035f706..3b63ab6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -151,6 +151,7 @@ EXTRA_DIST = \
        src/menu.ui \
        src/stopwatch.ui \
        src/timer.ui \
+       src/window.ui \
        src/world.ui
 
 CLEANFILES = \
diff --git a/src/alarm.vala b/src/alarm.vala
index edb3c52..4cbe375 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -507,17 +507,13 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
 
         load ();
 
-        var id = notify["visible-child"].connect (() => {
+        notify["visible-child"].connect (() => {
             if (visible_child == content_view) {
                 toolbar.mode = Toolbar.Mode.NORMAL;
             } else if (visible_child == ringing_panel) {
                 toolbar.mode = Toolbar.Mode.STANDALONE;
             }
         });
-        toolbar.destroy.connect(() => {
-            disconnect (id);
-            id = 0;
-        });
 
         visible_child = content_view;
         show_all ();
diff --git a/src/gnome-clocks.gresource.xml b/src/gnome-clocks.gresource.xml
index dacf3a2..16a74ce 100644
--- a/src/gnome-clocks.gresource.xml
+++ b/src/gnome-clocks.gresource.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/clocks/ui">
     <file preprocess="xml-stripblanks">menu.ui</file>
+    <file preprocess="xml-stripblanks">window.ui</file>
     <file preprocess="xml-stripblanks">world.ui</file>
     <file preprocess="xml-stripblanks">alarm.ui</file>
     <file preprocess="xml-stripblanks">stopwatch.ui</file>
diff --git a/src/widgets.vala b/src/widgets.vala
index e612690..bb3857a 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -53,11 +53,6 @@ public class Toolbar : Gd.MainToolbar {
 
     private Mode _mode;
 
-    public Toolbar () {
-        Object (show_modes: true, vexpand: false);
-        get_style_context ().add_class (Gtk.STYLE_CLASS_MENUBAR);
-    }
-
     public signal void clock_changed (Clock clock);
 
     public void add_clock (Clock clock) {
diff --git a/src/window.ui b/src/window.ui
new file mode 100644
index 0000000..18beb36
--- /dev/null
+++ b/src/window.ui
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkGrid" id="main_panel">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <child>
+      <object class="ClocksToolbar" id="toolbar">
+        <property name="visible">True</property>
+        <property name="vexpand">False</property>
+        <property name="show-modes">True</property>
+        <style>
+          <class name="menubar"/>
+        </style>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkFrame" id="frame1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label_xalign">0</property>
+        <style>
+          <class name="clocks-content-view"/>
+          <class name="view"/>
+          <class name="content-view"/>
+        </style>
+        <child>
+          <object class="GdStack" id="stack">
+            <property name="visible">True</property>
+            <property name="duration">0</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">1</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+  </object>
+</interface>
diff --git a/src/window.vala b/src/window.vala
index 0aa690b..f4e623f 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -48,7 +48,11 @@ public class Window : Gtk.ApplicationWindow {
 
         set_size_request (DEFAULT_WIDTH, DEFAULT_HEIGHT);
 
-        toolbar = new Toolbar ();
+        var builder = Utils.load_ui ("window.ui");
+
+        var main_panel = builder.get_object ("main_panel") as Gtk.Widget;
+        toolbar = builder.get_object ("toolbar") as Toolbar;
+        stack = builder.get_object ("stack") as Gd.Stack;
 
         world = new World.MainPanel (toolbar);
         alarm = new Alarm.MainPanel (toolbar);
@@ -60,8 +64,6 @@ public class Window : Gtk.ApplicationWindow {
         toolbar.add_clock (stopwatch);
         toolbar.add_clock (timer);
 
-        stack = new Gd.Stack ();
-        stack.duration = 0;
         stack.add (world);
         stack.add (alarm);
         stack.add (stopwatch);
@@ -71,16 +73,16 @@ public class Window : Gtk.ApplicationWindow {
             stack.visible_child = (Gtk.Widget) c;
         });
 
-        var id = stack.notify["visible-child"].connect (() => {
+        stack.notify["visible-child"].connect (() => {
             update_toolbar ();
         });
 
-        toolbar.notify["mode"].connect (() => {
+        var id = toolbar.notify["mode"].connect (() => {
             update_toolbar ();
         });
 
-        toolbar.destroy.connect(() => {
-            stack.disconnect (id);
+        stack.destroy.connect(() => {
+            toolbar.disconnect (id);
             id = 0;
         });
 
@@ -95,17 +97,7 @@ public class Window : Gtk.ApplicationWindow {
         stack.visible_child = world;
         world.update_toolbar ();
 
-        var frame = new Gtk.Frame (null);
-        frame.get_style_context ().add_class ("clocks-content-view");
-        frame.get_style_context ().add_class ("view");
-        frame.get_style_context ().add_class ("content-view");
-        frame.add (stack);
-
-        var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
-        vbox.pack_start (toolbar, false, false, 0);
-        vbox.pack_end (frame, true, true, 0);
-        add (vbox);
-
+        add (main_panel);
         show_all ();
     }
 
diff --git a/src/world.vala b/src/world.vala
index 1a63ad5..ef2dda5 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -285,17 +285,13 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
 
         load ();
 
-        var id = notify["visible-child"].connect (() => {
+        notify["visible-child"].connect (() => {
             if (visible_child == content_view) {
                 toolbar.mode = Toolbar.Mode.NORMAL;
             } else if (visible_child == standalone) {
                 toolbar.mode = Toolbar.Mode.STANDALONE;
             }
         });
-        toolbar.destroy.connect(() => {
-            disconnect (id);
-            id = 0;
-        });
 
         visible_child = content_view;
         show_all ();


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