Relative path support changes
- Changed placeholder to just "attachments:" for consistency with "storage:" - Reworked dialog text - Use a fancier (and undocumented) filefield XUL element for path - A few small code tweaks
This commit is contained in:
parent
69cb928d6c
commit
f1eb356c19
5 changed files with 103 additions and 51 deletions
|
@ -129,16 +129,13 @@ function init()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function chooseBaseAttachmentPath() {
|
||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||
.getService(Components.interfaces.nsIWindowMediator);
|
||||
var win = wm.getMostRecentWindow('navigator:browser');
|
||||
|
||||
//Prompt user to choose new base path
|
||||
var nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
||||
.createInstance(nsIFilePicker);
|
||||
fp.init(win, Zotero.getString('attachmentBasePath.selectDir'), nsIFilePicker.modeGetFolder);
|
||||
fp.init(window, Zotero.getString('attachmentBasePath.selectDir'), nsIFilePicker.modeGetFolder);
|
||||
fp.appendFilters(nsIFilePicker.filterAll);
|
||||
if (fp.show() != nsIFilePicker.returnOK) {
|
||||
return false;
|
||||
|
@ -149,10 +146,7 @@ function chooseBaseAttachmentPath() {
|
|||
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);
|
||||
if (!oldRelativeAttachmentIDs) {
|
||||
oldRelativeAttachmentIDs=[];
|
||||
}
|
||||
var oldRelativeAttachmentIDs = Zotero.DB.columnQuery(sql, params) || [];
|
||||
|
||||
//Find all attachments on the new base path
|
||||
var sql = "SELECT itemID FROM itemAttachments WHERE linkMode=?";
|
||||
|
@ -187,26 +181,43 @@ function chooseBaseAttachmentPath() {
|
|||
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
||||
.getService(Components.interfaces.nsIPromptService);
|
||||
|
||||
var confirmTitle=Zotero.getString('attachmentBasePath.confirmNewPath.title');
|
||||
var confirmString;
|
||||
var strPrefix = 'attachmentBasePath.confirmNewPath.';
|
||||
var confirmTitle = Zotero.getString(strPrefix + 'title');
|
||||
var confirmString = Zotero.getString(strPrefix + 'message');
|
||||
switch (newRelativeAttachmentIDs.length) {
|
||||
case 0:
|
||||
confirmString=Zotero.getString('attachmentBasePath.confirmNewPath.none');
|
||||
break;
|
||||
|
||||
case 1:
|
||||
confirmString=Zotero.getString('attachmentBasePath.confirmNewPath.singular');
|
||||
confirmString += "\n\n" + Zotero.getString(strPrefix + 'existingAttachments.singular');
|
||||
break;
|
||||
|
||||
default:
|
||||
confirmString=Zotero.getString('attachmentBasePath.confirmNewPath.plural',
|
||||
confirmString += "\n\n" + Zotero.getString(strPrefix + 'existingAttachments.plural',
|
||||
newRelativeAttachmentIDs.length);
|
||||
}
|
||||
if (!ps.confirm(null,confirmTitle,confirmString)) {
|
||||
|
||||
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
|
||||
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL);
|
||||
var index = ps.confirmEx(
|
||||
null,
|
||||
confirmTitle,
|
||||
confirmString,
|
||||
buttonFlags,
|
||||
Zotero.getString(strPrefix + 'button'),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
{}
|
||||
);
|
||||
|
||||
if (index == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set new data directory
|
||||
Zotero.debug("Setting new base directory");
|
||||
Zotero.Prefs.set('baseAttachmentPath', basePathFile.persistentDescriptor);
|
||||
Zotero.Prefs.set('lastDataDir', basePathFile.path);
|
||||
Zotero.Prefs.set('saveRelativeAttachmentPath', true);
|
||||
//Save all attachments on base path so that their paths become relative
|
||||
var tempAttachment;
|
||||
|
@ -218,14 +229,13 @@ function chooseBaseAttachmentPath() {
|
|||
tempAttachment._changedAttachmentData.path = true;
|
||||
tempAttachment.save();
|
||||
}
|
||||
|
||||
return basePathFile.path;
|
||||
}
|
||||
|
||||
function getBaseAttachmentPath() {
|
||||
function getBaseAttachmentPath(asFile) {
|
||||
var desc = Zotero.Prefs.get('baseAttachmentPath');
|
||||
if (desc == '') {
|
||||
return '';
|
||||
return asFile ? null : '';
|
||||
}
|
||||
|
||||
var file = Components.classes["@mozilla.org/file/local;1"].
|
||||
|
@ -234,9 +244,9 @@ function getBaseAttachmentPath() {
|
|||
file.persistentDescriptor = desc;
|
||||
}
|
||||
catch (e) {
|
||||
return '';
|
||||
return asFile ? null : '';
|
||||
}
|
||||
return file.path;
|
||||
return asFile ? file : file.path;
|
||||
}
|
||||
|
||||
function clearBaseAttachmentPath() {
|
||||
|
@ -244,32 +254,50 @@ function clearBaseAttachmentPath() {
|
|||
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);
|
||||
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.
|
||||
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
||||
.getService(Components.interfaces.nsIPromptService);
|
||||
|
||||
var confirmTitle=Zotero.getString('attachmentBasePath.clearBasePath.title');
|
||||
var confirmString;
|
||||
var strPrefix = 'attachmentBasePath.clearBasePath.';
|
||||
var confirmTitle = Zotero.getString(strPrefix + 'title');
|
||||
var confirmString = Zotero.getString(strPrefix + 'message');
|
||||
switch (relativeAttachmentIDs.length) {
|
||||
case 0:
|
||||
confirmString=Zotero.getString('attachmentBasePath.clearBasePath.none');
|
||||
break;
|
||||
|
||||
case 1:
|
||||
confirmString=Zotero.getString('attachmentBasePath.clearBasePath.singular');
|
||||
confirmString += "\n\n" + Zotero.getString(strPrefix + 'existingAttachments.singular');
|
||||
break;
|
||||
|
||||
default:
|
||||
confirmString=Zotero.getString('attachmentBasePath.clearBasePath.plural',
|
||||
confirmString += "\n\n" + Zotero.getString(strPrefix + 'existingAttachments.plural',
|
||||
relativeAttachmentIDs.length);
|
||||
}
|
||||
if (!ps.confirm(null,confirmTitle,confirmString)) {
|
||||
|
||||
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
|
||||
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL);
|
||||
var index = ps.confirmEx(
|
||||
window,
|
||||
confirmTitle,
|
||||
confirmString,
|
||||
buttonFlags,
|
||||
Zotero.getString(strPrefix + 'button'),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
{}
|
||||
);
|
||||
|
||||
if (index == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Set saveRelativeAttachmentPath preference to false 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++) {
|
||||
|
@ -280,10 +308,23 @@ function clearBaseAttachmentPath() {
|
|||
tempAttachment._changedAttachmentData.path = true;
|
||||
tempAttachment.save();
|
||||
}
|
||||
|
||||
Zotero.Prefs.set('baseAttachmentPath', '');
|
||||
}
|
||||
|
||||
function updateBaseAttachmentPathUI() {
|
||||
var filefield = document.getElementById('baseAttachmentPath');
|
||||
var file = getBaseAttachmentPath(true);
|
||||
filefield.file = file;
|
||||
if (file) {
|
||||
filefield.label = file.path;
|
||||
}
|
||||
else {
|
||||
filefield.label = '';
|
||||
}
|
||||
|
||||
document.getElementById('resetBasePath').disabled = !Zotero.Prefs.get('baseAttachmentPath');
|
||||
}
|
||||
|
||||
function onDataDirLoad() {
|
||||
var path = document.getElementById('dataDirPath');
|
||||
var useDataDir = Zotero.Prefs.get('useDataDir');
|
||||
|
|
|
@ -802,21 +802,30 @@ To add a new preference:
|
|||
|
||||
<tabpanel orient="vertical">
|
||||
<groupbox>
|
||||
<caption label="&zotero.preferences.attachments;"/>
|
||||
<caption label="&zotero.preferences.attachmentBaseDir.caption;"/>
|
||||
|
||||
<!-- This doesn't wrap without an explicit width -->
|
||||
<vbox>
|
||||
<description width="45em">&zotero.preferences.attachments.message;</description>
|
||||
<description width="45em">&zotero.preferences.attachmentBaseDir.message;</description>
|
||||
</vbox>
|
||||
|
||||
<hbox>
|
||||
<label value="&zotero.preferences.attachments.basePath;"/>
|
||||
<textbox id="baseAttachmentPath" preference="pref-baseAttachmentPath" onsyncfrompreference="return getBaseAttachmentPath();" readonly="true" flex="1"/>
|
||||
<button label="&zotero.preferences.attachments.selectBasePath;" oncommand="var file = chooseBaseAttachmentPath(); if (!file) { event.stopPropagation(); }"/>
|
||||
<hbox align="center">
|
||||
<label value="&zotero.preferences.attachmentBaseDir.basePath;"/>
|
||||
<filefield id="baseAttachmentPath"
|
||||
preference="pref-baseAttachmentPath"
|
||||
onsyncfrompreference="updateBaseAttachmentPathUI()"
|
||||
preference-editable="true"
|
||||
readonly="true"
|
||||
flex="1"
|
||||
tabindex="-1"/>
|
||||
<button label="&zotero.preferences.attachmentBaseDir.selectBasePath;"
|
||||
oncommand="chooseBaseAttachmentPath()"/>
|
||||
</hbox>
|
||||
|
||||
<hbox>
|
||||
<button label="&zotero.preferences.attachments.resetBasePath;" oncommand="clearBaseAttachmentPath();"/>
|
||||
<button id="resetBasePath"
|
||||
label="&zotero.preferences.attachmentBaseDir.resetBasePath;"
|
||||
oncommand="clearBaseAttachmentPath()"/>
|
||||
</hbox>
|
||||
|
||||
</groupbox>
|
||||
|
|
|
@ -28,7 +28,7 @@ Zotero.Attachments = new function(){
|
|||
this.LINK_MODE_IMPORTED_URL = 1;
|
||||
this.LINK_MODE_LINKED_FILE = 2;
|
||||
this.LINK_MODE_LINKED_URL = 3;
|
||||
this.BASE_PATH_PLACEHOLDER = '<BASE_ATTACHMENT_PATH>';
|
||||
this.BASE_PATH_PLACEHOLDER = 'attachments:';
|
||||
|
||||
this.importFromFile = importFromFile;
|
||||
this.linkFromFile = linkFromFile;
|
||||
|
|
|
@ -177,11 +177,11 @@
|
|||
<!ENTITY zotero.preferences.dataDir.choose "Choose...">
|
||||
<!ENTITY zotero.preferences.dataDir.reveal "Show Data Directory">
|
||||
|
||||
<!ENTITY zotero.preferences.attachments "Attachments">
|
||||
<!ENTITY zotero.preferences.attachments.message "Attached links to files below the base directory will be stored relative to the base directory. This will allow links to remain functional on computers with different locations for the base directory.">
|
||||
<!ENTITY zotero.preferences.attachments.basePath "Base directory:">
|
||||
<!ENTITY zotero.preferences.attachments.selectBasePath "Choose...">
|
||||
<!ENTITY zotero.preferences.attachments.resetBasePath "Revert to absolute paths">
|
||||
<!ENTITY zotero.preferences.attachmentBaseDir.caption "Linked Attachment Base Directory">
|
||||
<!ENTITY zotero.preferences.attachmentBaseDir.message "Zotero will use relative paths for linked file attachments within the base directory, allowing you to access files on different computers as long as the file structure within the base directory remains the same.">
|
||||
<!ENTITY zotero.preferences.attachmentBaseDir.basePath "Base directory:">
|
||||
<!ENTITY zotero.preferences.attachmentBaseDir.selectBasePath "Choose…">
|
||||
<!ENTITY zotero.preferences.attachmentBaseDir.resetBasePath "Revert to absolute paths">
|
||||
|
||||
<!ENTITY zotero.preferences.dbMaintenance "Database Maintenance">
|
||||
<!ENTITY zotero.preferences.dbMaintenance.integrityCheck "Check Database Integrity">
|
||||
|
|
|
@ -69,15 +69,17 @@ errorReport.stepsToReproduce = Steps to Reproduce:
|
|||
errorReport.expectedResult = Expected result:
|
||||
errorReport.actualResult = Actual result:
|
||||
|
||||
attachmentBasePath.selectDir = Choose base directory for attachments
|
||||
attachmentBasePath.confirmNewPath.title = Confirm new base directory
|
||||
attachmentBasePath.confirmNewPath.none = No attachments were found with an absolute path containing the new base directory. New attachment links below this directory will be saved relative to it.\n\nPress OK to continue or Cancel to keep the current base directory setting.
|
||||
attachmentBasePath.confirmNewPath.singular = Zotero found one attachment with an absolute path containing the new base directory. This attachment will be converted to a relative path. New attachment links below this directory will be saved relative to it.\n\nPress OK to continue or Cancel to keep the current base directory setting.
|
||||
attachmentBasePath.confirmNewPath.plural = Zotero found %S attachments with absolute paths containing the new base directory. These attachments will be converted to relative paths. New attachment links below this directory will be saved relative to it.\n\nPress OK to continue or Cancel to keep the current base directory setting.
|
||||
attachmentBasePath.clearBasePath.title = Revert to absolute paths
|
||||
attachmentBasePath.clearBasePath.none = No existing attachments were found beneath the current base directory. The base directory setting will be cleared and new attachments will be stored using absolute paths.
|
||||
attachmentBasePath.clearBasePath.singular = One relative attachment link will be converted to absolute using the last base directory setting. The base directory setting will be cleared and new attachments will be stored using absolute paths.
|
||||
attachmentBasePath.clearBasePath.plural = %S relative attachment links will be converted to absolute using the last base directory setting. The base directory setting will be cleared and new attachments will be stored using absolute paths.
|
||||
attachmentBasePath.selectDir = Choose Base Directory
|
||||
attachmentBasePath.confirmNewPath.title = Confirm new base directory
|
||||
attachmentBasePath.confirmNewPath.message = New linked file attachments below this directory will be saved using relative paths.
|
||||
attachmentBasePath.confirmNewPath.existingAttachments.singular = One existing attachment within the new base directory will be converted to use a relative path.
|
||||
attachmentBasePath.confirmNewPath.existingAttachments.plural = %S existing attachments within the new base directory will be converted to use relative paths.
|
||||
attachmentBasePath.confirmNewPath.button = Change Base Directory Setting
|
||||
attachmentBasePath.clearBasePath.title = Revert to absolute paths
|
||||
attachmentBasePath.clearBasePath.message = New linked file attachments will be saved using absolute paths.
|
||||
attachmentBasePath.clearBasePath.existingAttachments.singular = One existing attachment within the old base directory will be converted to use an absolute path.
|
||||
attachmentBasePath.clearBasePath.existingAttachments.plural = %S existing attachments within the old base directory will be converted to use absolute paths.
|
||||
attachmentBasePath.clearBasePath.button = Clear Base Directory Setting
|
||||
|
||||
dataDir.notFound = The Zotero data directory could not be found.
|
||||
dataDir.previousDir = Previous directory:
|
||||
|
|
Loading…
Reference in a new issue