From 579e53f02c994101a50e34a53493d4c127fe2cc5 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Fri, 15 Feb 2013 18:25:36 -0500 Subject: [PATCH] overview: move controls visibility handling to a separate object This keeps the core code of the overview clean and will help coordinate animations. https://bugzilla.gnome.org/show_bug.cgi?id=693924 --- js/ui/overview.js | 57 +++++++++++---------------------------- js/ui/overviewControls.js | 40 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/js/ui/overview.js b/js/ui/overview.js index c57ab9546..f5706f080 100644 --- a/js/ui/overview.js +++ b/js/ui/overview.js @@ -223,25 +223,20 @@ const Overview = new Lang.Class({ x_align: St.Align.MIDDLE }); this._overview.add_actor(this._searchEntryBin); - // TODO - recalculate everything when desktop size changes + // Create controls this._dash = new Dash.Dash(); - this.dashIconSize = this._dash.iconSize; - this._dash.connect('icon-size-changed', - Lang.bind(this, function() { - this.dashIconSize = this._dash.iconSize; - })); - - this._dashSlider = new OverviewControls.DashSlider(this._dash); - this._group.add_actor(this._dashSlider.actor); - this._viewSelector = new ViewSelector.ViewSelector(this._searchEntry, this._dash.showAppsButton); + this._thumbnailsBox = new WorkspaceThumbnail.ThumbnailsBox(); + this._controls = new OverviewControls.ControlsManager(this._dash, + this._thumbnailsBox, + this._viewSelector); + + // Pack all the actors into the group + this._group.add_actor(this._controls.dashActor); this._group.add(this._viewSelector.actor, { x_fill: true, expand: true }); - - this._thumbnailsBox = new WorkspaceThumbnail.ThumbnailsBox(); - this._thumbnailsSlider = new OverviewControls.ThumbnailsSlider(this._thumbnailsBox); - this._group.add_actor(this._thumbnailsSlider.actor); + this._group.add_actor(this._controls.thumbnailsActor); // Add our same-line elements after the search entry this._overview.add(this._group, { y_fill: true, @@ -255,39 +250,17 @@ const Overview = new Lang.Class({ y_fill: true }); this._overview.add_actor(this._messageTrayGhost); - this._viewSelector.connect('page-changed', Lang.bind(this, - function() { - this._setSideControlsVisibility(); - })); + // TODO - recalculate everything when desktop size changes + this.dashIconSize = this._dash.iconSize; + this._dash.connect('icon-size-changed', + Lang.bind(this, function() { + this.dashIconSize = this._dash.iconSize; + })); Main.layoutManager.connect('monitors-changed', Lang.bind(this, this._relayout)); this._relayout(); }, - _setSideControlsVisibility: function() { - // Ignore the case when we're leaving the overview, since - // actors will be made visible again when entering the overview - // next time, and animating them while doing so is just - // unnecesary noise - if (!this.visible || this._hideInProgress) - return; - - let activePage = this._viewSelector.getActivePage(); - let dashVisible = (activePage == ViewSelector.ViewPage.WINDOWS || - activePage == ViewSelector.ViewPage.APPS); - let thumbnailsVisible = (activePage == ViewSelector.ViewPage.WINDOWS); - - if (dashVisible) - this._dashSlider.slideIn(); - else - this._dashSlider.slideOut(); - - if (thumbnailsVisible) - this._thumbnailsSlider.slideIn(); - else - this._thumbnailsSlider.slideOut(); - }, - addSearchProvider: function(provider) { this._viewSelector.addSearchProvider(provider); }, diff --git a/js/ui/overviewControls.js b/js/ui/overviewControls.js index 8413874ba..495731a90 100644 --- a/js/ui/overviewControls.js +++ b/js/ui/overviewControls.js @@ -6,6 +6,7 @@ const St = imports.gi.St; const Main = imports.ui.main; const Tweener = imports.ui.tweener; +const ViewSelector = imports.ui.viewSelector; const SIDE_CONTROLS_ANIMATION_TIME = 0.2; @@ -232,3 +233,42 @@ const DashSlider = new Lang.Class({ return 0; } }); + +const ControlsManager = new Lang.Class({ + Name: 'ControlsManager', + + _init: function(dash, thumbnails, viewSelector) { + this._dashSlider = new DashSlider(dash); + this.dashActor = this._dashSlider.actor; + + this._thumbnailsSlider = new ThumbnailsSlider(thumbnails); + this.thumbnailsActor = this._thumbnailsSlider.actor; + + this._viewSelector = viewSelector; + this._viewSelector.connect('page-changed', Lang.bind(this, this._setVisibility)); + }, + + _setVisibility: function() { + // Ignore the case when we're leaving the overview, since + // actors will be made visible again when entering the overview + // next time, and animating them while doing so is just + // unnecessary noise + if (!Main.overview.visible) + return; + + let activePage = this._viewSelector.getActivePage(); + let dashVisible = (activePage == ViewSelector.ViewPage.WINDOWS || + activePage == ViewSelector.ViewPage.APPS); + let thumbnailsVisible = (activePage == ViewSelector.ViewPage.WINDOWS); + + if (dashVisible) + this._dashSlider.slideIn(); + else + this._dashSlider.slideOut(); + + if (thumbnailsVisible) + this._thumbnailsSlider.slideIn(); + else + this._thumbnailsSlider.slideOut(); + } +});