[gnome-games] ui: Introduce SelectionActionBar



commit 4185f0e1d7d88f96e00f30515652b9dbbb57ab95
Author: Neville <nevilleantony98 gmail com>
Date:   Thu Jun 18 20:57:38 2020 +0530

    ui: Introduce SelectionActionBar
    
    This will be used to present actions for games every page. Actions
    include add to favorite, add to a collection etc.

 data/org.gnome.Games.gresource.xml |  1 +
 data/ui/selection-action-bar.ui    | 47 +++++++++++++++++++++
 src/meson.build                    |  1 +
 src/ui/selection-action-bar.vala   | 86 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 135 insertions(+)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index 7799ce4f..c8d68589 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -45,6 +45,7 @@
     <file preprocess="xml-stripblanks">ui/resume-dialog.ui</file>
     <file preprocess="xml-stripblanks">ui/resume-failed-dialog.ui</file>
     <file preprocess="xml-stripblanks">ui/search-bar.ui</file>
+    <file preprocess="xml-stripblanks">ui/selection-action-bar.ui</file>
     <file preprocess="xml-stripblanks">ui/shortcuts-window.ui</file>
     <file preprocess="xml-stripblanks">ui/snapshot-row.ui</file>
     <file preprocess="xml-stripblanks">ui/snapshots-list.ui</file>
diff --git a/data/ui/selection-action-bar.ui b/data/ui/selection-action-bar.ui
new file mode 100644
index 00000000..1c7b8ad3
--- /dev/null
+++ b/data/ui/selection-action-bar.ui
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.24"/>
+  <template class="GamesSelectionActionBar" parent="GtkActionBar">
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkButton" id="favorite_button">
+        <property name="visible">True</property>
+        <property name="action-name">view.favorite-action</property>
+        <property name="tooltip-text" translatable="yes">Add/Remove games to favorite</property>
+        <child>
+          <object class="GtkStack" id="icon_stack">
+            <property name="visible">True</property>
+            <property name="transition-type">crossfade</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">starred-symbolic</property>
+              </object>
+              <packing>
+                <property name="name">starred-icon</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">non-starred-symbolic</property>
+              </object>
+              <packing>
+                <property name="name">non-starred-icon</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">semi-starred-symbolic</property>
+              </object>
+              <packing>
+                <property name="name">semi-starred-icon</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/meson.build b/src/meson.build
index eeff67df..a650d167 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -152,6 +152,7 @@ vala_sources = [
   'ui/resume-dialog.vala',
   'ui/resume-failed-dialog.vala',
   'ui/search-bar.vala',
+  'ui/selection-action-bar.vala',
   'ui/shortcuts-window.vala',
   'ui/snapshot-row.vala',
   'ui/snapshot-thumbnail.vala',
diff --git a/src/ui/selection-action-bar.vala b/src/ui/selection-action-bar.vala
new file mode 100644
index 00000000..7825aafa
--- /dev/null
+++ b/src/ui/selection-action-bar.vala
@@ -0,0 +1,86 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/selection-action-bar.ui")]
+private class Games.SelectionActionBar : Gtk.ActionBar {
+       [GtkChild]
+       private Gtk.Stack icon_stack;
+       [GtkChild]
+       private Gtk.Button favorite_button;
+
+       private FavoriteState _favorite_state;
+       public FavoriteState favorite_state {
+               get { return _favorite_state; }
+               set {
+                       _favorite_state = value;
+
+                       icon_stack.visible_child_name = favorite_state.get_child_name ();
+                       favorite_button.tooltip_text = favorite_state.get_tooltip_text ();
+               }
+       }
+
+       public enum FavoriteState {
+               NONE_FAVORITE,
+               ALL_FAVORITE,
+               SEMI_FAVORITE;
+
+               public string get_child_name () {
+                       switch (this) {
+                       case NONE_FAVORITE:
+                               return "starred-icon";
+
+                       case ALL_FAVORITE:
+                               return "non-starred-icon";
+
+                       case SEMI_FAVORITE:
+                               return "semi-starred-icon";
+
+                       default:
+                               assert_not_reached ();
+                       }
+               }
+
+               public string get_tooltip_text () {
+                       switch (this) {
+                       case ALL_FAVORITE:
+                               return  _("Remove selected games from favorites");
+
+                       case NONE_FAVORITE:
+                       case SEMI_FAVORITE:
+                               return _("Add selected games to favorites");
+
+                       default:
+                               assert_not_reached ();
+                       }
+               }
+       }
+
+       public void update (Game[] games) {
+               if (is_all_favorite (games)) {
+                       favorite_state = ALL_FAVORITE;
+                       return;
+               }
+
+               if (is_none_favorite (games)) {
+                       favorite_state = NONE_FAVORITE;
+                       return;
+               }
+
+               favorite_state = SEMI_FAVORITE;
+       }
+
+       private bool is_all_favorite (Game[] games) {
+               foreach (var game in games)
+                       if (!game.is_favorite)
+                               return false;
+
+               return true;
+       }
+
+       private bool is_none_favorite (Game[] games) {
+               foreach (var game in games)
+                       if (game.is_favorite)
+                               return false;
+
+               return true;
+       }
+}


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