Closes #647, Quick Copy option to copy HTML for bib formats
Adds Copy as HTML options for default and site-specific settings Also makes site-specific domain/path accept just paths, for things like "/wp-admin/"
This commit is contained in:
parent
df613a7268
commit
ce65e63ef2
|
@ -312,7 +312,7 @@ var Zotero_File_Interface = new function() {
|
|||
*
|
||||
* Does not check that items are actual references (and not notes or attachments)
|
||||
*/
|
||||
function copyItemsToClipboard(items, style) {
|
||||
function copyItemsToClipboard(items, style, asHTML) {
|
||||
// copy to clipboard
|
||||
var transferable = Components.classes["@mozilla.org/widget/transferable;1"].
|
||||
createInstance(Components.interfaces.nsITransferable);
|
||||
|
@ -329,8 +329,8 @@ var Zotero_File_Interface = new function() {
|
|||
transferable.addDataFlavor("text/html");
|
||||
transferable.setTransferData("text/html", str, bibliography.length*2);
|
||||
|
||||
// add text
|
||||
var bibliography = csl.formatBibliography(itemSet, "Text");
|
||||
// add text (or HTML source)
|
||||
var bibliography = csl.formatBibliography(itemSet, asHTML ? 'HTML' : 'Text');
|
||||
var str = Components.classes["@mozilla.org/supports-string;1"].
|
||||
createInstance(Components.interfaces.nsISupportsString);
|
||||
str.data = bibliography;
|
||||
|
@ -345,8 +345,10 @@ var Zotero_File_Interface = new function() {
|
|||
* Copies HTML and text citations for passed items in given style
|
||||
*
|
||||
* Does not check that items are actual references (and not notes or attachments)
|
||||
*
|
||||
* if |asHTML| is true, copy HTML source as text
|
||||
*/
|
||||
function copyCitationToClipboard(items, style) {
|
||||
function copyCitationToClipboard(items, style, asHTML) {
|
||||
// copy to clipboard
|
||||
var transferable = Components.classes["@mozilla.org/widget/transferable;1"].
|
||||
createInstance(Components.interfaces.nsITransferable);
|
||||
|
@ -369,8 +371,8 @@ var Zotero_File_Interface = new function() {
|
|||
transferable.addDataFlavor("text/html");
|
||||
transferable.setTransferData("text/html", str, bibliography.length*2);
|
||||
|
||||
// add text
|
||||
var bibliography = csl.formatCitation(citation, "Text");
|
||||
// add text (or HTML source)
|
||||
var bibliography = csl.formatCitation(citation, asHTML ? 'HTML' : 'Text');
|
||||
var str = Components.classes["@mozilla.org/supports-string;1"].
|
||||
createInstance(Components.interfaces.nsISupportsString);
|
||||
str.data = bibliography;
|
||||
|
|
|
@ -1139,13 +1139,14 @@ var ZoteroPane = new function()
|
|||
|
||||
var url = window.content.location.href;
|
||||
var [mode, format] = Zotero.QuickCopy.getFormatFromURL(url).split('=');
|
||||
var [mode, contentType] = mode.split('/');
|
||||
|
||||
if (mode == 'bibliography') {
|
||||
if (asCitations) {
|
||||
Zotero_File_Interface.copyCitationToClipboard(items, format);
|
||||
Zotero_File_Interface.copyCitationToClipboard(items, format, contentType == 'html');
|
||||
}
|
||||
else {
|
||||
Zotero_File_Interface.copyItemsToClipboard(items, format);
|
||||
Zotero_File_Interface.copyItemsToClipboard(items, format, contentType == 'html');
|
||||
}
|
||||
}
|
||||
else if (mode == 'export') {
|
||||
|
|
|
@ -134,18 +134,32 @@ function populateOpenURLResolvers() {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* Builds the main Quick Copy drop-down from the current global pref
|
||||
*/
|
||||
function populateQuickCopyList() {
|
||||
// Initialize default format drop-down
|
||||
var formatMenu = document.getElementById("quickCopy-menu");
|
||||
var format = Zotero.Prefs.get("export.quickCopy.setting");
|
||||
buildQuickCopyFormatDropDown(formatMenu, format);
|
||||
formatMenu.setAttribute('preference', "pref-quickCopy-setting");
|
||||
var menulist = document.getElementById("zotero-quickCopy-menu");
|
||||
buildQuickCopyFormatDropDown(menulist, Zotero.QuickCopy.getContentType(format), format);
|
||||
menulist.setAttribute('preference', "pref-quickCopy-setting");
|
||||
updateQuickCopyHTMLCheckbox();
|
||||
|
||||
refreshQuickCopySiteList();
|
||||
}
|
||||
|
||||
|
||||
function buildQuickCopyFormatDropDown(menulist, currentFormat) {
|
||||
/*
|
||||
* Builds a Quick Copy drop-down
|
||||
*/
|
||||
function buildQuickCopyFormatDropDown(menulist, contentType, currentFormat) {
|
||||
if (!currentFormat) {
|
||||
currentFormat = menulist.value;
|
||||
}
|
||||
// Strip contentType from mode
|
||||
currentFormat = Zotero.QuickCopy.stripContentType(currentFormat);
|
||||
|
||||
|
||||
menulist.selectedItem = null;
|
||||
menulist.removeAllItems();
|
||||
|
||||
|
@ -167,13 +181,15 @@ function buildQuickCopyFormatDropDown(menulist, currentFormat) {
|
|||
// add styles to list
|
||||
var styles = Zotero.Cite.getStyles();
|
||||
for (var i in styles) {
|
||||
var val = 'bibliography=' + i;
|
||||
var baseVal = 'bibliography=' + i;
|
||||
var val = 'bibliography' + (contentType == 'html' ? '/html' : '') + '=' + i;
|
||||
var itemNode = document.createElement("menuitem");
|
||||
itemNode.setAttribute("value", val);
|
||||
itemNode.setAttribute("label", styles[i]);
|
||||
itemNode.setAttribute("oncommand", 'updateQuickCopyHTMLCheckbox()');
|
||||
popup.appendChild(itemNode);
|
||||
|
||||
if (val == currentFormat) {
|
||||
if (baseVal == currentFormat) {
|
||||
menulist.selectedItem = itemNode;
|
||||
}
|
||||
}
|
||||
|
@ -198,6 +214,7 @@ function buildQuickCopyFormatDropDown(menulist, currentFormat) {
|
|||
var itemNode = document.createElement("menuitem");
|
||||
itemNode.setAttribute("value", val);
|
||||
itemNode.setAttribute("label", translators[i].label);
|
||||
itemNode.setAttribute("oncommand", 'updateQuickCopyHTMLCheckbox()');
|
||||
popup.appendChild(itemNode);
|
||||
|
||||
if (val == currentFormat) {
|
||||
|
@ -205,19 +222,37 @@ function buildQuickCopyFormatDropDown(menulist, currentFormat) {
|
|||
}
|
||||
}
|
||||
|
||||
menulist.click();
|
||||
|
||||
return popup;
|
||||
}
|
||||
|
||||
function updateQuickCopyHTMLCheckbox() {
|
||||
var format = document.getElementById('zotero-quickCopy-menu').value;
|
||||
var mode, contentType;
|
||||
|
||||
var checkbox = document.getElementById('zotero-quickCopy-copyAsHTML');
|
||||
[mode, format] = format.split('=');
|
||||
[mode, contentType] = mode.split('/');
|
||||
|
||||
checkbox.checked = contentType == 'html';
|
||||
checkbox.disabled = mode != 'bibliography';
|
||||
}
|
||||
|
||||
function showQuickCopySiteEditor(index) {
|
||||
var treechildren = document.getElementById('quickCopy-siteSettings-rows');
|
||||
|
||||
if (index != undefined && index > -1 && index < treechildren.childNodes.length) {
|
||||
var treerow = treechildren.childNodes[index].firstChild;
|
||||
var domain = treerow.childNodes[0].getAttribute('label')
|
||||
var format = treerow.childNodes[1].getAttribute('label')
|
||||
var domain = treerow.childNodes[0].getAttribute('label');
|
||||
var format = treerow.childNodes[1].getAttribute('label');
|
||||
var asHTML = treerow.childNodes[2].getAttribute('label') != '';
|
||||
}
|
||||
|
||||
var format = Zotero.QuickCopy.getSettingFromFormattedName(format);
|
||||
if (asHTML) {
|
||||
format = format.replace('bibliography=', 'bibliography/html=');
|
||||
}
|
||||
|
||||
var io = {domain: domain, format: format, ok: false};
|
||||
window.openDialog('chrome://zotero/content/preferences/quickCopySiteEditor.xul', "zotero-preferences-quickCopySiteEditor", "chrome, modal", io);
|
||||
|
@ -254,14 +289,18 @@ function refreshQuickCopySiteList() {
|
|||
var treerow = document.createElement('treerow');
|
||||
var domainCell = document.createElement('treecell');
|
||||
var formatCell = document.createElement('treecell');
|
||||
var HTMLCell = document.createElement('treecell');
|
||||
|
||||
domainCell.setAttribute('label', siteData[i].domainPath);
|
||||
|
||||
var formatted = Zotero.QuickCopy.getFormattedNameFromSetting(siteData[i].format);
|
||||
formatCell.setAttribute('label', formatted);
|
||||
var copyAsHTML = Zotero.QuickCopy.getContentType(siteData[i].format) == 'html';
|
||||
HTMLCell.setAttribute('label', copyAsHTML ? ' ✓ ' : '');
|
||||
|
||||
treerow.appendChild(domainCell);
|
||||
treerow.appendChild(formatCell);
|
||||
treerow.appendChild(HTMLCell);
|
||||
treeitem.appendChild(treerow);
|
||||
treechildren.appendChild(treeitem);
|
||||
}
|
||||
|
|
|
@ -262,30 +262,32 @@ To add a new preference:
|
|||
|
||||
<separator/>
|
||||
|
||||
<vbox>
|
||||
<label value="&zotero.preferences.quickCopy.defaultOutputFormat;" control="quickCopy-menu"/>
|
||||
<menulist id="quickCopy-menu"/>
|
||||
</vbox>
|
||||
<label value="&zotero.preferences.quickCopy.defaultOutputFormat;" control="quickCopy-menu"/>
|
||||
<menulist id="zotero-quickCopy-menu"/>
|
||||
|
||||
<separator/>
|
||||
|
||||
<vbox>
|
||||
<label value="&zotero.preferences.quickCopy.siteEditor.setings;" control="quickCopy-siteSettings"/>
|
||||
<tree flex="1" id="quickCopy-siteSettings" hidecolumnpicker="true" rows="6" seltype="single"
|
||||
ondblclick="showQuickCopySiteEditor(this.currentIndex)"
|
||||
onkeypress="if (event.keyCode == event.DOM_VK_DELETE) { deleteSelectedQuickCopySite(); }">
|
||||
<treecols>
|
||||
<treecol id="quickCopy-urlColumn" label="&zotero.preferences.quickCopy.siteEditor.domainPath;" flex="1"/>
|
||||
<treecol id="quickCopy-formatColumn" label="&zotero.preferences.quickCopy.siteEditor.outputFormat;" flex="2"/>
|
||||
</treecols>
|
||||
<treechildren id="quickCopy-siteSettings-rows"/>
|
||||
</tree>
|
||||
<separator class="thin"/>
|
||||
<hbox pack="end">
|
||||
<button label="-" onclick="deleteSelectedQuickCopySite()"/>
|
||||
<button label="+" onclick="showQuickCopySiteEditor()"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
<checkbox id="zotero-quickCopy-copyAsHTML" label="&zotero.preferences.quickCopy.copyAsHTML;"
|
||||
oncommand="buildQuickCopyFormatDropDown(document.getElementById('zotero-quickCopy-menu'), this.checked ? 'html' : '');"/>
|
||||
|
||||
<separator/>
|
||||
|
||||
<label value="&zotero.preferences.quickCopy.siteEditor.setings;" control="quickCopy-siteSettings"/>
|
||||
<tree flex="1" id="quickCopy-siteSettings" hidecolumnpicker="true" rows="6" seltype="single"
|
||||
ondblclick="showQuickCopySiteEditor(this.currentIndex)"
|
||||
onkeypress="if (event.keyCode == event.DOM_VK_DELETE) { deleteSelectedQuickCopySite(); }">
|
||||
<treecols>
|
||||
<treecol id="quickCopy-urlColumn" label="&zotero.preferences.quickCopy.siteEditor.domainPath;" flex="1"/>
|
||||
<treecol id="quickCopy-formatColumn" label="&zotero.preferences.quickCopy.siteEditor.outputFormat;" flex="2"/>
|
||||
<treecol id="quickCopy-copyAsHTML" label="HTML"/>
|
||||
</treecols>
|
||||
<treechildren id="quickCopy-siteSettings-rows"/>
|
||||
</tree>
|
||||
<separator class="thin"/>
|
||||
<hbox pack="end">
|
||||
<button label="-" onclick="deleteSelectedQuickCopySite()"/>
|
||||
<button label="+" onclick="showQuickCopySiteEditor()"/>
|
||||
</hbox>
|
||||
|
||||
<separator/>
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
function onAccept() {
|
||||
var io = window.arguments[0];
|
||||
io.domain = document.getElementById('zotero-quickCopy-domain').value;
|
||||
io.format = document.getElementById('zotero-quickCopy-format').value;
|
||||
io.format = document.getElementById('zotero-quickCopy-menu').value;
|
||||
io.ok = true;
|
||||
}
|
||||
}
|
||||
|
@ -28,21 +28,22 @@
|
|||
</script>
|
||||
|
||||
<vbox id="zotero-preferences-quickCopySiteEditor">
|
||||
<vbox>
|
||||
<label value="&zotero.preferences.quickCopy.siteEditor.domainPath; &zotero.preferences.quickCopy.siteEditor.domainPath.example;" control="zotero-quickCopy-domain"/>
|
||||
<textbox id="zotero-quickCopy-domain"/>
|
||||
</vbox>
|
||||
<vbox>
|
||||
<label value="&zotero.preferences.quickCopy.siteEditor.outputFormat;" control="zotero-quickCopy-format"/>
|
||||
<menulist id="zotero-quickCopy-format"/>
|
||||
</vbox>
|
||||
<label value="&zotero.preferences.quickCopy.siteEditor.domainPath; &zotero.preferences.quickCopy.siteEditor.domainPath.example;" control="zotero-quickCopy-domain"/>
|
||||
<textbox id="zotero-quickCopy-domain"/>
|
||||
<separator class="thin"/>
|
||||
<label value="&zotero.preferences.quickCopy.siteEditor.outputFormat;" control="zotero-quickCopy-menu"/>
|
||||
<menulist id="zotero-quickCopy-menu"/>
|
||||
<separator class="thin"/>
|
||||
<checkbox id="zotero-quickCopy-copyAsHTML" label="&zotero.preferences.quickCopy.copyAsHTML;"
|
||||
oncommand="buildQuickCopyFormatDropDown(document.getElementById('zotero-quickCopy-menu'), this.checked ? 'html' : '')"/>
|
||||
</vbox>
|
||||
|
||||
<script>
|
||||
<![CDATA[
|
||||
var io = window.arguments[0];
|
||||
document.getElementById('zotero-quickCopy-domain').value = io.domain ? io.domain : '';
|
||||
buildQuickCopyFormatDropDown(document.getElementById('zotero-quickCopy-format'), io.format);
|
||||
buildQuickCopyFormatDropDown(document.getElementById('zotero-quickCopy-menu'), Zotero.QuickCopy.getContentType(io.format), io.format);
|
||||
updateQuickCopyHTMLCheckbox();
|
||||
]]>
|
||||
</script>
|
||||
</dialog>
|
||||
|
|
|
@ -1432,9 +1432,6 @@ Zotero.ItemTreeCommandController.prototype.onEvent = function(evt)
|
|||
*/
|
||||
Zotero.ItemTreeView.prototype.onDragStart = function (evt,transferData,action)
|
||||
{
|
||||
try {
|
||||
|
||||
|
||||
transferData.data = new TransferData();
|
||||
transferData.data.addDataForFlavour("zotero/item", this.saveSelection());
|
||||
|
||||
|
@ -1472,17 +1469,13 @@ Zotero.ItemTreeView.prototype.onDragStart = function (evt,transferData,action)
|
|||
if (mode == 'export') {
|
||||
Zotero.QuickCopy.getContentFromItems(items, format, exportCallback);
|
||||
}
|
||||
else if (mode == 'bibliography') {
|
||||
else if (mode.indexOf('bibliography') == 0) {
|
||||
var content = Zotero.QuickCopy.getContentFromItems(items, format);
|
||||
transferData.data.addDataForFlavour("text/unicode", content.text);
|
||||
transferData.data.addDataForFlavour("text/html", content.html);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.debug(e);
|
||||
else {
|
||||
Components.utils.reportError("Invalid Quick Copy mode '" + mode + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
Zotero.QuickCopy = new function() {
|
||||
this.getFormattedNameFromSetting = getFormattedNameFromSetting;
|
||||
this.getSettingFromFormattedName = getSettingFromFormattedName;
|
||||
this.getContentType = getContentType;
|
||||
this.stripContentType = stripContentType;
|
||||
this.getFormatFromURL = getFormatFromURL;
|
||||
this.getContentFromItems = getContentFromItems;
|
||||
|
||||
|
@ -13,7 +15,7 @@ Zotero.QuickCopy = new function() {
|
|||
_init();
|
||||
}
|
||||
|
||||
return _formattedNames[setting];
|
||||
return _formattedNames[this.stripContentType(setting)];
|
||||
}
|
||||
|
||||
function getSettingFromFormattedName(name) {
|
||||
|
@ -31,6 +33,23 @@ Zotero.QuickCopy = new function() {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns the setting with any contentType stripped from the mode part
|
||||
*/
|
||||
function getContentType(setting) {
|
||||
var matches = setting.match(/(?:bibliography|export)\/([^=]+)=.+$/, '$1');
|
||||
return matches ? matches[1] : '';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns the setting with any contentType stripped from the mode part
|
||||
*/
|
||||
function stripContentType(setting) {
|
||||
return setting.replace(/(bibliography|export)(?:\/[^=]+)?=(.+)$/, '$1=$2');
|
||||
}
|
||||
|
||||
|
||||
function getFormatFromURL(url) {
|
||||
if (!url) {
|
||||
return Zotero.Prefs.get("export.quickCopy.setting");
|
||||
|
@ -51,9 +70,9 @@ Zotero.QuickCopy = new function() {
|
|||
var matches = [];
|
||||
|
||||
var sql = "SELECT key AS domainPath, value AS format FROM settings "
|
||||
+ "WHERE setting='quickCopySite' AND key LIKE ?";
|
||||
+ "WHERE setting='quickCopySite' AND (key LIKE ? OR key LIKE ?)";
|
||||
var urlDomain = urlHostPort.match(/[^\.]+\.[^\.]+$/);
|
||||
var rows = Zotero.DB.query(sql, ['%' + urlDomain + '%']);
|
||||
var rows = Zotero.DB.query(sql, ['%' + urlDomain + '%', '/%']);
|
||||
for each(var row in rows) {
|
||||
var [domain, path] = row.domainPath.split(/\//);
|
||||
path = '/' + (path ? path : '');
|
||||
|
@ -113,6 +132,7 @@ Zotero.QuickCopy = new function() {
|
|||
*/
|
||||
function getContentFromItems(items, format, callback) {
|
||||
var [mode, format] = format.split('=');
|
||||
var [mode, contentType] = mode.split('/');
|
||||
|
||||
if (mode == 'export') {
|
||||
var translation = new Zotero.Translate("export");
|
||||
|
@ -127,7 +147,7 @@ Zotero.QuickCopy = new function() {
|
|||
var csl = Zotero.Cite.getStyle(format);
|
||||
var itemSet = csl.createItemSet(items);
|
||||
var bibliography = {
|
||||
text: csl.formatBibliography(itemSet, "Text"),
|
||||
text: csl.formatBibliography(itemSet, contentType == "html" ? "HTML" : "Text"),
|
||||
html: csl.formatBibliography(itemSet, "HTML")
|
||||
};
|
||||
return bibliography;
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
|
||||
<!ENTITY zotero.preferences.quickCopy.caption "Quick Copy">
|
||||
<!ENTITY zotero.preferences.quickCopy.defaultOutputFormat "Default Output Format:">
|
||||
<!ENTITY zotero.preferences.quickCopy.copyAsHTML "Copy as HTML">
|
||||
<!ENTITY zotero.preferences.quickCopy.macWarning "Note: Rich-text formatting will be lost on Mac OS X.">
|
||||
<!ENTITY zotero.preferences.quickCopy.siteEditor.setings "Site-Specific Settings:">
|
||||
<!ENTITY zotero.preferences.quickCopy.siteEditor.domainPath "Domain/Path">
|
||||
|
|
|
@ -100,6 +100,14 @@ grid row hbox:first-child
|
|||
font-size: .85em;
|
||||
}
|
||||
|
||||
#quickCopy-siteSettings-rows::-moz-tree-cell(quickCopy-copyAsHTML) {
|
||||
/*
|
||||
DEBUG: possible to center checkmark here instead of with spaces?
|
||||
|
||||
Tried text-align, -moz-box-align, and -moz-box-pack
|
||||
*/
|
||||
}
|
||||
|
||||
#zotero-quickCopy-format
|
||||
{
|
||||
min-height: 1.5em; /* Fix collapse on Windows */
|
||||
|
|
Loading…
Reference in New Issue
Block a user