Update file-renaming prefs (#3228)

- Move file-renaming prefs to separate prefs section
- Fix template preview not updating on paste
- Update documentation URL
- Tweak text, styling, and ids
- Change "Automatically rename attachment files using parent metadata"
  to "Automatically rename locally added files" to reflect that
  downloaded files are always renamed, and add an intro saying so
This commit is contained in:
Dan Stillman 2023-08-06 17:46:23 -04:00
parent d32b061c95
commit 4e3977e9ce
7 changed files with 102 additions and 69 deletions

View file

@ -22,42 +22,41 @@
***** END LICENSE BLOCK *****
*/
/* eslint-disable camelcase */
/* global Zotero_Preferences: false */
Zotero_Preferences.FileRenaming = {
mockItem: null,
init: function () {
this.inputRef = document.getElementById('file-renaming-template');
this.inputRef = document.getElementById('file-renaming-format-template');
this.updatePreview();
this.inputRef.addEventListener('keyup', this.updatePreview.bind(this));
this.inputRef.addEventListener('input', this.updatePreview.bind(this));
Zotero.getActiveZoteroPane()?.itemsView.onSelect.addListener(this.updatePreview.bind(this));
},
updatePreview() {
const item = Zotero.getActiveZoteroPane()?.getSelectedItems()?.[0] ?? this.mockItem ?? this.makeMockItem();
const tpl = document.getElementById('file-renaming-template').value;
const tpl = document.getElementById('file-renaming-format-template').value;
const preview = Zotero.Attachments.getFileBaseNameFromItem(item, tpl);
document.getElementById('file-renaming-preview').innerText = `${preview}.pdf`;
document.getElementById('file-renaming-format-preview').innerText = `${preview}.pdf`;
},
makeMockItem() {
this.mockItem = new Zotero.Item('journalArticle');
this.mockItem.setField('title', 'Example Article: Zotero Engineering');
this.mockItem.setField('title', 'Example Title: Example Subtitle');
this.mockItem.setCreators([
{ firstName: 'Jane', lastName: 'Doe', creatorType: 'author' },
{ firstName: 'John', lastName: 'Smith', creatorType: 'author' }
]);
this.mockItem.setField('shortTitle', 'Example Article');
this.mockItem.setField('publicationTitle', 'Advances in Zotero Engineering');
this.mockItem.setField('shortTitle', 'Example Title');
this.mockItem.setField('publicationTitle', 'Advances in Example Engineering');
this.mockItem.setField('volume', '9');
this.mockItem.setField('issue', '1');
this.mockItem.setField('pages', '34-55');
this.mockItem.setField('date', '2016');
this.mockItem.setField('date', '2018');
this.mockItem.setField('DOI', '10.1016/1234-example');
this.mockItem.setField('ISSN', '1234-5678');
this.mockItem.setField('abstractNote', 'This is an example abstract.');
this.mockItem.setField('extra', 'This is an example extra field.');
this.mockItem.setField('extra', 'This is an example Extra field.');
this.mockItem.setField('accessDate', '2020-01-01');
this.mockItem.setField('url', 'https://example.com');
this.mockItem.setField('libraryCatalog', 'Example Library Catalog');

View file

@ -22,40 +22,47 @@
***** END LICENSE BLOCK *****
-->
<vbox class="main-section" id="zotero-prefpane-file-renaming" onload="Zotero_Preferences.FileRenaming.init()">
<html:h1 data-l10n-id="preferences-file-renaming-title" />
<label data-l10n-id="preferences-file-renaming-instructions" />
<vbox class="main-section" id="zotero-prefpane-file-renaming-format" onload="Zotero_Preferences.FileRenaming.init()">
<hbox class="header">
<html:h1 data-l10n-id="preferences-file-renaming-format-title" />
</hbox>
<label data-l10n-id="preferences-file-renaming-format-instructions" />
<separator class="thin" />
<label data-l10n-id="preferences-file-renaming-instructions-example" data-l10n-args='{"example": "{{ title truncate=\"50\" }}"}' />
<label data-l10n-id="preferences-file-renaming-format-instructions-example"
data-l10n-args='{"example": "{{ title truncate=\"50\" }}"}' />
<separator class="thin" />
<label data-l10n-id="preferences-file-renaming-instructions-more">
<label data-l10n-id="preferences-file-renaming-format-instructions-more">
<label
is="zotero-text-link"
href="https://www.zotero.org/support/preferences/general#file_renaming"
data-l10n-name="file-renaming-help-link"
href="https://www.zotero.org/support/file_renaming"
data-l10n-name="file-renaming-format-help-link"
/>
</label>
<separator class="thin" />
<groupbox>
<html:label
for="file-renaming-template"
id="file-renaming-template-label"
for="file-renaming-format-template"
id="file-renaming-format-template-label"
>
<html:h2 data-l10n-id="preferences-file-renaming-template" />
<html:h2 data-l10n-id="preferences-file-renaming-format-template" />
</html:label>
<html:textarea
aria-labelledby="file-renaming-template-label"
id="file-renaming-template"
aria-labelledby="file-renaming-format-template-label"
id="file-renaming-format-template"
preference="extensions.zotero.attachmentRenameTemplate"
rows="3"
/>
<html:label id="file-renaming-preview-label">
<html:label id="file-renaming-format-preview-label">
<html:h2
data-l10n-id="preferences-file-renaming-preview"
data-l10n-id="preferences-file-renaming-format-preview"
/>
</html:label>
<html:span
aria-labelledby="file-renaming-preview-label"
id="file-renaming-preview"
<html:label
aria-labelledby="file-renaming-format-preview-label"
id="file-renaming-format-preview"
/>
</groupbox>
</vbox>

View file

@ -47,13 +47,6 @@
native="true"/>
<checkbox label="&zotero.preferences.downloadAssociatedFiles;" preference="extensions.zotero.downloadAssociatedFiles" native="true"/>
<checkbox label="&zotero.preferences.autoRecognizeFiles;" preference="extensions.zotero.autoRecognizeFiles" native="true"/>
<checkbox label="&zotero.preferences.autoRenameFiles;"
preference="extensions.zotero.autoRenameFiles"
oncommand="Zotero_Preferences.General.updateAutoRenameFilesUI()" native="true"/>
<checkbox id="rename-linked-files" class="indented-pref"
label="&zotero.preferences.autoRenameFiles.renameLinked;"
preference="extensions.zotero.autoRenameFiles.linked"
oncommand="Zotero_Preferences.General.updateAutoRenameFilesUI()" native="true"/>
</vbox>
<vbox>
@ -78,6 +71,28 @@
</vbox>
</groupbox>
<groupbox id="zotero-prefpane-file-renaming-groupbox">
<label><html:h2 data-l10n-id="preferences-file-renaming-title"/></label>
<vbox align="start">
<label data-l10n-id="preferences-file-renaming-intro"/>
<separator class="thin"/>
<checkbox data-l10n-id="preferences-file-renaming-auto-rename-files"
preference="extensions.zotero.autoRenameFiles"
oncommand="Zotero_Preferences.General.updateAutoRenameFilesUI()" native="true"/>
<checkbox id="rename-linked-files" class="indented-pref"
label="&zotero.preferences.autoRenameFiles.renameLinked;"
preference="extensions.zotero.autoRenameFiles.linked"
oncommand="Zotero_Preferences.General.updateAutoRenameFilesUI()" native="true"/>
<button id="file-renaming-button"
data-l10n-id="preferences-file-renaming-customize-button"
oncommand="Zotero_Preferences.navigateToPane('zotero-subpane-file-renaming')"/>
<!-- data-search-strings="
preferences-file-renaming-format-title,
preferences-file-renaming-format-template" -->
</vbox>
</groupbox>
<groupbox>
<label><html:h2>&zotero.preferences.prefpane.locate;</html:h2></label>
@ -153,9 +168,4 @@
</vbox>
</groupbox>
</vbox>
<vbox class="main-section" id="file-renaming" align="start">
<html:h1 data-l10n-id="preferences-file-renaming-title" />
<button data-l10n-id="preferences-show-file-renaming-button"
oncommand="Zotero_Preferences.navigateToPane('zotero-subpane-file-renaming')" />
</vbox>
</vbox>

View file

@ -1,4 +1,4 @@
<vbox class="main-section" id="sync-reset" onload="Zotero_Preferences.Sync.initResetPane()">
<vbox class="main-section subpane" id="sync-reset" onload="Zotero_Preferences.Sync.initResetPane()">
<html:h1>&zotero.preferences.sync.reset;</html:h1>
<!-- This doesn't wrap without an explicit width, for some reason -->

View file

@ -15,7 +15,6 @@
<!ENTITY zotero.preferences.automaticSnapshots "Automatically take snapshots when creating items from web pages">
<!ENTITY zotero.preferences.downloadAssociatedFiles "Automatically attach associated PDFs and other files when saving items">
<!ENTITY zotero.preferences.autoRecognizeFiles "Automatically retrieve metadata for PDFs">
<!ENTITY zotero.preferences.autoRenameFiles "Automatically rename attachment files using parent metadata">
<!ENTITY zotero.preferences.autoRenameFiles.renameLinked "Rename linked files">
<!ENTITY zotero.preferences.fileHandler.openPDFsUsing "Open PDFs using">
<!ENTITY zotero.preferences.fileHandler.systemDefault "System Default">

View file

@ -1,10 +1,17 @@
preferences-window =
.title = { -app-name } Settings
preferences-show-file-renaming-button = Show File Renaming Options
preferences-file-renaming-title = File Renaming
preferences-file-renaming-template = Rename Template:
preferences-file-renaming-preview = Preview:
preferences-file-renaming-instructions = Zotero automatically renames attached files saved from translators. This setting controls how those names are formatted.
preferences-file-renaming-instructions-example = For example “{ $example }” in this template will be replaced with the title of an item, truncated at 50 characters.
preferences-file-renaming-instructions-more = See the <label data-l10n-name="file-renaming-help-link">documentation</label> for more information.
preferences-file-renaming-intro = { -app-name } automatically renames downloaded files based on the details of the parent item (title, author, etc.). You can choose to rename files added from your computer as well.
preferences-file-renaming-auto-rename-files =
.label = Automatically rename locally added files
preferences-file-renaming-customize-button =
.label = Customize Filename Format…
preferences-file-renaming-format-title = Filename Format
preferences-file-renaming-format-instructions = You can customize the filename pattern { -app-name } uses to rename attachment files from parent metadata.
preferences-file-renaming-format-instructions-example = For example, “{ $example }” in this template will be replaced with the title of the parent item, truncated at 50 characters.
preferences-file-renaming-format-instructions-more = See the <label data-l10n-name="file-renaming-format-help-link">documentation</label> for more information.
preferences-file-renaming-format-template = Filename Template:
preferences-file-renaming-format-preview = Preview:

View file

@ -115,11 +115,16 @@
}
h1 {
margin: 0 0 4px 0;
margin: 0 0 12px 0;
font-size: 1.3em;
font-weight: normal;
}
.header {
margin-bottom: 8px;
}
/* Headers in subsections */
.main-section {
margin-bottom: 16px;
}
@ -135,6 +140,10 @@ groupbox > label > h2, groupbox > * > label > h2 {
font-weight: bold;
}
groupbox:first-of-type label > h2 {
margin-top: .5em !important;
}
/* Space out sections */
groupbox:not(:first-of-type) label > h2 {
margin-top: 2em !important;
@ -273,6 +282,29 @@ button {
height: 16px;
}
/* File Renaming tab */
#file-renaming-customize-button {
margin-top: .6em;
}
#zotero-prefpane-file-renaming-format label:not([is=zotero-text-link]) {
display: block;
}
#file-renaming-format-template {
width: 100%;
min-height: 1.25em;
padding: 0.4em;
/* Match label margins */
margin-block: 1px 2px;
margin-inline: 6px 5px;
}
#file-renaming-format-preview {
width: 100%;
padding: 0.4em;
}
/*
* Sync pane
*/
@ -568,27 +600,6 @@ button {
margin-bottom: .5em;
}
#zotero-prefpane-file-renaming label:not([is=zotero-text-link]),
#zotero-prefpane-file-renaming div {
display: block;
}
#file-renaming-template {
width: 100%;
min-height: 1.25em;
padding: 0.25em;
}
#file-renaming-preview {
width: 100%;
padding: 0.25em;
font-family: monospace;
}
#file-renaming button {
font-size: 14px;
}
/* BEGIN 2X BLOCK -- DO NOT EDIT MANUALLY -- USE 2XIZE */
@media (min-resolution: 1.25dppx) {