[the-board] [things] Add photo-specific ToolBoxGroup to PhotoThing



commit 345ed66671d9d83334fe7510b0a45ad047431147
Author: Lucas Rocha <lucasr gnome org>
Date:   Sun Nov 7 20:02:12 2010 +0000

    [things] Add photo-specific ToolBoxGroup to PhotoThing

 src/js/ui/things/photo.js |  148 ++++++++-------------------------------------
 1 files changed, 25 insertions(+), 123 deletions(-)
---
diff --git a/src/js/ui/things/photo.js b/src/js/ui/things/photo.js
index 13580c3..5b73108 100644
--- a/src/js/ui/things/photo.js
+++ b/src/js/ui/things/photo.js
@@ -14,6 +14,8 @@ const Pango = imports.gi.Pango;
 
 // ui imports
 const Thing = imports.ui.thing;
+const ToolBox = imports.ui.toolBox;
+const ToolBoxGroup = imports.ui.toolBoxGroup;
 
 // util imports
 const Path = imports.util.path;
@@ -65,25 +67,12 @@ PhotoThing.prototype = {
             this._minHeight = 213;
         }
 
-        if ('showFileSelectionButton' in args) {
-            this._showFileSelectionButton = args.showFileSelectionButton;
-        } else {
-            this._showFileSelectionButton = true;
-        }
-
-        if ('showWebcamButton' in args) {
-            this._showWebcamButton = args.showWebcamButton;
-        } else {
-            this._showWebcamButton = false;
-        }
-
         this._style = new Mx.Style();
         this._style.load_from_file(STYLE);
 
         this._createPhotoBox();
         this._createPhoto();
         this._createCaptionText();
-        this._createButtonBox();
         this._createTapes();
 
         Thing.Thing.prototype._init.apply(this, [args]);
@@ -128,33 +117,6 @@ PhotoThing.prototype = {
                               Tb.BoxPackFlags.NONE);
     },
 
-    _createButtonBox : function() {
-        this._buttonBox =
-            new Tb.Box({ orientation: Tb.BoxOrientation.HORIZONTAL,
-                         xAlign: Tb.BoxAlignment.CENTER,
-                         yAlign: Tb.BoxAlignment.CENTER,
-                         opacity: 0,
-                         visible: false,
-                         name: "photo-thing-button-box" });
-
-        this._buttonBox.set_style(this._style);
-
-        if (this._showFileSelectionButton) {
-            this._createFileSelectionButton();
-        }
-
-        if (this._showWebcamButton) {
-            this._createWebcamButton();
-        }
-
-        this._photoBox.append(this._buttonBox,
-                              Tb.BoxPackFlags.FIXED);
-
-        this._photoBox.set_fixed_child_align(this._buttonBox,
-                                             Tb.BoxAlignment.CENTER,
-                                             Tb.BoxAlignment.CENTER);
-    },
-
     _createTapes : function() {
         this._topTape =
             new Clutter.Texture({ keepAspectRatio: true,
@@ -183,30 +145,6 @@ PhotoThing.prototype = {
         this._bottomTape.anchorY = -25;
     },
 
-    _createFileSelectionButton : function() {
-        this._fileSelectionButton =
-            new Mx.Button({ label: "File" });
-
-        this._fileSelectionButtonClickedId =
-            this._fileSelectionButton.connect("clicked",
-                                      Lang.bind(this, this._onFileSelectionButtonClicked));
-
-        this._buttonBox.append(this._fileSelectionButton,
-                               Tb.BoxPackFlags.NONE);
-    },
-
-    _createWebcamButton : function() {
-        this._webcamButton =
-            new Mx.Button({ label: "Webcam" });
-
-        this._webcamButtonClickedId =
-            this._webcamButton.connect("clicked",
-                                      Lang.bind(this, this._onWebcamButtonClicked));
-
-        this._buttonBox.append(this._webcamButton,
-                               Tb.BoxPackFlags.NONE);
-    },
-
     _connectPhotoSignals : function(fromState) {
         this._disconnectPhotoSignals();
 
@@ -249,7 +187,6 @@ PhotoThing.prototype = {
         if (this._imageFilename) {
             this._connectPhotoSignals(fromState);
             this._updateSpinner();
-            this._hideButtonBox();
 
             // hide photo while loading the new image file
             this._photo.opacity = 0;
@@ -285,28 +222,6 @@ PhotoThing.prototype = {
         this._photoHeight = newHeight;
     },
 
-    _showButtonBox : function() {
-        if (!this._showFileSelectionButton && !this._showWebcamButton) {
-            return;
-        }
-
-        Tweener.addTween(this._buttonBox,
-                         { opacity: 255,
-                           time: _SHOW_BUTTON_BOX_TIME,
-                           onStart: function() {
-                               this.show();
-                           }});
-    },
-
-    _hideButtonBox : function() {
-        Tweener.addTween(this._buttonBox,
-                         { opacity: 0,
-                           time: _SHOW_BUTTON_BOX_TIME,
-                           onComplete: function() {
-                               this.hide();
-                           }});
-    },
-
     _updatePhotoWithFileChooser : function() {
         let chooser = new Gtk.FileChooserDialog();
 
@@ -352,9 +267,7 @@ PhotoThing.prototype = {
 
         switch (key) {
         case Clutter.Return:
-            if (this._showFileSelectionButton) {
-                this._updatePhotoWithFileChooser();
-            }
+            this._updatePhotoWithFileChooser();
             return true;
         case Clutter.Escape:
             this.emit("deactivate");
@@ -384,13 +297,6 @@ PhotoThing.prototype = {
         return false;
     },
 
-    _onFileSelectionButtonClicked : function() {
-        this._updatePhotoWithFileChooser();
-    },
-
-    _onWebcamButtonClicked : function() {
-    },
-
     _onPhotoSizeChange : function(photo, width, height) {
         if (this._photoWidth > 0 && this._photoHeight > 0) {
             return;
@@ -403,10 +309,6 @@ PhotoThing.prototype = {
         this._disconnectPhotoSignals();
         this._updateSpinner();
 
-        if (!fromState) {
-            this._showButtonBox();
-        }
-
         [minTextHeight, naturalTextHeight] =
             this._captionLabel.get_preferred_height(-1);
 
@@ -436,12 +338,10 @@ PhotoThing.prototype = {
     activate : function() {
         this._captionLabel.clutterText.editable = true;
         this._captionLabel.clutterText.grab_key_focus();
-        this._showButtonBox();
     },
 
     deactivate : function() {
         this._captionLabel.clutterText.editable = false;
-        this._hideButtonBox();
     },
 
     loadState : function(state) {
@@ -460,6 +360,12 @@ PhotoThing.prototype = {
                  text: this._captionLabel.text };
     },
 
+    doAction : function(actionName, actionArgs) {
+        if (actionName == "chooseFile") {
+            this._updatePhotoWithFileChooser();
+        }
+    },
+
     validateSize : function(width, height) {
         // minWidth and minHeight always have a valid aspect
         // ratio once the image is loaded (see _onPhotoLoadFinished)
@@ -475,26 +381,6 @@ PhotoThing.prototype = {
     },
 
     destroy : function() {
-        if (this._fileSelectionButtonClickedId) {
-            this._fileSelectionButton.disconnect(this._fileSelectionButtonClickedId);
-            delete this._fileSelectionButtonClickedId;
-        }
-
-        if (this._webcamButtonClickedId) {
-            this._webcamButton.disconnect(this._webcamButtonClickedId);
-            delete this._webcamButtonClickedId;
-        }
-
-        if (this._fileSelectionButton) {
-            this._fileSelectionButton.destroy();
-            delete this._fileSelectionButton;
-        }
-
-        if (this._webcamButton) {
-            this._webcamButton.destroy();
-            delete this._webcamButton;
-        }
-
         this._disconnectPhotoSignals();
 
         if (this._saveTextTimeoutId) {
@@ -532,3 +418,19 @@ PhotoThing.prototype = {
 function create(args) {
     return new PhotoThing(args);
 }
+
+function createToolBoxGroup(args) {
+    let toolBoxGroup =
+        new ToolBoxGroup.ToolBoxGroup({ visible: false });
+
+    let toolBox =
+        new ToolBox.ToolBox({ title: Gettext.gettext("Load from"),
+                              isThingToolBox: true });
+
+    toolBox.addButton({ label: Gettext.gettext("File"),
+                        actionName: "chooseFile" });
+
+    toolBoxGroup.addToolBox(toolBox);
+
+    return toolBoxGroup;
+}



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