[california] Cancel buttons in all dialogs: Closes bgo#725771, bgo#725772



commit 56ed3fb34ee33ab9c909ab702fef695c0dc1abfb
Author: Jim Nelson <jim yorba org>
Date:   Mon Mar 10 15:12:26 2014 -0700

    Cancel buttons in all dialogs: Closes bgo#725771, bgo#725772
    
    This also marks all dialogs with a default button that's activated
    when Enter is pressed.

 src/Makefile.am                        |    1 +
 src/host/host-create-update-event.vala |   11 ++++-
 src/host/host-interaction.vala         |   39 ++++++++++++++
 src/host/host-main-window.vala         |   26 +++++-----
 src/host/host-show-event.vala          |   14 +++++-
 src/rc/create-update-event.ui          |   86 ++++++++++++++++++++++----------
 src/rc/show-event.ui                   |   33 ++++++++++---
 7 files changed, 161 insertions(+), 49 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index fd2c362..afa6a34 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -63,6 +63,7 @@ california_VALASOURCES = \
        host/host.vala \
        host/host-calendar-popup.vala \
        host/host-create-update-event.vala \
+       host/host-interaction.vala \
        host/host-main-window.vala \
        host/host-popup.vala \
        host/host-show-event.vala \
diff --git a/src/host/host-create-update-event.vala b/src/host/host-create-update-event.vala
index 8de92da..4e350d8 100644
--- a/src/host/host-create-update-event.vala
+++ b/src/host/host-create-update-event.vala
@@ -11,13 +11,15 @@ namespace California.Host {
  */
 
 [GtkTemplate (ui = "/org/yorba/california/rc/create-update-event.ui")]
-public class CreateUpdateEvent : Gtk.Grid {
+public class CreateUpdateEvent : Gtk.Grid, Interaction {
     public const string PROP_SELECTED_DATE_SPAN = "selected-date-span";
     
     private const int START_HOUR = 0;
     private const int END_HOUR = 23;
     private const int MIN_DIVISIONS = 15;
     
+    public Gtk.Widget? default_widget { get { return accept_button; } }
+    
     [GtkChild]
     private Gtk.Label title_label;
     
@@ -256,6 +258,13 @@ public class CreateUpdateEvent : Gtk.Grid {
             update_event(original_calendar_source, event);
         else
             create_event(event);
+        
+        dismissed();
+    }
+    
+    [GtkCallback]
+    private void on_cancel_button_clicked() {
+        dismissed();
     }
 }
 
diff --git a/src/host/host-interaction.vala b/src/host/host-interaction.vala
new file mode 100644
index 0000000..cf31c88
--- /dev/null
+++ b/src/host/host-interaction.vala
@@ -0,0 +1,39 @@
+/* Copyright 2014 Yorba Foundation
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later).  See the COPYING file in this distribution.
+ */
+
+namespace California.Host {
+
+/**
+ * A simple entry form or display for the user.
+ *
+ * This abstraction is to handle a couple of problems:
+ *
+ * (a) Because California currently works only with GTK+ 3.10, GtkPopup is unavailable, although
+ * it's a widget we'd like to use soon.  GtkDialog is used in its place, but we don't want to
+ * hard-code GtkDialog throughout the application.  So the Glade components are hosted inside a
+ * GtkDialog, but this poses other subtle problems (such as with activating default).
+ *
+ * (b) Glade, at time of writing, doesn't support GtkPopup anyway, so this layer is even required
+ * for GTK+ 3.12.
+ */
+
+public interface Interaction : Gtk.Widget {
+    /**
+     * Fired when the user has cancelled, closed, or dismissed the { link Interaction}.
+     *
+     * This should be called by implementing classes even if other signals suggest or imply that
+     * the Interaction is dismissed, so a single signal handler can deal with cleanup.
+     */
+    public signal void dismissed();
+    
+    /**
+     * The default widget for the { link Interaction}.
+     */
+    public abstract Gtk.Widget? default_widget { get; }
+}
+
+}
+
diff --git a/src/host/host-main-window.vala b/src/host/host-main-window.vala
index 12b4f10..39adeb1 100644
--- a/src/host/host-main-window.vala
+++ b/src/host/host-main-window.vala
@@ -81,24 +81,28 @@ public class MainWindow : Gtk.ApplicationWindow {
     }
     
     private Gtk.Widget show_interaction(Gtk.Widget relative_to, Gdk.Point? for_location,
-        Gtk.Widget child) {
+        Interaction child) {
         Gtk.Dialog dialog = new Gtk.Dialog();
         dialog.transient_for = this;
         dialog.modal = true;
         ((Gtk.Box) dialog.get_content_area()).pack_start(child, true, true, 0);
         
-        dialog.close.connect(on_interaction_dismissed);
+        // make sure it's closed and cleaned up when all's said and done
+        child.dismissed.connect(() => dialog.destroy());
+        
+        // when the dialog closes, reset View.Controllable state (selection is maintained while
+        // use is viewing/editing Interaction)
+        dialog.close.connect(() => current_view.unselect_all());
         
         dialog.show_all();
         
+        // the default widget is lost in the shuffle, reestablish its primacy
+        if (child.default_widget != null)
+            child.default_widget.grab_default();
+        
         return dialog;
     }
     
-    private void on_interaction_dismissed() {
-        // reset View.Controllable state whenever the interaction is dismissed
-        current_view.unselect_all();
-    }
-    
     private void on_new_event() {
         // create all-day event for today
         Calendar.DateSpan initial = new Calendar.DateSpan(Calendar.System.today, Calendar.System.today);
@@ -129,15 +133,13 @@ public class MainWindow : Gtk.ApplicationWindow {
         else
             create_update_event = new CreateUpdateEvent.update(existing);
         
-        Gtk.Widget interaction = show_interaction(relative_to, for_location, create_update_event);
+        show_interaction(relative_to, for_location, create_update_event);
         
         create_update_event.create_event.connect((event) => {
-            interaction.destroy();
             create_event_async.begin(event, null);
         });
         
         create_update_event.update_event.connect((original_source, event) => {
-            interaction.destroy();
             // TODO: Delete from original source if not the same as the new source
             update_event_async.begin(event, null);
         });
@@ -168,15 +170,13 @@ public class MainWindow : Gtk.ApplicationWindow {
     private void on_request_display_event(Component.Event event, Gtk.Widget relative_to,
         Gdk.Point? for_location) {
         ShowEvent show_event = new ShowEvent(event);
-        Gtk.Widget interaction = show_interaction(relative_to, for_location, show_event);
+        show_interaction(relative_to, for_location, show_event);
         
         show_event.remove_event.connect(() => {
-            interaction.destroy();
             remove_event_async.begin(event, null);
         });
         
         show_event.update_event.connect(() => {
-            interaction.destroy();
             create_event(null, null, event, relative_to, for_location);
         });
     }
diff --git a/src/host/host-show-event.vala b/src/host/host-show-event.vala
index b55c0ac..83dedac 100644
--- a/src/host/host-show-event.vala
+++ b/src/host/host-show-event.vala
@@ -7,7 +7,9 @@
 namespace California.Host {
 
 [GtkTemplate (ui = "/org/yorba/california/rc/show-event.ui")]
-public class ShowEvent : Gtk.Grid {
+public class ShowEvent : Gtk.Grid, Interaction {
+    public Gtk.Widget? default_widget { get { return close_button; } }
+    
     [GtkChild]
     private Gtk.Label text_label;
     
@@ -17,6 +19,9 @@ public class ShowEvent : Gtk.Grid {
     [GtkChild]
     private Gtk.Button remove_button;
     
+    [GtkChild]
+    private Gtk.Button close_button;
+    
     private new Component.Event event;
     
     public signal void remove_event(Component.Event event);
@@ -111,11 +116,18 @@ public class ShowEvent : Gtk.Grid {
     [GtkCallback]
     private void on_remove_button_clicked() {
         remove_event(event);
+        dismissed();
     }
     
     [GtkCallback]
     private void on_update_button_clicked() {
         update_event(event);
+        dismissed();
+    }
+    
+    [GtkCallback]
+    private void on_close_button_clicked() {
+        dismissed();
     }
 }
 
diff --git a/src/rc/create-update-event.ui b/src/rc/create-update-event.ui
index c15d0cd..f267612 100644
--- a/src/rc/create-update-event.ui
+++ b/src/rc/create-update-event.ui
@@ -39,9 +39,11 @@
         <property name="visible">True</property>
         <property name="can_focus">True</property>
         <property name="has_focus">True</property>
+        <property name="is_focus">True</property>
         <property name="max_length">64</property>
         <property name="activates_default">True</property>
         <property name="width_chars">24</property>
+        <property name="caps_lock_warning">False</property>
         <property name="placeholder_text" translatable="yes">Untitled event</property>
       </object>
       <packing>
@@ -74,7 +76,7 @@
             <property name="label">dtstart</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
+            <property name="receives_default">False</property>
             <property name="xalign">0.52999997138977051</property>
             <signal name="clicked" handler="on_date_button_clicked" object="CaliforniaHostCreateUpdateEvent" 
swapped="no"/>
           </object>
@@ -160,31 +162,6 @@
       </packing>
     </child>
     <child>
-      <object class="GtkButton" id="accept_button">
-        <property name="label" translatable="yes">_Create</property>
-        <property name="visible">True</property>
-        <property name="can_focus">True</property>
-        <property name="can_default">True</property>
-        <property name="has_default">True</property>
-        <property name="receives_default">True</property>
-        <property name="halign">end</property>
-        <property name="valign">end</property>
-        <property name="margin_top">8</property>
-        <property name="use_underline">True</property>
-        <property name="xalign">0.56000000238418579</property>
-        <signal name="clicked" handler="on_accept_clicked" object="CaliforniaHostCreateUpdateEvent" 
swapped="no"/>
-        <style>
-          <class name="suggested-action"/>
-        </style>
-      </object>
-      <packing>
-        <property name="left_attach">1</property>
-        <property name="top_attach">5</property>
-        <property name="width">1</property>
-        <property name="height">1</property>
-      </packing>
-    </child>
-    <child>
       <object class="GtkBox" id="calendar_box">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
@@ -222,7 +199,62 @@
       </packing>
     </child>
     <child>
-      <placeholder/>
+      <object class="GtkButtonBox" id="button_box">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">baseline</property>
+        <property name="valign">baseline</property>
+        <property name="margin_top">8</property>
+        <property name="spacing">8</property>
+        <property name="homogeneous">True</property>
+        <property name="baseline_position">bottom</property>
+        <property name="layout_style">end</property>
+        <child>
+          <object class="GtkButton" id="cancel_button">
+            <property name="label" translatable="yes">_Cancel</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="can_default">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_underline">True</property>
+            <property name="image_position">bottom</property>
+            <signal name="clicked" handler="on_cancel_button_clicked" 
object="CaliforniaHostCreateUpdateEvent" swapped="no"/>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton" id="accept_button">
+            <property name="label" translatable="yes">C_reate</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="can_default">True</property>
+            <property name="has_default">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_underline">True</property>
+            <property name="image_position">bottom</property>
+            <signal name="clicked" handler="on_accept_clicked" object="CaliforniaHostCreateUpdateEvent" 
swapped="no"/>
+            <style>
+              <class name="suggested-action"/>
+            </style>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">5</property>
+        <property name="width">2</property>
+        <property name="height">1</property>
+      </packing>
     </child>
     <child>
       <placeholder/>
diff --git a/src/rc/show-event.ui b/src/rc/show-event.ui
index f350c9d..da6c847 100644
--- a/src/rc/show-event.ui
+++ b/src/rc/show-event.ui
@@ -1,8 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.0 -->
+<!-- Generated with glade 3.16.1 -->
 <interface>
   <requires lib="gtk+" version="3.10"/>
-  <!-- interface-license-type gplv2 -->
   <template class="CaliforniaHostShowEvent" parent="GtkGrid">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -46,16 +45,16 @@
             <property name="label" translatable="yes">_Remove</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
+            <property name="receives_default">False</property>
             <property name="use_underline">True</property>
-            <property name="image_position">right</property>
+            <property name="image_position">bottom</property>
             <signal name="clicked" handler="on_remove_button_clicked" object="CaliforniaHostShowEvent" 
swapped="no"/>
             <style>
               <class name="destructive-action"/>
             </style>
           </object>
           <packing>
-            <property name="expand">True</property>
+            <property name="expand">False</property>
             <property name="fill">True</property>
             <property name="position">0</property>
           </packing>
@@ -65,17 +64,37 @@
             <property name="label" translatable="yes">_Update</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
+            <property name="can_default">True</property>
             <property name="receives_default">True</property>
             <property name="use_underline">True</property>
+            <property name="image_position">bottom</property>
             <signal name="clicked" handler="on_update_button_clicked" object="CaliforniaHostShowEvent" 
swapped="no"/>
           </object>
           <packing>
-            <property name="expand">True</property>
+            <property name="expand">False</property>
             <property name="fill">True</property>
-            <property name="pack_type">end</property>
             <property name="position">1</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkButton" id="close_button">
+            <property name="label" translatable="yes">_Close</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="can_default">True</property>
+            <property name="has_default">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_underline">True</property>
+            <property name="image_position">bottom</property>
+            <signal name="clicked" handler="on_close_button_clicked" object="CaliforniaHostShowEvent" 
swapped="no"/>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
       </object>
       <packing>
         <property name="left_attach">0</property>


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