- 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
This commit is contained in:
Dan Stillman 2009-12-26 03:40:30 +00:00
parent 1f9f780073
commit a5818604fb
5 changed files with 67 additions and 32 deletions

View file

@ -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;
}

View file

@ -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");
}
catch (e){}
if (!text || !text.length)
{
if (!text) {
return false;
}
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;
}

View file

@ -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"

View file

@ -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);

View file

@ -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/>