[gnome-shell] Cleanups for runDialog



commit 224538c885441a15602be15f2baa4c162e2133ec
Author: Colin Walters <walters verbum org>
Date:   Mon Aug 3 17:52:45 2009 -0400

    Cleanups for runDialog
    
    Using an internal boolean rather than the visibility property seems
    more reliable to me.  Add a list of internal functions rather than
    an if/else chain, so for example an extension could hook something on.
    
    Delete the javascript evaluator in favor of the upcoming lookingGlass.js.

 js/ui/main.js      |   11 +-----
 js/ui/runDialog.js |   92 ++++++++++++++++++++++------------------------------
 2 files changed, 41 insertions(+), 62 deletions(-)
---
diff --git a/js/ui/main.js b/js/ui/main.js
index cf834c9..f87f289 100644
--- a/js/ui/main.js
+++ b/js/ui/main.js
@@ -51,17 +51,10 @@ function start() {
 
     global.connect('panel-run-dialog', function(panel) {
         // Make sure not more than one run dialog is shown.
-        if (!runDialog) {
+        if (runDialog == null) {
             runDialog = new RunDialog.RunDialog();
-            let endHandler = function() {
-                runDialog.destroy();
-                runDialog = null;
-            };
-            runDialog.connect('run', endHandler);
-            runDialog.connect('cancel', endHandler);
-            if (!runDialog.show())
-                endHandler();
         }
+        runDialog.open();
     });
 
     overlay = new Overlay.Overlay();
diff --git a/js/ui/runDialog.js b/js/ui/runDialog.js
index c55b8d7..2334b5b 100644
--- a/js/ui/runDialog.js
+++ b/js/ui/runDialog.js
@@ -2,6 +2,8 @@
 
 const Big = imports.gi.Big;
 const Clutter = imports.gi.Clutter;
+const Lang = imports.lang;
+const Mainloop = imports.mainloop;
 const Shell = imports.gi.Shell;
 const Signals = imports.signals;
 
@@ -27,6 +29,14 @@ RunDialog.prototype = {
     _init : function() {
         let global = Shell.Global.get();
 
+        this._isOpen = false;
+
+        this._internalCommands = { 'restart': Lang.bind(this, function() {
+                                       let global = Shell.Global.get();
+                                       global.reexec_self();
+                                   })
+                                 };
+
         // All actors are inside _group. We create it initially
         // hidden then show it in show()
         this._group = new Clutter.Group({ visible: false });
@@ -70,35 +80,27 @@ RunDialog.prototype = {
         this._entry.set_position(6, 30);
         boxGroup.add_actor(this._entry);
 
-        let me = this;
-
-        this._entry.connect('activate', function (o, e) {
-            me.hide();
-            me._run(o.get_text());
+        this._entry.connect('activate', Lang.bind(this, function (o, e) {
+            this._run(o.get_text());
+            this._entry.text = '';
+            this.close();
             return false;
-        });
-
+        }));
+        
+        this._entry.connect('key-press-event', Lang.bind(this, function(o, e) {
+            let symbol = Shell.get_event_key_symbol(e); 
+            if (symbol == Clutter.Escape) {
+                this.close();
+                return true;
+            }
+            return false;
+        }));
     },
 
     _run : function(command) {
-        if (command.slice(0, 3) == 'js ') {
-            let commandHeader = "const Clutter = imports.gi.Clutter; " +
-                                 "const GLib = imports.gi.GLib; " +
-                                 "const Gtk = imports.gi.Gtk; " +
-                                 "const Mainloop = imports.mainloop; " +
-                                 "const Meta = imports.gi.Meta; " +
-                                 "const Shell = imports.gi.Shell; " +
-                                 "const Main = imports.ui.main; ";
-            let cmd = commandHeader + command.substring(2);
-            try {
-                let result = eval(cmd);
-                log("" + result);
-            } catch (e) {
-                log(e);
-            }
-        } else if (command == 'restart') {
-            let global = Shell.Global.get();
-            global.reexec_self();
+        let f = this._internalCommands[command];
+        if (f) {
+            f();
         } else if (command) {
             var p = new Shell.Process({'args' : [command]});
             try {
@@ -108,47 +110,31 @@ RunDialog.prototype = {
                 log('Could not run command ' + command + '.');
             }
         }
-
-        this.emit('run');
     },
 
-    show : function() {
-        let me = this;
-
-        if (this._group.visible) // Already shown
-            return false;
+    open : function() {
+        if (this._isOpen) // Already shown
+            return;
 
         if (!Main.startModal())
-            return false;
-
-        this._group.show_all();
-
-        this._entry.connect('key-press-event', function(o, e) {
-            if (Shell.get_event_key_symbol(e) == Clutter.Escape) {
-                me.hide();
-                me.emit('cancel');
-                return true;
-            } else
-                return false;
-        });
+            return;
+            
+        this._isOpen = true;
+        this._group.show();
 
         let global = Shell.Global.get();
         global.stage.set_key_focus(this._entry);
-
-        return true;
     },
 
-    hide : function() {
-        if (!this._group.visible)
+    close : function() {
+        if (!this._isOpen)
             return;
 
+        this._isOpen = false;
+        
         this._group.hide();
-        Main.endModal();
-    },
 
-    destroy : function(){
-        this.hide();
-        this._group.destroy();
+        Main.endModal();
     }
 };
 Signals.addSignalMethods(RunDialog.prototype);



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