[gnome-games] ui: Use checkmark in MediaSelector
- From: Abhinav Singh <abhinavsingh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] ui: Use checkmark in MediaSelector
- Date: Sun, 23 Apr 2017 00:27:36 +0000 (UTC)
commit 06dd9ddd3c84f2c9e6df1914a9d6da5c715d9761
Author: theawless <theawless gmail com>
Date: Wed Apr 12 17:48:02 2017 +0530
ui: Use checkmark in MediaSelector
Highlight the current media with a checkmark in MediaSelector following
the recommendations from the HIG. Solve the problem of changing disc on
selection by using 'row-activated' signal in place of 'row-selected'
signal. Also, reformat code to avoid the use of row_to_int hashtable.
https://bugzilla.gnome.org/show_bug.cgi?id=780778
data/ui/media-selector.ui | 18 ++++++++++-----
src/ui/media-selector.vala | 49 +++++++++++++------------------------------
2 files changed, 27 insertions(+), 40 deletions(-)
---
diff --git a/data/ui/media-selector.ui b/data/ui/media-selector.ui
index 8b451d8..8d75541 100644
--- a/data/ui/media-selector.ui
+++ b/data/ui/media-selector.ui
@@ -3,13 +3,19 @@
<requires lib="gtk+" version="3.16"/>
<template class="GamesMediaSelector" parent="GtkPopover">
<child>
- <object class="GtkListBox" id="list_box">
- <property name="margin-top">12</property>
- <property name="margin-bottom">12</property>
- <property name="margin-start">21</property>
- <property name="margin-end">21</property>
- <signal name="row-selected" after="yes" handler="on_row_selected"/>
+ <object class="GtkFrame">
+ <property name="visible">True</property>
+ <property name="shadow_type">none</property>
<child>
+ <object class="GtkListBox" id="list_box">
+ <property name="visible">True</property>
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="margin-start">6</property>
+ <property name="margin-end">6</property>
+ <property name="selection_mode">none</property>
+ <signal name="row-activated" after="yes" handler="on_row_activated"/>
+ </object>
</child>
</object>
</child>
diff --git a/src/ui/media-selector.vala b/src/ui/media-selector.vala
index adec1d1..4f2c4c2 100644
--- a/src/ui/media-selector.vala
+++ b/src/ui/media-selector.vala
@@ -15,12 +15,6 @@ private class Games.MediaSelector : Gtk.Popover {
[GtkChild]
private Gtk.ListBox list_box;
- private HashTable<Gtk.ListBoxRow, int> row_to_int;
-
- construct {
- row_to_int = new HashTable<Gtk.ListBoxRow, int> (direct_hash, direct_equal);
- }
-
private void update_media () {
var media_number = 0;
@@ -42,46 +36,33 @@ private class Games.MediaSelector : Gtk.Popover {
}
}
- var row = new Gtk.ListBoxRow ();
- var label = new Gtk.Label (media_name);
- row.add (label);
- if (media_number == _media_set.selected_media_number)
- list_box.select_row (row);
-
- row_to_int.insert (row, media_number);
-
- add_row (row);
+ var checkmark_item = new CheckmarkItem (media_name);
+ var is_current_media = (_media_set.selected_media_number == media_number);
+ checkmark_item.checkmark_visible = is_current_media;
+ list_box.add (checkmark_item);
media_number++;
});
}
private void remove_media () {
- row_to_int.remove_all ();
- list_box.unselect_all ();
list_box.foreach ((child) => child.destroy ());
}
- private void add_row (Gtk.ListBoxRow row) {
- list_box.insert (row, -1);
- list_box.show_all ();
- }
-
[GtkCallback]
- private void on_row_selected (Gtk.ListBoxRow? row) {
- if (row == null)
- return;
-
- if (!row_to_int.contains (row))
- return;
+ private void on_row_activated (Gtk.ListBoxRow activated_row) {
+ var media_number = activated_row.get_index ();
+ _media_set.selected_media_number = media_number;
- var media_number = row_to_int[row];
+ var i = 0;
+ var row = list_box.get_row_at_index (i);
+ while (row != null) {
+ var checkmark_item = (CheckmarkItem) row.get_child ();
+ checkmark_item.checkmark_visible = (i == media_number);
- if (media_number == _media_set.selected_media_number)
- return;
-
- _media_set.selected_media_number = media_number;
+ row = list_box.get_row_at_index (++i);
+ }
- hide ();
+ popdown ();
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]