From 0be9e73b51e9eacc6a3529717545efbe355e9203 Mon Sep 17 00:00:00 2001 From: rmzelle Date: Wed, 14 Jan 2015 21:21:00 -0500 Subject: [PATCH] Further improvements to Style Editor and Preview * Clean up code (remove some pre-CSL 0.8.1 code, see also https://github.com/zotero/zotero/commit/e32e6aa2f549065f9b841132bfe97f7d63015ce4 ) * Complete localization * Save vertical space. Editor: remove "pre-wrap" wrapping, use smaller headers, add grippy to collapse CSL code. Preview: remove groupbox --- chrome/content/zotero/tools/csledit.js | 53 ++++++++------------ chrome/content/zotero/tools/csledit.xul | 45 ++++++++++------- chrome/content/zotero/tools/cslpreview.js | 4 +- chrome/content/zotero/tools/cslpreview.xul | 38 +++++++------- chrome/locale/en-US/zotero/csledit.dtd | 4 ++ chrome/locale/en-US/zotero/cslpreview.dtd | 17 +++---- chrome/locale/en-US/zotero/zotero.dtd | 4 +- chrome/locale/en-US/zotero/zotero.properties | 10 +++- 8 files changed, 89 insertions(+), 86 deletions(-) create mode 100644 chrome/locale/en-US/zotero/csledit.dtd diff --git a/chrome/content/zotero/tools/csledit.js b/chrome/content/zotero/tools/csledit.js index cb89b6655..6a777b480 100644 --- a/chrome/content/zotero/tools/csledit.js +++ b/chrome/content/zotero/tools/csledit.js @@ -69,20 +69,20 @@ var Zotero_CSL_Editor = new function() { } pageList.selectedIndex = 0; - cslList.setAttribute('initialized', true) + cslList.setAttribute('initialized', true); } function refresh() { - var editor = document.getElementById('zotero-csl-editor') + var editor = document.getElementById('zotero-csl-editor'); generateBibliography(editor.value); } this.save = function() { - var editor = document.getElementById('zotero-csl-editor') + var editor = document.getElementById('zotero-csl-editor'); var style = editor.value; const nsIFilePicker = Components.interfaces.nsIFilePicker; var fp = Components.classes["@mozilla.org/filepicker;1"] .createInstance(nsIFilePicker); - fp.init(window, "Save Citation Style", nsIFilePicker.modeSave); + fp.init(window, Zotero.getString('styles.editor.save'), nsIFilePicker.modeSave); fp.appendFilter("Citation Style Language", "*.csl"); //get the filename from the id; we could consider doing even more here like creating the id from filename. var parser = new DOMParser(); @@ -100,7 +100,7 @@ var Zotero_CSL_Editor = new function() { var outputFile = fp.file; Zotero.File.putContents(outputFile, style); } - } + }; function handleKeyPress(event) { if (event.keyCode == 9 && @@ -112,7 +112,7 @@ var Zotero_CSL_Editor = new function() { function loadCSL(cslID) { - var editor = document.getElementById('zotero-csl-editor') + var editor = document.getElementById('zotero-csl-editor'); var style = Zotero.Styles.get(cslID); editor.value = Zotero.File.getContents(style.file); editor.cslID = cslID; @@ -127,26 +127,16 @@ var Zotero_CSL_Editor = new function() { var items = Zotero.getActiveZoteroPane().getSelectedItems(); if (items.length == 0) { - iframe.contentDocument.documentElement.innerHTML = '

No references selected in Zotero.

'; + iframe.contentDocument.documentElement.innerHTML = '

' + Zotero.getString('styles.editor.warning.noItems') + '

'; return; } var styleObject, styleEngine; - if (str.indexOf("' - + "Old-style CSLs are no longer supported." - + ''; - return; - } - else { - try { - styleObject = new Zotero.Style(str); - styleEngine = styleObject.getCiteProc(); - } catch(e) { - iframe.contentDocument.documentElement.innerHTML = '
Error parsing '+ - 'style:
'+e+'
'; - throw e; - } + try { + styleObject = new Zotero.Style(str); + styleEngine = styleObject.getCiteProc(); + } catch(e) { + iframe.contentDocument.documentElement.innerHTML = '
' + Zotero.getString('styles.editor.warning.parseError') + '
'+e+'
'; + throw e; } var itemIds = [items[i].id for (i in items)]; @@ -167,10 +157,10 @@ var Zotero_CSL_Editor = new function() { var search = document.getElementById('preview-pages'); var loc = document.getElementById('zotero-csl-page-type'); var pos = document.getElementById('zotero-ref-position').selectedItem.value; - var citations = '

Single Citations

'; + var citations = '

' + Zotero.getString('styles.editor.output.individualCitations') + '

'; for (var i=0; i' + styleEngine.previewCitationCluster(citation, [], [], "html"); // Generate bibliography styleEngine.updateItems(itemIds); - var bibliography = '

Bibliography

' + + var bibliography = '

' + Zotero.getString('styles.bibliography') + '

' + Zotero.Cite.makeFormattedBibliography(styleEngine, "html"); iframe.contentDocument.documentElement.innerHTML = - '
' - + citations + multCitations + bibliography - + '
'; + '
' + citations + multCitations + bibliography + '
'; } catch(e) { - iframe.contentDocument.documentElement.innerHTML = '
Error generating citations '+ - 'and bibliography:
'+e+'
'; + iframe.contentDocument.documentElement.innerHTML = '
' + Zotero.getString('styles.editor.warning.renderError') + '
'+e+'
'; throw e; } } @@ -219,4 +206,4 @@ var Zotero_CSL_Editor = new function() { controller.doCommandWithParams(command, params); } } -} +}(); diff --git a/chrome/content/zotero/tools/csledit.xul b/chrome/content/zotero/tools/csledit.xul index 240d52056..f646d266f 100644 --- a/chrome/content/zotero/tools/csledit.xul +++ b/chrome/content/zotero/tools/csledit.xul @@ -26,40 +26,47 @@ + %csleditDTD; + %zoteroDTD; +]> + + title="&styles.editor;">