From ebda79a95852a4714a85a0be5f07d27d457652a2 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 9 May 2019 01:59:43 -0400 Subject: [PATCH] zotero://select improvements - Support items within collections and searches: zotero://select/library/collections/:collectionKey/items/:itemKey zotero://select/groups/:groupID/collections/:collectionKey/items/:itemKey - Fix the 'itemKey' parameter: zotero://select/library/collections/:collectionKey/items?itemKey=:itemKey1,:itemKey2 - Select library root if collection/search not specified --- chrome/content/zotero/xpcom/api.js | 15 ++++++++------ components/zotero-protocol-handler.js | 29 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/xpcom/api.js b/chrome/content/zotero/xpcom/api.js index 72ef779f6e..ba39aad5c6 100644 --- a/chrome/content/zotero/xpcom/api.js +++ b/chrome/content/zotero/xpcom/api.js @@ -66,6 +66,10 @@ Zotero.API = { throw new Error('Invalid collection ID or key'); } results = col.getChildItems(); + if (params.objectKey) { + let item = results.find(item => item.key == params.objectKey); + results = item ? [item] : []; + } break; case 'searches': @@ -81,14 +85,13 @@ Zotero.API = { throw new Error('Invalid search ID or key'); } - // FIXME: Hack to exclude group libraries for now var s2 = new Zotero.Search(); s2.setScope(s); - var groups = Zotero.Groups.getAll(); - for (let group of groups) { - s2.addCondition('libraryID', 'isNot', group.libraryID); - } var ids = yield s2.search(); + if (params.objectKey) { + let id = Zotero.Items.getIDFromLibraryAndKey(s.libraryID, params.objectKey); + ids = ids.includes(id) ? [id] : []; + } break; default: @@ -126,7 +129,7 @@ Zotero.API = { if (results) { // Filter results by item key if (params.itemKey) { - results = results.filter(key => itemKeys.has(key)); + results = results.filter(item => itemKeys.has(item.key)); } } else if (ids) { diff --git a/components/zotero-protocol-handler.js b/components/zotero-protocol-handler.js index f3c7b10289..6421b5a8b5 100644 --- a/components/zotero-protocol-handler.js +++ b/components/zotero-protocol-handler.js @@ -874,6 +874,35 @@ function ZoteroProtocolHandler() { return zp.collectionsView.selectCollection(results[0].id); } else { + // Select collection first if specified + if (params.scopeObject == 'collections') { + let col; + if (params.scopeObjectKey) { + col = Zotero.Collections.getByLibraryAndKey( + params.libraryID, params.scopeObjectKey + ); + } + else { + col = Zotero.Collections.get(params.scopeObjectID); + } + yield zp.collectionsView.selectCollection(col.id); + } + else if (params.scopeObject == 'searches') { + let s; + if (params.scopeObjectKey) { + s = Zotero.Searches.getByLibraryAndKey( + params.libraryID, params.scopeObjectKey + ); + } + else { + s = Zotero.Searches.get(params.scopeObjectID); + } + yield zp.collectionsView.selectSearch(s.id); + } + // If collection not specified, select library root + else { + yield zp.collectionsView.selectLibrary(params.libraryID); + } return zp.selectItems(results.map(x => x.id)); } }),