[gnome-games/wip/exalm/prefs: 22/24] preferences-page-controllers: Migrate to HdyPreferencesGroup
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/prefs: 22/24] preferences-page-controllers: Migrate to HdyPreferencesGroup
- Date: Tue, 2 Jun 2020 11:11:26 +0000 (UTC)
commit fd33af8e1aea1ef146f37a75b18f2dbffb5b10b8
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue May 12 23:00:11 2020 +0500
preferences-page-controllers: Migrate to HdyPreferencesGroup
data/ui/preferences-page-controllers.ui | 38 ++-----------------
src/ui/preferences-page-controllers.vala | 65 ++++++++++++++------------------
2 files changed, 32 insertions(+), 71 deletions(-)
---
diff --git a/data/ui/preferences-page-controllers.ui b/data/ui/preferences-page-controllers.ui
index c9459c3b..59f56950 100644
--- a/data/ui/preferences-page-controllers.ui
+++ b/data/ui/preferences-page-controllers.ui
@@ -4,45 +4,15 @@
<template class="GamesPreferencesPageControllers" parent="GamesPreferencesPage">
<property name="visible">True</property>
<child>
- <object class="GtkLabel" id="gamepads_label">
+ <object class="HdyPreferencesGroup" id="gamepads_group">
<property name="visible">True</property>
- <property name="halign">start</property>
- <property name="label" translatable="yes">Gamepads</property>
- <attributes>
- <attribute name="weight" value="bold"/>
- </attributes>
+ <property name="title" translatable="yes">Gamepads</property>
</object>
</child>
<child>
- <object class="GtkListBox" id="gamepads_list_box">
+ <object class="HdyPreferencesGroup" id="keyboard_group">
<property name="visible">True</property>
- <property name="selection-mode">none</property>
- <signal name="row-activated" handler="gamepads_list_box_row_activated"/>
- <style>
- <class name="rounded"/>
- <class name="separators"/>
- </style>
- </object>
- </child>
- <child>
- <object class="GtkLabel">
- <property name="visible">True</property>
- <property name="halign">start</property>
- <property name="label" translatable="yes">Keyboard</property>
- <attributes>
- <attribute name="weight" value="bold"/>
- </attributes>
- </object>
- </child>
- <child>
- <object class="GtkListBox" id="keyboard_list_box">
- <property name="visible">True</property>
- <property name="selection-mode">none</property>
- <signal name="row-activated" handler="keyboard_list_box_row_activated"/>
- <style>
- <class name="rounded"/>
- <class name="separators"/>
- </style>
+ <property name="title" translatable="yes">Keyboard</property>
</object>
</child>
</template>
diff --git a/src/ui/preferences-page-controllers.vala b/src/ui/preferences-page-controllers.vala
index 2aabe6fc..1af6b712 100644
--- a/src/ui/preferences-page-controllers.vala
+++ b/src/ui/preferences-page-controllers.vala
@@ -3,11 +3,9 @@
[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-controllers.ui")]
private class Games.PreferencesPageControllers : PreferencesPage {
[GtkChild]
- private Gtk.Label gamepads_label;
+ private Hdy.PreferencesGroup gamepads_group;
[GtkChild]
- private Gtk.ListBox gamepads_list_box;
- [GtkChild]
- private Gtk.ListBox keyboard_list_box;
+ private Hdy.PreferencesGroup keyboard_group;
private Manette.Monitor monitor;
@@ -31,42 +29,35 @@ private class Games.PreferencesPageControllers : PreferencesPage {
Manette.Device device = null;
var i = 0;
var iterator = monitor.iterate ();
+
while (iterator.next (out device)) {
- i += 1;
var row = new Hdy.ActionRow ();
row.title = device.get_name ();
row.add (new Gtk.Image.from_icon_name ("go-next-symbolic", Gtk.IconSize.BUTTON));
row.activatable = true;
- row.show_all ();
- gamepads_list_box.add (row);
- }
- gamepads_label.visible = i > 0;
- gamepads_list_box.visible = i > 0;
- }
- private void clear_gamepad_list () {
- gamepads_list_box.foreach ((child) => child.destroy ());
- }
+ // The original device variable will be overwritten on the
+ // next iteration, while this one will remain there and can
+ // be used in the event handler.
+ var this_device = device;
- [GtkCallback]
- private void gamepads_list_box_row_activated (Gtk.ListBoxRow row_item) {
- Manette.Device? device = null;
- Manette.Device other_device = null;
- var i = 0;
- var row_index = row_item.get_index ();
+ row.activated.connect (() => {
+ var subpage_gamepad = new PreferencesSubpageGamepad (this_device);
+ back_handler_id = subpage_gamepad.back.connect (on_back);
+ subpage = subpage_gamepad;
+ });
- var iterator = monitor.iterate ();
- while (iterator.next (out other_device)) {
- if (i++ == row_index)
- device = other_device;
+ row.show_all ();
+ gamepads_group.add (row);
+
+ i += 1;
}
- if (device == null)
- return;
+ gamepads_group.visible = i > 0;
+ }
- var subpage_gamepad = new PreferencesSubpageGamepad (device);
- back_handler_id = subpage_gamepad.back.connect (on_back);
- subpage = subpage_gamepad;
+ private void clear_gamepad_list () {
+ gamepads_group.foreach ((child) => child.destroy ());
}
private void build_keyboard_list () {
@@ -74,15 +65,15 @@ private class Games.PreferencesPageControllers : PreferencesPage {
row.title = _("Keyboard");
row.add (new Gtk.Image.from_icon_name ("go-next-symbolic", Gtk.IconSize.BUTTON));
row.activatable = true;
- row.show_all ();
- keyboard_list_box.add (row);
- }
- [GtkCallback]
- private void keyboard_list_box_row_activated (Gtk.ListBoxRow row_item) {
- var subpage_keyboard = new PreferencesSubpageKeyboard ();
- back_handler_id = subpage_keyboard.back.connect (on_back);
- subpage = subpage_keyboard;
+ row.activated.connect (() => {
+ var subpage_keyboard = new PreferencesSubpageKeyboard ();
+ back_handler_id = subpage_keyboard.back.connect (on_back);
+ subpage = subpage_keyboard;
+ });
+
+ row.show_all ();
+ keyboard_group.add (row);
}
private void on_back () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]