commit 079b7679743e4d7a60793a8333fddff489bfa017
parent 2139603ae1ccb68d5267022d7f8d46ff867d9ab2
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 1 Nov 2012 21:36:12 -0400
Closes #44, Allow generating citations via right-click
Currently generates multi-source citations for multiple items for note
styles, but a list of note citations might be better.
Also, context menu option is unchanged, since it becomes very long if
you add "Citation/Bibliography".
Diffstat:
5 files changed, 79 insertions(+), 20 deletions(-)
diff --git a/chrome/content/zotero/bibliography.js b/chrome/content/zotero/bibliography.js
@@ -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
diff --git a/chrome/content/zotero/bibliography.xul b/chrome/content/zotero/bibliography.xul
@@ -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;"/>
diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js
@@ -489,30 +489,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);
@@ -549,7 +562,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) {
@@ -575,7 +588,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);
diff --git a/chrome/locale/en-US/zotero/zotero.dtd b/chrome/locale/en-US/zotero/zotero.dtd
@@ -131,9 +131,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">
diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties
@@ -567,6 +567,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: