From 6ac040304963f38cab0dc02a2aa59070b2e8ad4d Mon Sep 17 00:00:00 2001 From: Aurimas Vinckevicius Date: Thu, 14 May 2015 23:25:06 -0500 Subject: [PATCH] Reorganize and improve locale drop-down code --- chrome/content/zotero/bibliography.js | 68 +++----- chrome/content/zotero/bibliography.xul | 2 +- chrome/content/zotero/fileInterface.js | 4 +- .../integration/integrationDocPrefs.xul | 2 +- .../zotero/preferences/preferences_export.js | 57 ++----- .../zotero/preferences/preferences_export.xul | 11 +- .../preferences/quickCopySiteEditor.xul | 32 ++-- chrome/content/zotero/rtfScan.js | 8 +- chrome/content/zotero/rtfScan.xul | 2 +- chrome/content/zotero/tools/csledit.js | 98 +++++++---- chrome/content/zotero/tools/csledit.xul | 6 +- chrome/content/zotero/tools/cslpreview.js | 8 +- chrome/content/zotero/tools/cslpreview.xul | 2 +- chrome/content/zotero/xpcom/quickCopy.js | 18 +- chrome/content/zotero/xpcom/style.js | 156 +++++++++++------- chrome/content/zotero/xpcom/utilities.js | 23 +-- chrome/locale/en-US/zotero/preferences.dtd | 3 +- chrome/locale/en-US/zotero/zotero.dtd | 2 +- 18 files changed, 261 insertions(+), 241 deletions(-) diff --git a/chrome/content/zotero/bibliography.js b/chrome/content/zotero/bibliography.js index e279e0240..aaf7713eb 100644 --- a/chrome/content/zotero/bibliography.js +++ b/chrome/content/zotero/bibliography.js @@ -34,8 +34,7 @@ var Zotero_File_Interface_Bibliography = new function() { var _io, _saveStyle; - var selectedLocale = ""; - var defaultStyleLocale = ""; + var lastSelectedLocale; // Only changes when explicitly selected /* * Initialize some variables and prepare event listeners for when chrome is done @@ -57,18 +56,18 @@ var Zotero_File_Interface_Bibliography = new function() { } var listbox = document.getElementById("style-listbox"); - var styles = Zotero.Styles.getVisible(); - // if no style is set, get the last style used + // if no style is requested, get the last style used if(!_io.style) { _io.style = Zotero.Prefs.get("export.lastStyle"); _saveStyle = true; } // add styles to list + var styles = Zotero.Styles.getVisible(); var index = 0; var nStyles = styles.length; - var selectIndex = -1; + var selectIndex = null; for(var i=0; i - + \ No newline at end of file diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js index 0681c1de3..ba3ac11a7 100644 --- a/chrome/content/zotero/fileInterface.js +++ b/chrome/content/zotero/fileInterface.js @@ -428,7 +428,7 @@ var Zotero_File_Interface = new function() { getService(Components.interfaces.nsIClipboard); var style = Zotero.Styles.get(style); var cslEngine = style.getCiteProc(locale); - + // add HTML var bibliography = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, items, "html", asCitations); var str = Components.classes["@mozilla.org/supports-string;1"]. @@ -524,7 +524,7 @@ var Zotero_File_Interface = new function() { // generate bibliography try { if(io.method == 'copy-to-clipboard') { - copyItemsToClipboard(items, io.style, locale, false, io.mode === "citations"); + Zotero_File_Interface.copyItemsToClipboard(items, io.style, locale, false, io.mode === "citations"); } else { var style = Zotero.Styles.get(io.style); diff --git a/chrome/content/zotero/integration/integrationDocPrefs.xul b/chrome/content/zotero/integration/integrationDocPrefs.xul index 050626355..e2a3a8ab3 100644 --- a/chrome/content/zotero/integration/integrationDocPrefs.xul +++ b/chrome/content/zotero/integration/integrationDocPrefs.xul @@ -84,4 +84,4 @@ &zotero.integration.prefs.storeReferences.caption; - + \ No newline at end of file diff --git a/chrome/content/zotero/preferences/preferences_export.js b/chrome/content/zotero/preferences/preferences_export.js index 7746a2ff4..7dfc1fa0a 100644 --- a/chrome/content/zotero/preferences/preferences_export.js +++ b/chrome/content/zotero/preferences/preferences_export.js @@ -51,9 +51,10 @@ Zotero_Preferences.Export = { // Initialize locale drop-down var localeMenulist = document.getElementById("zotero-quickCopy-locale-menu"); - this.populateQuickCopyLocaleList(localeMenulist); + Zotero.Styles.populateLocaleList(localeMenulist); localeMenulist.setAttribute('preference', "pref-quickCopy-locale"); + this._lastSelectedLocale = Zotero.Prefs.get("export.quickCopy.locale"); this.updateQuickCopyUI(); if (!Zotero.isStandalone) { @@ -151,37 +152,11 @@ Zotero_Preferences.Export = { checkbox.checked = contentType == 'html'; checkbox.disabled = mode != 'bibliography'; - var menulist = document.getElementById('zotero-quickCopy-locale-menu'); - var menulistLabel = document.getElementById('zotero-quickCopy-locale-menu-label'); - - var lastSelectedLocale = menulist.value; - var localeLabel = ""; - if (menulist.disabled === true) { - menulist.removeItemAt(0); - } - - if (mode == 'bibliography') { - var defaultStyleLocale = Zotero.Styles.get(format).locale; - if (defaultStyleLocale) { - if (Zotero.Styles.locales[defaultStyleLocale] !== undefined) { - localeLabel = Zotero.Styles.locales[defaultStyleLocale]; - } else { - localeLabel = defaultStyleLocale; - } - } - menulistLabel.disabled = false; - } else { - menulistLabel.disabled = true; - } - - if (mode == 'bibliography' && !defaultStyleLocale) { - menulist.value = lastSelectedLocale; - menulist.disabled = false; - } else { - menulist.insertItemAt(0, localeLabel, lastSelectedLocale); - menulist.selectedIndex = 0; - menulist.disabled = true; - } + Zotero.Styles.updateLocaleList( + document.getElementById('zotero-quickCopy-locale-menu'), + mode == 'bibliography' ? Zotero.Styles.get(format) : null, + this._lastSelectedLocale + ); }, /** @@ -204,7 +179,7 @@ Zotero_Preferences.Export = { var treechildren = document.getElementById('quickCopy-siteSettings-rows'); var formattedName = document.getElementById('zotero-quickCopy-menu').label; - var locale = document.getElementById('zotero-quickCopy-locale-menu').value; + var locale = this._lastSelectedLocale; var asHTML = document.getElementById('zotero-quickCopy-copyAsHTML').checked; if (index !== undefined && index > -1 && index < treechildren.childNodes.length) { @@ -261,7 +236,7 @@ Zotero_Preferences.Export = { var domainCell = document.createElement('treecell'); var formatCell = document.createElement('treecell'); var localeCell = document.createElement('treecell'); - var HTMLCell = document.createElement('treecell'); + var htmlCell = document.createElement('treecell'); domainCell.setAttribute('label', siteData[i].domainPath); @@ -270,12 +245,12 @@ Zotero_Preferences.Export = { var format = Zotero.QuickCopy.unserializeSetting(siteData[i].format); localeCell.setAttribute('label', format.locale); - HTMLCell.setAttribute('label', format.contentType == 'html' ? ' ✓ ' : ''); + htmlCell.setAttribute('label', format.contentType == 'html' ? ' ✓ ' : ''); treerow.appendChild(domainCell); treerow.appendChild(formatCell); treerow.appendChild(localeCell); - treerow.appendChild(HTMLCell); + treerow.appendChild(htmlCell); treeitem.appendChild(treerow); treechildren.appendChild(treeitem); } @@ -292,16 +267,6 @@ Zotero_Preferences.Export = { this.refreshQuickCopySiteList(); }, - /* - * Builds the Quick Copy locale drop-down - */ - populateQuickCopyLocaleList: function (menulist, quickCopyLocale) { - if (!quickCopyLocale) { - quickCopyLocale = Zotero.Prefs.get("export.quickCopy.locale"); - } - - Zotero.Styles.populateLocaleList(menulist, quickCopyLocale); - }, updateQuickCopyInstructions: function () { var prefix = Zotero.isMac ? Zotero.getString('general.keys.cmdShift') : Zotero.getString('general.keys.ctrlShift'); diff --git a/chrome/content/zotero/preferences/preferences_export.xul b/chrome/content/zotero/preferences/preferences_export.xul index 8040c0be0..f2b57a1c3 100644 --- a/chrome/content/zotero/preferences/preferences_export.xul +++ b/chrome/content/zotero/preferences/preferences_export.xul @@ -23,7 +23,12 @@ ***** END LICENSE BLOCK ***** --> - + + %prefWindow; + + %common; +]> - + oncommand="Zotero_CSL_Editor.onStyleModified()"/> diff --git a/chrome/content/zotero/tools/cslpreview.js b/chrome/content/zotero/tools/cslpreview.js index f3ec7ceae..8ff06009d 100644 --- a/chrome/content/zotero/tools/cslpreview.js +++ b/chrome/content/zotero/tools/cslpreview.js @@ -30,11 +30,10 @@ var Zotero_CSL_Preview = new function() { this.generateBibliography = generateBibliography; function init() { - //refresh(); - var quickCopyLocale = Zotero.Prefs.get("export.quickCopy.locale"); var menulist = document.getElementById("locale-menu"); - Zotero.Styles.populateLocaleList(menulist, quickCopyLocale); + Zotero.Styles.populateLocaleList(menulist); + menulist.value = Zotero.Prefs.get('export.lastLocale');; var iframe = document.getElementById('zotero-csl-preview-box'); iframe.contentDocument.documentElement.innerHTML = '

' + Zotero.getString('styles.preview.instructions') + '

'; @@ -91,8 +90,7 @@ var Zotero_CSL_Preview = new function() { return ''; } - var locale = document.getElementById("locale-menu").selectedItem.value; - + var locale = document.getElementById("locale-menu").value; var styleEngine = style.getCiteProc(locale); // Generate multiple citations diff --git a/chrome/content/zotero/tools/cslpreview.xul b/chrome/content/zotero/tools/cslpreview.xul index b9e8420ab..3f60c1f04 100644 --- a/chrome/content/zotero/tools/cslpreview.xul +++ b/chrome/content/zotero/tools/cslpreview.xul @@ -57,7 +57,7 @@ - +