[gnome-maps/wip/gtk-builder: 3/4] Util: add getUIObject



commit 3282a0f2e83e2764b12962715173d14db623e75b
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Mon Jun 17 18:23:07 2013 +0200

    Util: add getUIObject
    
    Add getUIObject, a helper function for working with GtkBuilder.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=702657

 src/utils.js |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
---
diff --git a/src/utils.js b/src/utils.js
index ccd0a29..09df902 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -137,3 +137,19 @@ function CreateActorFromImageFile(path) {
         return null;
     }
 }
+
+function dashedToCamelCase(name) {
+    return name.replace(/(-.)/g, function(x) {
+        return x[1].toUpperCase();
+    });
+}
+
+function getUIObject(res, ids) {
+    let builder = new Gtk.Builder();
+    builder.add_from_resource('/org/gnome/maps/' + res + '.ui');
+    let ret = {};
+    ids.forEach(function(id) {
+        ret[dashedToCamelCase(id)] = builder.get_object(id);
+    });
+    return ret;
+}


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