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:
Dan Stillman 2016-04-05 02:16:18 -04:00
parent 8714816cec
commit f70c2bfa0a
6 changed files with 58 additions and 28 deletions

View File

@ -224,15 +224,25 @@ var ZoteroItemPane = new function() {
menu.removeChild(menu.firstChild); menu.removeChild(menu.firstChild);
} }
let target = Zotero.Prefs.get('feeds.lastTranslationTarget');
if (!target) {
target = "L" + Zotero.Libraries.userLibraryID;
}
var libraries = Zotero.Libraries.getAll(); var libraries = Zotero.Libraries.getAll();
for (let library of libraries) { for (let library of libraries) {
if (!library.editable || library.libraryType == 'publications') { if (!library.editable || library.libraryType == 'publications') {
continue; continue;
} }
Zotero.Utilities.Internal.createMenuForTarget(library, menu, function(event, libraryOrCollection) { Zotero.Utilities.Internal.createMenuForTarget(
ZoteroItemPane.setTranslationTarget(libraryOrCollection); library,
event.stopPropagation(); 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')) + (Zotero.isMac ? '⇧⌘' : Zotero.getString('general.keys.ctrlShift'))
+ key + ')'; + key + ')';
elem.setAttribute('tooltiptext', tooltip); elem.setAttribute('tooltiptext', tooltip);
elem.setAttribute('image', _translationTarget.collectionTreeViewImage);
var objectType = _translationTarget._objectType;
var imageSrc = Zotero.Utilities.Internal.getCollectionImageSrc(objectType);
elem.setAttribute('image', imageSrc);
}; };
this.setTranslationTarget = function(translationTarget) { this.setTranslationTarget = function(translationTarget) {
_translationTarget = translationTarget; _translationTarget = translationTarget;
if (translationTarget.objectType == 'collection') { Zotero.Prefs.set('feeds.lastTranslationTarget', translationTarget.collectionTreeViewID);
Zotero.Prefs.set('feeds.translationTarget', "C" + translationTarget.id);
} else {
Zotero.Prefs.set('feeds.translationTarget', "L" + translationTarget.libraryID);
}
ZoteroItemPane.setTranslateButton(); ZoteroItemPane.setTranslateButton();
}; };

View File

@ -43,9 +43,9 @@
<!-- Feed --> <!-- Feed -->
<hbox id="zotero-item-pane-top-buttons-feed" class="zotero-item-pane-top-buttons" hidden="true"> <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();"/> 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()"> oncommand="ZoteroItemPane.translateSelectedItems()">
<menupopup id="zotero-item-addTo-menu" onpopupshowing="ZoteroItemPane.buildTranslateSelectContextMenu(event);"/> <menupopup id="zotero-item-addTo-menu" onpopupshowing="ZoteroItemPane.buildTranslateSelectContextMenu(event);"/>
</button> </button>

View File

@ -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.Collection.prototype.getID = function() {
Zotero.debug('Collection.getID() deprecated -- use Collection.id'); Zotero.debug('Collection.getID() deprecated -- use Collection.id');

View File

@ -116,6 +116,7 @@ Zotero.defineProperty(Zotero.Library.prototype, 'id', {
get: function() this.libraryID, get: function() this.libraryID,
set: function(val) this.libraryID = val set: function(val) this.libraryID = val
}); });
Zotero.defineProperty(Zotero.Library.prototype, 'libraryType', { Zotero.defineProperty(Zotero.Library.prototype, 'libraryType', {
get: function() this._get('_libraryType'), get: function() this._get('_libraryType'),
set: function(v) this._set('_libraryType', v) 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', { Zotero.defineProperty(Zotero.Library.prototype, 'hasTrash', {
value: true value: true
}); });

View File

@ -939,11 +939,15 @@ Zotero.Utilities.Internal = {
* *
* @return {Node<menuitem>/Node<menu>} appended node * @return {Node<menuitem>/Node<menu>} appended node
*/ */
createMenuForTarget: function(libraryOrCollection, elem, clickAction) { createMenuForTarget: function(libraryOrCollection, elem, currentTarget, clickAction) {
var doc = elem.ownerDocument; var doc = elem.ownerDocument;
function _createMenuitem(label, value, icon, command) { function _createMenuitem(label, value, icon, command) {
let menuitem = doc.createElement('menuitem'); let menuitem = doc.createElement('menuitem');
menuitem.setAttribute("label", label); menuitem.setAttribute("label", label);
menuitem.setAttribute("type", "checkbox");
if (value == currentTarget) {
menuitem.setAttribute("checked", "true");
}
menuitem.setAttribute("value", value); menuitem.setAttribute("value", value);
menuitem.setAttribute("image", icon); menuitem.setAttribute("image", icon);
menuitem.addEventListener('command', command); menuitem.addEventListener('command', command);
@ -961,17 +965,19 @@ Zotero.Utilities.Internal = {
return menu; 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( var menuitem = _createMenuitem(
libraryOrCollection.name, libraryOrCollection.name,
libraryOrCollection.id, libraryOrCollection.collectionTreeViewID,
imageSrc, imageSrc,
function (event) { function (event) {
clickAction(event, libraryOrCollection); clickAction(event, libraryOrCollection);
} }
); );
var collections; var collections;
if (libraryOrCollection.objectType == 'collection') { if (libraryOrCollection.objectType == 'collection') {
collections = Zotero.Collections.getByParent(libraryOrCollection.id); collections = Zotero.Collections.getByParent(libraryOrCollection.id);
@ -989,17 +995,13 @@ Zotero.Utilities.Internal = {
menupopup.appendChild(menuitem); menupopup.appendChild(menuitem);
menupopup.appendChild(doc.createElement('menuseparator')); menupopup.appendChild(doc.createElement('menuseparator'));
for (let collection of collections) { for (let collection of collections) {
let collectionMenu = this.createMenuForTarget(collection, elem, clickAction); let collectionMenu = this.createMenuForTarget(
collection, elem, currentTarget, clickAction
);
menupopup.appendChild(collectionMenu); menupopup.appendChild(collectionMenu);
} }
elem.appendChild(menu); elem.appendChild(menu);
return 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";
} }
} }

View File

@ -55,7 +55,6 @@ pref("extensions.zotero.groups.copyTags", true);
pref("extensions.zotero.feeds.sortAscending", false); pref("extensions.zotero.feeds.sortAscending", false);
pref("extensions.zotero.feeds.defaultTTL", 1); pref("extensions.zotero.feeds.defaultTTL", 1);
pref("extensions.zotero.feeds.defaultCleanupAfter", 2); pref("extensions.zotero.feeds.defaultCleanupAfter", 2);
pref("extensions.zotero.feeds.lastTranslationTarget", false);
pref("extensions.zotero.backup.numBackups", 2); pref("extensions.zotero.backup.numBackups", 2);
pref("extensions.zotero.backup.interval", 1440); pref("extensions.zotero.backup.interval", 1440);