[california/wip/727120-webcal] Activator list to choose what kind of calendar to add
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/727120-webcal] Activator list to choose what kind of calendar to add
- Date: Fri, 28 Mar 2014 00:57:48 +0000 (UTC)
commit 75d6a9052b25b3aaace1744ba25f66025962f66d
Author: Jim Nelson <jim yorba org>
Date: Thu Mar 27 16:01:29 2014 -0700
Activator list to choose what kind of calendar to add
src/Makefile.am | 2 +
src/application/california-application.vala | 11 +++-
src/backing/backing-manager.vala | 14 +++--
src/backing/backing.vala | 2 +-
src/california-resources.xml | 3 +
src/host/host-activator-list.vala | 58 +++++++++++++++
src/rc/activator-list.ui | 105 +++++++++++++++++++++++++++
src/rc/app-menu.interface | 3 +-
8 files changed, 189 insertions(+), 9 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index b8ee931..93d896c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -66,6 +66,7 @@ california_VALASOURCES = \
component/component-vtype.vala \
\
host/host.vala \
+ host/host-activator-list.vala \
host/host-calendar-popup.vala \
host/host-color-chooser-popup.vala \
host/host-create-update-event.vala \
@@ -100,6 +101,7 @@ california_SOURCES = \
$(NULL)
california_RC = \
+ rc/activator-list.ui \
rc/app-menu.interface \
rc/calendar-manager-list.ui \
rc/calendar-manager-list-item.ui \
diff --git a/src/application/california-application.vala b/src/application/california-application.vala
index a92a8d2..13e9924 100644
--- a/src/application/california-application.vala
+++ b/src/application/california-application.vala
@@ -133,7 +133,16 @@ public class Application : Gtk.Application {
private void on_new_calendar() {
Host.ModalWindow modal = new Host.ModalWindow(main_window);
- modal.content_area.add(Backing.Manager.instance.primary_activator.create_interaction(null));
+ Host.ActivatorList list = new Host.ActivatorList();
+ modal.content_area.add(list);
+
+ // when a Backing.Activator is selected from the list, swap out the list for the
+ // Activator's own interaction
+ list.selected.connect(activator => {
+ modal.content_area.remove(list);
+ modal.content_area.add(activator.create_interaction(null));
+ });
+
modal.run();
modal.destroy();
}
diff --git a/src/backing/backing-manager.vala b/src/backing/backing-manager.vala
index 8a7929f..b54a3be 100644
--- a/src/backing/backing-manager.vala
+++ b/src/backing/backing-manager.vala
@@ -17,8 +17,6 @@ public class Manager : BaseObject {
public bool is_open { get; private set; default = false; }
- public Activator primary_activator { get; private set; }
-
private Gee.List<Store> stores = new Gee.ArrayList<Store>();
private Gee.List<Activator> activators = new Gee.ArrayList<Activator>();
@@ -60,9 +58,6 @@ public class Manager : BaseObject {
internal void register_activator(Activator activator) {
if (!activators.contains(activator))
activators.add(activator);
-
- if (primary_activator == null)
- primary_activator = activator;
}
/**
@@ -121,6 +116,15 @@ public class Manager : BaseObject {
}
/**
+ * Returns a read-only list of all available { link Activator}s.
+ *
+ * Must only be called wheil the { link Manager} is open.
+ */
+ public Gee.List<Activator> get_activators() {
+ return activators.read_only_view;
+ }
+
+ /**
* Returns a read-only list of all available { link Store}s.
*
* Must only be called while the { link Manager} is open.
diff --git a/src/backing/backing.vala b/src/backing/backing.vala
index acb3c2d..14f833e 100644
--- a/src/backing/backing.vala
+++ b/src/backing/backing.vala
@@ -42,7 +42,7 @@ public void init() throws Error {
// Register all Stores and Activators here
EdsStore eds_store = new EdsStore();
Manager.instance.register_store(eds_store);
- Manager.instance.register_activator(new WebCalActivator(_("Web Calendar"), eds_store));
+ Manager.instance.register_activator(new WebCalActivator(_("Web calendar (.ics)"), eds_store));
// open Manager, pumping event loop until it completes (possibly w/ error)
Manager.instance.open_async.begin(null, on_backing_manager_opened);
diff --git a/src/california-resources.xml b/src/california-resources.xml
index 41751b3..9635cc3 100644
--- a/src/california-resources.xml
+++ b/src/california-resources.xml
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/yorba/california">
+ <file compressed="true">rc/activator-list.ui</file>
+ </gresource>
+ <gresource prefix="/org/yorba/california">
<file compressed="true">rc/app-menu.interface</file>
</gresource>
<gresource prefix="/org/yorba/california">
diff --git a/src/host/host-activator-list.vala b/src/host/host-activator-list.vala
new file mode 100644
index 0000000..85ed143
--- /dev/null
+++ b/src/host/host-activator-list.vala
@@ -0,0 +1,58 @@
+/* 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/activator-list.ui")]
+public class ActivatorList : Gtk.Grid, Host.Interaction {
+ private class ActivatorListItem : Gtk.Label {
+ public Backing.Activator activator;
+
+ public ActivatorListItem(Backing.Activator activator) {
+ this.activator = activator;
+
+ label = activator.title;
+ xalign = 0.0f;
+ margin = 4;
+ }
+ }
+
+ public Gtk.Widget? default_widget { get { return add_button; } }
+
+ [GtkChild]
+ private Gtk.ListBox listbox;
+
+ [GtkChild]
+ private Gtk.Button add_button;
+
+ public signal void selected(Backing.Activator activator);
+
+ public ActivatorList() {
+ foreach (Backing.Activator activator in Backing.Manager.instance.get_activators())
+ listbox.add(new ActivatorListItem(activator));
+
+ show_all();
+ }
+
+ [GtkCallback]
+ private void on_listbox_row_activated(Gtk.ListBoxRow? row) {
+ if (row != null)
+ selected(((ActivatorListItem) row.get_child()).activator);
+ }
+
+ [GtkCallback]
+ private void on_add_button_clicked() {
+ on_listbox_row_activated(listbox.get_selected_row());
+ }
+
+ [GtkCallback]
+ private void on_cancel_button_clicked() {
+ dismissed(true);
+ }
+}
+
+}
+
diff --git a/src/rc/activator-list.ui b/src/rc/activator-list.ui
new file mode 100644
index 0000000..a6d6f71
--- /dev/null
+++ b/src/rc/activator-list.ui
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.1 -->
+<interface>
+ <requires lib="gtk+" version="3.10"/>
+ <template class="CaliforniaHostActivatorList" parent="GtkGrid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="row_spacing">8</property>
+ <child>
+ <object class="GtkButtonBox" id="button_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</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="receives_default">True</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="on_cancel_button_clicked" object="CaliforniaHostActivatorList"
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="add_button">
+ <property name="label" translatable="yes">_Add</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_add_button_clicked" object="CaliforniaHostActivatorList"
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">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkViewport" id="viewport">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <child>
+ <object class="GtkListBox" id="listbox">
+ <property name="width_request">300</property>
+ <property name="height_request">200</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="activate_on_single_click">False</property>
+ <signal name="row-activated" handler="on_listbox_row_activated"
object="CaliforniaHostActivatorList" swapped="no"/>
+ </object>
+ </child>
+ </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="GtkLabel" id="title_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_bottom">8</property>
+ <property name="label" translatable="yes">Add Calendar</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>
+ </template>
+</interface>
diff --git a/src/rc/app-menu.interface b/src/rc/app-menu.interface
index d607e13..c71aa40 100644
--- a/src/rc/app-menu.interface
+++ b/src/rc/app-menu.interface
@@ -3,9 +3,8 @@
<menu id="app-menu">
<section>
<item>
- <attribute name="label" translatable="yes">_Add a new calendar...</attribute>
+ <attribute name="label" translatable="yes">_Add calendar...</attribute>
<attribute name="action">app.new-calendar</attribute>
- <attribute name="accel"><Primary>n</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Calendars</attribute>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]