Add zotero://select support for collections
zotero://select/(library|groups/:groupID)/collections/:collectionKey
This commit is contained in:
parent
2d38a0102c
commit
1e3608e82e
2 changed files with 34 additions and 7 deletions
|
@ -35,6 +35,9 @@ Zotero.API = {
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {(Zotero.Collection|Zotero.Item)[]}
|
||||||
|
*/
|
||||||
getResultsFromParams: Zotero.Promise.coroutine(function* (params) {
|
getResultsFromParams: Zotero.Promise.coroutine(function* (params) {
|
||||||
if (!params.objectType) {
|
if (!params.objectType) {
|
||||||
throw new Error("objectType not specified");
|
throw new Error("objectType not specified");
|
||||||
|
@ -42,7 +45,13 @@ Zotero.API = {
|
||||||
|
|
||||||
var results;
|
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) {
|
switch (params.scopeObject) {
|
||||||
case 'collections':
|
case 'collections':
|
||||||
if (params.scopeObjectKey) {
|
if (params.scopeObjectKey) {
|
||||||
|
|
|
@ -835,24 +835,42 @@ function ZoteroProtocolHandler() {
|
||||||
}
|
}
|
||||||
delete params.id;
|
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);
|
router.run(path);
|
||||||
|
|
||||||
Zotero.API.parseParams(params);
|
Zotero.API.parseParams(params);
|
||||||
var results = yield Zotero.API.getResultsFromParams(params);
|
var results = yield Zotero.API.getResultsFromParams(params);
|
||||||
|
|
||||||
if (!results.length) {
|
if (!results.length) {
|
||||||
var msg = "Items not found";
|
var msg = "Objects not found";
|
||||||
Zotero.debug(msg, 2);
|
Zotero.debug(msg, 2);
|
||||||
Components.utils.reportError(msg);
|
Components.utils.reportError(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
var zp = Zotero.getActiveZoteroPane();
|
||||||
.getService(Components.interfaces.nsIWindowMediator);
|
if (!zp) {
|
||||||
var win = wm.getMostRecentWindow("navigator:browser");
|
// TEMP
|
||||||
|
throw new Error("Pane not open");
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Currently only able to select one item
|
if (params.objectType == 'collection') {
|
||||||
return win.ZoteroPane.selectItem(results[0].id);
|
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) {
|
newChannel: function (uri) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue