[gnome-shell] Resolve cyclic dependency on StatusMenu



commit 5a7201ef4dda7cc2bd3a31ca0dd10767e2f576e0
Author: Giovanni Campagna <scampa giovanni gmail com>
Date:   Tue Jun 22 23:02:26 2010 +0200

    Resolve cyclic dependency on StatusMenu
    
    Solved by splitting the base class (PanelMenuButton) in a separate
    module, ui.panelMenu, which is meant to hold also other reusable
    button classes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=621705

 js/ui/Makefile.am   |    1 +
 js/ui/panel.js      |   45 ++++++---------------------------------------
 js/ui/panelMenu.js  |   38 ++++++++++++++++++++++++++++++++++++++
 js/ui/statusMenu.js |    5 +++--
 4 files changed, 48 insertions(+), 41 deletions(-)
---
diff --git a/js/ui/Makefile.am b/js/ui/Makefile.am
index 9dcd24e..b9b2241 100644
--- a/js/ui/Makefile.am
+++ b/js/ui/Makefile.am
@@ -23,6 +23,7 @@ dist_jsui_DATA =		\
 	notificationDaemon.js   \
 	overview.js		\
 	panel.js		\
+	panelMenu.js		\
 	placeDisplay.js		\
 	popupMenu.js		\
 	runDialog.js		\
diff --git a/js/ui/panel.js b/js/ui/panel.js
index 901d6ed..dbb7ddf 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -21,6 +21,8 @@ const BoxPointer = imports.ui.boxpointer;
 const Calendar = imports.ui.calendar;
 const Overview = imports.ui.overview;
 const PopupMenu = imports.ui.popupMenu;
+const PanelMenu = imports.ui.panelMenu;
+const StatusMenu = imports.ui.statusMenu;
 const Main = imports.ui.main;
 const Tweener = imports.ui.tweener;
 
@@ -176,38 +178,6 @@ TextShadower.prototype = {
     }
 };
 
-function PanelMenuButton(menuAlignment) {
-    this._init(menuAlignment);
-}
-
-PanelMenuButton.prototype = {
-    _init: function(menuAlignment) {
-        this.actor = new St.Bin({ style_class: 'panel-button',
-                                  reactive: true,
-                                  x_fill: true,
-                                  y_fill: false,
-                                  track_hover: true });
-        this.actor._delegate = this;
-        this.actor.connect('button-press-event', Lang.bind(this, this._onButtonPress));
-        this.menu = new PopupMenu.PopupMenu(this.actor, menuAlignment, St.Side.TOP, /* FIXME */ 0);
-        this.menu.connect('open-state-changed', Lang.bind(this, this._onOpenStateChanged));
-        Main.chrome.addActor(this.menu.actor, { visibleInOverview: true,
-                                                affectsStruts: false });
-        this.menu.actor.hide();
-    },
-
-    _onButtonPress: function(actor, event) {
-        this.menu.toggle();
-    },
-
-    _onOpenStateChanged: function(menu, open) {
-        if (open)
-            this.actor.add_style_pseudo_class('pressed');
-        else
-            this.actor.remove_style_pseudo_class('pressed');
-    }
-};
-
 /**
  * AppMenuButton:
  *
@@ -221,10 +191,10 @@ function AppMenuButton() {
 }
 
 AppMenuButton.prototype = {
-    __proto__: PanelMenuButton.prototype,
+    __proto__: PanelMenu.Button.prototype,
 
     _init: function() {
-        PanelMenuButton.prototype._init.call(this, St.Align.START);
+        PanelMenu.Button.prototype._init.call(this, St.Align.START);
         this._metaDisplay = global.screen.get_display();
 
         this._focusedApp = null;
@@ -510,10 +480,10 @@ function ClockButton() {
 }
 
 ClockButton.prototype = {
-    __proto__: PanelMenuButton.prototype,
+    __proto__: PanelMenu.Button.prototype,
 
     _init: function() {
-        PanelMenuButton.prototype._init.call(this, St.Align.START);
+        PanelMenu.Button.prototype._init.call(this, St.Align.START);
         this.menu.addAction(_("Preferences"), Lang.bind(this, this._onPrefs));
 
         this._clock = new St.Label();
@@ -847,9 +817,6 @@ Panel.prototype = {
             }));
         this._traymanager.manage_stage(global.stage);
 
-        // We need to do this here to avoid a circular import with
-        // prototype dependencies.
-        let StatusMenu = imports.ui.statusMenu;
         this._statusmenu = new StatusMenu.StatusMenuButton();
         this._menus.addMenu(this._statusmenu.menu);
         this._rightBox.add(this._statusmenu.actor);
diff --git a/js/ui/panelMenu.js b/js/ui/panelMenu.js
new file mode 100644
index 0000000..b4c601f
--- /dev/null
+++ b/js/ui/panelMenu.js
@@ -0,0 +1,38 @@
+/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
+
+const St = imports.gi.St;
+const Lang = imports.lang;
+const PopupMenu = imports.ui.popupMenu;
+const Main = imports.ui.main;
+
+function Button(menuAlignment) {
+    this._init(menuAlignment);
+}
+
+Button.prototype = {
+    _init: function(menuAlignment) {
+        this.actor = new St.Bin({ style_class: 'panel-button',
+                                  reactive: true,
+                                  x_fill: true,
+                                  y_fill: false,
+                                  track_hover: true });
+        this.actor._delegate = this;
+        this.actor.connect('button-press-event', Lang.bind(this, this._onButtonPress));
+        this.menu = new PopupMenu.PopupMenu(this.actor, menuAlignment, St.Side.TOP, /* FIXME */ 0);
+        this.menu.connect('open-state-changed', Lang.bind(this, this._onOpenStateChanged));
+        Main.chrome.addActor(this.menu.actor, { visibleInOverview: true,
+                                                affectsStruts: false });
+        this.menu.actor.hide();
+    },
+
+    _onButtonPress: function(actor, event) {
+        this.menu.toggle();
+    },
+
+    _onOpenStateChanged: function(menu, open) {
+        if (open)
+            this.actor.add_style_pseudo_class('pressed');
+        else
+            this.actor.remove_style_pseudo_class('pressed');
+    }
+};
\ No newline at end of file
diff --git a/js/ui/statusMenu.js b/js/ui/statusMenu.js
index 40d97be..ce13555 100644
--- a/js/ui/statusMenu.js
+++ b/js/ui/statusMenu.js
@@ -11,6 +11,7 @@ const _ = Gettext.gettext;
 const GnomeSession = imports.misc.gnomeSession;
 const Main = imports.ui.main;
 const Panel = imports.ui.panel;
+const PanelMenu = imports.ui.panelMenu;
 const PopupMenu = imports.ui.popupMenu;
 
 // Adapted from gdm/gui/user-switch-applet/applet.c
@@ -23,10 +24,10 @@ function StatusMenuButton() {
 }
 
 StatusMenuButton.prototype = {
-    __proto__: Panel.PanelMenuButton.prototype,
+    __proto__: PanelMenu.Button.prototype,
 
     _init: function() {
-        Panel.PanelMenuButton.prototype._init.call(this, St.Align.START);
+        PanelMenu.Button.prototype._init.call(this, St.Align.START);
         let box = new St.BoxLayout({ name: 'panelStatusMenu' });
         this.actor.set_child(box);
 



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