simplify setting of sort properties and order

This commit is contained in:
Myk Melez 2008-08-25 17:52:58 -07:00
Родитель 492e46ba28
Коммит 71ddb6401c
4 изменённых файлов: 18 добавлений и 14 удалений

Просмотреть файл

@ -572,7 +572,9 @@ this._log.info("_toggleRead: all? " + aAll);
let order = (direction == "ascending" ? 1 : -1);
// Perform the sort.
this._collection.sort([property], order);
this._collection.sortProperty = [property];
this._collection.sortOrder = order;
this._collection.sort();
}
};

Просмотреть файл

@ -317,8 +317,7 @@ let SnowlMessageView = {
// Presumably here we could do messages.reverse(), which would be faster,
// but can we be sure the messages started in the reverse of the new state?
this._collection.sort(this._collection.sortProperty,
this._collection.sortOrder);
this._collection.sort();
this.rebuildView();
this._updateURI();
},

Просмотреть файл

@ -146,8 +146,9 @@ let SnowlMessageView = {
this._document = this._window.document;
this._collection = new SnowlCollection();
this._collection.sortProperty = "received";
this._collection.sortProperty = ["received"];
this._collection.sortOrder = -1;
this._collection.sort();
this.rebuildView();
},

Просмотреть файл

@ -232,7 +232,7 @@ SnowlCollection.prototype = {
// Retrieval
// sortProperty gets set to its default value in the constructor
// since the default is an array which would be a singleton if defined here.
// since the default is an array, which would be a singleton if defined here.
sortProperty: null,
sortOrder: 1,
@ -265,7 +265,7 @@ SnowlCollection.prototype = {
statement.reset();
}
this.sort(this.sortProperty, this.sortOrder);
this.sort();
// A bug in SQLite breaks relating a virtual table via a LEFT JOIN, so we
// can't pull content with our initial query. Instead we do it here.
@ -342,23 +342,25 @@ SnowlCollection.prototype = {
return statement;
},
sort: function(aProperties, aOrder) {
this.sortProperty = aProperties;
this.sortOrder = aOrder;
sort: function() {
// Reflect these into local variables that the compare function closure
// can access.
let properties = this.sortProperty;
let order = this.sortOrder;
// Fall back on subject.
// XXX Should we let callers make this decision?
if (aProperties[aProperties.length - 1] != "subject")
aProperties.push("subject");
if (properties[properties.length - 1] != "subject")
properties.push("subject");
let compare = function(a, b) {
for each (let property in aProperties) {
for each (let property in properties) {
if (prepareObjectForComparison(a[property]) >
prepareObjectForComparison(b[property]))
return 1 * aOrder;
return 1 * order;
if (prepareObjectForComparison(a[property]) <
prepareObjectForComparison(b[property]))
return -1 * aOrder;
return -1 * order;
}
// Return an inconclusive result.