[california] Show color sample next to calendar name in dropdowns: Bug #734562
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california] Show color sample next to calendar name in dropdowns: Bug #734562
- Date: Thu, 21 Aug 2014 23:05:38 +0000 (UTC)
commit 6bdba1708db9715df5bce88a28fd766e2bf46be4
Author: Jim Nelson <jim yorba org>
Date: Thu Aug 21 16:03:47 2014 -0700
Show color sample next to calendar name in dropdowns: Bug #734562
Displays a color circle in all GtkComboBoxText widgets holding the
calendar list.
src/host/host-create-update-event.vala | 10 +--------
src/host/host-quick-create-event.vala | 9 +-------
src/host/host.vala | 27 +++++++++++++++++++++++++
src/toolkit/toolkit-combo-box-text-model.vala | 18 ++++++++++++++++
4 files changed, 47 insertions(+), 17 deletions(-)
---
diff --git a/src/host/host-create-update-event.vala b/src/host/host-create-update-event.vala
index dc927d7..5320792 100644
--- a/src/host/host-create-update-event.vala
+++ b/src/host/host-create-update-event.vala
@@ -76,15 +76,7 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
clear_text_connector.connect_to(location_entry);
// use model to control calendars combo box
- calendar_model = new Toolkit.ComboBoxTextModel<Backing.CalendarSource>(calendar_combo,
- (cal) => cal.title);
- foreach (Backing.CalendarSource calendar_source in
- Backing.Manager.instance.get_sources_of_type<Backing.CalendarSource>()) {
- if (!calendar_source.visible || calendar_source.read_only)
- continue;
-
- calendar_model.add(calendar_source);
- }
+ calendar_model = build_calendar_source_combo_model(calendar_combo);
accept_button.can_default = true;
accept_button.has_default = true;
diff --git a/src/host/host-quick-create-event.vala b/src/host/host-quick-create-event.vala
index a721dda..eec35e9 100644
--- a/src/host/host-quick-create-event.vala
+++ b/src/host/host-quick-create-event.vala
@@ -47,14 +47,7 @@ public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
private Toolkit.EntryClearTextConnector clear_text_connector = new Toolkit.EntryClearTextConnector();
public QuickCreateEvent() {
- // create and initialize combo box model
- model = new Toolkit.ComboBoxTextModel<Backing.CalendarSource>(calendar_combo_box,
- (cal) => cal.title);
- foreach (Backing.CalendarSource calendar_source in
- Backing.Manager.instance.get_sources_of_type<Backing.CalendarSource>()) {
- if (calendar_source.visible && !calendar_source.read_only)
- model.add(calendar_source);
- }
+ model = build_calendar_source_combo_model(calendar_combo_box);
clear_text_connector.connect_to(details_entry);
details_entry.bind_property("text", create_button, "sensitive", BindingFlags.SYNC_CREATE,
diff --git a/src/host/host.vala b/src/host/host.vala
index c11f7ba..7f5758c 100644
--- a/src/host/host.vala
+++ b/src/host/host.vala
@@ -35,5 +35,32 @@ public void terminate() {
Toolkit.terminate();
}
+private Toolkit.ComboBoxTextModel<Backing.CalendarSource> build_calendar_source_combo_model(
+ Gtk.ComboBoxText combo, bool include_invisible = false, bool include_read_only = false) {
+ Toolkit.ComboBoxTextModel<Backing.CalendarSource> model = new
Toolkit.ComboBoxTextModel<Backing.CalendarSource>(
+ combo, (calendar) => {
+ // Use Pango to display a colored circle next to the calendar title
+ return "<span color='%s'>●</span> %s".printf(calendar.color, calendar.title);
+ });
+
+ // returning Pango markup in model presentation
+ model.is_markup = true;
+
+ // initialize with current list of calendars ... this control does not auto-update as
+ // calendars are added/removed/modified
+ foreach (Backing.CalendarSource calendar_source in
+ Backing.Manager.instance.get_sources_of_type<Backing.CalendarSource>()) {
+ if (!include_invisible && !calendar_source.visible)
+ continue;
+
+ if (!include_read_only && calendar_source.read_only)
+ continue;
+
+ model.add(calendar_source);
+ }
+
+ return model;
+}
+
}
diff --git a/src/toolkit/toolkit-combo-box-text-model.vala b/src/toolkit/toolkit-combo-box-text-model.vala
index a317ca6..dc556cb 100644
--- a/src/toolkit/toolkit-combo-box-text-model.vala
+++ b/src/toolkit/toolkit-combo-box-text-model.vala
@@ -12,6 +12,7 @@ namespace California.Toolkit {
public class ComboBoxTextModel<G> : BaseObject {
public const string PROP_ACTIVE = "active";
+ public const string PROP_IS_MARKUP = "is-markup";
/**
* Returns a string that is the representation of the item in the Gtk.ComboBoxText.
@@ -25,6 +26,11 @@ public class ComboBoxTextModel<G> : BaseObject {
*/
public G? active { get; private set; }
+ /**
+ * Set to true if the { link ModelPresentation} returns Pango markup instead of plain text.
+ */
+ public bool is_markup { get; set; default = false; }
+
private unowned ModelPresentation<G> model_presentation;
private unowned CompareDataFunc<G>? comparator;
private unowned Gee.HashDataFunc<G> hash_func;
@@ -44,6 +50,8 @@ public class ComboBoxTextModel<G> : BaseObject {
items = new Gee.ArrayList<G>(item_equal_func);
indices = new Gee.HashMap<G, int>(item_hash_func, item_equal_func);
+ notify[PROP_IS_MARKUP].connect(on_is_markup_changed);
+
combo_box.notify["active"].connect(on_combo_box_active);
}
@@ -72,6 +80,16 @@ public class ComboBoxTextModel<G> : BaseObject {
return Gee.Functions.get_hash_func_for(typeof(G))(item);
}
+ private void on_is_markup_changed() {
+ // this relies pretty heavily on the implementation of GtkComboBoxText and could break
+ // if their cell renderer/tree model changes
+ List<weak Gtk.CellRenderer> list = combo_box.get_cells();
+ if (list.data != null)
+ combo_box.set_attributes(list.data, is_markup ? "markup" : "text", 0);
+ else
+ message("Unable to use Pango markup in GtkComboBoxText");
+ }
+
/**
* Add an item to the model and the Gtk.ComboBoxText.
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]