diff --git a/chrome/content/zotero/itemPane.js b/chrome/content/zotero/itemPane.js index 2e65b11f2..9f9dbf571 100644 --- a/chrome/content/zotero/itemPane.js +++ b/chrome/content/zotero/itemPane.js @@ -1540,7 +1540,7 @@ var ZoteroItemPane = new function() function addNote() { - ZoteroPane.openNoteWindow(_itemBeingEdited.getID()); + ZoteroPane.openNoteWindow(null, null, _itemBeingEdited.getID()); } function _noteToTitle(text) diff --git a/chrome/content/zotero/note.js b/chrome/content/zotero/note.js index 0123129dc..714b797b5 100644 --- a/chrome/content/zotero/note.js +++ b/chrome/content/zotero/note.js @@ -39,21 +39,18 @@ function onLoad() params[b[i].substr(0,mid)] = b[i].substr(mid+1); } - var id = params['id']; + var itemID = params['id']; var collectionID = params['coll']; + var parentItemID = params['p']; - if(id && id != '' && id != 'undefined') - { - var ref = Zotero.Items.get(id); - if(ref.isNote()) - { - noteEditor.note = ref; - document.title = Zotero.getString('noteEditor.editNote'); - } - else - { - noteEditor.item = ref; - } + if (itemID) { + var ref = Zotero.Items.get(itemID); + noteEditor.note = ref; + document.title = ref.getNoteTitle(); + } + else if (parentItemID) { + var ref = Zotero.Items.get(parentItemID); + noteEditor.item = ref; } else { @@ -77,6 +74,9 @@ var NotifyCallback = { // DEBUG: why does this reset without checking the modified ids? if (noteEditor.note){ noteEditor.note = noteEditor.note; + document.title = noteEditor.note.getNoteTitle(); + // Update the window name (used for focusing) in case this is a new note + window.name = 'zotero-note-' + noteEditor.note.getID(); } } } diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 74845fb5c..39b8a94fe 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -1785,14 +1785,33 @@ var ZoteroPane = new function() return false; } - function openNoteWindow(id, parent) + function openNoteWindow(itemID, col, parentItemID) { - if (id) { - var item = Zotero.Items.get(id) + var name = null; + + if (itemID) { + // Create a name for this window so we can focus it later + // + // Collection is only used on new notes, so we don't need to + // include it in the name + name = 'zotero-note-' + itemID; + + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + var e = wm.getEnumerator(''); + while (e.hasMoreElements()) { + var w = e.getNext(); + if (w.name == name) { + w.focus(); + return; + } + } } + window.open('chrome://zotero/content/note.xul?v=1' - + (id ? '&id=' + id : '') + (parent ? '&coll=' + parent : ''), - '', 'chrome,resizable,centerscreen'); + + (itemID ? '&id=' + itemID : '') + (col ? '&coll=' + col : '') + + (parentItemID ? '&p=' + parentItemID : ''), + name, 'chrome,resizable,centerscreen'); }