[california/wip/725763-google] Deal with initial focus and default widget when changing Cards in Deck
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/725763-google] Deal with initial focus and default widget when changing Cards in Deck
- Date: Fri, 4 Apr 2014 00:08:34 +0000 (UTC)
commit 2dcdd7c9b35b1d82ee1465329637310504026792
Author: Jim Nelson <jim yorba org>
Date: Thu Apr 3 14:57:38 2014 -0700
Deal with initial focus and default widget when changing Cards in Deck
.../activator-google-authenticating-pane.vala | 4 ++
.../activator-google-calendar-list-pane.vala | 4 ++
.../google/activator-google-login-pane.vala | 4 ++
src/util/util-deck.vala | 40 ++++++++++++++++++++
4 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/src/activator/google/activator-google-authenticating-pane.vala
b/src/activator/google/activator-google-authenticating-pane.vala
index 75efcb2..caa9afd 100644
--- a/src/activator/google/activator-google-authenticating-pane.vala
+++ b/src/activator/google/activator-google-authenticating-pane.vala
@@ -30,6 +30,10 @@ public class GoogleAuthenticatingPane : Gtk.Grid, Card {
public string? title { get { return null; } }
+ public Gtk.Widget? default_widget { get { return again_button; } }
+
+ public Gtk.Widget? initial_focus { get { return null; } }
+
[GtkChild]
private Gtk.Spinner spinner;
diff --git a/src/activator/google/activator-google-calendar-list-pane.vala
b/src/activator/google/activator-google-calendar-list-pane.vala
index ea765dc..eceffd0 100644
--- a/src/activator/google/activator-google-calendar-list-pane.vala
+++ b/src/activator/google/activator-google-calendar-list-pane.vala
@@ -28,6 +28,10 @@ public class GoogleCalendarListPane : Gtk.Grid, Card {
public string? title { get { return null; } }
+ public Gtk.Widget? default_widget { get { return subscribe_button; } }
+
+ public Gtk.Widget? initial_focus { get { return null; } }
+
[GtkChild]
private Gtk.ListBox own_calendars_listbox;
diff --git a/src/activator/google/activator-google-login-pane.vala
b/src/activator/google/activator-google-login-pane.vala
index 1968407..877e8f2 100644
--- a/src/activator/google/activator-google-login-pane.vala
+++ b/src/activator/google/activator-google-login-pane.vala
@@ -14,6 +14,10 @@ internal class GoogleLoginPane : Gtk.Grid, Card {
public string? title { get { return null; } }
+ public Gtk.Widget? default_widget { get { return login_button; } }
+
+ public Gtk.Widget? initial_focus { get { return account_entry; } }
+
[GtkChild]
private Gtk.Entry account_entry;
diff --git a/src/util/util-deck.vala b/src/util/util-deck.vala
index bf1f587..89e9610 100644
--- a/src/util/util-deck.vala
+++ b/src/util/util-deck.vala
@@ -28,6 +28,23 @@ public interface Card : Gtk.Widget {
*/
public abstract string? title { get; }
+ /**
+ * The widget the { link Card} wants to be default when navigated to.
+ *
+ * The widget must have can-default set to true.
+ */
+ public abstract Gtk.Widget? default_widget { get; }
+
+ /**
+ * The widget the { link Card} wants to have initial focus when navigated to.
+ *
+ * Focus is set after { link default_widget} is handled, so if this widget has receives-default
+ * set to true, it will get the default as well.
+ *
+ * The widget must have can-focus set to true.
+ */
+ public abstract Gtk.Widget? initial_focus { get; }
+
/**
* Fired when the { link Card} wishes to jump to another Card in the same { link Deck.}
*
@@ -87,6 +104,9 @@ public interface Card : Gtk.Widget {
*
* message may be null even if the Card expects one; generally this means { link jump_back}
* or { link jump_home} was invoked, resulting in this Card being activated.
+ *
+ * This is called before dealing with { link default_widget} and { link initial_focus}, so
+ * changes to those properties in this call, if need be.
*/
public abstract void jumped_to(Card from, Value? message);
}
@@ -123,6 +143,11 @@ public class Deck : Gtk.Stack, Host.Interaction {
notify["visible-child"].connect(on_child_to_top);
}
+ ~Deck() {
+ foreach (Card card in names.values)
+ card.map.disconnect(on_card_mapped);
+ }
+
private void on_child_to_top() {
// disconnect from previous top card and push onto nav stack
if (top != null) {
@@ -177,6 +202,11 @@ public class Deck : Gtk.Stack, Host.Interaction {
names.set(card.card_id, card);
+ // deal with initial_focus and default_widget when mapped, as the calls aren't
+ // guaranteed to work during programmatic navigation (especially for the first card,
+ // i.e. home)
+ card.map.connect(on_card_mapped);
+
// first Card seen is home card
if (home == null)
home = card;
@@ -230,6 +260,16 @@ public class Deck : Gtk.Stack, Host.Interaction {
private void on_completed() {
completed();
}
+
+ private void on_card_mapped(Gtk.Widget widget) {
+ Card card = (Card) widget;
+
+ if (card.default_widget != null && card.default_widget.can_default)
+ card.default_widget.grab_default();
+
+ if (card.initial_focus != null && card.initial_focus.can_focus)
+ card.initial_focus.grab_focus();
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]