From 9c52ebdf8b0911b722aedc32a428157db7cef35f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 6 Oct 2016 01:14:37 -0400 Subject: [PATCH] Show saved searches under "Collection" search condition With icons to identify collections and searches Also: - `savedSearch` search condition in general - Clean up some search window code - Reorganize search tests --- .../content/zotero/bindings/zoterosearch.xml | 105 ++++----- .../zotero/xpcom/collectionTreeView.js | 1 + .../content/zotero/xpcom/data/collection.js | 3 + .../content/zotero/xpcom/data/collections.js | 11 +- chrome/content/zotero/xpcom/data/search.js | 30 ++- .../zotero/xpcom/data/searchConditions.js | 2 +- chrome/content/zotero/xpcom/data/searches.js | 18 ++ test/tests/advancedSearchTest.js | 140 ++++++++++++ test/tests/collectionsTest.js | 9 + test/tests/searchTest.js | 201 +++++++++++------- 10 files changed, 380 insertions(+), 140 deletions(-) diff --git a/chrome/content/zotero/bindings/zoterosearch.xml b/chrome/content/zotero/bindings/zoterosearch.xml index ccf678671b..380d2e36a2 100644 --- a/chrome/content/zotero/bindings/zoterosearch.xml +++ b/chrome/content/zotero/bindings/zoterosearch.xml @@ -425,68 +425,63 @@ var rows = []; var libraryID = this.parent.search.libraryID; - var cols = Zotero.Collections.getByLibrary(libraryID, true); - for (var i in cols) { + + // Add collections + let cols = Zotero.Collections.getByLibrary(libraryID, true); + for (let col of cols) { // Indent subcollections var indent = ''; - if (cols[i].level) { - for (var j=1; j ({ + name: Zotero.ItemTypes.getLocalizedString(type.id), + value: type.name + })); // Sort by localized name - var types = []; - for (var i=0; i collation.compareString(1, a.name, b.name)); - for (var i in types) { - types[i][0] = types[i].localized; - types[i][1] = types[i].name; - delete types[i]['name']; - delete types[i]['id']; - } - this.createValueMenu(types); + this.createValueMenu(rows); break; case 'fileTypeID': - var types = Zotero.FileTypes.getTypes(); - for (var i in types) { - types[i][0] = Zotero.getString('fileTypes.' + types[i]['name']); - types[i][1] = types[i]['id']; - delete types[i]['name']; - delete types[i]['id']; - } - this.createValueMenu(types); + var rows = Zotero.FileTypes.getTypes().map(type => ({ + name: Zotero.getString('fileTypes.' + type.name), + value: type.id + })); + + // Sort by localized name + var collation = Zotero.getLocaleCollation(); + rows.sort((a, b) => collation.compareString(1, a.name, b.name)); + + this.createValueMenu(rows); break; default: @@ -522,7 +517,6 @@ // Drop-down menu if (conditionsMenu.value == 'collection' - || conditionsMenu.value == 'savedSearch' || conditionsMenu.value == 'itemType' || conditionsMenu.value == 'fileTypeID') { this.id('valuefield').hidden = true; @@ -557,19 +551,21 @@ - +