Merge branch '3.0'

Conflicts:
	chrome/content/zotero/tinymce/plugins/paste/editor_plugin.js
	chrome/content/zotero/xpcom/translation/translate_firefox.js
	chrome/content/zotero/zoteroPane.js
	install.rdf
	update.rdf
This commit is contained in:
Dan Stillman 2012-11-01 22:14:08 -04:00
commit 3a9483070e
18 changed files with 268 additions and 109 deletions

View file

@ -95,9 +95,24 @@ var Zotero_File_Interface_Bibliography = new function() {
// ONLY FOR bibliography.xul: export options
if(document.getElementById("save-as-rtf")) {
var settings = Zotero.Prefs.get("export.bibliographySettings");
try {
settings = JSON.parse(settings);
var mode = settings.mode;
var method = settings.method;
}
// If not JSON, assume it's the previous format-as-a-string
catch (e) {
method = settings;
}
if (!mode) mode = "bibliography";
if (!method) method = "save-as-rtf";
// restore saved bibliographic settings
document.getElementById('output-radio').selectedItem =
document.getElementById(Zotero.Prefs.get("export.bibliographySettings"));
document.getElementById('output-mode-radio').selectedItem =
document.getElementById(mode);
document.getElementById('output-method-radio').selectedItem =
document.getElementById(method);
}
// ONLY FOR integrationDocPrefs.xul: update status of displayAs, set
@ -126,7 +141,7 @@ var Zotero_File_Interface_Bibliography = new function() {
}
/*
* ONLY FOR integrationDocPrefs.xul: called when style is changed
* Called when style is changed
*/
function styleChanged(index) {
// When called from init(), selectedItem isn't yet set
@ -139,6 +154,10 @@ var Zotero_File_Interface_Bibliography = new function() {
var selectedStyle = selectedItem.getAttribute('value');
//
// For integrationDocPrefs.xul
//
// update status of displayAs box based on style class
if(document.getElementById("displayAs")) {
var isNote = Zotero.Styles.get(selectedStyle).class == "note";
@ -151,16 +170,32 @@ var Zotero_File_Interface_Bibliography = new function() {
document.getElementById("bookmarks").disabled = isNote;
document.getElementById("bookmarks-caption").disabled = isNote;
}
//
// For bibliography.xul
//
// Change label to "Citation" or "Note" depending on style class
if(document.getElementById("citation")) {
if(Zotero.Styles.get(selectedStyle).class == "note") {
var label = Zotero.getString('citation.note');
} else {
var label = Zotero.getString('citation.citation');
}
document.getElementById("citation").label = label;
}
}
function acceptSelection() {
// collect code
_io.style = document.getElementById("style-listbox").selectedItem.value;
if(document.getElementById("output-radio")) {
if(document.getElementById("output-method-radio")) {
// collect settings
_io.output = document.getElementById("output-radio").selectedItem.id;
_io.mode = document.getElementById("output-mode-radio").selectedItem.id;
_io.method = document.getElementById("output-method-radio").selectedItem.id;
// save settings
Zotero.Prefs.set("export.bibliographySettings", _io.output);
Zotero.Prefs.set("export.bibliographySettings",
JSON.stringify({ mode: _io.mode, method: _io.method }));
}
// ONLY FOR integrationDocPrefs.xul: collect displayAs

View file

@ -14,11 +14,18 @@
<vbox id="zotero-bibliography-container">
<groupbox>
<caption label="&zotero.bibliography.style.label;"/>
<listbox id="style-listbox" oncommand="Zotero_File_Interface_Bibliography.styleChanged()"/>
<listbox id="style-listbox" onselect="Zotero_File_Interface_Bibliography.styleChanged()"/>
</groupbox>
<groupbox>
<caption label="&zotero.bibliography.output.label;"/>
<radiogroup id="output-radio">
<caption label="&zotero.bibliography.outputMode;"/>
<radiogroup id="output-mode-radio">
<radio id="citation"/>
<radio id="bibliography" label="&zotero.bibliography.bibliography;"/>
</radiogroup>
</groupbox>
<groupbox>
<caption label="&zotero.bibliography.outputMethod;"/>
<radiogroup id="output-method-radio">
<radio id="save-as-rtf" label="&zotero.bibliography.saveAsRTF.label;"/>
<radio id="save-as-html" label="&zotero.bibliography.saveAsHTML.label;"/>
<radio id="copy-to-clipboard" label="&zotero.bibliography.copyToClipboard.label;"/>

View file

@ -268,11 +268,28 @@
<body>
<![CDATA[
switch (event.keyCode) {
// Insert tab manually
case 9:
if (event.shiftKey || event.ctrlKey || event.altKey) {
if (event.ctrlKey || event.altKey) {
return;
}
event.stopPropagation();
event.preventDefault();
// On shift-tab, focus the element specified in
// the 'previousfocus' attribute
if (event.shiftKey) {
let id = this.getAttribute('previousfocus');
if (id) {
setTimeout(function () {
document.getElementById(id).focus();
}, 0);
}
return;
}
// Insert tab manually
//
// From http://kb.mozillazine.org/Inserting_text_at_cursor
try {
var command = "cmd_insertText";
@ -289,9 +306,6 @@
Zotero.debug("Can't do cmd_insertText!\n" + e, 1);
}
event.stopPropagation();
event.preventDefault();
// DEBUG: is there a better way to prevent blur()?
setTimeout(function() { event.target.focus(); }, 1);
break;

View file

@ -521,30 +521,43 @@ var Zotero_File_Interface = new function() {
var newDialog = window.openDialog("chrome://zotero/content/bibliography.xul",
"_blank","chrome,modal,centerscreen", io);
if(!io.output) return;
if(!io.method) return;
// determine output format
var format = "html";
if(io.output == "save-as-rtf") {
if(io.method == "save-as-rtf") {
format = "rtf";
}
// generate bibliography
try {
if(io.output == 'copy-to-clipboard') {
copyItemsToClipboard(items, io.style);
if(io.method == 'copy-to-clipboard') {
if (io.mode == 'citation') {
copyCitationToClipboard(items, io.style);
}
else {
copyItemsToClipboard(items, io.style);
}
return;
}
else {
var style = Zotero.Styles.get(io.style);
var bibliography = Zotero.Cite.makeFormattedBibliographyOrCitationList(style, items, format);
if (io.mode == 'citation') {
var csl = Zotero.Styles.get(format).csl;
csl.updateItems([item.id for each(item in items)]);
var citation = {citationItems:[{id:item.id} for each(item in items)], properties:{}};
var bibliography = csl.previewCitationCluster(citation, [], [], "html");
}
else {
var style = Zotero.Styles.get(io.style);
var bibliography = Zotero.Cite.makeFormattedBibliographyOrCitationList(style, items, format);
}
}
} catch(e) {
window.alert(Zotero.getString("fileInterface.bibliographyGenerationError"));
throw(e);
}
if(io.output == "print") {
if(io.method == "print") {
// printable bibliography, using a hidden browser
var browser = Zotero.Browser.createHiddenBrowser(window);
@ -581,7 +594,7 @@ var Zotero_File_Interface = new function() {
browser.addEventListener("pageshow", listener, false);
browser.loadURIWithFlags("data:text/html;charset=utf-8,"+encodeURI(bibliography),
Components.interfaces.nsIWebNavigation.LOAD_FLAGS_BYPASS_HISTORY, null, "utf-8", null);
} else if(io.output == "save-as-html") {
} else if(io.method == "save-as-html") {
var fStream = _saveBibliography(name, "HTML");
if(fStream !== false) {
@ -607,7 +620,7 @@ var Zotero_File_Interface = new function() {
os.close();
fStream.close();
}
} else if(io.output == "save-as-rtf") {
} else if(io.method == "save-as-rtf") {
var fStream = _saveBibliography(name, "RTF");
if(fStream !== false) {
fStream.write(bibliography, bibliography.length);

View file

@ -90,7 +90,7 @@
<!-- Note item -->
<groupbox id="zotero-view-note" flex="1">
<zoteronoteeditor id="zotero-note-editor" flex="1" notitle="1"/>
<zoteronoteeditor id="zotero-note-editor" flex="1" notitle="1" previousfocus="zotero-items-tree"/>
<button id="zotero-view-note-button" label="&zotero.notes.separate;" oncommand="ZoteroPane_Local.openNoteWindow(this.getAttribute('noteID')); if(this.hasAttribute('sourceID')) ZoteroPane_Local.selectItem(this.getAttribute('sourceID'));"/>
</groupbox>

View file

@ -118,7 +118,9 @@ const Zotero_Lookup = new function () {
/**
* Cancels the popup and resets fields
*/
this.onHidden = function() {
document.getElementById("zotero-lookup-textbox").value = "";
this.onHidden = function(event) {
if (event.target.id == 'zotero-lookup-panel') {
document.getElementById("zotero-lookup-textbox").value = "";
}
}
}

File diff suppressed because one or more lines are too long

View file

@ -1394,7 +1394,7 @@ Zotero.Attachments = new function(){
var win = doc.defaultView;
if(win) {
win = win.wrappedJSObject;
if(win && "PDFJS" in win && win.PDFJS.isFirefoxExtension) {
if(win && "PDFJS" in win) {
return true;
}
}

View file

@ -174,6 +174,10 @@ Zotero.ItemTreeView.prototype._setTreeGenerator = function(treebox)
// in overlay.js::onCollectionSelected()
this.listener = listener;
tree.addEventListener('keypress', listener, false);
// This seems to be the only way to prevent Enter/Return
// from toggle row open/close. The event is handled by
// handleKeyPress() in zoteroPane.js.
tree._handleEnter = function () {};
this.sort();

View file

@ -70,12 +70,17 @@ Zotero.Report = new function() {
// Independent note
if (arr['note']) {
content += '\n';
if (arr.note.substr(0, 1024).match(/<p[^>]*>/)) {
content += arr.note + '\n';
// If not valid XML, display notes with entities encoded
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
.createInstance(Components.interfaces.nsIDOMParser);
var doc = parser.parseFromString(arr.note, "application/xml");
if (doc.documentElement.tagName == 'parsererror') {
content += '<p class="plaintext">' + escapeXML(arr.note) + '</p>\n';
}
// Wrap plaintext notes in <p>
// Otherwise render markup normally
else {
content += '<p class="plaintext">' + arr.note + '</p>\n';
content += arr.note + '\n';
}
}
}
@ -92,13 +97,17 @@ Zotero.Report = new function() {
for each(var note in arr.reportChildren.notes) {
content += '<li id="i' + note.itemID + '">\n';
if (note.note.substr(0, 1024).match(/<p[^>]*>/)) {
content += note.note + '\n';
}
// Wrap plaintext notes in <p>
else {
// If not valid XML, display notes with entities encoded
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
.createInstance(Components.interfaces.nsIDOMParser);
var doc = parser.parseFromString(note.note, "application/xml");
if (doc.documentElement.tagName == 'parsererror') {
content += '<p class="plaintext">' + escapeXML(note.note) + '</p>\n';
}
// Otherwise render markup normally
else {
content += note.note + '\n';
}
// Child note tags
content += _generateTagsList(note);

View file

@ -453,7 +453,8 @@ Zotero.Translate.SandboxManager.prototype = {
*/
"importObject":function(object, passAsFirstArgument, attachTo) {
if(!attachTo) attachTo = this.sandbox.Zotero;
var newExposedProps = false;
var newExposedProps = false,
sandbox = this.sandbox;
if(!object.__exposedProps__) newExposedProps = {};
for(var key in (newExposedProps ? object : object.__exposedProps__)) {
let localKey = key;
@ -464,11 +465,16 @@ Zotero.Translate.SandboxManager.prototype = {
var isObject = typeof object[localKey] === "object";
if(isFunction || isObject) {
if(isFunction) {
if(passAsFirstArgument) {
attachTo[localKey] = object[localKey].bind(object, passAsFirstArgument);
} else {
attachTo[localKey] = object[localKey].bind(object);
}
attachTo[localKey] = function() {
var args = Array.prototype.slice.apply(arguments);
if(passAsFirstArgument) args.unshift(passAsFirstArgument);
var out = object[localKey].apply(object, args);
if(out instanceof Array) {
// Copy to sandbox
out = sandbox.Array.prototype.slice.apply(out);
}
return out;
};
} else {
attachTo[localKey] = {};
}

View file

@ -35,7 +35,7 @@ const ZOTERO_CONFIG = {
API_URL: 'https://api.zotero.org/',
PREF_BRANCH: 'extensions.zotero.',
BOOKMARKLET_URL: 'https://www.zotero.org/bookmarklet/',
VERSION: "3.0.8.SOURCE"
VERSION: "3.0.9.SOURCE"
};
// Commonly used imports accessible anywhere

View file

@ -502,6 +502,19 @@ var ZoteroPane = new function()
return;
}
else if (from == 'zotero-items-tree') {
// Focus TinyMCE explicitly on tab key, since the normal focusing
// doesn't work right
if (!event.shiftKey && event.keyCode == event.DOM_VK_TAB) {
var deck = document.getElementById('zotero-item-pane-content');
if (deck.selectedPanel.id == 'zotero-view-note') {
setTimeout(function () {
document.getElementById('zotero-note-editor').focus();
}, 0);
}
}
return;
}
// Ignore keystrokes if Zotero pane is closed
var zoteroPane = document.getElementById('zotero-pane-stack');
@ -657,6 +670,19 @@ var ZoteroPane = new function()
event.preventDefault();
return;
}
else if (event.keyCode == event.DOM_VK_RETURN) {
var items = this.itemsView.getSelectedItems();
// Don't do anything if more than 20 items selected
if (!items.length || items.length > 20) {
return;
}
ZoteroPane_Local.viewItems(items, event);
// These don't seem to do anything. Instead we override
// the tree binding's _handleEnter method in itemTreeView.js.
//event.preventDefault();
//event.stopPropagation();
return;
}
}
}
@ -738,7 +764,7 @@ var ZoteroPane = new function()
return false;
}
if (!this.canEdit()) {
if (!this.canEditLibrary()) {
this.displayCannotEditLibraryMessage();
return;
}
@ -1087,7 +1113,24 @@ var ZoteroPane = new function()
];
for(var i=0; i<disableIfNoEdit.length; i++) {
var el = document.getElementById(disableIfNoEdit[i]);
if(itemgroup.editable) {
// If a trash is selected, new collection depends on the
// editability of the library
if (itemgroup.isTrash() &&
disableIfNoEdit[i] == 'cmd_zotero_newCollection') {
if (itemgroup.ref.libraryID) {
var overrideEditable =
Zotero.Libraries.isEditable(itemgroup.ref.libraryID);
}
else {
var overrideEditable = true;
}
}
else {
var overrideEditable = false;
}
if (itemgroup.editable || overrideEditable) {
if(el.hasAttribute("disabled")) el.removeAttribute("disabled");
} else {
el.setAttribute("disabled", "true");
@ -2602,66 +2645,23 @@ var ZoteroPane = new function()
}
}
else if (tree.id == 'zotero-items-tree') {
var viewOnDoubleClick = Zotero.Prefs.get('viewOnDoubleClick');
// Expand/collapse on triple-click
if (viewOnDoubleClick) {
if (event.detail == 3) {
tree.view.toggleOpenState(tree.view.selection.currentIndex);
return;
}
// Don't expand/collapse on double-click
event.stopPropagation();
if (!Zotero.Prefs.get('viewOnDoubleClick')) {
return;
}
if (event.detail == 3) {
tree.view.toggleOpenState(tree.view.selection.currentIndex);
return;
}
// Don't expand/collapse on double-click
event.stopPropagation();
if (tree.view && tree.view.selection.currentIndex > -1) {
var item = ZoteroPane_Local.getSelectedItems()[0];
if (item) {
if (item.isRegularItem()) {
if (itemGroup.isBucket()) {
var uri = itemGroup.ref.getItemURI(item);
ZoteroPane_Local.loadURI(uri);
event.stopPropagation();
return;
}
if (!viewOnDoubleClick) {
return;
}
var uri = Components.classes["@mozilla.org/network/standard-url;1"].
createInstance(Components.interfaces.nsIURI);
var snapID = item.getBestAttachment();
if (snapID) {
ZoteroPane_Local.viewAttachment(snapID, event);
return;
}
var uri = item.getField('url');
if (!uri) {
var doi = item.getField('DOI');
if (doi) {
// Pull out DOI, in case there's a prefix
doi = Zotero.Utilities.cleanDOI(doi);
if (doi) {
uri = "http://dx.doi.org/" + encodeURIComponent(doi);
}
}
}
if (uri) {
ZoteroPane_Local.loadURI(uri);
}
}
else if (item.isNote()) {
if (!ZoteroPane_Local.collectionsView.editable) {
return;
}
document.getElementById('zotero-view-note-button').doCommand();
}
else if (item.isAttachment()) {
ZoteroPane_Local.viewSelectedAttachment(event);
}
ZoteroPane_Local.viewItems([item], event);
}
}
}
@ -3368,6 +3368,51 @@ var ZoteroPane = new function()
}
this.viewItems = function (items, event) {
if (items.length > 1) {
if (!event || (!event.metaKey && !event.shiftKey)) {
event = { metaKey: true, shiftKey: true };
}
}
for each(var item in items) {
if (item.isRegularItem()) {
var uri = Components.classes["@mozilla.org/network/standard-url;1"]
.createInstance(Components.interfaces.nsIURI);
var snapID = item.getBestAttachment();
if (snapID) {
ZoteroPane_Local.viewAttachment(snapID, event);
continue;
}
var uri = item.getField('url');
if (!uri) {
var doi = item.getField('DOI');
if (doi) {
// Pull out DOI, in case there's a prefix
doi = Zotero.Utilities.cleanDOI(doi);
if (doi) {
uri = "http://dx.doi.org/" + encodeURIComponent(doi);
}
}
}
if (uri) {
ZoteroPane_Local.loadURI(uri, event);
}
}
else if (item.isNote()) {
if (!ZoteroPane_Local.collectionsView.editable) {
continue;
}
document.getElementById('zotero-view-note-button').doCommand();
}
else if (item.isAttachment()) {
ZoteroPane_Local.viewAttachment(item.id, event);
}
}
}
function viewAttachment(itemIDs, event, noLocateOnMissing, forceExternalViewer) {
// If view isn't editable, don't show Locate button, since the updated
// path couldn't be sent back up
@ -3591,8 +3636,7 @@ var ZoteroPane = new function()
/**
* Test if the user can edit the currently selected library/collection,
* and display an error if not
* Test if the user can edit the currently selected view
*
* @param {Integer} [row]
*
@ -3610,8 +3654,28 @@ var ZoteroPane = new function()
/**
* Test if the user can edit the currently selected library/collection,
* and display an error if not
* Test if the user can edit the parent library of the selected view
*
* @param {Integer} [row]
* @return {Boolean} TRUE if user can edit, FALSE if not
*/
this.canEditLibrary = function (row) {
// Currently selected row
if (row === undefined) {
row = this.collectionsView.selection.currentIndex;
}
var itemGroup = this.collectionsView._getItemAtRow(row);
// TODO: isEditable for user library should just return true
if (itemGroup.ref.libraryID) {
return Zotero.Libraries.isEditable(itemGroup.ref.libraryID);
}
return true;
}
/**
* Test if the user can edit the currently selected library/collection
*
* @param {Integer} [row]
*

View file

@ -142,7 +142,7 @@
<toolbarbutton id="zotero-tb-item-from-page" class="zotero-tb-button" tooltiptext="&zotero.toolbar.newItemFromPage.label;" command="cmd_zotero_newItemFromCurrentPage"/>
<toolbarbutton id="zotero-tb-lookup" class="zotero-tb-button" tooltiptext="&zotero.toolbar.lookup.label;" type="panel">
<panel id="zotero-lookup-panel" type="arrow" onpopupshown="Zotero_Lookup.onShowing()"
onpopuphidden="Zotero_Lookup.onHidden()">
onpopuphidden="Zotero_Lookup.onHidden(event)">
<vbox>
<description>&zotero.lookup.description;</description>
<stack>
@ -331,6 +331,7 @@
id="zotero-items-tree" context="zotero-itemmenu"
enableColumnDrag="true"
onfocus="if (ZoteroPane_Local.itemsView.rowCount &amp;&amp; !ZoteroPane_Local.itemsView.selection.count) { ZoteroPane_Local.itemsView.selection.select(0); }"
onkeydown="ZoteroPane_Local.handleKeyDown(event, this.id)"
onkeypress="ZoteroPane_Local.handleKeyPress(event, this.id)"
onselect="ZoteroPane_Local.itemSelected(event)"
ondragstart="if (event.target.localName == 'treechildren') { ZoteroPane_Local.itemsView.onDragStart(event); }"

View file

@ -146,9 +146,11 @@
<!ENTITY zotero.selectitems.cancel.label "Cancel">
<!ENTITY zotero.selectitems.select.label "OK">
<!ENTITY zotero.bibliography.title "Create Bibliography">
<!ENTITY zotero.bibliography.title "Create Citation/Bibliography">
<!ENTITY zotero.bibliography.style.label "Citation Style:">
<!ENTITY zotero.bibliography.output.label "Output Format">
<!ENTITY zotero.bibliography.outputMode "Output Mode:">
<!ENTITY zotero.bibliography.bibliography "Bibliography">
<!ENTITY zotero.bibliography.outputMethod "Output Method:">
<!ENTITY zotero.bibliography.saveAsRTF.label "Save as RTF">
<!ENTITY zotero.bibliography.saveAsHTML.label "Save as HTML">
<!ENTITY zotero.bibliography.copyToClipboard.label "Copy to Clipboard">

View file

@ -569,6 +569,8 @@ citation.multipleSources = Multiple Sources…
citation.singleSource = Single Source…
citation.showEditor = Show Editor…
citation.hideEditor = Hide Editor…
citation.citation = Citation
citation.note = Note
report.title.default = Zotero Report
report.parentItem = Parent Item:

View file

@ -25,7 +25,7 @@
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>5.0</em:minVersion>
<em:maxVersion>19.0a1</em:maxVersion>
<em:maxVersion>17.*</em:maxVersion>
</Description>
</em:targetApplication>

View file

@ -12,7 +12,7 @@
<RDF:Description>
<id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</id>
<minVersion>5.0</minVersion>
<maxVersion>19.0a1</maxVersion>
<maxVersion>17.*</maxVersion>
<updateLink>http://download.zotero.org/extension/zotero.xpi</updateLink>
<updateHash>sha1:</updateHash>
</RDF:Description>