[gnome-boxes] selectionbar: update favorite button when selection changes



commit 32c1f7f9de9765203d46f5923c42502bd8b783a7
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Mon Aug 20 19:01:38 2012 +0200

    selectionbar: update favorite button when selection changes
    
    Update favorite button sensitivity and state depending on selected
    machines.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=682292

 src/selectionbar.vala |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/src/selectionbar.vala b/src/selectionbar.vala
index 3c59716..a8262d3 100644
--- a/src/selectionbar.vala
+++ b/src/selectionbar.vala
@@ -55,6 +55,7 @@ private class Boxes.Selectionbar: GLib.Object {
 
         App.app.notify["selected-items"].connect (() => {
             update_visible ();
+            update_favorite_btn ();
         });
     }
 
@@ -65,6 +66,28 @@ private class Boxes.Selectionbar: GLib.Object {
             visible = App.app.selected_items.length () > 0;
     }
 
+    private void update_favorite_btn () {
+        var active = false;
+        var sensitive = App.app.selected_items.length () > 0;
+
+        foreach (var item in App.app.selected_items) {
+            var machine = item as Machine;
+            if (machine == null)
+                continue;
+
+            var is_favorite = "favorite" in machine.config.categories;
+            if (!active) {
+                active = is_favorite;
+            } else if (!is_favorite) {
+                sensitive = false;
+                break;
+            }
+        }
+
+        favorite_btn.active = active;
+        favorite_btn.sensitive = sensitive;
+    }
+
     private bool visible {
         set {
             fade_actor (actor, value ? 255 : 0);



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