Add UI for editing attachment rename format pref (#3228)

This commit is contained in:
Tom Najdek 2023-07-25 18:47:27 +02:00 committed by Dan Stillman
parent af91173734
commit d32b061c95
6 changed files with 291 additions and 119 deletions

View file

@ -0,0 +1,66 @@
/*
***** BEGIN LICENSE BLOCK *****
Copyright © Corporation for Digital Scholarship
Vienna, Virginia, USA
https://www.zotero.org
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** 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.updatePreview();
this.inputRef.addEventListener('keyup', 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 preview = Zotero.Attachments.getFileBaseNameFromItem(item, tpl);
document.getElementById('file-renaming-preview').innerText = `${preview}.pdf`;
},
makeMockItem() {
this.mockItem = new Zotero.Item('journalArticle');
this.mockItem.setField('title', 'Example Article: Zotero Engineering');
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('volume', '9');
this.mockItem.setField('issue', '1');
this.mockItem.setField('pages', '34-55');
this.mockItem.setField('date', '2016');
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('accessDate', '2020-01-01');
this.mockItem.setField('url', 'https://example.com');
this.mockItem.setField('libraryCatalog', 'Example Library Catalog');
return this.mockItem;
},
};

View file

@ -0,0 +1,61 @@
<!--
***** BEGIN LICENSE BLOCK *****
Copyright © Corporation for Digital Scholarship
Vienna, Virginia, USA
https://www.zotero.org
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** 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" />
<separator class="thin" />
<label data-l10n-id="preferences-file-renaming-instructions-example" data-l10n-args='{"example": "{{ title truncate=\"50\" }}"}' />
<separator class="thin" />
<label data-l10n-id="preferences-file-renaming-instructions-more">
<label
is="zotero-text-link"
href="https://www.zotero.org/support/preferences/general#file_renaming"
data-l10n-name="file-renaming-help-link"
/>
</label>
<groupbox>
<html:label
for="file-renaming-template"
id="file-renaming-template-label"
>
<html:h2 data-l10n-id="preferences-file-renaming-template" />
</html:label>
<html:textarea
aria-labelledby="file-renaming-template-label"
id="file-renaming-template"
preference="extensions.zotero.attachmentRenameTemplate"
rows="3"
/>
<html:label id="file-renaming-preview-label">
<html:h2
data-l10n-id="preferences-file-renaming-preview"
/>
</html:label>
<html:span
aria-labelledby="file-renaming-preview-label"
id="file-renaming-preview"
/>
</groupbox>
</vbox>

View file

@ -23,6 +23,7 @@
***** END LICENSE BLOCK ***** ***** END LICENSE BLOCK *****
--> -->
<vbox id="zotero-prefpane-general" onload="Zotero_Preferences.General.init()"> <vbox id="zotero-prefpane-general" onload="Zotero_Preferences.General.init()">
<vbox class="main-section">
<groupbox> <groupbox>
<label><html:h2>&zotero.preferences.interface;</html:h2></label> <label><html:h2>&zotero.preferences.interface;</html:h2></label>
@ -151,4 +152,10 @@
<checkbox label="&zotero.preferences.groups.tags;" preference="extensions.zotero.groups.copyTags" native="true"/> <checkbox label="&zotero.preferences.groups.tags;" preference="extensions.zotero.groups.copyTags" native="true"/>
</vbox> </vbox>
</groupbox> </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> </vbox>

View file

@ -81,6 +81,15 @@ Zotero.PreferencePanes = {
scripts: ['chrome://zotero/content/preferences/preferences_sync.js'], scripts: ['chrome://zotero/content/preferences/preferences_sync.js'],
defaultXUL: true, defaultXUL: true,
helpURL: 'https://www.zotero.org/support/preferences/sync#reset', helpURL: 'https://www.zotero.org/support/preferences/sync#reset',
},
{
id: 'zotero-subpane-file-renaming',
parent: 'zotero-prefpane-general',
label: '',
src: 'chrome://zotero/content/preferences/preferences_file_renaming.xhtml',
scripts: ['chrome://zotero/content/preferences/preferences_file_renaming.js'],
defaultXUL: true,
helpURL: null,
} }
]), ]),

View file

@ -1,2 +1,10 @@
preferences-window = preferences-window =
.title = { -app-name } Settings .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.

View file

@ -568,6 +568,27 @@ button {
margin-bottom: .5em; 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 */ /* BEGIN 2X BLOCK -- DO NOT EDIT MANUALLY -- USE 2XIZE */
@media (min-resolution: 1.25dppx) { @media (min-resolution: 1.25dppx) {