[gnome-games/wip/exalm/developers: 7/8] sidebar-view: Merge into PlatformsView
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/developers: 7/8] sidebar-view: Merge into PlatformsView
- Date: Thu, 2 May 2019 18:44:18 +0000 (UTC)
commit 9de4f927f11cac8228166699cfbf85a7072176c1
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Wed May 1 20:46:46 2019 +0500
sidebar-view: Merge into PlatformsView
Since DevelopersView is gone, there's no reason to keep the superclas
anymore.
data/org.gnome.Games.gresource.xml | 2 +-
data/ui/{sidebar-view.ui => platforms-view.ui} | 2 +-
src/meson.build | 1 -
src/ui/platforms-view.vala | 259 +++++++++++++++++++++++--
src/ui/sidebar-view.vala | 245 -----------------------
5 files changed, 247 insertions(+), 262 deletions(-)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index d2c6dd40..5c32b72a 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -30,6 +30,7 @@
<file preprocess="xml-stripblanks">ui/keyboard-tester.ui</file>
<file preprocess="xml-stripblanks">ui/media-menu-button.ui</file>
<file preprocess="xml-stripblanks">ui/media-selector.ui</file>
+ <file preprocess="xml-stripblanks">ui/platforms-view.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page-controllers.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page-platforms.ui</file>
@@ -49,6 +50,5 @@
<file preprocess="xml-stripblanks">ui/search-bar.ui</file>
<file preprocess="xml-stripblanks">ui/shortcuts-window.ui</file>
<file preprocess="xml-stripblanks">ui/sidebar-list-item.ui</file>
- <file preprocess="xml-stripblanks">ui/sidebar-view.ui</file>
</gresource>
</gresources>
diff --git a/data/ui/sidebar-view.ui b/data/ui/platforms-view.ui
similarity index 96%
rename from data/ui/sidebar-view.ui
rename to data/ui/platforms-view.ui
index d782cbd9..0cfbb72d 100644
--- a/data/ui/sidebar-view.ui
+++ b/data/ui/platforms-view.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.24"/>
- <template class="GamesSidebarView" parent="GtkBox">
+ <template class="GamesPlatformsView" parent="GtkBox">
<property name="visible">True</property>
<property name="expand">True</property>
<signal name="map" after="yes" handler="on_map"/>
diff --git a/src/meson.build b/src/meson.build
index d54fc23d..f9ebc312 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -180,7 +180,6 @@ vala_sources = [
'ui/search-bar.vala',
'ui/shortcuts-window.vala',
'ui/sidebar-list-item.vala',
- 'ui/sidebar-view.vala',
'ui/ui-view.vala',
'utils/composite-cover.vala',
diff --git a/src/ui/platforms-view.vala b/src/ui/platforms-view.vala
index 55548873..5510f769 100644
--- a/src/ui/platforms-view.vala
+++ b/src/ui/platforms-view.vala
@@ -1,37 +1,268 @@
// This file is part of GNOME Games. License: GPL-3.0+.
-private class Games.PlatformsView : SidebarView {
- private GenericSet<Platform> platforms = new GenericSet<Platform> (Platform.hash, Platform.equal);
+[GtkTemplate (ui = "/org/gnome/Games/ui/platforms-view.ui")]
+private class Games.PlatformsView : Gtk.Box {
+ public signal void game_activated (Game game);
+
+ private ulong model_items_changed_id;
+ private GenericSet<Platform> platforms;
private Platform selected_platform;
- protected override void game_added (Game game) {
- var platform = game.get_platform ();
+ private string[] filtering_terms;
+ public string filtering_text {
+ set {
+ collection_view.filtering_text = value;
+
+ if (value != null)
+ filtering_terms = value.split (" ");
- if (!platforms.contains (platform)) {
- platforms.add (platform);
- var platform_list_item = new PlatformListItem (platform);
- list_box.add (platform_list_item);
+ hide_empty_sidebar_items ();
}
}
- protected override void invalidate (Gtk.ListBoxRow row_item) {
- var row = row_item as PlatformListItem;
- var platform = row.platform;
- selected_platform = platform;
+ private ListModel _model;
+ public ListModel model {
+ get { return _model; }
+ set {
+ if (model_items_changed_id != 0) {
+ _model.disconnect (model_items_changed_id);
+ model_items_changed_id = 0;
+ }
+
+ _model = value;
+ collection_view.model = _model;
+
+ if (model != null)
+ model_items_changed_id = model.items_changed.connect (on_model_changed);
+ }
+ }
+
+ private Binding window_active_binding;
+ private bool _is_active;
+ public bool is_active {
+ get {
+ return _is_active;
+ }
+ set {
+ if (_is_active == value)
+ return;
+
+ _is_active = value;
+
+ if (!_is_active)
+ gamepad_browse.cancel_cursor_movement ();
+ }
}
- protected override int sort_rows (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) {
+ [GtkChild]
+ private CollectionIconView collection_view;
+
+ [GtkChild]
+ private Gtk.ListBox list_box;
+
+ [GtkChild]
+ private GamepadBrowse gamepad_browse;
+
+ construct {
+ platforms = new GenericSet<Platform> (Platform.hash, Platform.equal);
+
+ list_box.set_sort_func (sort_rows);
+
+ collection_view.game_activated.connect ((game) => {
+ game_activated (game);
+ });
+
+ collection_view.set_game_filter (filter_game);
+ }
+
+ private int sort_rows (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) {
var item1 = row1 as PlatformListItem;
var item2 = row2 as PlatformListItem;
return PlatformListItem.compare (item1, item2);
}
- protected override bool filter_game (Game game) {
+ private bool filter_game (Game game) {
if (selected_platform != null &&
selected_platform.get_name () != game.get_platform ().get_name ())
return false;
return true;
}
+
+ [GtkCallback]
+ public void on_map () {
+ window_active_binding = null;
+ is_active = false;
+
+ var window = get_ancestor (typeof (Gtk.Window));
+ if (window == null)
+ return;
+
+ window_active_binding = window.bind_property ("is-active", this, "is-active",
BindingFlags.SYNC_CREATE);
+ }
+
+ [GtkCallback]
+ public void on_unmap () {
+ window_active_binding = null;
+ is_active = false;
+ }
+
+ public bool gamepad_button_press_event (Manette.Event event) {
+ if (!get_mapped ())
+ return false;
+
+ if (collection_view.has_game_selected ())
+ if (collection_view.gamepad_button_press_event (event))
+ return true;
+
+ return gamepad_browse.gamepad_button_press_event (event);
+ }
+
+ public bool gamepad_button_release_event (Manette.Event event) {
+ if (!get_mapped ())
+ return false;
+
+ if (collection_view.has_game_selected ())
+ if (collection_view.gamepad_button_release_event (event))
+ return true;
+
+ return gamepad_browse.gamepad_button_release_event (event);
+ }
+
+ public bool gamepad_absolute_axis_event (Manette.Event event) {
+ if (!get_mapped ())
+ return false;
+
+ if (collection_view.has_game_selected ())
+ if (collection_view.gamepad_absolute_axis_event (event))
+ return true;
+
+ return gamepad_browse.gamepad_absolute_axis_event (event);
+ }
+
+ [GtkCallback]
+ private bool on_gamepad_browse (Gtk.DirectionType direction) {
+ if (list_box.get_selected_rows ().length () == 0) {
+ var first_row = list_box.get_row_at_index (0);
+ if (first_row == null)
+ return false;
+
+ list_box.select_row (first_row);
+ // This is needed to start moving the cursor with the gamepad only.
+ first_row.focus (direction);
+
+ return true;
+ }
+
+ switch (direction) {
+ case Gtk.DirectionType.UP:
+ list_box.move_cursor (Gtk.MovementStep.DISPLAY_LINES, -1);
+
+ return true;
+ case Gtk.DirectionType.DOWN:
+ list_box.move_cursor (Gtk.MovementStep.DISPLAY_LINES, 1);
+
+ return true;
+ case Gtk.DirectionType.RIGHT:
+ list_box.activate_cursor_row ();
+
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ [GtkCallback]
+ private bool on_gamepad_accept () {
+ list_box.activate_cursor_row ();
+
+ return true;
+ }
+
+ [GtkCallback]
+ private bool on_gamepad_cancel () {
+ collection_view.unselect_game ();
+
+ return true;
+ }
+
+ [GtkCallback]
+ private void on_list_box_row_selected (Gtk.ListBoxRow? row_item) {
+ if (row_item == null)
+ return;
+
+ var row = row_item as PlatformListItem;
+ list_box.select_row (row);
+ row.focus (Gtk.DirectionType.LEFT);
+ selected_platform = row.platform;
+
+ collection_view.invalidate_flow_box_filter ();
+ collection_view.reset_scroll_position ();
+ collection_view.unselect_game ();
+ }
+
+ [GtkCallback]
+ private void on_list_box_row_activated (Gtk.ListBoxRow row_item) {
+ collection_view.select_default_game (Gtk.DirectionType.RIGHT);
+ }
+
+ private void on_model_changed (uint position, uint removed, uint added) {
+ // FIXME: currently games are never removed, update this function if
+ // necessary.
+ assert (removed == 0);
+
+ for (uint i = position; i < position + added; i++) {
+ var game = model.get_item (i) as Game;
+ var platform = game.get_platform ();
+
+ if (!platforms.contains (platform)) {
+ platforms.add (platform);
+
+ var platform_list_item = new PlatformListItem (platform);
+ list_box.add (platform_list_item);
+ }
+ }
+ }
+
+ public void select_default_row () {
+ foreach (var child in list_box.get_children ()) {
+ var row = child as Gtk.ListBoxRow;
+
+ if (row.visible) {
+ on_list_box_row_selected (row);
+ break;
+ }
+ }
+ }
+
+ private void hide_empty_sidebar_items () {
+ // Create an array of all the games which fit the search text entered
+ // in the top search bar
+ Game[] visible_games = {};
+
+ for (int i = 0; i < model.get_n_items (); i++) {
+ var game = model.get_item (i) as Game;
+
+ if (game.matches_search_terms (filtering_terms))
+ visible_games += game;
+ }
+
+ foreach (var row in list_box.get_children ()) {
+ var sidebar_item = row as SidebarListItem;
+ // Assume row doesn't have any games to show
+ var is_row_visible = false;
+
+ foreach (var game in visible_games) {
+ if (sidebar_item.has_game (game)) {
+ is_row_visible = true;
+ break;
+ }
+ }
+
+ row.visible = is_row_visible;
+ }
+
+ select_default_row ();
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]