[gnome-shell] main: Use Params for optional parameters to pushModal()



commit c2065cc3e2251785974073f24a87f0a900878b8b
Author: Florian MÃllner <fmuellner gnome org>
Date:   Fri Aug 10 17:54:39 2012 +0200

    main: Use Params for optional parameters to pushModal()
    
    As the number of optional parameters grows, it gets more convenient
    to use Params instead of passing in a lot of undefined/null/0 values.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688202

 js/ui/altTab.js      |    2 +-
 js/ui/main.js        |   22 ++++++++++++----------
 js/ui/modalDialog.js |    4 ++--
 3 files changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/js/ui/altTab.js b/js/ui/altTab.js
index f8fdb00..9d2727e 100644
--- a/js/ui/altTab.js
+++ b/js/ui/altTab.js
@@ -172,7 +172,7 @@ const AltTabPopup = new Lang.Class({
 
         if (!Main.pushModal(this.actor)) {
             // Probably someone else has a pointer grab, try again with keyboard only
-            if (!Main.pushModal(this.actor, global.get_current_time(), Meta.ModalOptions.POINTER_ALREADY_GRABBED)) {
+            if (!Main.pushModal(this.actor, { options: Meta.ModalOptions.POINTER_ALREADY_GRABBED })) {
                 return false;
             }
         }
diff --git a/js/ui/main.js b/js/ui/main.js
index db7698b..cc0587c 100644
--- a/js/ui/main.js
+++ b/js/ui/main.js
@@ -20,6 +20,7 @@ const Keyboard = imports.ui.keyboard;
 const MessageTray = imports.ui.messageTray;
 const Overview = imports.ui.overview;
 const Panel = imports.ui.panel;
+const Params = imports.misc.params;
 const RunDialog = imports.ui.runDialog;
 const Layout = imports.ui.layout;
 const LookingGlass = imports.ui.lookingGlass;
@@ -478,7 +479,7 @@ function isInModalStack(actor) {
 /**
  * pushModal:
  * @actor: #ClutterActor which will be given keyboard focus
- * @timestamp: optional timestamp
+ * @params: optional parameters
  *
  * Ensure we are in a mode where all keyboard and mouse input goes to
  * the stage, and focus @actor. Multiple calls to this function act in
@@ -489,21 +490,22 @@ function isInModalStack(actor) {
  * modal stack returns to this actor, reset the focus to the actor
  * which was focused at the time pushModal() was invoked.
  *
- * @timestamp is optionally used to associate the call with a specific user
- * initiated event.  If not provided then the value of
- * global.get_current_time() is assumed.
+ * @params may be used to provide the following parameters:
+ *  - timestamp: used to associate the call with a specific user initiated
+ *               event.  If not provided then the value of
+ *               global.get_current_time() is assumed.
  *
- * @options: optional Meta.ModalOptions flags to indicate that the
- *           pointer is alrady grabbed
+ *  - options: Meta.ModalOptions flags to indicate that the pointer is
+ *             already grabbed
  *
  * Returns: true iff we successfully acquired a grab or already had one
  */
-function pushModal(actor, timestamp, options) {
-    if (timestamp == undefined)
-        timestamp = global.get_current_time();
+function pushModal(actor, params) {
+    params = Params.parse(params, { timestamp: global.get_current_time(),
+                                    options: 0 });
 
     if (modalCount == 0) {
-        if (!global.begin_modal(timestamp, options ? options : 0)) {
+        if (!global.begin_modal(params.timestamp, params.options)) {
             log('pushModal: invocation of begin_modal failed');
             return false;
         }
diff --git a/js/ui/modalDialog.js b/js/ui/modalDialog.js
index 3045daf..cb0a15f 100644
--- a/js/ui/modalDialog.js
+++ b/js/ui/modalDialog.js
@@ -226,7 +226,7 @@ const ModalDialog = new Lang.Class({
         if (this.state == State.OPENED || this.state == State.OPENING)
             return true;
 
-        if (!this.pushModal(timestamp))
+        if (!this.pushModal({ timestamp: timestamp }))
             return false;
 
         this._fadeOpen(onPrimary);
@@ -276,7 +276,7 @@ const ModalDialog = new Lang.Class({
     pushModal: function (timestamp) {
         if (this._hasModal)
             return true;
-        if (!Main.pushModal(this._group, timestamp))
+        if (!Main.pushModal(this._group, { timestamp: timestamp }))
             return false;
 
         this._hasModal = true;



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