[california/wip/725792-quick-add: 1/2] UI and plumbing in place



commit 859798d1c7cec39a82c47725b12e8bcc00f9269d
Author: Jim Nelson <jim yorba org>
Date:   Wed Apr 16 18:39:20 2014 -0700

    UI and plumbing in place

 src/Makefile.am                       |    3 +
 src/base/base-properties.vala         |   31 +++++++++
 src/california-resources.xml          |    3 +
 src/host/host-main-window.vala        |   25 +++----
 src/host/host-quick-create-event.vala |   55 ++++++++++++++++
 src/rc/quick-create-event.ui          |  114 +++++++++++++++++++++++++++++++++
 6 files changed, 217 insertions(+), 14 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index f535a81..f9e3564 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -43,6 +43,7 @@ california_VALASOURCES = \
        backing/eds/backing-eds-store.vala \
        \
        base/base-object.vala \
+       base/base-properties.vala \
        base/base-unit.vala \
        \
        calendar/calendar.vala \
@@ -85,6 +86,7 @@ california_VALASOURCES = \
        host/host-create-update-event.vala \
        host/host-import-calendar.vala \
        host/host-main-window.vala \
+       host/host-quick-create-event.vala \
        host/host-show-event.vala \
        \
        manager/manager.vala \
@@ -131,6 +133,7 @@ california_RC = \
        rc/google-authenticating.ui \
        rc/google-calendar-list.ui \
        rc/google-login.ui \
+       rc/quick-create-event.ui \
        rc/show-event.ui \
        rc/webcal-subscribe.ui \
        $(NULL)
diff --git a/src/base/base-properties.vala b/src/base/base-properties.vala
new file mode 100644
index 0000000..f71a691
--- /dev/null
+++ b/src/base/base-properties.vala
@@ -0,0 +1,31 @@
+/* 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.
+ */
+
+/**
+ * Helper functions for using GObject properties and bindings.
+ */
+
+namespace California.Properties {
+
+public delegate bool ValueToBoolCallback(Value source_value);
+
+/**
+ * Simplified binding transformation of a property of any value to a boolean.
+ *
+ * The transformation is always considered successful.  Use bind_property directly if finer control
+ * is required.
+ */
+public void value_to_bool(Object source, string source_property, Object target, string target_property,
+    BindingFlags flags, ValueToBoolCallback cb) {
+    source.bind_property(source_property, target, target_property, flags, (binding, source, ref target) => {
+        target = cb(source);
+        
+        return true;
+    });
+}
+
+}
+
diff --git a/src/california-resources.xml b/src/california-resources.xml
index 03bb412..9bae540 100644
--- a/src/california-resources.xml
+++ b/src/california-resources.xml
@@ -31,6 +31,9 @@
         <file compressed="true">rc/google-login.ui</file>
     </gresource>
     <gresource prefix="/org/yorba/california">
+        <file compressed="true">rc/quick-create-event.ui</file>
+    </gresource>
+    <gresource prefix="/org/yorba/california">
         <file compressed="false">rc/show-event.ui</file>
     </gresource>
     <gresource prefix="/org/yorba/california">
diff --git a/src/host/host-main-window.vala b/src/host/host-main-window.vala
index 1706122..59cfdad 100644
--- a/src/host/host-main-window.vala
+++ b/src/host/host-main-window.vala
@@ -13,8 +13,8 @@ namespace California.Host {
 public class MainWindow : Gtk.ApplicationWindow {
     private const string PROP_FIRST_OF_WEEK = "first-of-week";
     
-    private const string ACTION_NEW_EVENT = "win.new-event";
-    private const string ACCEL_NEW_EVENT = "<Primary>n";
+    private const string ACTION_QUICK_CREATE_EVENT = "win.quick-create-event";
+    private const string ACCEL_QUICK_CREATE_EVENT = "<Primary>n";
     
     private const string ACTION_JUMP_TO_TODAY = "win.jump-to-today";
     private const string ACCEL_JUMP_TO_TODAY = "<Primary>t";
@@ -26,7 +26,7 @@ public class MainWindow : Gtk.ApplicationWindow {
     private const string ACCEL_PREVIOUS = "<Alt>Left";
     
     private static const ActionEntry[] action_entries = {
-        { "new-event", on_new_event },
+        { "quick-create-event", on_quick_create_event },
         { "jump-to-today", on_jump_to_today },
         { "next", on_next },
         { "previous", on_previous }
@@ -37,6 +37,7 @@ public class MainWindow : Gtk.ApplicationWindow {
     
     private View.Controllable current_view;
     private View.Month.Controllable month_view = new View.Month.Controllable();
+    private Gtk.Button quick_add_button;
     
     public MainWindow(Application app) {
         Object (application: app);
@@ -49,7 +50,7 @@ public class MainWindow : Gtk.ApplicationWindow {
         bool rtl = get_direction() == Gtk.TextDirection.RTL;
         
         add_action_entries(action_entries, this);
-        Application.instance.add_accelerator(ACCEL_NEW_EVENT, ACTION_NEW_EVENT, null);
+        Application.instance.add_accelerator(ACCEL_QUICK_CREATE_EVENT, ACTION_QUICK_CREATE_EVENT, null);
         Application.instance.add_accelerator(ACCEL_JUMP_TO_TODAY, ACTION_JUMP_TO_TODAY, null);
         Application.instance.add_accelerator(rtl ? ACCEL_PREVIOUS : ACCEL_NEXT, ACTION_NEXT, null);
         Application.instance.add_accelerator(rtl ? ACCEL_NEXT : ACCEL_PREVIOUS, ACTION_PREVIOUS, null);
@@ -91,9 +92,9 @@ public class MainWindow : Gtk.ApplicationWindow {
         headerbar.pack_start(today);
         headerbar.pack_start(nav_buttons);
         
-        Gtk.Button new_event = new Gtk.Button.from_icon_name("list-add-symbolic", Gtk.IconSize.MENU);
-        new_event.tooltip_text = _("Create a new event (Ctrl+N)");
-        new_event.set_action_name(ACTION_NEW_EVENT);
+        quick_add_button = new Gtk.Button.from_icon_name("list-add-symbolic", Gtk.IconSize.MENU);
+        quick_add_button.tooltip_text = _("Quick add event (Ctrl+N)");
+        quick_add_button.set_action_name(ACTION_QUICK_CREATE_EVENT);
         
         Gtk.Button calendars = new Gtk.Button.from_icon_name("x-office-calendar-symbolic",
             Gtk.IconSize.MENU);
@@ -101,7 +102,7 @@ public class MainWindow : Gtk.ApplicationWindow {
         calendars.set_action_name(Application.ACTION_CALENDAR_MANAGER);
         
         // pack right-side of window
-        headerbar.pack_end(new_event);
+        headerbar.pack_end(quick_add_button);
         headerbar.pack_end(calendars);
         
         Gtk.Box layout = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
@@ -137,12 +138,8 @@ public class MainWindow : Gtk.ApplicationWindow {
         deck_window.destroy();
     }
     
-    private void on_new_event() {
-        // create all-day event for today
-        Calendar.DateSpan initial = new Calendar.DateSpan(Calendar.System.today, Calendar.System.today);
-        
-        // revert to today's date and use the widget for the popover
-        create_event(null, initial, null, current_view.today(), null);
+    private void on_quick_create_event() {
+        show_deck(quick_add_button, null, iterate<Toolkit.Card>(new QuickCreateEvent()).to_array_list());
     }
     
     private void on_jump_to_today() {
diff --git a/src/host/host-quick-create-event.vala b/src/host/host-quick-create-event.vala
new file mode 100644
index 0000000..d004422
--- /dev/null
+++ b/src/host/host-quick-create-event.vala
@@ -0,0 +1,55 @@
+/* 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 {
+
+[GtkTemplate (ui = "/org/yorba/california/rc/quick-create-event.ui")]
+public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
+    public const string ID = "QuickCreateEvent";
+    
+    public string card_id { get { return ID; } }
+    
+    public string? title { get { return null; } }
+    
+    public Gtk.Widget? default_widget { get { return create_button; } }
+    
+    public Gtk.Widget? initial_focus { get { return details_entry; } }
+    
+    [GtkChild]
+    private Gtk.Entry details_entry;
+    
+    [GtkChild]
+    private Gtk.Button create_button;
+    
+    public QuickCreateEvent() {
+        Properties.value_to_bool(details_entry, "text-length", create_button, "sensitive",
+            BindingFlags.SYNC_CREATE, () => !String.is_empty(details_entry.text));
+    }
+    
+    public void jumped_to(Toolkit.Card? from, Value? message) {
+    }
+    
+    [GtkCallback]
+    private void on_details_entry_icon_release(Gtk.Entry entry, Gtk.EntryIconPosition icon,
+        Gdk.Event event) {
+        if (icon == Gtk.EntryIconPosition.SECONDARY)
+            details_entry.text = "";
+    }
+    
+    [GtkCallback]
+    private void on_cancel_button_clicked() {
+        dismissed(true);
+    }
+    
+    [GtkCallback]
+    private void on_create_button_clicked() {
+        completed();
+        dismissed(true);
+    }
+}
+
+}
+
diff --git a/src/rc/quick-create-event.ui b/src/rc/quick-create-event.ui
new file mode 100644
index 0000000..3dd2983
--- /dev/null
+++ b/src/rc/quick-create-event.ui
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.1 -->
+<interface>
+  <requires lib="gtk+" version="3.10"/>
+  <template class="CaliforniaHostQuickCreateEvent" parent="GtkGrid">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="row_spacing">8</property>
+    <child>
+      <object class="GtkLabel" id="title_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">0</property>
+        <property name="label" translatable="yes">Quick add event:</property>
+        <attributes>
+          <attribute name="weight" value="bold"/>
+        </attributes>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkEntry" id="details_entry">
+        <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="hexpand">True</property>
+        <property name="activates_default">True</property>
+        <property name="width_chars">40</property>
+        <property name="secondary_icon_name">edit-delete-symbolic</property>
+        <signal name="icon-release" handler="on_details_entry_icon_release" 
object="CaliforniaHostQuickCreateEvent" swapped="no"/>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">1</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButtonBox" id="buttonbox1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_top">8</property>
+        <property name="spacing">8</property>
+        <property name="homogeneous">True</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="receives_default">True</property>
+            <property name="use_underline">True</property>
+            <signal name="clicked" handler="on_cancel_button_clicked" 
object="CaliforniaHostQuickCreateEvent" 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="create_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="use_underline">True</property>
+            <signal name="clicked" handler="on_create_button_clicked" 
object="CaliforniaHostQuickCreateEvent" swapped="no"/>
+            <style>
+              <class name="suggested-action"/>
+            </style>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">3</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="example_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">0</property>
+        <property name="label" translatable="yes">Example: Dinner at Tadich Grill 7:30pm tomorrow</property>
+        <attributes>
+          <attribute name="style" value="italic"/>
+        </attributes>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">2</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+  </template>
+</interface>


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