Feed item button tweaks
- Fix persistence of last translation target - Add checkbox to menuitem of selected target - Remove unnecessary flex attributes Also: - Move collectionTreeView row id (e.g., "L1", "C123") and image generation to Zotero.Library and Zotero.Collection properaties, .collectionTreeViewID and .collectionTreeViewImage -- currently used only for the feed add-to button, but could be expanded for use in collectionTreeView
This commit is contained in:
parent
8714816cec
commit
f70c2bfa0a
6 changed files with 58 additions and 28 deletions
|
@ -224,15 +224,25 @@ var ZoteroItemPane = new function() {
|
|||
menu.removeChild(menu.firstChild);
|
||||
}
|
||||
|
||||
let target = Zotero.Prefs.get('feeds.lastTranslationTarget');
|
||||
if (!target) {
|
||||
target = "L" + Zotero.Libraries.userLibraryID;
|
||||
}
|
||||
|
||||
var libraries = Zotero.Libraries.getAll();
|
||||
for (let library of libraries) {
|
||||
if (!library.editable || library.libraryType == 'publications') {
|
||||
continue;
|
||||
}
|
||||
Zotero.Utilities.Internal.createMenuForTarget(library, menu, function(event, libraryOrCollection) {
|
||||
ZoteroItemPane.setTranslationTarget(libraryOrCollection);
|
||||
event.stopPropagation();
|
||||
});
|
||||
Zotero.Utilities.Internal.createMenuForTarget(
|
||||
library,
|
||||
menu,
|
||||
target,
|
||||
function(event, libraryOrCollection) {
|
||||
ZoteroItemPane.setTranslationTarget(libraryOrCollection);
|
||||
event.stopPropagation();
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -249,20 +259,13 @@ var ZoteroItemPane = new function() {
|
|||
+ (Zotero.isMac ? '⇧⌘' : Zotero.getString('general.keys.ctrlShift'))
|
||||
+ key + ')';
|
||||
elem.setAttribute('tooltiptext', tooltip);
|
||||
|
||||
var objectType = _translationTarget._objectType;
|
||||
var imageSrc = Zotero.Utilities.Internal.getCollectionImageSrc(objectType);
|
||||
elem.setAttribute('image', imageSrc);
|
||||
elem.setAttribute('image', _translationTarget.collectionTreeViewImage);
|
||||
};
|
||||
|
||||
|
||||
this.setTranslationTarget = function(translationTarget) {
|
||||
_translationTarget = translationTarget;
|
||||
if (translationTarget.objectType == 'collection') {
|
||||
Zotero.Prefs.set('feeds.translationTarget', "C" + translationTarget.id);
|
||||
} else {
|
||||
Zotero.Prefs.set('feeds.translationTarget', "L" + translationTarget.libraryID);
|
||||
}
|
||||
Zotero.Prefs.set('feeds.lastTranslationTarget', translationTarget.collectionTreeViewID);
|
||||
ZoteroItemPane.setTranslateButton();
|
||||
};
|
||||
|
||||
|
|
|
@ -43,9 +43,9 @@
|
|||
|
||||
<!-- Feed -->
|
||||
<hbox id="zotero-item-pane-top-buttons-feed" class="zotero-item-pane-top-buttons" hidden="true">
|
||||
<button id="zotero-feed-item-toggleRead-button" flex="1"
|
||||
<button id="zotero-feed-item-toggleRead-button"
|
||||
oncommand="ZoteroPane_Local.toggleSelectedItemsRead();"/>
|
||||
<button id="zotero-feed-item-addTo-button" type="menu-button" flex="1"
|
||||
<button id="zotero-feed-item-addTo-button" type="menu-button"
|
||||
oncommand="ZoteroItemPane.translateSelectedItems()">
|
||||
<menupopup id="zotero-item-addTo-menu" onpopupshowing="ZoteroItemPane.buildTranslateSelectContextMenu(event);"/>
|
||||
</button>
|
||||
|
|
|
@ -83,6 +83,18 @@ Zotero.defineProperty(Zotero.Collection.prototype, 'parent', {
|
|||
}
|
||||
});
|
||||
|
||||
Zotero.defineProperty(Zotero.Collection.prototype, 'collectionTreeViewID', {
|
||||
get: function () {
|
||||
return "C" + this.id
|
||||
}
|
||||
});
|
||||
|
||||
Zotero.defineProperty(Zotero.Collection.prototype, 'collectionTreeViewImage', {
|
||||
get: function () {
|
||||
var suffix = Zotero.hiDPI ? "@2x" : "";
|
||||
return "chrome://zotero/skin/treesource-collection" + suffix + ".png";
|
||||
}
|
||||
});
|
||||
|
||||
Zotero.Collection.prototype.getID = function() {
|
||||
Zotero.debug('Collection.getID() deprecated -- use Collection.id');
|
||||
|
|
|
@ -116,6 +116,7 @@ Zotero.defineProperty(Zotero.Library.prototype, 'id', {
|
|||
get: function() this.libraryID,
|
||||
set: function(val) this.libraryID = val
|
||||
});
|
||||
|
||||
Zotero.defineProperty(Zotero.Library.prototype, 'libraryType', {
|
||||
get: function() this._get('_libraryType'),
|
||||
set: function(v) this._set('_libraryType', v)
|
||||
|
@ -173,6 +174,19 @@ Zotero.defineProperty(Zotero.Library.prototype, 'name', {
|
|||
}
|
||||
});
|
||||
|
||||
Zotero.defineProperty(Zotero.Library.prototype, 'collectionTreeViewID', {
|
||||
get: function () {
|
||||
return "L" + this._libraryID
|
||||
}
|
||||
});
|
||||
|
||||
Zotero.defineProperty(Zotero.Library.prototype, 'collectionTreeViewImage', {
|
||||
get: function () {
|
||||
var suffix = Zotero.hiDPI ? "@2x" : "";
|
||||
return "chrome://zotero/skin/treesource-library" + suffix + ".png";
|
||||
}
|
||||
});
|
||||
|
||||
Zotero.defineProperty(Zotero.Library.prototype, 'hasTrash', {
|
||||
value: true
|
||||
});
|
||||
|
|
|
@ -939,11 +939,15 @@ Zotero.Utilities.Internal = {
|
|||
*
|
||||
* @return {Node<menuitem>/Node<menu>} appended node
|
||||
*/
|
||||
createMenuForTarget: function(libraryOrCollection, elem, clickAction) {
|
||||
createMenuForTarget: function(libraryOrCollection, elem, currentTarget, clickAction) {
|
||||
var doc = elem.ownerDocument;
|
||||
function _createMenuitem(label, value, icon, command) {
|
||||
let menuitem = doc.createElement('menuitem');
|
||||
menuitem.setAttribute("label", label);
|
||||
menuitem.setAttribute("type", "checkbox");
|
||||
if (value == currentTarget) {
|
||||
menuitem.setAttribute("checked", "true");
|
||||
}
|
||||
menuitem.setAttribute("value", value);
|
||||
menuitem.setAttribute("image", icon);
|
||||
menuitem.addEventListener('command', command);
|
||||
|
@ -961,17 +965,19 @@ Zotero.Utilities.Internal = {
|
|||
return menu;
|
||||
}
|
||||
|
||||
var imageSrc = this.getCollectionImageSrc(libraryOrCollection._objectType);
|
||||
var imageSrc = libraryOrCollection.collectionTreeViewImage;
|
||||
|
||||
// Create menuitem for library or collection itself, to be placed either directly in the
|
||||
// containing menu or as the top item in a submenu
|
||||
var menuitem = _createMenuitem(
|
||||
libraryOrCollection.name,
|
||||
libraryOrCollection.id,
|
||||
libraryOrCollection.collectionTreeViewID,
|
||||
imageSrc,
|
||||
function (event) {
|
||||
clickAction(event, libraryOrCollection);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
var collections;
|
||||
if (libraryOrCollection.objectType == 'collection') {
|
||||
collections = Zotero.Collections.getByParent(libraryOrCollection.id);
|
||||
|
@ -989,17 +995,13 @@ Zotero.Utilities.Internal = {
|
|||
menupopup.appendChild(menuitem);
|
||||
menupopup.appendChild(doc.createElement('menuseparator'));
|
||||
for (let collection of collections) {
|
||||
let collectionMenu = this.createMenuForTarget(collection, elem, clickAction);
|
||||
let collectionMenu = this.createMenuForTarget(
|
||||
collection, elem, currentTarget, clickAction
|
||||
);
|
||||
menupopup.appendChild(collectionMenu);
|
||||
}
|
||||
elem.appendChild(menu);
|
||||
return menu;
|
||||
},
|
||||
|
||||
getCollectionImageSrc: function(objectType) {
|
||||
var suffix = Zotero.hiDPI ? "@2x" : "";
|
||||
var collectionType = objectType == 'group' ? 'library' : objectType;
|
||||
return "chrome://zotero/skin/treesource-" + collectionType + suffix + ".png";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,6 @@ pref("extensions.zotero.groups.copyTags", true);
|
|||
pref("extensions.zotero.feeds.sortAscending", false);
|
||||
pref("extensions.zotero.feeds.defaultTTL", 1);
|
||||
pref("extensions.zotero.feeds.defaultCleanupAfter", 2);
|
||||
pref("extensions.zotero.feeds.lastTranslationTarget", false);
|
||||
|
||||
pref("extensions.zotero.backup.numBackups", 2);
|
||||
pref("extensions.zotero.backup.interval", 1440);
|
||||
|
|
Loading…
Reference in a new issue