[gnome-games/wip/exalm/tnum: 10/24] collection-view: Add support for adding games to collections




commit 48809ad5778d3a4d1d12d50eeb0eb0c44bb30cfc
Author: Neville <nevilleantony98 gmail com>
Date:   Fri Aug 7 00:01:31 2020 +0530

    collection-view: Add support for adding games to collections
    
    Also add "Add to Collection" button in selection action bar.

 data/ui/selection-action-bar.ui |  9 +++++++++
 src/ui/collection-view.vala     | 43 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 48 insertions(+), 4 deletions(-)
---
diff --git a/data/ui/selection-action-bar.ui b/data/ui/selection-action-bar.ui
index 8700c34e8..236468736 100644
--- a/data/ui/selection-action-bar.ui
+++ b/data/ui/selection-action-bar.ui
@@ -44,5 +44,14 @@
         </child>
       </object>
     </child>
+    <child>
+      <object class="GtkButton" id="add_to_collection_button">
+        <property name="visible">True</property>
+        <property name="label" translatable="yes">_Add to Collection</property>
+        <property name="use-underline">True</property>
+        <property name="action-name">view.add-to-collection</property>
+        <property name="tooltip-text" translatable="yes">Add selected games to a collection</property>
+      </object>
+    </child>
   </template>
 </interface>
diff --git a/src/ui/collection-view.vala b/src/ui/collection-view.vala
index a7763a8f2..1ce4ea927 100644
--- a/src/ui/collection-view.vala
+++ b/src/ui/collection-view.vala
@@ -130,10 +130,11 @@ private class Games.CollectionView : Gtk.Box, UiView {
        private KonamiCode konami_code;
        private SimpleActionGroup action_group;
        private const ActionEntry[] action_entries = {
-               { "select-all",      select_all },
-               { "select-none",     select_none },
-               { "toggle-select",   toggle_select },
-               { "favorite-action", favorite_action }
+               { "select-all",        select_all },
+               { "select-none",       select_none },
+               { "toggle-select",     toggle_select },
+               { "favorite-action",   favorite_action },
+               { "add-to-collection", add_to_collection }
        };
 
        construct {
@@ -342,6 +343,40 @@ private class Games.CollectionView : Gtk.Box, UiView {
                is_selection_mode = !is_selection_mode;
        }
 
+       private Game[] get_currently_selected_games () {
+               Game[] games;
+
+               if (viewstack.visible_child == games_page)
+                       games = games_page.get_selected_games ();
+               else if (viewstack.visible_child == platforms_page)
+                       games = platforms_page.get_selected_games ();
+               else
+                       games = collections_page.get_selected_games ();
+
+               return games;
+       }
+
+       private void add_to_collection () {
+               // Finalize any pending removal of collection and dismiss undo notification if shown.
+               collections_page.finalize_collection_removal ();
+
+               var current_collection = !collections_page.is_subpage_open ? null :
+                                        collections_page.current_collection;
+               var dialog = new CollectionActionWindow (false, current_collection);
+               dialog.collection_model = collection_model;
+               dialog.transient_for = get_toplevel () as ApplicationWindow;
+               dialog.modal = true;
+               dialog.visible = true;
+
+               dialog.confirmed.connect ((collections) => {
+                       var games = get_currently_selected_games ();
+                       foreach (var collection in collections)
+                               collection.add_games (games);
+
+                       select_none ();
+               });
+       }
+
        private void favorite_action () {
                if (viewstack.visible_child == games_page)
                        collection_manager.toggle_favorite (games_page.get_selected_games ());


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