www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit a5818604fb0fd6f4e70d1dde96126eb1005aa914
parent 1f9f780073173a75902653c59b1f2894a61677a7
Author: Dan Stillman <dstillman@zotero.org>
Date:   Sat, 26 Dec 2009 03:40:30 +0000

- When creating or adding to note from web page context menu, put text in <blockquote> with 'cite' attribute
- Zotero.Utilities.text2html(str, singleNewlineIsParagraph) -- conversion of 1.0 notes on upgrade to 2.0 uses the second parameter to treat a single newline as a paragraph, which may or may not be the desired behavior but is what was done previously
- Shortcut key for New Item wasn't properly selecting item type menu and wasn't preventing Firefox's Recently Closed Window shortcut


Diffstat:
Mchrome/content/zotero/bindings/itembox.xml | 14+++++++-------
Mchrome/content/zotero/overlay.js | 44++++++++++++++++++++++++++++++--------------
Mchrome/content/zotero/overlay.xul | 4++--
Mchrome/content/zotero/xpcom/db.js | 8+-------
Mchrome/content/zotero/xpcom/utilities.js | 25+++++++++++++++++++++++++
5 files changed, 65 insertions(+), 30 deletions(-)

diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml @@ -185,10 +185,10 @@ </setter> </property> + <property name="itemTypeMenu" onget="return this._id('item-type-menu')"/> <!-- Private properties --> <property name="_dynamicFields" onget="return this._id('dynamic-fields')"/> - <property name="_itemTypeMenu" onget="return this._id('item-type-menu')"/> <property name="_creatorTypeMenu" onget="return this._id('creator-type-menu')"/> <field name="_selectField"/> @@ -330,27 +330,27 @@ // Item type menu if (this.showTypeMenu) { // Build item type menu if it hasn't been built yet - if (!this._itemTypeMenu.firstChild.hasChildNodes()) { + if (!this.itemTypeMenu.firstChild.hasChildNodes()) { var itemTypes = Zotero.ItemTypes.getTypes(); for (var i=0; i<itemTypes.length; i++) { var name = itemTypes[i].name; if (name != 'attachment' && name != 'note') { - this._itemTypeMenu.appendItem(Zotero.getString("itemTypes." + name), itemTypes[i].id); + this.itemTypeMenu.appendItem(Zotero.getString("itemTypes." + name), itemTypes[i].id); } } } - var listitems = this._itemTypeMenu.firstChild.childNodes; + var listitems = this.itemTypeMenu.firstChild.childNodes; for (var i=0, len=listitems.length; i < len; i++) { if (listitems[i].getAttribute('value') == this.item.itemTypeID) { - this._itemTypeMenu.selectedIndex = i; + this.itemTypeMenu.selectedIndex = i; } } - this._itemTypeMenu.parentNode.hidden = false; + this.itemTypeMenu.parentNode.hidden = false; } else { - this._itemTypeMenu.parentNode.hidden = true; + this.itemTypeMenu.parentNode.hidden = true; } diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js @@ -539,6 +539,9 @@ var ZoteroPane = new function() Zotero.debug(command); + // Errors don't seem to make it out otherwise + try { + switch (command) { case 'openZotero': try { @@ -563,7 +566,9 @@ var ZoteroPane = new function() break; case 'newItem': ZoteroPane.newItem(2); // book - document.getElementById('zotero-editpane-type-menu').focus(); + var menu = document.getElementById('zotero-editpane-item-box').itemTypeMenu; + menu.focus(); + document.getElementById('zotero-editpane-item-box').itemTypeMenu.menupopup.openPopup(menu, "before_start", 0, 0); break; case 'newNote': // Use key that's not the modifier as the popup toggle @@ -588,6 +593,12 @@ var ZoteroPane = new function() throw ('Command "' + command + '" not found in ZoteroPane.handleKeyDown()'); } + } + catch (e) { + Zotero.debug(e, 1); + Components.utils.reportError(e); + } + event.preventDefault(); } @@ -2380,7 +2391,7 @@ var ZoteroPane = new function() } - this.newNote = function (popup, parent, text) { + this.newNote = function (popup, parent, text, citeURI) { if (!Zotero.stateCheck()) { this.displayErrorMessage(true); return; @@ -2397,6 +2408,12 @@ var ZoteroPane = new function() } text = Zotero.Utilities.prototype.trim(text); + if (text) { + text = '<blockquote' + + (citeURI ? ' cite="' + citeURI + '"' : '') + + '>' + Zotero.Utilities.prototype.text2html(text) + "</blockquote>"; + } + var item = new Zotero.Item('note'); item.libraryID = this.getSelectedLibraryID(); item.setNote(text); @@ -2427,37 +2444,36 @@ var ZoteroPane = new function() } - function addTextToNote(text) + function addTextToNote(text, citeURI) { if (!this.canEdit()) { this.displayCannotEditLibraryMessage(); return; } - try { - // trim - text = text.replace(/^[\xA0\r\n\s]*(.*)[\xA0\r\n\s]*$/m, "$1"); + if (!text) { + return false; } - catch (e){} - if (!text || !text.length) - { + text = Zotero.Utilities.prototype.trim(text); + + if (!text.length) { return false; } + text = '<blockquote' + + (citeURI ? ' cite="' + citeURI + '"' : '') + + '>' + Zotero.Utilities.prototype.text2html(text) + "</blockquote>"; + var items = this.getSelectedItems(); if (this.itemsView.selection.count == 1 && items[0] && items[0].isNote()) { var note = items[0].getNote() - items[0].setNote(note == '' ? text : note + "\n\n" + text); + items[0].setNote(note + text); items[0].save(); var noteElem = document.getElementById('zotero-note-editor') noteElem.focus(); - noteElem.noteField.inputField.editor. - selectionController.scrollSelectionIntoView(1, - 1, - true); return true; } diff --git a/chrome/content/zotero/overlay.xul b/chrome/content/zotero/overlay.xul @@ -58,10 +58,10 @@ <menupopup> <menuitem id="zotero-context-add-to-current-note" class="menu-iconic" label="&zotero.contextMenu.addTextToCurrentNote;" hidden="true" - oncommand="var str = event.currentTarget.ownerDocument.popupNode.ownerDocument.defaultView.getSelection().toString(); ZoteroPane.addTextToNote(str)"/> + oncommand="var str = event.currentTarget.ownerDocument.popupNode.ownerDocument.defaultView.getSelection().toString(); var uri = event.currentTarget.ownerDocument.popupNode.ownerDocument.location.href; ZoteroPane.addTextToNote(str, uri)"/> <menuitem id="zotero-context-add-to-new-note" class="menu-iconic" label="&zotero.contextMenu.addTextToNewNote;" hidden="true" - oncommand="var str = event.currentTarget.ownerDocument.popupNode.ownerDocument.defaultView.getSelection().toString(); var itemID = ZoteroPane.addItemFromPage(); ZoteroPane.newNote(false, itemID, str)"/> + oncommand="var str = event.currentTarget.ownerDocument.popupNode.ownerDocument.defaultView.getSelection().toString(); var uri = event.currentTarget.ownerDocument.popupNode.ownerDocument.location.href; var itemID = ZoteroPane.addItemFromPage(); ZoteroPane.newNote(false, itemID, str, uri)"/> <!-- TODO: localize and remove zotero.contextMenu.saveLinkAsItem/saveImageAsSnapshot --> <menuitem id="zotero-context-save-link-as-item" class="menu-iconic" label="Save Link as Zotero Item" hidden="true" diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js @@ -1186,13 +1186,7 @@ Zotero.DBConnection.prototype._getDBConnection = function () { var rx = { onFunctionCall: function (arg) { var str = arg.getUTF8String(0); - str = Zotero.Utilities.prototype.htmlSpecialChars(str); - str = '<p>' - + str.replace(/\n/g, '</p><p>') - .replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;') - .replace(/ /g, '&nbsp;&nbsp;') - + '</p>'; - return str.replace(/<p>\s*<\/p>/g, '<p>&nbsp;</p>'); + return Zotero.Utilities.prototype.text2html(str, true); } }; this._connection.createFunction('text2html', 1, rx); diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js @@ -153,6 +153,31 @@ Zotero.Utilities.prototype.cleanDOI = function(/**String**/ x) { } +Zotero.Utilities.prototype.text2html = function (/**String**/ str, singleNewlineIsParagraph) { + str = Zotero.Utilities.prototype.htmlSpecialChars(str); + + // \n => <p> + if (singleNewlineIsParagraph) { + str = '<p>' + + str.replace(/\n/g, '</p><p>') + .replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;') + .replace(/ /g, '&nbsp;&nbsp;') + + '</p>'; + } + // \n\n => <p>, \n => <br/> + else { + str = Zotero.Utilities.prototype.htmlSpecialChars(str); + str = '<p>' + + str.replace(/\n\n/g, '</p><p>') + .replace(/\n/g, '<br/>') + .replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;') + .replace(/ /g, '&nbsp;&nbsp;') + + '</p>'; + } + return str.replace(/<p>\s*<\/p>/g, '<p>&nbsp;</p>'); +} + + /** * Encode special XML/HTML characters<br/> * <br/>