[california/wip/732029-gtk-312] Fix some initial focus/default widget issues w/ Gtk.Popover



commit ae032eae62d5a365e4a30d83f4bef1e119d09635
Author: Jim Nelson <jim yorba org>
Date:   Tue Jul 22 17:48:34 2014 -0700

    Fix some initial focus/default widget issues w/ Gtk.Popover

 src/host/host-create-update-event.vala |    2 ++
 src/host/host-show-event.vala          |    3 +++
 src/toolkit/toolkit-card.vala          |    3 +++
 src/toolkit/toolkit-deck-window.vala   |   19 +++++++++++++++++++
 src/toolkit/toolkit-deck.vala          |   31 +++++++++++++++++++++++++------
 5 files changed, 52 insertions(+), 6 deletions(-)
---
diff --git a/src/host/host-create-update-event.vala b/src/host/host-create-update-event.vala
index 3f5b9b0..a3e9206 100644
--- a/src/host/host-create-update-event.vala
+++ b/src/host/host-create-update-event.vala
@@ -115,6 +115,8 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
             calendar_model.add(calendar_source);
         }
         
+        accept_button.can_default = true;
+        accept_button.has_default = true;
         accept_button.get_style_context().add_class("suggested-action");
         
         accept_button.clicked.connect(on_accept_button_clicked);
diff --git a/src/host/host-show-event.vala b/src/host/host-show-event.vala
index e406dd5..275ec49 100644
--- a/src/host/host-show-event.vala
+++ b/src/host/host-show-event.vala
@@ -66,6 +66,9 @@ public class ShowEvent : Gtk.Grid, Toolkit.Card {
         Calendar.System.instance.is_24hr_changed.connect(build_display);
         Calendar.System.instance.today_changed.connect(build_display);
         
+        close_button.can_default = true;
+        close_button.has_default = true;
+        
         remove_button.get_style_context().add_class("destructive-action");
         remove_this_button.get_style_context().add_class("destructive-action");
         remove_this_future_button.get_style_context().add_class("destructive-action");
diff --git a/src/toolkit/toolkit-card.vala b/src/toolkit/toolkit-card.vala
index 8e2daee..eec4c1c 100644
--- a/src/toolkit/toolkit-card.vala
+++ b/src/toolkit/toolkit-card.vala
@@ -66,6 +66,9 @@ public interface Card : Gtk.Widget {
      * set to true, it will get the default as well.
      *
      * The widget must have can-focus set to true.
+     *
+     * TODO: This is no longer necessary with Toolkit.DeckWindow using Gtk.Popover.  This can be
+     * removed in the future when feeling secure about the transition.
      */
     public abstract Gtk.Widget? initial_focus { get; }
     
diff --git a/src/toolkit/toolkit-deck-window.vala b/src/toolkit/toolkit-deck-window.vala
index 80b2d41..25adc40 100644
--- a/src/toolkit/toolkit-deck-window.vala
+++ b/src/toolkit/toolkit-deck-window.vala
@@ -18,9 +18,13 @@ public class DeckWindow : Gtk.Popover {
      */
     public signal void dismiss(bool user_request, bool final);
     
+    private bool preserve_modal;
+    
     public DeckWindow(Gtk.Widget rel_to, Gdk.Point? for_location, Deck? starter_deck) {
         Object (relative_to: rel_to);
         
+        preserve_modal = modal;
+        
         // treat "closed" signal as dismissal by user request
         closed.connect(() => {
             dismiss(true, true);
@@ -34,6 +38,12 @@ public class DeckWindow : Gtk.Popover {
             pointing_to = for_location_rect;
         }
         
+        // because adding/removing cards can cause deep in Gtk.Widget the Popover to lose focus,
+        // those operations can prematurely close the Popover.  Catching these signals allow for
+        // DeckWindow to go modeless during the operation and not close.  (RotatingButtonBox has a
+        // similar issue.)
+        deck.adding_removing_cards.connect(on_adding_removing_cards);
+        deck.added_removed_cards.connect(on_added_removed_cards);
         deck.dismiss.connect(on_deck_dismissed);
         
         // store Deck in box so margin can be applied
@@ -48,6 +58,15 @@ public class DeckWindow : Gtk.Popover {
         deck.dismiss.disconnect(on_deck_dismissed);
     }
     
+    private void on_adding_removing_cards() {
+        preserve_modal = modal;
+        modal = false;
+    }
+    
+    private void on_added_removed_cards() {
+        modal = preserve_modal;
+    }
+    
     private void on_deck_dismissed(bool user_request, bool final) {
         dismiss(user_request, final);
     }
diff --git a/src/toolkit/toolkit-deck.vala b/src/toolkit/toolkit-deck.vala
index 6592690..c640b7b 100644
--- a/src/toolkit/toolkit-deck.vala
+++ b/src/toolkit/toolkit-deck.vala
@@ -44,6 +44,16 @@ public class Deck : Gtk.Stack {
     private Gee.HashMap<string, Card> names = new Gee.HashMap<string, Card>();
     
     /**
+     * Fired before { link Card}s are added or removed.
+     */
+    public signal void adding_removing_cards(Gee.List<Card>? adding, Gee.Collection<Card>? removing);
+    
+    /**
+     * Fired after { link Card}s are added or removed.
+     */
+    public signal void added_removed_cards(Gee.List<Card>? added, Gee.Collection<Card>? removed);
+    
+    /**
      * @see Card.dismiss
      */
     public signal void dismiss(bool user_request, bool final);
@@ -124,6 +134,8 @@ public class Deck : Gtk.Stack {
         if (cards.size == 0)
             return;
         
+        adding_removing_cards(cards, null);
+        
         // if empty, first card is home and should be made visible when added
         bool set_home_visible = size == 0;
         
@@ -153,6 +165,8 @@ public class Deck : Gtk.Stack {
             set_visible_child(home);
             home.jumped_to(null, Card.Jump.HOME, null);
         }
+        
+        added_removed_cards(cards, null);
     }
     
     /**
@@ -161,9 +175,11 @@ public class Deck : Gtk.Stack {
      * If the { link top} card is removed, the Deck will return { link home}, clearing the
      * navigation stack in the process.
      */
-    public void remove_cards(Gee.Iterable<Card> cards) {
+    public void remove_cards(Gee.Collection<Card> cards) {
         bool displaying = top != null;
         
+        adding_removing_cards(null, cards);
+        
         foreach (Card card in cards) {
             if (!names.has_key(card.card_id)) {
                 message("Card %s not found in Deck", card.card_id);
@@ -189,6 +205,8 @@ public class Deck : Gtk.Stack {
             set_visible_child(home);
             home.jumped_to(null, Card.Jump.HOME, null);
         }
+        
+        added_removed_cards(null, cards);
     }
     
     private Value? strip_null_value(Value? message) {
@@ -288,11 +306,12 @@ public class Deck : Gtk.Stack {
     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();
+        if (card.default_widget != null) {
+            if (card.default_widget.can_default)
+                card.default_widget.grab_default();
+            else
+                message("Card %s specifies default widget that cannot be default", card.card_id);
+        }
     }
 }
 


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