commit f018e7d433130151e0e56b16efba72fc83b85c49
parent fa348d346cb9099b2693b89dc841ef2460441cfc
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 18 May 2009 09:05:11 +0000
- Fix an error with translate.translate(true)
- Add Zotero.Libraries.isEditable(libraryID) (currently unused)
- Addresses #1444, Attachment arrow/count persists after delete, for items (problem probably remains for collections)
- Dragging PDF favicon or link or clicking Create New Item from Current Page when viewing a PDF creates a top-level PDF -- this is a temporary solution that allows "Retrieve PDF Metadata" to be used until it can be run automatically
- Allow PDF child snapshots to be dragged out of parents
- Dragging a link to a collection now creates parent item and child snapshot
- ZoteroPane.newItem(), addItemFromDocument(), addItemFromPage(), addItemFromURL(), and canEdit() now all take an optional row parameter
Diffstat:
7 files changed, 129 insertions(+), 35 deletions(-)
diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js
@@ -621,27 +621,41 @@ var ZoteroPane = new function()
*
* _data_ is an optional object with field:value for itemData
*/
- function newItem(typeID, data)
+ function newItem(typeID, data, row)
{
if (!Zotero.stateCheck()) {
this.displayErrorMessage(true);
return false;
}
- if (!this.canEdit()) {
+ if (!this.canEdit(row)) {
this.displayCannotEditLibraryMessage();
return;
}
+ // Currently selected row
+ if (row === undefined) {
+ row = this.collectionsView.selection.currentIndex;
+ }
+
+ if (row !== undefined) {
+ var itemGroup = this.collectionsView._getItemAtRow(row);
+ var libraryID = itemGroup.ref.libraryID;
+ }
+ else {
+ var libraryID = null;
+ var itemGroup = null;
+ }
+
var item = new Zotero.Item(typeID);
- item.libraryID = this.getSelectedLibraryID();
+ item.libraryID = libraryID;
for (var i in data) {
item.setField(i, data[i]);
}
var itemID = item.save();
- if (this.itemsView && this.itemsView._itemGroup.isCollection()) {
- this.itemsView._itemGroup.ref.addItem(itemID);
+ if (itemGroup && itemGroup.isCollection()) {
+ itemGroup.ref.addItem(itemID);
}
//set to Info tab
@@ -652,6 +666,7 @@ var ZoteroPane = new function()
return Zotero.Items.get(itemID);
}
+
function newCollection(parent)
{
if (!Zotero.stateCheck()) {
@@ -2228,8 +2243,8 @@ var ZoteroPane = new function()
}
- this.addItemFromPage = function (itemType) {
- return this.addItemFromDocument(window.content.document, itemType);
+ this.addItemFromPage = function (itemType, row) {
+ return this.addItemFromDocument(window.content.document, itemType, row);
}
@@ -2239,17 +2254,31 @@ var ZoteroPane = new function()
* @param {Boolean} [saveSnapshot] Force saving of a snapshot,
* regardless of automaticSnapshots pref
*/
- this.addItemFromDocument = function (doc, itemType, saveSnapshot) {
+ this.addItemFromDocument = function (doc, itemType, saveSnapshot, row) {
if (!Zotero.stateCheck()) {
this.displayErrorMessage(true);
return false;
}
- if (!this.canEdit()) {
+ // Currently selected row
+ if (row === undefined) {
+ row = this.collectionsView.selection.currentIndex;
+ }
+
+ if (!this.canEdit(row)) {
this.displayCannotEditLibraryMessage();
return;
}
+ if (row !== undefined) {
+ var itemGroup = this.collectionsView._getItemAtRow(row);
+ var libraryID = itemGroup.ref.libraryID;
+ }
+ else {
+ var libraryID = null;
+ var itemGroup = null;
+ }
+
var progressWin = new Zotero.ProgressWindow();
progressWin.changeHeadline(Zotero.getString('ingester.scraping'));
var icon = 'chrome://zotero/skin/treeitem-webpage.png';
@@ -2263,14 +2292,54 @@ var ZoteroPane = new function()
accessDate: "CURRENT_TIMESTAMP"
}
+ // TODO: this, needless to say, is a temporary hack
+ if (itemType == 'temporaryPDFHack') {
+ itemType = null;
+ var isPDF = false;
+ if (doc.title.indexOf('application/pdf') != -1) {
+ isPDF = true;
+ }
+ else {
+ var ios = Components.classes["@mozilla.org/network/io-service;1"].
+ getService(Components.interfaces.nsIIOService);
+ try {
+ var uri = ios.newURI(doc.location, null, null);
+ if (uri.fileName && uri.fileName.match(/pdf$/)) {
+ isPDF = true;
+ }
+ }
+ catch (e) {
+ Zotero.debug(e);
+ Components.utils.reportError(e);
+ }
+ }
+
+ if (isPDF) {
+ if (libraryID) {
+ var pr = Components.classes["@mozilla.org/network/default-prompt;1"]
+ .getService(Components.interfaces.nsIPrompt);
+ pr.alert("", "Files cannot currently be added to group libraries.");
+ return;
+ }
+
+ if (itemGroup && itemGroup.isCollection()) {
+ var collectionID = itemGroup.ref.id;
+ }
+ else {
+ var collectionID = false;
+ }
+ Zotero.Attachments.importFromDocument(doc, false, false, collectionID);
+ return;
+ }
+ }
+
// Save web page item by default
if (!itemType) {
itemType = 'webpage';
}
itemType = Zotero.ItemTypes.getID(itemType);
- var item = this.newItem(itemType, data);
+ var item = this.newItem(itemType, data, row);
- var filesEditable = false;
if (item.libraryID) {
var group = Zotero.Groups.getByLibraryID(item.libraryID);
filesEditable = group.filesEditable;
@@ -2295,13 +2364,13 @@ var ZoteroPane = new function()
}
- this.addItemFromURL = function (url, itemType) {
+ this.addItemFromURL = function (url, itemType, row) {
if (url == window.content.document.location.href) {
- return this.addItemFromPage(itemType);
+ return this.addItemFromPage(itemType, row);
}
var processor = function (doc) {
- ZoteroPane.addItemFromDocument(doc, itemType);
+ ZoteroPane.addItemFromDocument(doc, itemType, null, row);
};
var done = function () {}
@@ -2445,10 +2514,17 @@ var ZoteroPane = new function()
* Test if the user can edit the currently selected library/collection,
* and display an error if not
*
+ * @param {Integer} [row]
+ *
* @return {Boolean} TRUE if user can edit, FALSE if not
*/
- this.canEdit = function () {
- var itemGroup = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex);
+ this.canEdit = function (row) {
+ // Currently selected row
+ if (row === undefined) {
+ row = this.collectionsView.selection.currentIndex;
+ }
+
+ var itemGroup = this.collectionsView._getItemAtRow(row);
return itemGroup.isEditable();
}
diff --git a/chrome/content/zotero/overlay.xul b/chrome/content/zotero/overlay.xul
@@ -193,7 +193,7 @@
</menu>
</menupopup>
</toolbarbutton>
- <toolbarbutton id="zotero-tb-item-from-page" tooltiptext="&zotero.toolbar.newItemFromPage.label;" oncommand="ZoteroPane.addItemFromPage()"/>
+ <toolbarbutton id="zotero-tb-item-from-page" tooltiptext="&zotero.toolbar.newItemFromPage.label;" oncommand="ZoteroPane.addItemFromPage('temporaryPDFHack')"/>
<toolbarbutton id="zotero-tb-lookup" tooltiptext="&zotero.toolbar.lookup.label;" oncommand="ZoteroPane.openLookupWindow()"/>
<!--
<toolbarseparator/>
diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js
@@ -1329,7 +1329,10 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient)
// Still string, so remote URL
if (typeof file == 'string') {
- Zotero.Attachments.importFromURL(url, false, false, false, parentCollectionID);
+ 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', row); // TODO: don't do this
continue;
}
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -1757,23 +1757,18 @@ Zotero.Item.prototype.save = function() {
}
if (this._previousData) {
- var oldSourceItemIDOrKey = this._previousData.sourceItem;
- if (oldSourceItemIDOrKey) {
- if (typeof oldSourceItemIDOrKey == 'number') {
- var oldSourceItem = Zotero.Items.get(oldSourceItemIDOrKey);
- }
- else {
- var oldSourceItem = Zotero.Items.getByLibraryAndKey(this.libraryID, oldSourceItemIDOrKey);
- }
+ var oldSourceItemID = this._previousData.sourceItemID;
+ if (oldSourceItemID) {
+ var oldSourceItem = Zotero.Items.get(oldSourceItemID);
}
if (oldSourceItem) {
var oldSourceItemNotifierData = {};
oldSourceItemNotifierData[oldSourceItem.id] =
{ old: oldSourceItem.serialize() };
}
- else if (oldSourceItemIDOrKey) {
+ else if (oldSourceItemID) {
var oldSourceItemNotifierData = null;
- Zotero.debug("Old source item " + oldSourceItemIDOrKey
+ Zotero.debug("Old source item " + oldSourceItemID
+ " didn't exist in setSource()", 2);
}
}
@@ -1782,7 +1777,7 @@ Zotero.Item.prototype.save = function() {
// If this was an independent item, remove from any collections
// where it existed previously and add source instead if
// there is one
- if (!oldSourceItemIDOrKey) {
+ if (!oldSourceItemID) {
var sql = "SELECT collectionID FROM collectionItems "
+ "WHERE itemID=?";
var changedCollections = Zotero.DB.columnQuery(sql, this.id);
@@ -1796,9 +1791,13 @@ Zotero.Item.prototype.save = function() {
sql = "DELETE FROM collectionItems WHERE itemID=?";
Zotero.DB.query(sql, this.id);
}
+
+ for each(var c in changedCollections) {
+ Zotero.Notifier.trigger('remove', 'collection-item', c + '-' + this.id);
+ }
+
+ Zotero.Collections.reload(changedCollections);
}
-
- // TODO: collection notifier trigger?
}
// Update DB, if not a note or attachment we already changed above
diff --git a/chrome/content/zotero/xpcom/data/libraries.js b/chrome/content/zotero/xpcom/data/libraries.js
@@ -41,4 +41,18 @@ Zotero.Libraries = new function () {
}
return libraryType;
}
+
+
+ this.isEditable = function (libraryID) {
+ var type = this.getType(libraryID);
+ switch (type) {
+ case 'group':
+ var groupID = Zotero.Groups.getGroupIDFromLibraryID(libraryID);
+ var group = Zotero.Groups.get(groupID);
+ return group.editable;
+
+ default:
+ throw ("Unsupported library type '" + type + "' in Zotero.Libraries.getName()");
+ }
+ }
}
diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js
@@ -2078,7 +2078,9 @@ Zotero.ItemTreeView.prototype.canDrop = function(row, orient, dragData)
return false;
}
- if (item.isWebAttachment()) {
+ // Don't allow web attachments to be dragged out of parents,
+ // but do allow PDFs for now so they can be recognized
+ if (item.isWebAttachment() && item.attachmentMIMEType != 'application/pdf') {
return false;
}
@@ -2168,7 +2170,7 @@ Zotero.ItemTreeView.prototype.drop = function(row, orient)
item.setSource();
item.save()
}
- itemGroup.ref.addItem(id);
+ itemGroup.ref.addItem(item.id);
}
}
}
@@ -2241,7 +2243,7 @@ Zotero.ItemTreeView.prototype.drop = function(row, orient)
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
- win.ZoteroPane.addItemFromURL(url);
+ win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack'); // TODO: don't do this
}
continue;
}
diff --git a/chrome/content/zotero/xpcom/translate.js b/chrome/content/zotero/xpcom/translate.js
@@ -635,7 +635,7 @@ Zotero.Translate.prototype.translate = function(libraryID, saveAttachments) {
throw("cannot translate: no location specified");
}
- this.libraryID = (libraryID == undefined) ? null : libraryID;
+ this.libraryID = (libraryID === true || libraryID == undefined) ? null : libraryID;
this.saveAttachments = !(saveAttachments === false);
this.saveFiles = this.saveAttachments;