Closes #367, Display dialog to locate missing attachment files

New "Locate..." button in file not found dialog.

Split file not found message into two parts and updated localizations accordingly
This commit is contained in:
Dan Stillman 2007-02-18 10:15:44 +00:00
parent 7199b6cc21
commit 38416da753
15 changed files with 114 additions and 21 deletions

View File

@ -77,6 +77,8 @@ var ZoteroPane = new function()
this.viewAttachment = viewAttachment;
this.viewSelectedAttachment = viewSelectedAttachment;
this.showSelectedAttachmentInFilesystem = showSelectedAttachmentInFilesystem;
this.showAttachmentNotFoundDialog = showAttachmentNotFoundDialog;
this.relinkAttachment = relinkAttachment;
var self = this;
@ -1495,7 +1497,7 @@ var ZoteroPane = new function()
}
}
else {
alert(Zotero.getString('pane.item.attachments.fileNotFound'));
this.showAttachmentNotFoundDialog(itemID);
}
}
@ -1530,11 +1532,57 @@ var ZoteroPane = new function()
}
}
else {
alert(Zotero.getString('pane.item.attachments.fileNotFound'));
this.showAttachmentNotFoundDialog(attachment.getID())
}
}
}
}
function showAttachmentNotFoundDialog(itemID) {
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
createInstance(Components.interfaces.nsIPromptService);
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_OK)
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING);
var index = ps.confirmEx(null,
Zotero.getString('pane.item.attachments.fileNotFound.title'),
Zotero.getString('pane.item.attachments.fileNotFound.text'),
buttonFlags, null, Zotero.getString('pane.item.attachments.locate'),
null, null, {});
if (index == 1) {
this.relinkAttachment(itemID);
}
}
function relinkAttachment(itemID) {
var item = Zotero.Items.get(itemID);
if (!item) {
throw('Item ' + itemID + ' not found in ZoteroPane.relinkAttachment()');
}
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
fp.init(window, Zotero.getString('pane.item.attachments.select'), nsIFilePicker.modeOpen);
var file = item.getFile(false, true);
var dir = Zotero.File.getClosestDirectory(file);
if (dir) {
dir.QueryInterface(Components.interfaces.nsILocalFile);
fp.displayDirectory = dir;
}
fp.appendFilters(Components.interfaces.nsIFilePicker.filterAll);
if (fp.show() == nsIFilePicker.returnOK) {
var file = fp.file;
file.QueryInterface(Components.interfaces.nsILocalFile);
item.relinkAttachmentFile(file);
}
}
}
window.addEventListener("load", function(e) { ZoteroPane.onLoad(e); }, false);

View File

@ -499,6 +499,10 @@ Zotero.Attachments = new function(){
}
/*
* Gets a relative path for imported attachments and an absolute path
* for files outside the storage directory
*/
function getPath(file, linkMode) {
if (linkMode == self.LINK_MODE_IMPORTED_URL ||
linkMode == self.LINK_MODE_IMPORTED_FILE) {

View File

@ -1300,7 +1300,7 @@ Zotero.Item.prototype.numAttachments = function(){
* Note: Always returns false for items with LINK_MODE_LINKED_URL,
* since they have no files -- use getField('url') instead
**/
Zotero.Item.prototype.getFile = function(row){
Zotero.Item.prototype.getFile = function(row, skipExistsCheck) {
if (!this.isAttachment()){
throw ("getFile() can only be called on items of type 'attachment'");
}
@ -1379,7 +1379,7 @@ Zotero.Item.prototype.getFile = function(row){
}
}
if (!file.exists()){
if (!skipExistsCheck && !file.exists()){
return false;
}
@ -1416,12 +1416,7 @@ Zotero.Item.prototype.renameAttachmentFile = function(newName, overwrite) {
}
file.moveTo(file.parent, newName);
var linkMode = this.getAttachmentLinkMode();
var path = Zotero.Attachments.getPath(file, linkMode);
var sql = "UPDATE itemAttachments SET path=? WHERE itemID=?";
Zotero.DB.query(sql, [path, this.getID()]);
this.relinkAttachmentFile(file);
return true;
}
@ -1431,6 +1426,21 @@ Zotero.Item.prototype.renameAttachmentFile = function(newName, overwrite) {
}
Zotero.Item.prototype.relinkAttachmentFile = function(file) {
var linkMode = this.getAttachmentLinkMode();
if (linkMode == Zotero.Attachments.LINK_MODE_LINKED_URL) {
throw('Cannot relink linked URL in Zotero.Items.relinkAttachmentFile()');
}
var path = Zotero.Attachments.getPath(file, linkMode);
var sql = "UPDATE itemAttachments SET path=? WHERE itemID=?";
Zotero.DB.query(sql, [path, this.getID()]);
}
/*
* Return a file:/// URL path to files and snapshots
*/

View File

@ -22,6 +22,7 @@
Zotero.File = new function(){
this.getExtension = getExtension;
this.getClosestDirectory = getClosestDirectory;
this.getSample = getSample;
this.getContents = getContents;
this.getCharsetFromFile = getCharsetFromFile;
@ -34,6 +35,24 @@ Zotero.File = new function(){
}
/*
* Traverses up the filesystem from a file until it finds an existing
* directory, or false if it hits the root
*/
function getClosestDirectory(file) {
var dir = file.parent;
while (dir && !dir.exists()) {
var dir = dir.parent;
}
if (dir && dir.exists()) {
return dir;
}
return false;
}
/*
* Get the first 128 bytes of the file as a string (multibyte-safe)
*/

View File

@ -60,7 +60,8 @@ pane.item.attachments.rename.error=An error occurred while renaming the file.
pane.item.attachments.view.link=Seite ansehen
pane.item.attachments.view.snapshot=Schnappschuss ansehen
pane.item.attachments.view.file=Datei ansehen
pane.item.attachments.fileNotFound=Die angehängte Datei wurde nicht gefunden.\n\nSie wurde möglicherweise außerhalb von Zotero verschoben oder gelöscht.
pane.item.attachments.fileNotFound.title = Die angehängte Datei wurde nicht gefunden.
pane.item.attachments.fileNotFound.text = Sie wurde möglicherweise außerhalb von Zotero verschoben oder gelöscht.
pane.item.attachments.delete.confirm=Sind Sie sicher, dass Sie diesen Anhang löschen möchten?
pane.item.attachments.count.zero=%S attachments:
pane.item.attachments.count.singular=%S Anhang

View File

@ -60,7 +60,8 @@ pane.item.attachments.rename.error=An error occurred while renaming the file.
pane.item.attachments.view.link=Seite ansehen
pane.item.attachments.view.snapshot=Schnappschuss ansehen
pane.item.attachments.view.file=Datei ansehen
pane.item.attachments.fileNotFound=Die angehängte Datei wurde nicht gefunden.\n\nSie wurde möglicherweise ausserhalb von Zotero verschoben oder gelöscht.
pane.item.attachments.fileNotFound.title = Die angehängte Datei wurde nicht gefunden.
pane.item.attachments.fileNotFound.text = Sie wurde möglicherweise ausserhalb von Zotero verschoben oder gelöscht.
pane.item.attachments.delete.confirm=Sind Sie sicher, dass Sie diesen Anhang löschen möchten?
pane.item.attachments.count.zero=%S attachments:
pane.item.attachments.count.singular=%S Anhang

View File

@ -60,7 +60,8 @@ pane.item.attachments.rename.error=An error occurred while renaming the file.
pane.item.attachments.view.link=Seite ansehen
pane.item.attachments.view.snapshot=Schnappschuss ansehen
pane.item.attachments.view.file=Datei ansehen
pane.item.attachments.fileNotFound=Die angehängte Datei wurde nicht gefunden.\n\nSie wurde möglicherweise außerhalb von Zotero verschoben oder gelöscht.
pane.item.attachments.fileNotFound.title = Die angehängte Datei wurde nicht gefunden.
pane.item.attachments.fileNotFound.text = Sie wurde möglicherweise außerhalb von Zotero verschoben oder gelöscht.
pane.item.attachments.delete.confirm=Sind Sie sicher, dass Sie diesen Anhang löschen möchten?
pane.item.attachments.count.zero=%S attachments:
pane.item.attachments.count.singular=%S Anhang

View File

@ -66,7 +66,9 @@ pane.item.attachments.rename.error = An error occurred while renaming the fi
pane.item.attachments.view.link = View Page
pane.item.attachments.view.snapshot = View Snapshot
pane.item.attachments.view.file = View File
pane.item.attachments.fileNotFound = The attached file could not be found.\n\nIt may have been moved or deleted outside of Zotero.
pane.item.attachments.fileNotFound.title = The attached file could not be found.
pane.item.attachments.fileNotFound.text = It may have been moved or deleted outside of Zotero.
pane.item.attachments.locate = Locate...
pane.item.attachments.delete.confirm = Are you sure you want to delete this attachment?
pane.item.attachments.count.zero = %S attachments:
pane.item.attachments.count.singular = %S attachment:

View File

@ -60,7 +60,8 @@ pane.item.attachments.rename.error=An error occurred while renaming the file.
pane.item.attachments.view.link=Afficher la page
pane.item.attachments.view.snapshot=Afficher la capture
pane.item.attachments.view.file=Afficher le fichier
pane.item.attachments.fileNotFound=Le fichier joint n'a pu être trouvé.\n\nIl a pu être déplacé ou supprimé de Zotero.
pane.item.attachments.fileNotFound.title = Le fichier joint n'a pu être trouvé.
pane.item.attachments.fileNotFound.text = Il a pu être déplacé ou supprimé de Zotero.
pane.item.attachments.delete.confirm=Souhaitez-vous vraiment supprimer cette pièce jointe ?
pane.item.attachments.count.zero=%S attachments:
pane.item.attachments.count.singular=%S pièce jointe

View File

@ -60,7 +60,8 @@ pane.item.attachments.rename.error=An error occurred while renaming the file.
pane.item.attachments.view.link=Visualizza pagina
pane.item.attachments.view.snapshot=Visualizza istantanea
pane.item.attachments.view.file=Visualizza file
pane.item.attachments.fileNotFound=Impossibile trovare il file allegato. \n\nPotrebbe essere stato spostato o eliminato senza l'utilizzo di Zotero.
pane.item.attachments.fileNotFound.title = Impossibile trovare il file allegato.
pane.item.attachments.fileNotFound.text = Potrebbe essere stato spostato o eliminato senza l'utilizzo di Zotero.
pane.item.attachments.delete.confirm=Eliminare questo allegato?
pane.item.attachments.count.zero=%S attachments:
pane.item.attachments.count.singular=%S allegato

View File

@ -60,7 +60,8 @@ pane.item.attachments.rename.error=An error occurred while renaming the file.
pane.item.attachments.view.link=페이지 보기
pane.item.attachments.view.snapshot=스냅샷 보기
pane.item.attachments.view.file=파일 보기
pane.item.attachments.fileNotFound=첨부 파일을 찾을 수 없습니다.\n\n Zotero 밖으로 이동했거나 삭제되었을 가능성이 있습니다.
pane.item.attachments.fileNotFound.title = 첨부 파일을 찾을 수 없습니다.
pane.item.attachments.fileNotFound.text = Zotero 밖으로 이동했거나 삭제되었을 가능성이 있습니다.
pane.item.attachments.delete.confirm=이 첨부를 삭제하길 원하는게 맞습니까?
pane.item.attachments.count.zero=%S attachments:
pane.item.attachments.count.singular=%s 첨부

View File

@ -60,7 +60,8 @@ pane.item.attachments.rename.error=An error occurred while renaming the file.
pane.item.attachments.view.link=Vis side
pane.item.attachments.view.snapshot=Vis snapshot
pane.item.attachments.view.file=Vis fil
pane.item.attachments.fileNotFound=Den vedlagte filen ble ikke funnet.\n\nDen kan ha blitt flyttet eller slettet utenfor Zotero.
pane.item.attachments.fileNotFound.title = Den vedlagte filen ble ikke funnet.
pane.item.attachments.fileNotFound.text = Den kan ha blitt flyttet eller slettet utenfor Zotero.
pane.item.attachments.delete.confirm=Er du sikker på at du vil slette dette vedlegget?
pane.item.attachments.count.zero=%S attachments:
pane.item.attachments.count.singular=%S vedlegg

View File

@ -60,7 +60,8 @@ pane.item.attachments.rename.error=An error occurred while renaming the file.
pane.item.attachments.view.link=Pagina Weergeven
pane.item.attachments.view.snapshot=Snapshot Weergeven
pane.item.attachments.view.file=Bestand Weergeven
pane.item.attachments.fileNotFound=De bijlage kan niet gevonden worden.\n\nHet kan zijn dat deze verplaatst of verwijderd is buiten Zotero.
pane.item.attachments.fileNotFound.title = De bijlage kan niet gevonden worden.
pane.item.attachments.fileNotFound.text = Het kan zijn dat deze verplaatst of verwijderd is buiten Zotero.
pane.item.attachments.delete.confirm=Ben je zeker dat je deze bijlage wil verwijderen?
pane.item.attachments.count.zero=%S attachments:
pane.item.attachments.count.singular=%S bijlage

View File

@ -60,7 +60,8 @@ pane.item.attachments.rename.error=An error occurred while renaming the file.
pane.item.attachments.view.link=Види страницу
pane.item.attachments.view.snapshot=Види снимак
pane.item.attachments.view.file=Види датотеку
pane.item.attachments.fileNotFound=Додата датотека се није могла наћи.\n\nМожда је померена или избрисана изван Зотера.
pane.item.attachments.fileNotFound.title = Додата датотека се није могла наћи.
pane.item.attachments.fileNotFound.text = Можда је померена или избрисана изван Зотера.
pane.item.attachments.delete.confirm=Да ли сте сигурни да желите изврисати овај додатак?
pane.item.attachments.count.zero=%S attachments:
pane.item.attachments.count.singular=%S додатак

View File

@ -60,7 +60,8 @@ pane.item.attachments.rename.error=An error occurred while renaming the file.
pane.item.attachments.view.link=查看页面
pane.item.attachments.view.snapshot=查看快照
pane.item.attachments.view.file=查看文件
pane.item.attachments.fileNotFound=附件无法找到.\n\n 可能已在 Zotero 外移走或删除.
pane.item.attachments.fileNotFound.title = 附件无法找到.
pane.item.attachments.fileNotFound.text = 可能已在 Zotero 外移走或删除.
pane.item.attachments.delete.confirm=确实要删除此附件吗?
pane.item.attachments.count.zero=%S attachments:
pane.item.attachments.count.singular=%S 个附件