- Double-clicking an item without a URL didn't open child attachment
- Fixed various issues with adding/dragging files/links to group libraries
This commit is contained in:
parent
1c3a10909a
commit
020553607d
6 changed files with 58 additions and 27 deletions
|
@ -240,7 +240,7 @@
|
||||||
createInstance(Components.interfaces.nsIURI);
|
createInstance(Components.interfaces.nsIURI);
|
||||||
|
|
||||||
// First try to find a snapshot matching the item's URL field
|
// First try to find a snapshot matching the item's URL field
|
||||||
var snapID = this.item.getBestSnapshot();
|
var snapID = this.item.getBestAttachment();
|
||||||
if (snapID) {
|
if (snapID) {
|
||||||
spec = Zotero.Items.get(snapID).getLocalFileURL();
|
spec = Zotero.Items.get(snapID).getLocalFileURL();
|
||||||
uri.spec = spec;
|
uri.spec = spec;
|
||||||
|
|
|
@ -1121,8 +1121,8 @@ var ZoteroPane = new function()
|
||||||
this.updateNoteButtonMenu = function () {
|
this.updateNoteButtonMenu = function () {
|
||||||
var items = ZoteroPane.getSelectedItems();
|
var items = ZoteroPane.getSelectedItems();
|
||||||
var button = document.getElementById('zotero-tb-add-child-note');
|
var button = document.getElementById('zotero-tb-add-child-note');
|
||||||
button.disabled = this.canEdit() && !(items.length == 1
|
button.disabled = !this.canEdit() ||
|
||||||
&& (items[0].isRegularItem() || !items[0].isTopLevelItem()));
|
!(items.length == 1 && (items[0].isRegularItem() || !items[0].isTopLevelItem()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2130,7 +2130,7 @@ var ZoteroPane = new function()
|
||||||
|
|
||||||
var uri = Components.classes["@mozilla.org/network/standard-url;1"].
|
var uri = Components.classes["@mozilla.org/network/standard-url;1"].
|
||||||
createInstance(Components.interfaces.nsIURI);
|
createInstance(Components.interfaces.nsIURI);
|
||||||
var snapID = item.getBestSnapshot();
|
var snapID = item.getBestAttachment();
|
||||||
if (snapID) {
|
if (snapID) {
|
||||||
spec = Zotero.Items.get(snapID).getLocalFileURL();
|
spec = Zotero.Items.get(snapID).getLocalFileURL();
|
||||||
if (spec) {
|
if (spec) {
|
||||||
|
@ -2482,11 +2482,22 @@ var ZoteroPane = new function()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var itemGroup = ZoteroPane.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex);
|
||||||
|
if (link && itemGroup.isWithinGroup()) {
|
||||||
|
var pr = Components.classes["@mozilla.org/network/default-prompt;1"]
|
||||||
|
.getService(Components.interfaces.nsIPrompt);
|
||||||
|
pr.alert("", "Linked files cannot be added to group libraries.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: disable in menu
|
||||||
if (!this.canEditFiles()) {
|
if (!this.canEditFiles()) {
|
||||||
this.displayCannotEditLibraryFilesMessage();
|
this.displayCannotEditLibraryFilesMessage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var libraryID = itemGroup.ref.libraryID;
|
||||||
|
|
||||||
var nsIFilePicker = Components.interfaces.nsIFilePicker;
|
var nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||||
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
||||||
.createInstance(nsIFilePicker);
|
.createInstance(nsIFilePicker);
|
||||||
|
@ -2503,7 +2514,7 @@ var ZoteroPane = new function()
|
||||||
if(link)
|
if(link)
|
||||||
attachmentID = Zotero.Attachments.linkFromFile(file, id);
|
attachmentID = Zotero.Attachments.linkFromFile(file, id);
|
||||||
else
|
else
|
||||||
attachmentID = Zotero.Attachments.importFromFile(file, id);
|
attachmentID = Zotero.Attachments.importFromFile(file, id, libraryID);
|
||||||
|
|
||||||
if(attachmentID && !id)
|
if(attachmentID && !id)
|
||||||
{
|
{
|
||||||
|
@ -2703,10 +2714,8 @@ var ZoteroPane = new function()
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
if (libraryID) {
|
if (!ZoteroPane.canEditFiles(row)) {
|
||||||
var pr = Components.classes["@mozilla.org/network/default-prompt;1"]
|
ZoteroPane.displayCannotEditLibraryFilesMessage();
|
||||||
.getService(Components.interfaces.nsIPrompt);
|
|
||||||
pr.alert("", "Files cannot currently be added to group libraries.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2717,7 +2726,7 @@ var ZoteroPane = new function()
|
||||||
var collectionID = false;
|
var collectionID = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.Attachments.importFromURL(url, false, false, false, collectionID);
|
Zotero.Attachments.importFromURL(url, false, false, false, collectionID, null, libraryID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,7 +190,7 @@ Zotero.Attachments = new function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function importFromURL(url, sourceItemID, forceTitle, forceFileBaseName, parentCollectionIDs, mimeType) {
|
function importFromURL(url, sourceItemID, forceTitle, forceFileBaseName, parentCollectionIDs, mimeType, libraryID) {
|
||||||
Zotero.debug('Importing attachment from URL');
|
Zotero.debug('Importing attachment from URL');
|
||||||
|
|
||||||
if (sourceItemID && parentCollectionIDs) {
|
if (sourceItemID && parentCollectionIDs) {
|
||||||
|
@ -228,7 +228,7 @@ Zotero.Attachments = new function(){
|
||||||
Zotero.Browser.deleteHiddenBrowser(browser);
|
Zotero.Browser.deleteHiddenBrowser(browser);
|
||||||
};
|
};
|
||||||
Zotero.Attachments.importFromDocument(browser.contentDocument,
|
Zotero.Attachments.importFromDocument(browser.contentDocument,
|
||||||
sourceItemID, forceTitle, parentCollectionIDs, callback);
|
sourceItemID, forceTitle, parentCollectionIDs, callback, libraryID);
|
||||||
imported = true;
|
imported = true;
|
||||||
};
|
};
|
||||||
browser.addEventListener("pageshow", onpageshow, false);
|
browser.addEventListener("pageshow", onpageshow, false);
|
||||||
|
@ -259,7 +259,10 @@ Zotero.Attachments = new function(){
|
||||||
try {
|
try {
|
||||||
// Create a new attachment
|
// Create a new attachment
|
||||||
var attachmentItem = new Zotero.Item('attachment');
|
var attachmentItem = new Zotero.Item('attachment');
|
||||||
if (sourceItemID) {
|
if (libraryID) {
|
||||||
|
attachmentItem.libraryID = libraryID;
|
||||||
|
}
|
||||||
|
else if (sourceItemID) {
|
||||||
var parentItem = Zotero.Items.get(sourceItemID);
|
var parentItem = Zotero.Items.get(sourceItemID);
|
||||||
attachmentItem.libraryID = parentItem.libraryID;
|
attachmentItem.libraryID = parentItem.libraryID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1468,7 +1468,7 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient)
|
||||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||||
.getService(Components.interfaces.nsIWindowMediator);
|
.getService(Components.interfaces.nsIWindowMediator);
|
||||||
var win = wm.getMostRecentWindow("navigator:browser");
|
var win = wm.getMostRecentWindow("navigator:browser");
|
||||||
win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack', row); // TODO: don't do this
|
win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack', null, row); // TODO: don't do this
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3108,27 +3108,34 @@ Zotero.Item.prototype.getAttachments = function(includeTrashed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Zotero.Item.prototype.getBestSnapshot = function () {
|
||||||
|
var msg = "Zotero.Item.getBestSnapshot() is deprecated -- use getBestAttachment";
|
||||||
|
Zotero.debug(msg, 2);
|
||||||
|
Components.utils.reportError(msg);
|
||||||
|
return this.getBestAttachment();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the itemID of the latest child snapshot of this item with the
|
* Looks for attachment in the following order: oldest PDF attachment matching parent URL,
|
||||||
* same URL as the item itself, or false if none
|
* oldest non-PDF attachment matching parent URL, oldest PDF attachment not matching URL,
|
||||||
|
* old non-PDF attachment not matching URL
|
||||||
|
*
|
||||||
|
* @return {Integer} itemID for attachment
|
||||||
*/
|
*/
|
||||||
Zotero.Item.prototype.getBestSnapshot = function() {
|
Zotero.Item.prototype.getBestAttachment = function() {
|
||||||
if (!this.isRegularItem()) {
|
if (!this.isRegularItem()) {
|
||||||
throw ("getBestSnapshot() can only be called on regular items");
|
throw ("getBestAttachment() can only be called on regular items");
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = this.getField('url');
|
var url = this.getField('url');
|
||||||
if (!url) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sql = "SELECT IA.itemID, value FROM itemAttachments IA NATURAL JOIN items I "
|
var sql = "SELECT IA.itemID FROM itemAttachments IA NATURAL JOIN items I "
|
||||||
+ "LEFT JOIN itemData ID ON (IA.itemID=ID.itemID AND fieldID=1) "
|
+ "LEFT JOIN itemData ID ON (IA.itemID=ID.itemID AND fieldID=1) "
|
||||||
+ "LEFT JOIN itemDataValues IDV ON (ID.valueID=IDV.valueID) "
|
+ "LEFT JOIN itemDataValues IDV ON (ID.valueID=IDV.valueID) "
|
||||||
+ "WHERE sourceItemID=? AND linkMode NOT IN (?) "
|
+ "WHERE sourceItemID=? AND linkMode NOT IN (?) "
|
||||||
+ "AND IA.itemID NOT IN (SELECT itemID FROM deletedItems) "
|
+ "AND IA.itemID NOT IN (SELECT itemID FROM deletedItems) "
|
||||||
+ "ORDER BY value=? DESC, mimeType='application/pdf' DESC, dateAdded ASC";
|
+ "ORDER BY value=? DESC, mimeType='application/pdf' DESC, dateAdded ASC";
|
||||||
|
|
||||||
return Zotero.DB.valueQuery(sql, [this.id, Zotero.Attachments.LINK_MODE_LINKED_URL, url]);
|
return Zotero.DB.valueQuery(sql, [this.id, Zotero.Attachments.LINK_MODE_LINKED_URL, url]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2274,10 +2274,22 @@ Zotero.ItemTreeView.prototype.drop = function(row, orient)
|
||||||
|
|
||||||
// Still string, so remote URL
|
// Still string, so remote URL
|
||||||
if (typeof file == 'string') {
|
if (typeof file == 'string') {
|
||||||
|
if (sourceItemID) {
|
||||||
|
if (!itemGroup.filesEditable) {
|
||||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||||
.getService(Components.interfaces.nsIWindowMediator);
|
.getService(Components.interfaces.nsIWindowMediator);
|
||||||
var win = wm.getMostRecentWindow("navigator:browser");
|
var win = wm.getMostRecentWindow("navigator:browser");
|
||||||
win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack', row); // TODO: don't do this
|
win.ZoteroPane.displayCannotEditLibraryFilesMessage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Zotero.Attachments.importFromURL(url, sourceItemID, false, false, null, null, targetLibraryID);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||||
|
.getService(Components.interfaces.nsIWindowMediator);
|
||||||
|
var win = wm.getMostRecentWindow("navigator:browser");
|
||||||
|
win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack'); // TODO: don't do this
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue