Closes #603, Add preference to disable title-casing in translators
- Zotero.Utilities.capitalizeTitle() now follows the capitalizeTitles pref, enabled by default; added |force| parameter to override - Added context menu on metadata fields to lowercase or title case title-ish fields; only works in non-editor mode currently, since overriding the textbox context menu is more annoying - Fixed error in capitalizeTitle() on string with just whitespace
This commit is contained in:
parent
9d8c427d1e
commit
311bccaa78
|
@ -70,6 +70,7 @@ var ZoteroItemPane = new function()
|
|||
this.handleKeyPress = handleKeyPress;
|
||||
this.handleCreatorAutoCompleteSelect = handleCreatorAutoCompleteSelect;
|
||||
this.hideEditor = hideEditor;
|
||||
this.textTransform = textTransform;
|
||||
this.getCreatorFields = getCreatorFields;
|
||||
this.modifyCreator = modifyCreator;
|
||||
this.removeNote = removeNote;
|
||||
|
@ -873,6 +874,9 @@ var ZoteroItemPane = new function()
|
|||
|
||||
function createValueElement(valueText, fieldName, tabindex, noedit)
|
||||
{
|
||||
var fieldID = Zotero.ItemFields.getID(fieldName);
|
||||
|
||||
// If an abstract, check last expand state
|
||||
var abstractAsVbox = (fieldName == 'abstractNote') &&
|
||||
Zotero.Prefs.get('lastAbstractExpand');
|
||||
|
||||
|
@ -893,7 +897,7 @@ var ZoteroItemPane = new function()
|
|||
valueElement.className = 'zotero-clicky';
|
||||
}
|
||||
|
||||
switch (fieldName){
|
||||
switch (fieldName) {
|
||||
case 'tag':
|
||||
_tabIndexMaxTagsFields = Math.max(_tabIndexMaxTagsFields, tabindex);
|
||||
break;
|
||||
|
@ -914,13 +918,22 @@ var ZoteroItemPane = new function()
|
|||
break;
|
||||
}
|
||||
|
||||
// Display the SQL date as a tooltip for date fields
|
||||
var fieldID = Zotero.ItemFields.getID(fieldName);
|
||||
if (fieldID && Zotero.ItemFields.isFieldOfBase(fieldID, 'date')) {
|
||||
valueElement.setAttribute('tooltiptext',
|
||||
Zotero.Date.multipartToSQL(_itemBeingEdited.getField(fieldName, true)));
|
||||
if (fieldID) {
|
||||
// Display the SQL date as a tooltip for date fields
|
||||
if (Zotero.ItemFields.isFieldOfBase(fieldID, 'date')) {
|
||||
valueElement.setAttribute('tooltiptext',
|
||||
Zotero.Date.multipartToSQL(_itemBeingEdited.getField(fieldName, true)));
|
||||
}
|
||||
|
||||
// Display a context menu for certain fields
|
||||
if (fieldName == 'seriesTitle' || fieldName == 'shortTitle' ||
|
||||
Zotero.ItemFields.isFieldOfBase(fieldID, 'title') ||
|
||||
Zotero.ItemFields.isFieldOfBase(fieldID, 'publicationTitle')) {
|
||||
valueElement.setAttribute('contextmenu', 'zotero-field-menu');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (fieldName.indexOf('firstName')!=-1){
|
||||
valueElement.setAttribute('flex', '1');
|
||||
}
|
||||
|
@ -1081,6 +1094,8 @@ var ZoteroItemPane = new function()
|
|||
|
||||
_tabDirection = false;
|
||||
_lastTabIndex = tabindex;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1356,8 +1371,9 @@ var ZoteroItemPane = new function()
|
|||
}
|
||||
}
|
||||
|
||||
if(saveChanges)
|
||||
modifyField(fieldName,value);
|
||||
if (saveChanges) {
|
||||
_modifyField(fieldName,value);
|
||||
}
|
||||
|
||||
elem = createValueElement(_itemBeingEdited.getField(fieldName), fieldName, tabindex);
|
||||
}
|
||||
|
@ -1376,12 +1392,13 @@ var ZoteroItemPane = new function()
|
|||
}
|
||||
}
|
||||
|
||||
function modifyField(field, value)
|
||||
function _modifyField(field, value)
|
||||
{
|
||||
_itemBeingEdited.setField(field,value);
|
||||
return _itemBeingEdited.save();
|
||||
}
|
||||
|
||||
|
||||
function _getFieldValue(field)
|
||||
{
|
||||
return field.firstChild
|
||||
|
@ -1400,6 +1417,26 @@ var ZoteroItemPane = new function()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: work with textboxes too
|
||||
function textTransform(label, mode) {
|
||||
var val = _getFieldValue(label);
|
||||
switch (mode) {
|
||||
case 'lower':
|
||||
var newVal = val.toLowerCase();
|
||||
break;
|
||||
case 'title':
|
||||
var utils = new Zotero.Utilities();
|
||||
var newVal = utils.capitalizeTitle(val.toLowerCase(), true);
|
||||
break;
|
||||
default:
|
||||
throw ("Invalid transform mode '" + mode + "' in ZoteroItemPane.textTransform()");
|
||||
}
|
||||
_setFieldValue(label, newVal);
|
||||
_modifyField(label.getAttribute('fieldname'), newVal);
|
||||
}
|
||||
|
||||
|
||||
function getCreatorFields(row){
|
||||
var typeID = row.getElementsByTagName('toolbarbutton')[0].getAttribute('typeid');
|
||||
var label1 = row.getElementsByTagName('hbox')[0].firstChild.firstChild;
|
||||
|
@ -1464,6 +1501,7 @@ var ZoteroItemPane = new function()
|
|||
_itemBeingEdited.save();
|
||||
}
|
||||
|
||||
|
||||
function removeNote(id)
|
||||
{
|
||||
var note = Zotero.Items.get(id);
|
||||
|
|
|
@ -38,6 +38,16 @@
|
|||
document.popupNode.setAttribute('typeid', typeID);
|
||||
ZoteroItemPane.modifyCreator(document.popupNode.getAttribute('fieldname').split('-')[1],
|
||||
'typeID', typeID, otherFields)"/>
|
||||
<popup id="zotero-field-menu">
|
||||
<menu label="&zotero.item.textTransform;">
|
||||
<menupopup>
|
||||
<menuitem label="&zotero.item.textTransform.lowercase;" class="menuitem-non-iconic"
|
||||
oncommand="ZoteroItemPane.textTransform(document.popupNode, 'lower')"/>
|
||||
<menuitem label="&zotero.item.textTransform.titlecase;" class="menuitem-non-iconic"
|
||||
oncommand="ZoteroItemPane.textTransform(document.popupNode, 'title')"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
</popup>
|
||||
</popupset>
|
||||
<hbox id="zotero-editpane-go-buttons" align="center">
|
||||
<button id="zotero-go-to-url"
|
||||
|
|
|
@ -4255,10 +4255,12 @@ Zotero.ItemFields = new function(){
|
|||
}
|
||||
|
||||
|
||||
function getLocalizedString(itemTypeID, field) {
|
||||
function getLocalizedString(itemType, field) {
|
||||
// unused currently
|
||||
//var typeName = Zotero.ItemTypes.getName(itemType);
|
||||
var fieldName = this.getName(field);
|
||||
|
||||
// Fields in items are special cases
|
||||
// Fields in the items table are special cases
|
||||
switch (field) {
|
||||
case 'dateAdded':
|
||||
case 'dateModified':
|
||||
|
|
|
@ -304,13 +304,21 @@ Zotero.Utilities.prototype.getLocalizedCreatorType = function(type) {
|
|||
|
||||
/*
|
||||
* Cleans a title, capitalizing the proper words and replacing " :" with ":"
|
||||
*
|
||||
* Follows capitalizeTitles pref, unless |force| is true
|
||||
*/
|
||||
Zotero.Utilities.capitalizeSkipWords = ["but", "or", "yet", "so", "for", "and",
|
||||
"nor", "a", "an", "the", "at", "by", "from", "in", "into", "of", "on", "to",
|
||||
"with", "up", "down"];
|
||||
Zotero.Utilities.prototype.capitalizeTitle = function(title) {
|
||||
Zotero.Utilities.prototype.capitalizeTitle = function(title, force) {
|
||||
if (!Zotero.Prefs.get('capitalizeTitles') && !force) {
|
||||
return title;
|
||||
}
|
||||
title = this.cleanString(title);
|
||||
title = title.replace(/ : /g, ": ");
|
||||
if (!title) {
|
||||
return '';
|
||||
}
|
||||
title = title.replace(/ : /g, ": ");
|
||||
var words = title.split(" ");
|
||||
|
||||
// always capitalize first
|
||||
|
@ -444,6 +452,7 @@ Zotero.Utilities.Ingester.prototype.parseContextObject = function(co, item) {
|
|||
return Zotero.OpenURL.parseContextObject(co, item);
|
||||
}
|
||||
|
||||
|
||||
// Ingester adapters for Zotero.Utilities.HTTP to handle proxies
|
||||
|
||||
Zotero.Utilities.Ingester.prototype.loadDocument = function(url, succeeded, failed) {
|
||||
|
|
|
@ -73,6 +73,9 @@
|
|||
|
||||
<!ENTITY zotero.item.add "Add">
|
||||
<!ENTITY zotero.item.attachment.file.show "Show File">
|
||||
<!ENTITY zotero.item.textTransform "Transform Text">
|
||||
<!ENTITY zotero.item.textTransform.lowercase "lower case">
|
||||
<!ENTITY zotero.item.textTransform.titlecase "Title Case">
|
||||
|
||||
<!ENTITY zotero.toolbar.note.standalone "New Standalone Note">
|
||||
<!ENTITY zotero.toolbar.attachment.linked "Link to File...">
|
||||
|
|
|
@ -19,6 +19,7 @@ pref("extensions.zotero.automaticTags",true);
|
|||
pref("extensions.zotero.fontSize", "1.0");
|
||||
pref("extensions.zotero.recursiveCollections", false);
|
||||
pref("extensions.zotero.attachmentRenameFormatString", '{%c - }{%y - }{%t{50}}');
|
||||
pref("extensions.zotero.capitalizeTitles", false);
|
||||
|
||||
pref("extensions.zotero.lastCreatorFieldMode",0);
|
||||
pref("extensions.zotero.lastAbstractExpand",0);
|
||||
|
|
Loading…
Reference in New Issue
Block a user