[gnome-maps/wip/osrm-routing: 14/21] Sidebar: refactor



commit f2f6e624c6a12eb4a3441bf82ee934ed76a9496d
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Thu Jun 13 04:27:02 2013 +0200

    Sidebar: refactor
    
    Refactor, clean up and expose more of Gd.Revealer functionality
    needed later.

 src/sidebar.js |   51 ++++++++++++++++++++++++++++++---------------------
 1 files changed, 30 insertions(+), 21 deletions(-)
---
diff --git a/src/sidebar.js b/src/sidebar.js
index 491a931..8912a3d 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -44,10 +44,9 @@ const Sidebar = new Lang.Class({
                                          x_align: Clutter.ActorAlign.END });
 
         // create the button
-        let revealButton = new Gd.HeaderSimpleButton({ symbolic_icon_name: 'go-previous-symbolic',
-                                                       valign: Gtk.Align.CENTER });
-        revealButton.get_style_context().add_class('osd');
-        revealButton.show();
+        this._revealButton = new Gd.HeaderSimpleButton({ valign: Gtk.Align.CENTER });
+        this._revealButton.get_style_context().add_class('osd');
+        this._revealButton.connect('clicked', this.toggle.bind(this));
 
         // then the sidebar itself, packed into the revealer
         let grid = new Gtk.Grid({ vexpand: true,
@@ -64,31 +63,41 @@ const Sidebar = new Lang.Class({
                                         width_request: 200 });
         container.get_style_context().add_class('maps-sidebar');
 
-        let revealer = new Gd.Revealer({ child: container,
-                                         reveal_child: false,
-                                         orientation: Gtk.Orientation.VERTICAL });
-        revealer.show_all();
-
-        revealButton.connect('clicked', Lang.bind(this, function() {
-            if (revealer.reveal_child) {
-                revealer.reveal_child = false;
-                revealButton.symbolic_icon_name = 'go-previous-symbolic';
-            } else {
-                revealer.reveal_child = true;
-                revealButton.symbolic_icon_name = 'go-next-symbolic';
-            }
-        }));
-
+        this._revealer = new Gd.Revealer({ child: container,
+                                           orientation: Gtk.Orientation.VERTICAL });
+        this._revealer.show_all();
         // now create actors
-        let buttonActor = new GtkClutter.Actor({ contents: revealButton,
+        let buttonActor = new GtkClutter.Actor({ contents: this._revealButton,
                                                  x_align: Clutter.ActorAlign.END });
         Utils.clearGtkClutterActorBg(buttonActor);
         this.actor.add_child(buttonActor);
 
-        let revealerActor = new GtkClutter.Actor({ contents: revealer,
+        let revealerActor = new GtkClutter.Actor({ contents: this._revealer,
                                                    x_align: Clutter.ActorAlign.END,
                                                    x_expand: true,
                                                    y_expand: true });
         this.actor.add_child(revealerActor);
+        this.conceal();
+    },
+
+    reveal: function() {
+        this._revealer.reveal_child = true;
+        this._revealButton.symbolic_icon_name = 'go-next-symbolic';
+    },
+
+    conceal: function() {
+        this._revealer.reveal_child = false;
+        this._revealButton.symbolic_icon_name = 'go-previous-symbolic';
+    },
+
+    toggle: function() {
+        if(this.isRevealed())
+            this.conceal();
+        else
+            this.reveal();
+    },
+
+    isRevealed: function() {
+        return this._revealer.reveal_child;
     }
 });


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