[gnome-boxes] Add select All/None/Running menu to selection toolbar



commit 7b0c6368d6fa7b3bcb39936a09957ce320375dcf
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Oct 25 20:35:16 2012 +0200

    Add select All/None/Running menu to selection toolbar
    
    This is similar to gnome-documents, although we added
    the "running" state as proposed by jimmac.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686883

 src/app.vala             |   16 ++++++++++++++++
 src/collection-view.vala |   36 ++++++++++++++++++++++++++++++++++++
 src/topbar.vala          |    7 +++++++
 3 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index e2adb6d..cec1d13 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -84,6 +84,18 @@ private class Boxes.App: Boxes.UI {
         action_properties.activate.connect (() => { ui_state = UIState.PROPERTIES; });
         application.add_action (action_properties);
 
+        action = new GLib.SimpleAction ("select-all", null);
+        action.activate.connect (() => { view.select (Selection.ALL); });
+        application.add_action (action);
+
+        action = new GLib.SimpleAction ("select-running", null);
+        action.activate.connect (() => { view.select (Selection.RUNNING); });
+        application.add_action (action);
+
+        action = new GLib.SimpleAction ("select-none", null);
+        action.activate.connect (() => { view.select (Selection.NONE); });
+        application.add_action (action);
+
         action = new GLib.SimpleAction ("about", null);
         action.activate.connect (() => {
             string[] authors = {
@@ -671,6 +683,10 @@ private class Boxes.App: Boxes.UI {
                    (event.state & Gdk.ModifierType.MODIFIER_MASK) == Gdk.ModifierType.CONTROL_MASK) {
             quit ();
             return true;
+        } else if (event.keyval == Gdk.Key.a &&
+                   (event.state & Gdk.ModifierType.MODIFIER_MASK) == Gdk.ModifierType.MOD1_MASK) {
+            quit ();
+            return true;
         }
 
         return false;
diff --git a/src/collection-view.vala b/src/collection-view.vala
index ef18b8d..9dc051a 100644
--- a/src/collection-view.vala
+++ b/src/collection-view.vala
@@ -1,6 +1,12 @@
 // This file is part of GNOME Boxes. License: LGPLv2+
 using Clutter;
 
+public enum Boxes.Selection {
+    ALL,
+    NONE,
+    RUNNING
+}
+
 private class Boxes.CollectionView: Boxes.UI {
     public override Clutter.Actor actor { get { return gtkactor; } }
 
@@ -458,4 +464,34 @@ private class Boxes.CollectionView: Boxes.UI {
 
         return false;
     }
+
+    public void select (Selection selection) {
+        App.app.selection_mode = true;
+
+        model_filter.foreach ( (filter_model, filter_path, filter_iter) => {
+            Gtk.TreeIter iter;
+            model_filter.convert_iter_to_child_iter (out iter, filter_iter);
+            bool selected;
+            switch (selection) {
+            default:
+            case Selection.ALL:
+                selected = true;
+                break;
+            case Selection.NONE:
+                selected = false;
+                break;
+            case Selection.RUNNING:
+                CollectionItem item;
+                model.get (iter, ModelColumns.ITEM, out item);
+                selected = item != null && item is Machine &&
+                    (item as Machine).is_running ();
+                break;
+            }
+            model.set (iter, ModelColumns.SELECTED, selected);
+            return false;
+        });
+        icon_view.queue_draw ();
+        App.app.notify_property ("selected-items");
+    }
+
 }
diff --git a/src/topbar.vala b/src/topbar.vala
index 6d33125..272ede7 100644
--- a/src/topbar.vala
+++ b/src/topbar.vala
@@ -83,6 +83,13 @@ private class Boxes.Topbar: Boxes.UI {
         selection_toolbar = new Gd.MainToolbar ();
         selection_toolbar.get_style_context ().add_class ("selection-mode");
         selection_toolbar.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUBAR);
+
+        var menu = new GLib.Menu ();
+        menu.append (_("Select All"), "app.select-all");
+        menu.append (_("Select Running"), "app.select-running");
+        menu.append (_("Select None"), "app.select-none");
+
+        selection_toolbar.set_labels_menu (menu);
         hbox.pack_start (selection_toolbar, true, true, 0);
 
         update_selection_label ();



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