Kill button as back button when on zavai
[gregoa/zavai.git] / src / app.vala
index 16ab25239a47b5b44b8498fd0936e9ee86b7ec2a..2478d2bac4e5d1b576eb03c06d3423e98162d8eb 100644 (file)
@@ -104,13 +104,13 @@ public class Zavai : Gtk.Window, zavai.Resource
                if (current_name == name)
                        return;
 
-stderr.printf("push applet %s -> %s\n", current_name, name);
+//stderr.printf("push applet %s -> %s\n", current_name, name);
                zavai.Applet applet = zavai.registry.geta(name);
 
                // Remove the current applet
                if (current != null)
                {
-stderr.printf("push applet remove %s\n", current_name);
+//stderr.printf("push applet remove %s\n", current_name);
                        applet.back_link = current_name;
                        current.stop();
                        remove(current);
@@ -118,7 +118,7 @@ stderr.printf("push applet remove %s\n", current_name);
                        current_name = null;
                }
 
-stderr.printf("push applet add %s\n", name);
+//stderr.printf("push applet add %s\n", name);
                // Add the new applet
                current = applet;
                current_name = name;
@@ -127,6 +127,12 @@ stderr.printf("push applet add %s\n", name);
                current.show_all();
        }
 
+       public void back()
+       {
+               if (current != null)
+                       current.back();
+       }
+
        public void shutdown()
        {
        }
@@ -172,22 +178,24 @@ public abstract class Applet : Gtk.VBox, Resource
        }
        public signal void label_changed();
 
+       protected Gtk.HBox button_box;
+
        // 'back_link' property: link to use to "go back". If null, do not show
        // a way to go back.
        protected AppletLink _back_link = null;
        public string back_link {
                get { return _back_link.target; }
                set {
-stderr.printf("Set back link of %s to %s\n", _label, value);
+//stderr.printf("Set back link of %s to %s\n", _label, value);
                        if (value == null && _back_link != null)
                        {
                                _back_link.target = value;
-                               remove(_back_link);
+                               button_box.remove(_back_link);
                        } else if (value != null) {
                                if (_back_link.target == null)
                                {
                                        _back_link.target = value;
-                                       pack_end(_back_link, false, false, 0);
+                                       button_box.pack_end(_back_link, true, true, 0);
                                        _back_link.show();
                                } else
                                        _back_link.target = value;
@@ -197,8 +205,10 @@ stderr.printf("Set back link of %s to %s\n", _label, value);
 
        public Applet()
        {
+               button_box = new Gtk.HBox(true, 0);
                this.homogeneous = false;
                this.spacing = 0;
+               pack_end(button_box, false, true, 0);
                _back_link = new AppletStraightLink();
        }
 /*
@@ -223,6 +233,11 @@ stderr.printf("Set back link of %s to %s\n", _label, value);
         self.pack_start(widget, True, True)
 */
 
+       public virtual void back()
+       {
+               _back_link.activate();
+       }
+
        public void shutdown()
        {
                stop();
@@ -303,13 +318,18 @@ public abstract class AppletLink : BigButton
 
                clicked += on_clicked;
        }
+
+       public virtual void activate()
+       {
+               on_clicked(this);
+       }
 }
 
 public class AppletStraightLink : AppletLink
 {
        private override void on_clicked(Gtk.Button src)
        {
-stderr.printf("straight link: %s\n", _target);
+//stderr.printf("straight link: %s\n", _target);
                if (_target != null)
                        zavai.app.show_applet(_target);
        }
@@ -324,7 +344,7 @@ public class AppletPushLink : AppletLink
 {
        private override void on_clicked(Gtk.Button src)
        {
-stderr.printf("push link: %s\n", _target);
+//stderr.printf("push link: %s\n", _target);
                if (_target != null)
                        zavai.app.push_applet(_target);
        }