[Xfce4-commits] <design:master> Show a cancel icon when hovering the spinner.

Jannis Pohlmann noreply at xfce.org
Tue May 31 01:58:01 CEST 2011


Updating branch refs/heads/master
         to 619717e24639700c0d575e153a52323703e4ea8f (commit)
       from e2857b9b6a06bff09782f34b8c2c9c87b24d5955 (commit)

commit 619717e24639700c0d575e153a52323703e4ea8f
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Tue May 31 01:57:27 2011 +0200

    Show a cancel icon when hovering the spinner.

 .../demo-code/custom-view/shortcut-row.vala        |   55 +++++++++++++++-----
 1 files changed, 41 insertions(+), 14 deletions(-)

diff --git a/thunar/shortcuts-pane/demo-code/custom-view/shortcut-row.vala b/thunar/shortcuts-pane/demo-code/custom-view/shortcut-row.vala
index 4e997f1..7a9070c 100644
--- a/thunar/shortcuts-pane/demo-code/custom-view/shortcut-row.vala
+++ b/thunar/shortcuts-pane/demo-code/custom-view/shortcut-row.vala
@@ -28,8 +28,9 @@ public class ShortcutRow : EventBox {
   public bool connected { get; set; }
 
   private Image disconnect_icon { get; set; }
+  private Image disconnect_cancel_icon { get; set; }
   private Button disconnect_button { get; set; }
-  private Spinner connect_spinner { get; set; }
+  private Spinner spinner { get; set; }
 
   public ShortcutRow (string title, string icon_name, bool connected) {
     this.title = title;
@@ -59,42 +60,68 @@ public class ShortcutRow : EventBox {
 
     disconnect_icon = new Image.from_icon_name ("media-eject", IconSize.MENU);
     disconnect_icon.set_pixel_size (16);
-
     disconnect_icon.ref ();
 
+    disconnect_cancel_icon = new Image.from_stock (Stock.CANCEL, IconSize.MENU);
+    disconnect_cancel_icon.set_pixel_size (16);
+    disconnect_cancel_icon.ref ();
+
     disconnect_button = new Button ();
     disconnect_button.set_relief (ReliefStyle.NONE);
     disconnect_button.set_image (disconnect_icon);
     disconnect_button.set_no_show_all (true);
     box.pack_start (disconnect_button, false, true, 0);
 
+    disconnect_button.enter.connect (() => {
+      if (spinner.active) {
+        disconnect_button.set_image (disconnect_cancel_icon);
+      }
+    });
+
+    disconnect_button.leave.connect (() => {
+      if (spinner.active) {
+        disconnect_button.set_image (spinner);
+      }
+    });
+
     disconnect_button.clicked.connect (connect_device);
 
     if (connected) {
       disconnect_button.show ();
     }
 
-    connect_spinner = new Spinner ();
-    connect_spinner.set_size_request (16, 16);
-    connect_spinner.stop ();
-    connect_spinner.show ();
+    spinner = new Spinner ();
+    spinner.set_size_request (16, 16);
+    spinner.stop ();
+    spinner.show ();
 
-    connect_spinner.ref ();
+    spinner.ref ();
   }
 
-  public void connect_device () {
-    disconnect_button.set_image (connect_spinner);
+  ~ShortcutRow () {
+    disconnect_icon.unref ();
+    disconnect_cancel_icon.unref ();
+    spinner.unref ();
+  }
 
-    connect_spinner.start ();
+  public void connect_device () {
+    Gdk.ModifierType state;
+
+    if (get_current_event_state (out state)
+        && (state & Gdk.ModifierType.BUTTON1_MASK) != 0)
+    {
+      disconnect_button.set_image (disconnect_cancel_icon);
+    } else {
+      disconnect_button.set_image (spinner);
+    }
 
-    GLib.Timeout.add (1000, stop_spinner);
+    spinner.start ();
+    GLib.Timeout.add (2000, stop_spinner);
   }
 
   public bool stop_spinner () {
-    connect_spinner.stop ();
-
+    spinner.stop ();
     disconnect_button.set_image (disconnect_icon);
-
     return false;
   }
 



More information about the Xfce4-commits mailing list