[the-board] [ui] Implement support for thing-specific toolbars
- From: Lucas Almeida Rocha <lucasr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [the-board] [ui] Implement support for thing-specific toolbars
- Date: Sun, 7 Nov 2010 23:21:15 +0000 (UTC)
commit 1fee11443e4d46d88a14d2d9047ee37bfe1c80e3
Author: Lucas Rocha <lucasr gnome org>
Date: Fri Nov 5 01:02:57 2010 +0000
[ui] Implement support for thing-specific toolbars
src/js/ui/mainWindow.js | 126 ++++++++++++++++++++++++++++++++++++++++++-----
src/js/ui/thing.js | 14 +++++
2 files changed, 127 insertions(+), 13 deletions(-)
---
diff --git a/src/js/ui/mainWindow.js b/src/js/ui/mainWindow.js
index 5f8ad48..c57a9b3 100644
--- a/src/js/ui/mainWindow.js
+++ b/src/js/ui/mainWindow.js
@@ -16,6 +16,7 @@ const Mx = imports.gi.Mx;
// ui imports
const Page = imports.ui.page;
const PhotoThing = imports.ui.things.photo;
+const Thing = imports.ui.thing;
const ToolBox = imports.ui.toolBox;
const ToolBoxBackgrounds = imports.ui.toolBoxBackgrounds;
const ToolBoxGroup = imports.ui.toolBoxGroup;
@@ -50,6 +51,10 @@ MainWindow.prototype = {
this._keyFocusActor = null;
this._currentPage = null;
+ this._activeToolBoxGroup = null;
+ this._thingToolBoxGroup = null;
+ this._toolBoxGroupsByThingId = {};
+
this._createGtkWindow();
this._createClutterEmbed();
this._createPageManager();
@@ -188,11 +193,6 @@ MainWindow.prototype = {
_createToolBoxGroup : function() {
this._mainToolBoxGroup = new ToolBoxGroup.ToolBoxGroup();
- this._toolBoxGroupActiveChangedId =
- this._mainToolBoxGroup.connect("active-changed",
- Lang.bind(this,
- this._onToolBoxGroupActiveChanged));
-
this._mainToolBoxGroup.actor.depth = _LAYER_TOOLBOX;
this._createToolBoxPages();
@@ -205,6 +205,8 @@ MainWindow.prototype = {
this._contentBox.set_fixed_child_align(this._mainToolBoxGroup.actor,
Tb.BoxAlignment.CENTER,
Tb.BoxAlignment.START);
+
+ this._updateActiveToolBoxGroup();
},
_createSpinner : function() {
@@ -314,6 +316,100 @@ MainWindow.prototype = {
onComplete: Lang.bind(this, onComplete) });
},
+ _setActiveToolBoxGroup : function(activeToolBoxGroup) {
+ if (this._activeToolBoxGroup == activeToolBoxGroup) {
+ return;
+ }
+
+ if (this._activeToolBoxGroup) {
+ this._activeToolBoxGroup.disconnect(this._toolBoxGroupActiveChangedId);
+ delete this._toolBoxGroupActiveChangedId;
+ }
+
+ this._activeToolBoxGroup = activeToolBoxGroup;
+
+ if (this._activeToolBoxGroup) {
+ this._toolBoxGroupActiveChangedId =
+ this._activeToolBoxGroup.connect("active-changed",
+ Lang.bind(this,
+ this._onToolBoxGroupActiveChanged));
+ }
+ },
+
+ _updateActiveToolBoxGroup : function() {
+ let activeToolBoxGroup = null;
+
+ if (this._currentPage &&
+ this._currentPage.activeThing) {
+ activeToolBoxGroup = this._thingToolBoxGroup;
+ } else {
+ activeToolBoxGroup = this._mainToolBoxGroup;
+ }
+
+ if (this._activeToolBoxGroup == activeToolBoxGroup) {
+ return;
+ }
+
+ let oldActiveToolBoxGroup = this._activeToolBoxGroup;
+ this._setActiveToolBoxGroup(activeToolBoxGroup);
+
+ let onSlideOut = function() {
+ if (activeToolBoxGroup) {
+ activeToolBoxGroup.slideIn();
+ }
+ };
+
+ if (oldActiveToolBoxGroup) {
+ oldActiveToolBoxGroup.slideOut(onSlideOut);
+ } else if (activeToolBoxGroup) {
+ activeToolBoxGroup.slideIn();
+ }
+ },
+
+ _createThingToolBoxGroup : function() {
+ if (!this._currentPage ||
+ !this._currentPage.activeThing) {
+ return null;
+ }
+
+ let thingId = this._currentPage.activeThing.id;
+
+ if (thingId in this._toolBoxGroupsByThingId) {
+ return this._toolBoxGroupsByThingId[thingId];
+ }
+
+ let thingToolBoxGroup =
+ Thing.createToolBoxGroup(thingId,
+ { mainWindow: this });
+
+ if (thingToolBoxGroup) {
+ thingToolBoxGroup.actor.depth = _LAYER_TOOLBOX;
+
+ this._toolBoxGroupsByThingId[thingId] = thingToolBoxGroup;
+
+ this._contentBox.append(thingToolBoxGroup.actor,
+ Tb.BoxPackFlags.FIXED);
+
+ this._contentBox.set_fixed_child_align(thingToolBoxGroup.actor,
+ Tb.BoxAlignment.CENTER,
+ Tb.BoxAlignment.START);
+ }
+
+ return thingToolBoxGroup;
+ },
+
+ _updateThingToolBoxGroup : function() {
+ let newThingToolBoxGroup =
+ this._createThingToolBoxGroup();
+
+ if (this._thingToolBoxGroup == newThingToolBoxGroup) {
+ return;
+ }
+
+ this._thingToolBoxGroup = newThingToolBoxGroup;
+ this._updateActiveToolBoxGroup();
+ },
+
_showSpinner : function() {
Tweener.addTween(this._spinnerBox,
{ opacity: 255,
@@ -494,7 +590,7 @@ MainWindow.prototype = {
},
_onToolBoxGroupActiveChanged : function() {
- if (this._currentPage && this._mainToolBoxGroup.active) {
+ if (this._currentPage && this._activeToolBoxGroup.active) {
this._currentPage.setActiveThing(null);
}
},
@@ -587,13 +683,15 @@ MainWindow.prototype = {
_onPageActiveThingChanged : function() {
if (this._currentPage.activeThing === null) {
this._mainBox.grab_key_focus();
- } else {
- this._mainToolBoxGroup.deactivate();
+ } else if (this._activeToolBoxGroup) {
+ this._activeToolBoxGroup.deactivate();
}
+
+ this._updateThingToolBoxGroup();
},
_onPageButtonPressEvent : function() {
- this._mainToolBoxGroup.deactivate();
+ this._activeToolBoxGroup.deactivate();
this._mainBox.grab_key_focus();
},
@@ -670,6 +768,11 @@ MainWindow.prototype = {
},
destroy : function() {
+ for (let thingId in this._mainToolBoxGroupsByThingId) {
+ let toolBoxGroup = this._mainToolBoxGroupsByThingId[thingId];
+ toolBoxGroup.destroy();
+ }
+
if (this._pageManagerStateChangedId) {
this._pageManager.disconnect(this._pageManagerStateChangedId);
delete this._pageManagerStateChangedId;
@@ -680,10 +783,7 @@ MainWindow.prototype = {
delete this._pageActiveThingChangedId;
}
- if (this._toolBoxGroupActiveChangedId) {
- this._currentPage.disconnect(this._toolBoxGroupActiveChangedId);
- delete this._toolBoxGroupActiveChangedId;
- }
+ this._setActiveToolBoxGroup(null);
if (this._pageButtonPressEventId) {
this._currentPage.disconnect(this._pageButtonPressEventId);
diff --git a/src/js/ui/thing.js b/src/js/ui/thing.js
index 1000313..8c29a27 100644
--- a/src/js/ui/thing.js
+++ b/src/js/ui/thing.js
@@ -462,4 +462,18 @@ function createThingFromId(thingId, args) {
return constructorModule.create(args);
}
+function createToolBoxGroup(thingId, args) {
+ if (!thingId) {
+ throw new Error("Can't create tool box group without thing id");
+ }
+
+ let constructorModule = imports.ui.things[thingId];
+
+ if ('createToolBoxGroup' in constructorModule) {
+ return constructorModule.createToolBoxGroup(args);
+ }
+
+ return null;
+}
+
Signals.addSignalMethods(Thing.prototype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]