From 2f423da30948b9ac7116fbd393dfade8245bd3af Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 16 Apr 2007 05:00:32 +0000 Subject: [PATCH] Sort collections and items using locale-specific collation sort --- chrome/content/zotero/xpcom/data_access.js | 23 ++++++++++++++------- chrome/content/zotero/xpcom/itemTreeView.js | 15 +++++++++++--- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js index eed16f736..8e1c88d43 100644 --- a/chrome/content/zotero/xpcom/data_access.js +++ b/chrome/content/zotero/xpcom/data_access.js @@ -4548,22 +4548,29 @@ Zotero.getCollections = function(parent, recursive){ parent = null; } - var sql = 'SELECT collectionID FROM collections C WHERE parentCollectionID'; - sql += parent ? '=' + parent : ' IS NULL'; - - sql += ' ORDER BY collectionName COLLATE NOCASE'; - - var children = Zotero.DB.columnQuery(sql); + var sql = "SELECT collectionID AS id, collectionName AS name FROM collections C " + + "WHERE parentCollectionID " + (parent ? '=' + parent : ' IS NULL'); + var children = Zotero.DB.query(sql); if (!children){ Zotero.debug('No child collections of collection ' + parent, 5); return toReturn; } + // Do proper collation sort + var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"] + .getService(Components.interfaces.nsILocaleService); + var collationFactory = Components.classes["@mozilla.org/intl/collation-factory;1"] + .getService(Components.interfaces.nsICollationFactory); + var collation = collationFactory.CreateCollation(localeService.getApplicationLocale()); + children.sort(function (a, b) { + return collation.compareString(0, a.name, b.name); + }); + for (var i=0, len=children.length; i fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0; + //cmp = (fieldA > fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0; + cmp = collation.compareString(0, fieldA, fieldB); if (cmp) { return cmp; } @@ -815,7 +822,8 @@ Zotero.ItemTreeView.prototype.sort = function(itemID) return cmp; } - cmp = (fieldA > fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0; + //cmp = (fieldA > fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0; + cmp = collation.compareString(0, fieldA, fieldB); if (cmp) { return cmp; } @@ -840,7 +848,8 @@ Zotero.ItemTreeView.prototype.sort = function(itemID) fieldA = a.getField('dateModified'); fieldB = b.getField('dateModified'); - return (fieldA > fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0; + //return (fieldA > fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0; + return collation.compareString(0, fieldA, fieldB); } function doSort(a,b)