[gnome-boxes] Add ActionsPopover



commit 1b1e0a704fb0884c7753c1c7853fa59a06e4c735
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Nov 14 14:10:06 2014 +0000

    Add ActionsPopover
    
    Add a popover to present a item-specific actions menu that includes:
    
    * Open in new window
    * Favorite
    * Pause
    * Delete
    * Properties
    
    https://bugzilla.gnome.org/show_bug.cgi?id=738761

 src/Makefile.am          |    1 +
 src/actions-popover.vala |   89 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 7709d21..7578ac0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -96,6 +96,7 @@ gnome_boxes_SOURCES =                         \
        $(BUILT_SOURCES)                        \
        app.vala                                \
        app-window.vala                         \
+       actions-popover.vala                    \
        archive-reader.vala                     \
        archive-writer.vala                     \
        auth-notification.vala                  \
diff --git a/src/actions-popover.vala b/src/actions-popover.vala
new file mode 100644
index 0000000..1d3fcb5
--- /dev/null
+++ b/src/actions-popover.vala
@@ -0,0 +1,89 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+
+private class Boxes.ActionsPopover: Gtk.Popover {
+    private const GLib.ActionEntry[] action_entries = {
+        {"open-in-new-win", open_in_new_win_activated},
+        {"favorite",        favorite_activated},
+        {"pause",           pause_activated},
+        {"delete",          delete_activated},
+        {"properties",      properties_activated}
+    };
+
+    private AppWindow window;
+    private GLib.SimpleActionGroup action_group;
+
+    public ActionsPopover (AppWindow window) {
+        this.window = window;
+
+        action_group = new GLib.SimpleActionGroup ();
+        action_group.add_action_entries (action_entries, this);
+        this.insert_action_group ("box", action_group);
+    }
+
+    public void update_for_item (CollectionItem item) {
+        return_if_fail (item is Machine);
+        var machine = item as Machine;
+
+        var menu = new GLib.Menu ();
+
+        // Open in new Window
+        menu.append (_("Open in new Window"), "box.open-in-new-win");
+
+        // Favorite
+        if (("favorite" in machine.config.categories))
+            menu.append (_("Remove favorite"), "box.favorite");
+        else
+            menu.append (_("Favorite"), "box.favorite");
+
+        // Pause
+        menu.append (_("Pause"), "box.pause");
+        var action = action_group.lookup_action ("pause") as GLib.SimpleAction;
+        action.set_enabled (machine.can_save);
+
+        // Delete
+        menu.append (_("Delete"), "box.delete");
+        action = action_group.lookup_action ("delete") as GLib.SimpleAction;
+        action.set_enabled (machine.can_delete);
+
+        // Properties (in separate section)
+        var section = new GLib.Menu ();
+        section.append (_("Properties"), "box.properties");
+        menu.append_section (null, section);
+
+        bind_model (menu, null);
+        window.current_item = item;
+    }
+
+    private void open_in_new_win_activated () {
+        App.app.open_in_new_window (window.current_item as Machine);
+    }
+
+    private void favorite_activated () {
+        var machine = window.current_item as Machine;
+        var enabled = !("favorite" in machine.config.categories);
+        machine.config.set_category ("favorite", enabled);
+    }
+
+    private void pause_activated () {
+        var machine = window.current_item as Machine;
+
+        machine.save.begin ((obj, result) => {
+            try {
+                machine.save.end (result);
+            } catch (GLib.Error e) {
+                window.notificationbar.display_error (_("Pausing '%s' failed").printf (machine.name));
+            }
+        });
+    }
+
+    private void delete_activated () {
+        var items = new List<CollectionItem> ();
+        items.append (window.current_item);
+
+        App.app.delete_machines_undoable ((owned) items);
+    }
+
+    private void properties_activated () {
+        window.show_properties ();
+    }
+}


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