Code style/consistency updates for relative path changes
This commit is contained in:
parent
27a2a9c1f7
commit
ed94d84a93
2 changed files with 35 additions and 40 deletions
|
@ -165,15 +165,15 @@ function chooseBaseAttachmentPath() {
|
|||
return false;
|
||||
}
|
||||
|
||||
//Find all current attachments with relative attachment paths
|
||||
var sql = "SELECT itemID FROM itemAttachments WHERE linkMode=? AND path LIKE '" +
|
||||
Zotero.Attachments.BASE_PATH_PLACEHOLDER + "%'";
|
||||
var params=[Zotero.Attachments.LINK_MODE_LINKED_FILE];
|
||||
// Find all current attachments with relative attachment paths
|
||||
var sql = "SELECT itemID FROM itemAttachments WHERE linkMode=? AND path LIKE '"
|
||||
+ Zotero.Attachments.BASE_PATH_PLACEHOLDER + "%'";
|
||||
var params = [Zotero.Attachments.LINK_MODE_LINKED_FILE];
|
||||
var oldRelativeAttachmentIDs = Zotero.DB.columnQuery(sql, params) || [];
|
||||
|
||||
//Find all attachments on the new base path
|
||||
var sql = "SELECT itemID FROM itemAttachments WHERE linkMode=?";
|
||||
var params=[Zotero.Attachments.LINK_MODE_LINKED_FILE];
|
||||
var params = [Zotero.Attachments.LINK_MODE_LINKED_FILE];
|
||||
var allAttachments = Zotero.DB.columnQuery(sql,params);
|
||||
var newAttachmentPaths = {};
|
||||
var numNewAttachments = 0;
|
||||
|
@ -188,7 +188,7 @@ function chooseBaseAttachmentPath() {
|
|||
attachmentFile.persistentDescriptor = attachment.attachmentPath;
|
||||
}
|
||||
catch (e) {
|
||||
//Don't deal with bad attachment paths. Just skip them.
|
||||
// Don't deal with bad attachment paths. Just skip them.
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -297,8 +297,8 @@ function getBaseAttachmentPath(asFile) {
|
|||
return asFile ? null : '';
|
||||
}
|
||||
|
||||
var file = Components.classes["@mozilla.org/file/local;1"].
|
||||
createInstance(Components.interfaces.nsILocalFile);
|
||||
var file = Components.classes["@mozilla.org/file/local;1"]
|
||||
.createInstance(Components.interfaces.nsILocalFile);
|
||||
try {
|
||||
file.persistentDescriptor = desc;
|
||||
}
|
||||
|
@ -309,30 +309,29 @@ function getBaseAttachmentPath(asFile) {
|
|||
}
|
||||
|
||||
function clearBaseAttachmentPath() {
|
||||
//Find all current attachments with relative attachment paths
|
||||
var sql = "SELECT itemID FROM itemAttachments WHERE linkMode=? AND path LIKE '" +
|
||||
Zotero.Attachments.BASE_PATH_PLACEHOLDER + "%'";
|
||||
var params=[Zotero.Attachments.LINK_MODE_LINKED_FILE];
|
||||
// Find all current attachments with relative paths
|
||||
var sql = "SELECT itemID FROM itemAttachments WHERE linkMode=? AND path LIKE '"
|
||||
+ Zotero.Attachments.BASE_PATH_PLACEHOLDER + "%'";
|
||||
var params = [Zotero.Attachments.LINK_MODE_LINKED_FILE];
|
||||
var relativeAttachmentIDs = Zotero.DB.columnQuery(sql, params) || [];
|
||||
|
||||
//Confirm the clearing of the base path and restoring of relative paths to absolute
|
||||
//ones with the user.
|
||||
// Prompt for confirmation
|
||||
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
||||
.getService(Components.interfaces.nsIPromptService);
|
||||
|
||||
var strPrefix = 'attachmentBasePath.clearBasePath.';
|
||||
var confirmTitle = Zotero.getString(strPrefix + 'title');
|
||||
var confirmString = Zotero.getString(strPrefix + 'message');
|
||||
var title = Zotero.getString(strPrefix + 'title');
|
||||
var msg = Zotero.getString(strPrefix + 'message');
|
||||
switch (relativeAttachmentIDs.length) {
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 1:
|
||||
confirmString += "\n\n" + Zotero.getString(strPrefix + 'existingAttachments.singular');
|
||||
msg += "\n\n" + Zotero.getString(strPrefix + 'existingAttachments.singular');
|
||||
break;
|
||||
|
||||
default:
|
||||
confirmString += "\n\n" + Zotero.getString(strPrefix + 'existingAttachments.plural',
|
||||
msg += "\n\n" + Zotero.getString(strPrefix + 'existingAttachments.plural',
|
||||
relativeAttachmentIDs.length);
|
||||
}
|
||||
|
||||
|
@ -340,8 +339,8 @@ function clearBaseAttachmentPath() {
|
|||
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL);
|
||||
var index = ps.confirmEx(
|
||||
window,
|
||||
confirmTitle,
|
||||
confirmString,
|
||||
title,
|
||||
msg,
|
||||
buttonFlags,
|
||||
Zotero.getString(strPrefix + 'button'),
|
||||
null,
|
||||
|
@ -354,22 +353,17 @@ function clearBaseAttachmentPath() {
|
|||
return false;
|
||||
}
|
||||
|
||||
//Set saveRelativeAttachmentPath preference to false and then resave all relative
|
||||
//attachments so that their absolute paths are stored.
|
||||
// Disable relative path saving and then resave all relative
|
||||
// attachments so that their absolute paths are stored
|
||||
Zotero.debug('Clearing base directory');
|
||||
Zotero.Prefs.set('saveRelativeAttachmentPath', false);
|
||||
var tempAttachment;
|
||||
for (var index=0; index<relativeAttachmentIDs.length; index++) {
|
||||
tempAttachment=Zotero.Items.get(relativeAttachmentIDs[index]);
|
||||
if (!tempAttachment._changedAttachmentData) {
|
||||
tempAttachment._changedAttachmentData = {};
|
||||
}
|
||||
tempAttachment._changedAttachmentData.path = true;
|
||||
tempAttachment.save();
|
||||
}
|
||||
for (var i=0; i<relativeAttachmentIDs.length; i++) {
|
||||
Zotero.Items.get(relativeAttachmentIDs[i]).updateAttachmentPath();
|
||||
}
|
||||
Zotero.Prefs.set('baseAttachmentPath', '');
|
||||
}
|
||||
|
||||
|
||||
function updateBaseAttachmentPathUI() {
|
||||
var filefield = document.getElementById('baseAttachmentPath');
|
||||
var file = getBaseAttachmentPath(true);
|
||||
|
@ -384,6 +378,7 @@ function updateBaseAttachmentPathUI() {
|
|||
document.getElementById('resetBasePath').disabled = !Zotero.Prefs.get('baseAttachmentPath');
|
||||
}
|
||||
|
||||
|
||||
function onDataDirLoad() {
|
||||
var path = document.getElementById('dataDirPath');
|
||||
var useDataDir = Zotero.Prefs.get('useDataDir');
|
||||
|
|
|
@ -3245,17 +3245,16 @@ Zotero.Item.prototype.__defineGetter__('attachmentPath', function () {
|
|||
var pathIsRelative = false;
|
||||
|
||||
if (this._attachmentPath !== null) {
|
||||
pathIsRelative = (this._attachmentPath.indexOf(Zotero.Attachments.BASE_PATH_PLACEHOLDER)==0);
|
||||
pathIsRelative = (pathIsRelative && this.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE);
|
||||
|
||||
|
||||
pathIsRelative = this._attachmentPath.indexOf(Zotero.Attachments.BASE_PATH_PLACEHOLDER) == 0
|
||||
&& this.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE;
|
||||
if (!pathIsRelative) {
|
||||
return this._attachmentPath;
|
||||
}
|
||||
}
|
||||
else if (!this.id) {
|
||||
return '';
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
var sql = "SELECT path FROM itemAttachments WHERE itemID=?";
|
||||
var path = Zotero.DB.valueQuery(sql, this.id);
|
||||
if (!path) {
|
||||
|
@ -3265,8 +3264,8 @@ Zotero.Item.prototype.__defineGetter__('attachmentPath', function () {
|
|||
|
||||
this._attachmentPath = path;
|
||||
|
||||
pathIsRelative = (path.indexOf(Zotero.Attachments.BASE_PATH_PLACEHOLDER)==0);
|
||||
pathIsRelative = (pathIsRelative && this.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE);
|
||||
pathIsRelative = path.indexOf(Zotero.Attachments.BASE_PATH_PLACEHOLDER) == 0
|
||||
&& this.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE;
|
||||
}
|
||||
|
||||
if (pathIsRelative) {
|
||||
|
@ -3286,8 +3285,9 @@ Zotero.Item.prototype.__defineGetter__('attachmentPath', function () {
|
|||
return '';
|
||||
}
|
||||
|
||||
var relativePath = this._attachmentPath.substr(
|
||||
Zotero.Attachments.BASE_PATH_PLACEHOLDER.length);
|
||||
var relativePath = this._attachmentPath.substr(
|
||||
Zotero.Attachments.BASE_PATH_PLACEHOLDER.length
|
||||
);
|
||||
var attachmentFile = Components.classes["@mozilla.org/file/local;1"]
|
||||
.createInstance(Components.interfaces.nsILocalFile);
|
||||
attachmentFile.setRelativeDescriptor(baseDir,relativePath);
|
||||
|
|
Loading…
Reference in a new issue