diff --git a/chrome/content/zotero/itemPane.js b/chrome/content/zotero/itemPane.js
index 6ca7cb271..45750693f 100644
--- a/chrome/content/zotero/itemPane.js
+++ b/chrome/content/zotero/itemPane.js
@@ -55,7 +55,6 @@ var ZoteroItemPane = new function()
this.viewItem = viewItem;
this.loadPane = loadPane;
this.changeTypeTo = changeTypeTo;
- this.onGoToURLClick = onGoToURLClick;
this.onOpenURLClick = onOpenURLClick;
this.addCreatorRow = addCreatorRow;
this.switchCreatorMode = switchCreatorMode;
@@ -175,7 +174,17 @@ var ZoteroItemPane = new function()
testView: try
{
var validURI = false;
- var spec = _itemBeingEdited.getField('url');
+
+ var snapID = _itemBeingEdited.getBestSnapshot();
+ if (snapID)
+ {
+ var spec = Zotero.Items.get(snapID).getLocalFileURL();
+ }
+ else
+ {
+ var spec = _itemBeingEdited.getField('url');
+ }
+
if (!spec)
{
break testView;
@@ -183,7 +192,10 @@ var ZoteroItemPane = new function()
var uri = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newURI(spec, null, null);
- validURI = uri.scheme && uri.host;
+
+ validURI = uri.scheme && (uri.host || uri.scheme=='file');
+
+ document.getElementById('tb-go-to-url').setAttribute('viewURL', spec);
}
catch (e){}
document.getElementById('tb-go-to-url').setAttribute('disabled', !validURI);
@@ -392,11 +404,6 @@ var ZoteroItemPane = new function()
}
}
- function onGoToURLClick()
- {
- window.loadURI(_itemBeingEdited.getField('url'));
- }
-
function onOpenURLClick()
{
var url = Zotero.OpenURL.resolve(_itemBeingEdited);
diff --git a/chrome/content/zotero/itemPane.xul b/chrome/content/zotero/itemPane.xul
index da9da2f83..7413e9722 100644
--- a/chrome/content/zotero/itemPane.xul
+++ b/chrome/content/zotero/itemPane.xul
@@ -38,7 +38,7 @@
'typeID', typeID, otherFields)"/>
-
+
diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js
index 4bf367a58..9fb07b7f8 100644
--- a/chrome/content/zotero/xpcom/data_access.js
+++ b/chrome/content/zotero/xpcom/data_access.js
@@ -879,15 +879,15 @@ Zotero.Item.prototype.isNote = function(){
/**
* Update an item note
*
-* Note: This can only be called on note items.
+* Note: This can only be called on notes and attachments
**/
Zotero.Item.prototype.updateNote = function(text){
if (!this.isNote() && !this.isAttachment()){
- throw ("updateNote() can only be called on items of type 'note'");
+ throw ("updateNote() can only be called on notes and attachments");
}
if (!this.getID()){
- throw ("Cannot call updateNote() on unsaved note");
+ throw ("Cannot call updateNote() on unsaved item");
}
Zotero.DB.beginTransaction();
@@ -1261,6 +1261,28 @@ Zotero.Item.prototype.getAttachments = function(){
}
+/*
+ * Returns the itemID of the latest child snapshot of this item with the
+ * same URL as the item itself, or false if none
+ */
+Zotero.Item.prototype.getBestSnapshot = function(){
+ if (!this.isRegularItem()){
+ throw ("getBestSnapshot() can only be called on regular items");
+ }
+
+ if (!this.getField('url')){
+ return false;
+ }
+
+ var sql = "SELECT IA.itemID FROM itemAttachments IA NATURAL JOIN items I "
+ + "LEFT JOIN itemData ID ON (IA.itemID=ID.itemID AND fieldID=1) "
+ + "WHERE sourceItemID=? AND linkMode=? AND value=? "
+ + "ORDER BY dateAdded DESC LIMIT 1";
+
+ return Zotero.DB.valueQuery(sql, [this.getID(),
+ Zotero.Attachments.LINK_MODE_IMPORTED_URL, {string:this.getField('url')}]);
+}
+
//
// Methods dealing with item tags