[gnome-games/wip/exalm/tnum: 13/24] collection-view: Add support for removing collections
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/tnum: 13/24] collection-view: Add support for removing collections
- Date: Wed, 19 Aug 2020 18:22:23 +0000 (UTC)
commit 4f97ce1c48265de023703464d28c7ce02418986f
Author: Neville <nevilleantony98 gmail com>
Date: Sat Aug 8 21:33:26 2020 +0530
collection-view: Add support for removing collections
Add menu to collection subpage headerbar. Also add delete action on \
collections when viewing a collection. Shows undo notification on
collection deletion
data/ui/collection-view.ui | 34 ++++++++++++++++++++++++++++++++++
src/ui/collection-view.vala | 14 +++++++++++++-
src/ui/collections-page.vala | 40 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 87 insertions(+), 1 deletion(-)
---
diff --git a/data/ui/collection-view.ui b/data/ui/collection-view.ui
index c54b86344..7fed118ba 100644
--- a/data/ui/collection-view.ui
+++ b/data/ui/collection-view.ui
@@ -248,6 +248,26 @@
</style>
</object>
</child>
+ <child>
+ <object class="GtkMenuButton">
+ <property name="menu-model">collection_menu</property>
+ <property name="tooltip-text" translatable="yes">Collection menu</property>
+ <property name="valign">center</property>
+ <property name="visible" bind-source="collections_page"
bind-property="is-showing-user-collection"/>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="icon-name">view-more-symbolic</property>
+ </object>
+ </child>
+ <style>
+ <class name="image-button"/>
+ </style>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
@@ -514,6 +534,12 @@
</child>
</object>
</child>
+ <child type="overlay">
+ <object class="GamesUndoNotification" id="undo_notification">
+ <property name="visible">True</property>
+ <property name="label" bind-source="collections_page"
bind-property="removed-notification-title"/>
+ </object>
+ </child>
</object>
</child>
<child>
@@ -571,4 +597,12 @@
</item>
</section>
</menu>
+ <menu id="collection_menu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">R_emove</attribute>
+ <attribute name="action">view.remove-collection</attribute>
+ </item>
+ </section>
+ </menu>
</interface>
diff --git a/src/ui/collection-view.vala b/src/ui/collection-view.vala
index 7ba53239e..2e56ea0c1 100644
--- a/src/ui/collection-view.vala
+++ b/src/ui/collection-view.vala
@@ -48,6 +48,8 @@ private class Games.CollectionView : Gtk.Box, UiView {
private Hdy.SwipeGroup swipe_group;
[GtkChild]
private Hdy.SwipeGroup collections_swipe_group;
+ [GtkChild]
+ private UndoNotification undo_notification;
private bool _is_view_active;
public bool is_view_active {
@@ -134,7 +136,8 @@ private class Games.CollectionView : Gtk.Box, UiView {
{ "select-none", select_none },
{ "toggle-select", toggle_select },
{ "favorite-action", favorite_action },
- { "add-to-collection", add_to_collection }
+ { "add-to-collection", add_to_collection },
+ { "remove-collection", remove_collection }
};
construct {
@@ -143,6 +146,10 @@ private class Games.CollectionView : Gtk.Box, UiView {
collections_page.invalidate_filter ();
});
+ undo_notification.undo.connect (collections_page.undo_remove_collection);
+ undo_notification.closed.connect (collections_page.finalize_collection_removal);
+ window.destroy.connect (collections_page.finalize_collection_removal);
+
var icon_name = Config.APPLICATION_ID + "-symbolic";
viewstack.child_set (games_page, "icon-name", icon_name);
@@ -397,6 +404,11 @@ private class Games.CollectionView : Gtk.Box, UiView {
update_selection_action_bar ();
}
+ public void remove_collection () {
+ collections_page.remove_current_user_collection ();
+ undo_notification.show_notification ();
+ }
+
[GtkCallback]
private void update_selection_action_bar () {
Game[] games = {};
diff --git a/src/ui/collections-page.vala b/src/ui/collections-page.vala
index d2a80e4d5..485de0a66 100644
--- a/src/ui/collections-page.vala
+++ b/src/ui/collections-page.vala
@@ -16,6 +16,7 @@ private class Games.CollectionsPage : Gtk.Bin {
[GtkChild]
private CollectionEmpty collection_empty_subpage;
+ private UserCollection? last_removed_collection;
private CollectionManager collection_manager;
private bool _is_collection_empty;
@@ -50,12 +51,14 @@ private class Games.CollectionsPage : Gtk.Bin {
}
}
+ public ApplicationWindow application_window { get; set; }
public bool is_search_mode { get; set; }
public bool is_subpage_open { get; set; }
public bool is_selection_mode { get; set; }
public bool is_showing_user_collection { get; set; }
public bool can_swipe_back { get; set; }
public string collection_title { get; set; }
+ public string removed_notification_title { get; set; }
construct {
collection_manager = Application.get_default ().get_collection_manager ();
@@ -126,6 +129,40 @@ private class Games.CollectionsPage : Gtk.Bin {
collections_main_page.invalidate_filter ();
}
+ public void remove_current_user_collection () {
+ if (!is_showing_user_collection || current_collection == null)
+ return;
+
+ /* translators: This is displayed in an undo notification when a game collection is removed */
+ removed_notification_title = _("%s removed").printf (current_collection.get_title ());
+
+ if (last_removed_collection != null)
+ collection_manager.remove_user_collection (last_removed_collection);
+
+ assert (current_collection is UserCollection);
+ last_removed_collection = current_collection as UserCollection;
+ collection_model.remove_collection (current_collection);
+
+ on_subpage_back_clicked ();
+ }
+
+ public void undo_remove_collection () {
+ if (last_removed_collection == null)
+ return;
+
+ collection_model.add_collection (last_removed_collection);
+ last_removed_collection.games_changed ();
+ last_removed_collection = null;
+ }
+
+ public void finalize_collection_removal () {
+ if (last_removed_collection == null)
+ return;
+
+ collection_manager.remove_user_collection (last_removed_collection);
+ last_removed_collection = null;
+ }
+
[GtkCallback]
private bool on_subpage_back_clicked () {
if (!is_subpage_open)
@@ -141,6 +178,9 @@ private class Games.CollectionsPage : Gtk.Bin {
private void on_collection_activated (Collection collection) {
if (collection.get_collection_type () ==
Collection.CollectionType.PLACEHOLDER) {
+ // Finalize any pending removal of collection and dismiss undo notification
if shown.
+ finalize_collection_removal ();
+
var dialog = new CollectionActionWindow ();
dialog.transient_for = get_toplevel () as ApplicationWindow;
dialog.modal = true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]