[california] Display "read-only" icon in Calendar Manager
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california] Display "read-only" icon in Calendar Manager
- Date: Tue, 29 Apr 2014 02:22:05 +0000 (UTC)
commit c17c5529771f071a0fc25d982649c95b554c38bc
Author: Jim Nelson <jim yorba org>
Date: Mon Apr 28 19:21:17 2014 -0700
Display "read-only" icon in Calendar Manager
Something I've thought of doing in the past, but bug #729111 made
me decide it was worth doing.
src/base/base-properties.vala | 29 ++++++++++++-
src/host/host-quick-create-event.vala | 4 +-
src/manager/manager-calendar-list-item.vala | 13 +++++-
src/rc/calendar-manager-list-item.ui | 59 +++++++++++++++++---------
4 files changed, 76 insertions(+), 29 deletions(-)
---
diff --git a/src/base/base-properties.vala b/src/base/base-properties.vala
index f71a691..edfa006 100644
--- a/src/base/base-properties.vala
+++ b/src/base/base-properties.vala
@@ -10,7 +10,15 @@
namespace California.Properties {
-public delegate bool ValueToBoolCallback(Value source_value);
+/**
+ * Transformation callback used by { link xform_to_bool}.
+ */
+public delegate bool BoolTransformer(Value source_value);
+
+/**
+ * Transformation callback used by { link xform_to_string}.
+ */
+public delegate string? StringTransformer(Value source_value);
/**
* Simplified binding transformation of a property of any value to a boolean.
@@ -18,8 +26,23 @@ public delegate bool ValueToBoolCallback(Value source_value);
* 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) {
+public void xform_to_bool(Object source, string source_property, Object target, string target_property,
+ BoolTransformer cb, BindingFlags flags = BindingFlags.SYNC_CREATE) {
+ source.bind_property(source_property, target, target_property, flags, (binding, source, ref target) => {
+ target = cb(source);
+
+ return true;
+ });
+}
+
+/**
+ * Simplified binding transformation of a property of any value to a nullable string.
+ *
+ * The transformation is always considered successful. Use bind_property directly if finer control
+ * is required.
+ */
+public void xform_to_string(Object source, string source_property, Object target, string target_property,
+ StringTransformer cb, BindingFlags flags = BindingFlags.SYNC_CREATE) {
source.bind_property(source_property, target, target_property, flags, (binding, source, ref target) => {
target = cb(source);
diff --git a/src/host/host-quick-create-event.vala b/src/host/host-quick-create-event.vala
index c271b51..635f056 100644
--- a/src/host/host-quick-create-event.vala
+++ b/src/host/host-quick-create-event.vala
@@ -44,8 +44,8 @@ public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
// make first item active
calendar_combo_box.active = 0;
- Properties.value_to_bool(details_entry, "text-length", create_button, "sensitive",
- BindingFlags.SYNC_CREATE, () => !String.is_empty(details_entry.text));
+ Properties.xform_to_bool(details_entry, "text-length", create_button, "sensitive",
+ () => !String.is_empty(details_entry.text));
}
public void jumped_to(Toolkit.Card? from, Value? message) {
diff --git a/src/manager/manager-calendar-list-item.vala b/src/manager/manager-calendar-list-item.vala
index 917385a..977453d 100644
--- a/src/manager/manager-calendar-list-item.vala
+++ b/src/manager/manager-calendar-list-item.vala
@@ -17,6 +17,9 @@ public class CalendarListItem : Gtk.Grid {
public Backing.CalendarSource source { get; private set; }
[GtkChild]
+ private Gtk.Image readonly_icon;
+
+ [GtkChild]
private Gtk.CheckButton visible_check_button;
[GtkChild]
@@ -35,7 +38,11 @@ public class CalendarListItem : Gtk.Grid {
source.bind_property(Backing.Source.PROP_VISIBLE, visible_check_button, "active",
BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
source.bind_property(Backing.Source.PROP_COLOR, color_button, "rgba",
- BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL, source_to_button, button_to_source);
+ BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL, source_to_color, color_to_source);
+ Properties.xform_to_string(source, Backing.Source.PROP_READONLY, readonly_icon, "icon-name",
+ () => source.read_only ? "changes-prevent-symbolic" : "");
+ Properties.xform_to_string(source, Backing.Source.PROP_READONLY, readonly_icon, "tooltip-text",
+ () => source.read_only ? _("Calendar is read-only") : null);
}
public override bool query_tooltip(int x, int y, bool keyboard_mode, Gtk.Tooltip tooltip) {
@@ -48,14 +55,14 @@ public class CalendarListItem : Gtk.Grid {
return true;
}
- public bool source_to_button(Binding binding, Value source_value, ref Value target_value) {
+ private bool source_to_color(Binding binding, Value source_value, ref Value target_value) {
bool used_default;
target_value = Gfx.rgb_string_to_rgba(source.color, Gfx.RGBA_BLACK, out used_default);
return !used_default;
}
- public bool button_to_source(Binding binding, Value source_value, ref Value target_value) {
+ private bool color_to_source(Binding binding, Value source_value, ref Value target_value) {
target_value = Gfx.rgb_to_uint8_rgb_string(Gfx.rgba_to_rgb(color_button.rgba));
return true;
diff --git a/src/rc/calendar-manager-list-item.ui b/src/rc/calendar-manager-list-item.ui
index a636784..2b756cf 100644
--- a/src/rc/calendar-manager-list-item.ui
+++ b/src/rc/calendar-manager-list-item.ui
@@ -7,26 +7,6 @@
<property name="can_focus">False</property>
<property name="column_spacing">4</property>
<child>
- <object class="GtkCheckButton" id="visible_check_button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="halign">start</property>
- <property name="valign">center</property>
- <property name="xalign">0.50999999046325684</property>
- <property name="draw_indicator">True</property>
- <child>
- <placeholder/>
- </child>
- </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="GtkLabel" id="title_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -40,7 +20,7 @@
<property name="single_line_mode">True</property>
</object>
<packing>
- <property name="left_attach">2</property>
+ <property name="left_attach">3</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
@@ -56,11 +36,48 @@
<property name="title" translatable="yes">Calendar color</property>
</object>
<packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="visible_check_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="halign">start</property>
+ <property name="valign">center</property>
+ <property name="xalign">0.50999999046325684</property>
+ <property name="draw_indicator">True</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkImage" id="readonly_icon">
+ <property name="width_request">16</property>
+ <property name="height_request">16</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="icon_size">1</property>
+ </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>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]