- Make "Save Link As Zotero Snapshot" save attachment to selected collection

- Fix hourglass cursor on importFromURL (happened with "Save Link As Z Snapshot")
This commit is contained in:
Dan Stillman 2007-01-21 22:56:46 +00:00
parent 61dba96bf8
commit b8fba0335d
4 changed files with 27 additions and 10 deletions

View File

@ -55,10 +55,10 @@
oncommand="var itemID = ZoteroPane.addItemFromPage(); ZoteroPane.newNote(false, itemID, window.content.getSelection().toString())"/>
<menuitem id="zotero-context-save-link-as-snapshot" class="menu-iconic"
label="&zotero.contextMenu.saveLinkAsSnapshot;"
oncommand="Zotero.Attachments.importFromURL(window.gContextMenu.linkURL)"/>
oncommand="Zotero.Attachments.importFromURL(window.gContextMenu.linkURL, false, false, ZoteroPane.getSelectedCollection(true))"/>
<menuitem id="zotero-context-save-image-as-snapshot" class="menu-iconic"
label="&zotero.contextMenu.saveImageAsSnapshot;"
oncommand="Zotero.Attachments.importFromURL(window.gContextMenu.onImage ? window.gContextMenu.imageURL : window.gContextMenu.bgImageURL)"/>
oncommand="Zotero.Attachments.importFromURL(window.gContextMenu.onImage ? window.gContextMenu.imageURL : window.gContextMenu.bgImageURL, false, false, ZoteroPane.getSelectedCollection(true))"/>
</popup>
<vbox id="appcontent">

View File

@ -168,7 +168,7 @@ Zotero.Attachments = new function(){
}
function importFromURL(url, sourceItemID, forceTitle){
function importFromURL(url, sourceItemID, forceTitle, parentCollectionIDs){
Zotero.debug('Importing attachment from URL');
Zotero.Utilities.HTTP.doHead(url, function(obj){
@ -191,9 +191,13 @@ Zotero.Attachments = new function(){
if (Zotero.MIME.hasNativeHandler(mimeType, ext)){
var browser = Zotero.Browser.createHiddenBrowser();
browser.addEventListener("pageshow", function(){
Zotero.Attachments.importFromDocument(browser.contentDocument, sourceItemID, forceTitle);
browser.removeEventListener("pageshow", arguments.callee, true);
Zotero.Browser.deleteHiddenBrowser(browser);
var callback = function () {
browser.removeEventListener("pageshow", arguments.callee, true);
Zotero.Browser.deleteHiddenBrowser(browser);
};
Zotero.Attachments.importFromDocument(browser.contentDocument,
sourceItemID, forceTitle, parentCollectionIDs, callback);
}, true);
browser.loadURI(url);
}
@ -221,6 +225,15 @@ Zotero.Attachments = new function(){
attachmentItem.save();
var itemID = attachmentItem.getID();
// Add to collections
if (parentCollectionIDs){
var ids = Zotero.flattenArguments(parentCollectionIDs);
for each(var id in ids){
var col = Zotero.Collections.get(id);
col.addItem(itemID);
}
}
// Create a new folder for this item in the storage directory
var destDir = Zotero.getStorageDirectory();
destDir.append(itemID);
@ -351,7 +364,7 @@ Zotero.Attachments = new function(){
}
function importFromDocument(document, sourceItemID, forceTitle, parentCollectionIDs){
function importFromDocument(document, sourceItemID, forceTitle, parentCollectionIDs, callback){
Zotero.debug('Importing attachment from document');
var url = document.location.href;
@ -444,6 +457,10 @@ Zotero.Attachments = new function(){
}
Zotero.Fulltext.indexDocument(document, itemID);
if (callback) {
callback();
}
});
// The attachment is still incomplete here, but we can't risk
@ -635,6 +652,8 @@ Zotero.Attachments = new function(){
// Chain fulltext indexer inside the charset callback,
// since it's asynchronous and a prerequisite
Zotero.Fulltext.indexDocument(browser.contentDocument, itemID);
Zotero.Browser.deleteHiddenBrowser(browser);
}
}, itemID);

View File

@ -155,8 +155,6 @@ Zotero.File = new function(){
prefService.setCharPref('intl.charset.detector', oldPref);
callback(charset, args);
Zotero.Browser.deleteHiddenBrowser(browser);
}, false);
}
}