From 2a1658228b401eb773c2658235592415045d29b5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 6 Apr 2007 15:54:03 +0000 Subject: [PATCH] Closes #601, Allow Quick Copy to be site-specific Closes #560, Method for inserting bibliography/export format into text box on current page Dragging items to external text apps is also possible now (the one oddity being that the format has to be set at the beginning of the drag session, so if the window's current page matches a site-specific setting, the dragged references will use that format even the if the text is dropped into an external app or another window) --- chrome/content/zotero/overlay.js | 3 +- chrome/content/zotero/preferences.js | 108 ++++++++++-- chrome/content/zotero/preferences.xul | 28 ++- chrome/content/zotero/quickCopySiteEditor.xul | 46 +++++ chrome/content/zotero/xpcom/data_access.js | 2 +- chrome/content/zotero/xpcom/itemTreeView.js | 39 +++++ chrome/content/zotero/xpcom/quickCopy.js | 162 ++++++++++++++++++ chrome/locale/en-US/zotero/preferences.dtd | 9 +- chrome/locale/en-US/zotero/zotero.properties | 2 +- chrome/skin/default/zotero/preferences.css | 4 + components/zotero-service.js | 4 + userdata.sql | 13 +- 12 files changed, 394 insertions(+), 26 deletions(-) create mode 100644 chrome/content/zotero/quickCopySiteEditor.xul create mode 100644 chrome/content/zotero/xpcom/quickCopy.js diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 412ef810a..55d6b6147 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -895,8 +895,7 @@ var ZoteroPane = new function() } var [mode, format] = Zotero.Prefs.get("export.quickCopy.setting").split('='); - Zotero.debug(mode); - Zotero.debug(format); + if (mode == 'bibliography') { Zotero_File_Interface.copyItemsToClipboard(items, format); } diff --git a/chrome/content/zotero/preferences.js b/chrome/content/zotero/preferences.js index ace67b0c8..ab0079662 100644 --- a/chrome/content/zotero/preferences.js +++ b/chrome/content/zotero/preferences.js @@ -134,14 +134,31 @@ function populateOpenURLResolvers() { function populateQuickCopyList() { + // Initialize default format drop-down var formatMenu = document.getElementById("quickCopy-menu"); - var listbox = formatMenu.firstChild; var format = Zotero.Prefs.get("export.quickCopy.setting"); + buildQuickCopyFormatDropDown(formatMenu, format); + formatMenu.setAttribute('preference', "pref-quickCopy-setting"); + + refreshQuickCopySiteList(); +} + + +function buildQuickCopyFormatDropDown(menulist, currentFormat) { + // Prevent Cmd-w from setting "Wikipedia" + menulist.onkeydown = function (event) { + if ((Zotero.isMac && event.metaKey) || event.ctrlKey) { + event.preventDefault(); + } + } + + var popup = document.createElement('menupopup'); + menulist.appendChild(popup); var itemNode = document.createElement("menuitem"); itemNode.setAttribute("label", Zotero.getString('zotero.preferences.export.quickCopy.bibStyles')); itemNode.setAttribute("disabled", true); - listbox.appendChild(itemNode); + popup.appendChild(itemNode); // add styles to list var styles = Zotero.Cite.getStyles(); @@ -150,23 +167,23 @@ function populateQuickCopyList() { var itemNode = document.createElement("menuitem"); itemNode.setAttribute("value", val); itemNode.setAttribute("label", styles[i]); - listbox.appendChild(itemNode); + popup.appendChild(itemNode); - if (val == format) { - formatMenu.selectedItem = itemNode; + if (val == currentFormat) { + menulist.selectedItem = itemNode; } } var itemNode = document.createElement("menuitem"); itemNode.setAttribute("label", Zotero.getString('zotero.preferences.export.quickCopy.exportFormats')); itemNode.setAttribute("disabled", true); - listbox.appendChild(itemNode); + popup.appendChild(itemNode); // add export formats to list var translation = new Zotero.Translate("export"); var translators = translation.getTranslators(); - for (var i in translators) { + for (var i=0; i -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 format = Zotero.QuickCopy.getSettingFromFormattedName(format); + + var io = {domain: domain, format: format, ok: false}; + window.openDialog('chrome://zotero/content/quickCopySiteEditor.xul', "zotero-preferences-quickCopySiteEditor", "chrome, modal", io); + + if (!io.ok) { + return; + } + + if (domain && domain != io.domain) { + Zotero.DB.query("DELETE FROM settings WHERE setting='quickCopySite' AND key=?", [domain]); + } + + Zotero.DB.query("REPLACE INTO settings VALUES ('quickCopySite', ?, ?)", [io.domain, io.format]); + + refreshQuickCopySiteList(); +} + +function refreshQuickCopySiteList() { + var treechildren = document.getElementById('quickCopy-siteSettings-rows'); + while (treechildren.hasChildNodes()) { + treechildren.removeChild(treechildren.firstChild); + } + + var sql = "SELECT key AS domainPath, value AS format FROM settings " + + "WHERE setting='quickCopySite' ORDER BY domainPath COLLATE NOCASE"; + var siteData = Zotero.DB.query(sql); + + if (!siteData) { + return; + } + + for (var i=0; i -