Add zotero://select support for collections

zotero://select/(library|groups/:groupID)/collections/:collectionKey
This commit is contained in:
Dan Stillman 2018-10-10 20:31:15 -04:00
parent 2d38a0102c
commit 1e3608e82e
2 changed files with 34 additions and 7 deletions

View file

@ -35,6 +35,9 @@ Zotero.API = {
},
/**
* @return {(Zotero.Collection|Zotero.Item)[]}
*/
getResultsFromParams: Zotero.Promise.coroutine(function* (params) {
if (!params.objectType) {
throw new Error("objectType not specified");
@ -42,7 +45,13 @@ Zotero.API = {
var results;
if (params.objectType == 'item') {
if (params.objectType == 'collection') {
let col = Zotero.Collections.getByLibraryAndKey(params.libraryID, params.objectKey);
if (col) {
results = [col];
}
}
else if (params.objectType == 'item') {
switch (params.scopeObject) {
case 'collections':
if (params.scopeObjectKey) {

View file

@ -835,24 +835,42 @@ function ZoteroProtocolHandler() {
}
delete params.id;
});
// Collection
router.add('library/collections/:objectKey', function () {
params.objectType = 'collection'
params.libraryID = userLibraryID;
});
router.add('groups/:groupID/collections/:objectKey', function () {
params.objectType = 'collection'
params.libraryID = userLibraryID;
});
router.run(path);
Zotero.API.parseParams(params);
var results = yield Zotero.API.getResultsFromParams(params);
if (!results.length) {
var msg = "Items not found";
var msg = "Objects not found";
Zotero.debug(msg, 2);
Components.utils.reportError(msg);
return;
}
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
var zp = Zotero.getActiveZoteroPane();
if (!zp) {
// TEMP
throw new Error("Pane not open");
}
// TODO: Currently only able to select one item
return win.ZoteroPane.selectItem(results[0].id);
if (params.objectType == 'collection') {
return zp.collectionsView.selectCollection(results[0].id);
}
else {
// TODO: Currently only able to select one item
return zp.selectItem(results[0].id);
}
}),
newChannel: function (uri) {