Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
bug 893: Ensure 1 image is always selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain Pasche authored and eletuchy committed May 13, 2009
1 parent 2661af4 commit 03eeaf4
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions chrome/content/photoupload/photoupload.js
Expand Up @@ -123,11 +123,9 @@ PeopleTag.prototype = {
* This objects represents a photo that is going to be uploaded.
*/
function Photo(/* nsIFile */ file) {
LOG("Creating new photo " + file);
this.file = file.QueryInterface(Ci.nsIFile);
this.caption = "";
this.tags = [];
LOG(" Constructed " + this.file);
};

Photo.prototype = {
Expand All @@ -147,6 +145,9 @@ Photo.prototype = {
},
removeTag: function(tag) {
this.tags = this.tags.filter(function(p) p != tag);
},
toString: function() {
return "<Photo file: " + this.filename + ">";
}
};

Expand All @@ -166,19 +167,22 @@ var PhotoSet = {
_listeners: [],
_cancelled: false,

add: function(aFiles) {
Array.prototype.push.apply(this._photos, aFiles)

add: function(photos) {
Array.prototype.push.apply(this._photos, photos)
// Selects the last added photos. When adding only one photo, that's
// useful to have it selected for direct metadata editing.
this._selected = photos[photos.length - 1];
this._notifyChanged();
},

_updateSelected: function() {
var p = this._photos.filter(function(p) p == this._selected);
var p = this._photos.filter(function(p) p == this._selected, this);
if (p.length > 1) {
LOG("ERROR: more that once selected photo?");
return;
}
if (p.length == 0) {
LOG("No selected photo");
this._selected = null;
}
},
Expand All @@ -190,7 +194,15 @@ var PhotoSet = {
},

remove: function(photo) {
this._photos = this._photos.filter(function(p) p != photo);
var photoIndex = this._photos.indexOf(photo);
if (photoIndex == -1) {
LOG("Warning: trying to remove a photo not in set");
return;
}
this._photos.splice(photoIndex, 1);
// Select the photo just after the removed one.
var selectedIndex = Math.min(photoIndex, this._photos.length - 1);
this._selected = this._photos[selectedIndex];
this._updateSelected();
this._notifyChanged();
},
Expand Down

0 comments on commit 03eeaf4

Please sign in to comment.