Closes #494, Remember "Rename associated file" setting

Also:

- Clicking OK on rename dialog with "Rename associated file" checked but without changing the filename would delete the original file.
- Add "Show File" button for snapshots
This commit is contained in:
Dan Stillman 2007-01-12 07:18:53 +00:00
parent 9c666cef3a
commit 28a6b5f7cb
3 changed files with 20 additions and 6 deletions

View File

@ -481,7 +481,7 @@ var ZoteroPane = new function()
.getService(Components.interfaces.nsIPromptService); .getService(Components.interfaces.nsIPromptService);
var newTitle = { value: val }; var newTitle = { value: val };
var checkState = { value: false }; var checkState = { value: Zotero.Prefs.get('lastRenameAssociatedFile') };
while (true) { while (true) {
var result = nsIPS.prompt(window, var result = nsIPS.prompt(window,
@ -490,10 +490,14 @@ var ZoteroPane = new function()
Zotero.getString('pane.item.attachments.rename.renameAssociatedFile'), Zotero.getString('pane.item.attachments.rename.renameAssociatedFile'),
checkState); checkState);
// If they hit cancel or left it blank
if (!result || !newTitle.value) { if (!result || !newTitle.value) {
return; return;
} }
Zotero.Prefs.set('lastRenameAssociatedFile', checkState.value);
// Rename associated file
if (checkState.value) { if (checkState.value) {
var renamed = item.ref.renameAttachmentFile(newTitle.value); var renamed = item.ref.renameAttachmentFile(newTitle.value);
if (renamed == -1) { if (renamed == -1) {
@ -502,6 +506,8 @@ var ZoteroPane = new function()
item.ref.renameAttachmentFile(newTitle.value, true); item.ref.renameAttachmentFile(newTitle.value, true);
break; break;
} }
// If they said not to overwrite existing file,
// start again
continue; continue;
} }
else if (renamed == -2 || !renamed) { else if (renamed == -2 || !renamed) {
@ -520,12 +526,14 @@ var ZoteroPane = new function()
} }
var isImportedURL = item.ref.getAttachmentLinkMode() == Zotero.Attachments.LINK_MODE_IMPORTED_URL;
// Metadata for URL's // Metadata for URL's
if (item.ref.getAttachmentLinkMode() == Zotero.Attachments.LINK_MODE_LINKED_URL if (item.ref.getAttachmentLinkMode() == Zotero.Attachments.LINK_MODE_LINKED_URL
|| item.ref.getAttachmentLinkMode() == Zotero.Attachments.LINK_MODE_IMPORTED_URL) || isImportedURL)
{ {
// "View Page"/"View Snapshot" label // "View Page"/"View Snapshot" label
if (item.ref.getAttachmentLinkMode() == Zotero.Attachments.LINK_MODE_IMPORTED_URL) if (isImportedURL)
{ {
var str = Zotero.getString('pane.item.attachments.view.snapshot'); var str = Zotero.getString('pane.item.attachments.view.snapshot');
} }
@ -534,7 +542,7 @@ var ZoteroPane = new function()
var str = Zotero.getString('pane.item.attachments.view.link'); var str = Zotero.getString('pane.item.attachments.view.link');
} }
document.getElementById('zotero-attachment-show').setAttribute('hidden', true); document.getElementById('zotero-attachment-show').setAttribute('hidden', !isImportedURL);
// URL // URL
document.getElementById('zotero-attachment-url').setAttribute('value', item.getField('url')); document.getElementById('zotero-attachment-url').setAttribute('value', item.getField('url'));

View File

@ -1426,17 +1426,21 @@ Zotero.Item.prototype.getFile = function(row){
* -2 Error renaming * -2 Error renaming
* false Attachment file not found or other error * false Attachment file not found or other error
*/ */
Zotero.Item.prototype.renameAttachmentFile = function(newName, force) { Zotero.Item.prototype.renameAttachmentFile = function(newName, overwrite) {
var file = this.getFile(); var file = this.getFile();
if (!file) { if (!file) {
return false; return false;
} }
try { try {
if (file.leafName == newName) {
return true;
}
var dest = file.parent; var dest = file.parent;
dest.append(newName); dest.append(newName);
if (force) { if (overwrite) {
dest.remove(null); dest.remove(null);
} }
else if (dest.exists()) { else if (dest.exists()) {

View File

@ -14,7 +14,9 @@ pref("extensions.zotero.automaticSnapshots",true);
pref("extensions.zotero.downloadAssociatedFiles",false); pref("extensions.zotero.downloadAssociatedFiles",false);
pref("extensions.zotero.reportTranslationFailure",true); pref("extensions.zotero.reportTranslationFailure",true);
pref("extensions.zotero.enableMacClipboard",false); pref("extensions.zotero.enableMacClipboard",false);
pref("extensions.zotero.lastCreatorFieldMode",0); pref("extensions.zotero.lastCreatorFieldMode",0);
pref("extensions.zotero.lastRenameAssociatedFile", false);
// Keyboard shortcuts // Keyboard shortcuts
pref("extensions.zotero.keys.overrideGlobal", true); pref("extensions.zotero.keys.overrideGlobal", true);