[gnome-weather/wip/gjs-experiments: 5/6] Util: further improve GtkBuilder



commit 988f90dd7e0989ea2356e9229da5ffc640abffad
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sat Mar 9 14:51:11 2013 +0100

    Util: further improve GtkBuilder
    
    Allow embedding small JS snippets directly in GtkBuilder, in the form
    of special signal handlers.

 data/window.ui |    2 ++
 src/util.js    |    8 +++++++-
 src/window.js  |    6 ------
 3 files changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/data/window.ui b/data/window.ui
index ec55e87..b9cbf57 100644
--- a/data/window.ui
+++ b/data/window.ui
@@ -36,6 +36,7 @@
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="symbolic-icon-name">object-select-symbolic</property>
+            <signal name="clicked" handler="javascript:this._worldView.selection_mode = true;"/>
           </object>
           <packing>
             <property name="pack_type">end</property>
@@ -47,6 +48,7 @@
             <property name="no_show_all">True</property>
             <property name="can_focus">False</property>
             <property name="label" translatable="yes">Done</property>
+            <signal name="clicked" handler="javascript:this._worldView.selection_mode = false;"/>
             <style>
               <class name="suggested-action"/>
             </style>
diff --git a/src/util.js b/src/util.js
index c1fc2ab..a7c2128 100644
--- a/src/util.js
+++ b/src/util.js
@@ -34,7 +34,13 @@ function loadUI(resource, scope) {
 
     ui.add_from_resource(resource);
     ui.connect_signals_full(function(builder, object, signal_name, handler_name, connect_object, flags) {
-        let realHandler = scope[handler_name];
+        let realHandler;
+        if (handler_name.substr(0, 11) == 'javascript:') {
+            realHandler = new Function('object', handler_name.substr(11));
+        } else {
+            realHandler = scope[handler_name];
+        }
+
         let handler;
         if (connect_object) {
             if (flags & GObject.ConnectFlags.SWAPPED) {
diff --git a/src/window.js b/src/window.js
index fc49556..53010bc 100644
--- a/src/window.js
+++ b/src/window.js
@@ -141,12 +141,6 @@ const MainWindow = new Lang.Class({
         }));
         this._stack.add(this._worldView);
 
-        select.connect('clicked', Lang.bind(this, function() {
-            this._worldView.selection_mode = true;
-        }));
-        selectDone.connect('clicked', Lang.bind(this, function() {
-            this._worldView.selection_mode = false;
-        }));
         this._worldView.connect('notify::selection-mode', Lang.bind(this, function() {
             let mode = this._worldView.selection_mode;
 


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