[geary/wip/714104-refine-account-dialog] fixup enum work
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/714104-refine-account-dialog] fixup enum work
- Date: Wed, 12 Sep 2018 11:54:51 +0000 (UTC)
commit 287eae59cf781016b1196a3c435fd0581775f785
Author: Michael James Gratton <mike vee net>
Date: Wed Sep 5 23:36:47 2018 +1000
fixup enum work
src/engine/util/util-object.vala | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
---
diff --git a/src/engine/util/util-object.vala b/src/engine/util/util-object.vala
index b124d9eb..e47aa5a3 100644
--- a/src/engine/util/util-object.vala
+++ b/src/engine/util/util-object.vala
@@ -42,5 +42,22 @@ public void unmirror_properties(Gee.List<Binding> bindings) {
bindings.clear();
}
+/** Convenience method for getting an enum value's nick name. */
+internal string to_enum_nick<E>(GLib.Type type, E value) {
+ GLib.EnumClass enum_type = (GLib.EnumClass) type.class_ref();
+ return enum_type.get_value((int) value).value_nick;
}
+/** Convenience method for getting an enum value's from its nick name. */
+internal E from_enum_nick<E>(GLib.Type type, string nick) throws EngineError {
+ GLib.EnumClass enum_type = (GLib.EnumClass) type.class_ref();
+ unowned GLib.EnumValue? e_value = enum_type.get_value_by_nick(nick);
+ if (e_value == null) {
+ throw new EngineError.BAD_PARAMETERS(
+ "Unknown %s enum value: %s", typeof(E).name(), nick
+ );
+ }
+ return (E) e_value.value;
+}
+
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]