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,132 +23,139 @@
***** END LICENSE BLOCK *****
-->
<vbox id="zotero-prefpane-general" onload="Zotero_Preferences.General.init()">
<groupbox>
<label><html:h2>&zotero.preferences.interface;</html:h2></label>
<vbox class="main-section">
<groupbox>
<label><html:h2>&zotero.preferences.interface;</html:h2></label>
<hbox align="center">
<label value="&zotero.bibliography.locale.label;"/>
<menulist id="locale-menu"
onblur="if (!Zotero.isMac) Zotero_Preferences.General.onLocaleChange()"
native="true">
<menupopup onpopuphidden="Zotero_Preferences.General.onLocaleChange()"/>
</menulist>
</hbox>
</groupbox>
<groupbox id="zotero-prefpane-file-handling-groupbox">
<label><html:h2>&zotero.preferences.fileHandling;</html:h2></label>
<vbox>
<checkbox id="automaticSnapshots-checkbox"
label="&zotero.preferences.automaticSnapshots;"
preference="extensions.zotero.automaticSnapshots"
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>
<hbox align="center">
<label value="&zotero.preferences.fileHandler.openPDFsUsing;" control="file-handler-pdf"/>
<menulist id="fileHandler-pdf" class="fileHandler-menu" native="true">
<menupopup>
<menuitem id="fileHandler-internal"
oncommand="Zotero_Preferences.General.setFileHandler('pdf', '')"/>
<menuitem label="&zotero.preferences.fileHandler.systemDefault;"
oncommand="Zotero_Preferences.General.setFileHandler('pdf', 'system')"/>
<menuitem id="fileHandler-custom"/>
<menuitem label="&zotero.preferences.custom;"
oncommand="Zotero_Preferences.General.chooseFileHandler('pdf')"/>
<label value="&zotero.bibliography.locale.label;"/>
<menulist id="locale-menu"
onblur="if (!Zotero.isMac) Zotero_Preferences.General.onLocaleChange()"
native="true">
<menupopup onpopuphidden="Zotero_Preferences.General.onLocaleChange()"/>
</menulist>
</hbox>
</groupbox>
<groupbox id="zotero-prefpane-file-handling-groupbox">
<label><html:h2>&zotero.preferences.fileHandling;</html:h2></label>
<vbox>
<checkbox id="automaticSnapshots-checkbox"
label="&zotero.preferences.automaticSnapshots;"
preference="extensions.zotero.automaticSnapshots"
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>
<hbox align="center">
<label value="&zotero.preferences.fileHandler.openPDFsUsing;" control="file-handler-pdf"/>
<menulist id="fileHandler-pdf" class="fileHandler-menu" native="true">
<menupopup>
<menuitem id="fileHandler-internal"
oncommand="Zotero_Preferences.General.setFileHandler('pdf', '')"/>
<menuitem label="&zotero.preferences.fileHandler.systemDefault;"
oncommand="Zotero_Preferences.General.setFileHandler('pdf', 'system')"/>
<menuitem id="fileHandler-custom"/>
<menuitem label="&zotero.preferences.custom;"
oncommand="Zotero_Preferences.General.chooseFileHandler('pdf')"/>
</menupopup>
</menulist>
</hbox>
<checkbox id="open-reader-in-new-window" class="indented-pref"
label="&zotero.preferences.fileHandler.openReaderInNewWindow;"
preference="extensions.zotero.openReaderInNewWindow"
native="true"/>
</vbox>
</groupbox>
<groupbox>
<label><html:h2>&zotero.preferences.prefpane.locate;</html:h2></label>
<hbox>
<menulist id="openurl-menu" native="true">
<menupopup
id="openurl-primary-popup"
onpopupshowing="Zotero_Preferences.General.handleOpenURLPopupShowing(event)"
oncommand="Zotero_Preferences.General.handleOpenURLSelected(event)">
<menuitem label="&zotero.preferences.openurl.choose;"/>
</menupopup>
</menulist>
</hbox>
<checkbox id="open-reader-in-new-window" class="indented-pref"
label="&zotero.preferences.fileHandler.openReaderInNewWindow;"
preference="extensions.zotero.openReaderInNewWindow"
native="true"/>
</vbox>
</groupbox>
<groupbox>
<label><html:h2>&zotero.preferences.prefpane.locate;</html:h2></label>
<hbox style="display: flex; align-items: center;">
<label value="&zotero.preferences.openurl.server;"/>
<html:input type="text" id="openURLServerField" style="flex: 1;"
oninput="Zotero_Preferences.General.onOpenURLCustomized();"
preference="extensions.zotero.openURL.resolver"
/>
</hbox>
<hbox>
<menulist id="openurl-menu" native="true">
<menupopup
id="openurl-primary-popup"
onpopupshowing="Zotero_Preferences.General.handleOpenURLPopupShowing(event)"
oncommand="Zotero_Preferences.General.handleOpenURLSelected(event)">
<menuitem label="&zotero.preferences.openurl.choose;"/>
</menupopup>
</menulist>
</hbox>
<hbox align="center">
<label value="&zotero.preferences.openurl.version;" control="openURLVersionMenu"/>
<menulist id="openURLVersionMenu"
oncommand="Zotero_Preferences.General.onOpenURLCustomized();"
preference="extensions.zotero.openURL.version"
native="true">
<menupopup>
<menuitem label="0.1" value="0.1"/>
<menuitem label="1.0" value="1.0"/>
</menupopup>
</menulist>
</hbox>
</groupbox>
<hbox style="display: flex; align-items: center;">
<label value="&zotero.preferences.openurl.server;"/>
<html:input type="text" id="openURLServerField" style="flex: 1;"
oninput="Zotero_Preferences.General.onOpenURLCustomized();"
preference="extensions.zotero.openURL.resolver"
/>
</hbox>
<hbox align="center">
<label value="&zotero.preferences.openurl.version;" control="openURLVersionMenu"/>
<menulist id="openURLVersionMenu"
oncommand="Zotero_Preferences.General.onOpenURLCustomized();"
preference="extensions.zotero.openURL.version"
native="true">
<menupopup>
<menuitem label="0.1" value="0.1"/>
<menuitem label="1.0" value="1.0"/>
</menupopup>
</menulist>
</hbox>
</groupbox>
<groupbox id="zotero-prefpane-miscellaneous-groupbox">
<label><html:h2>&zotero.preferences.miscellaneous;</html:h2></label>
<groupbox id="zotero-prefpane-miscellaneous-groupbox">
<label><html:h2>&zotero.preferences.miscellaneous;</html:h2></label>
<checkbox label="&zotero.preferences.automaticTags;" preference="extensions.zotero.automaticTags" native="true"/>
<hbox align="center">
<label value="&zotero.preferences.trashAutoEmptyDaysPre;"/>
<html:input type="text" size="2" preference="extensions.zotero.trashAutoEmptyDays"/>
<label value="&zotero.preferences.trashAutoEmptyDaysPost;"/>
</hbox>
</groupbox>
<checkbox label="&zotero.preferences.automaticTags;" preference="extensions.zotero.automaticTags" native="true"/>
<hbox align="center">
<label value="&zotero.preferences.trashAutoEmptyDaysPre;"/>
<html:input type="text" size="2" preference="extensions.zotero.trashAutoEmptyDays"/>
<label value="&zotero.preferences.trashAutoEmptyDaysPost;"/>
</hbox>
</groupbox>
<groupbox id="zotero-prefpane-reader-groupbox">
<label><html:h2>&zotero.preferences.pdfReader;</html:h2></label>
<groupbox id="zotero-prefpane-reader-groupbox">
<label><html:h2>&zotero.preferences.pdfReader;</html:h2></label>
<hbox align="center">
<label value="&zotero.preferences.reader.tabsTitle.label;" control="reader-tabs-title"/>
<menulist id="reader-tabs-title" preference="extensions.zotero.tabs.title.reader" native="true">
<menupopup>
<menuitem label="&zotero.preferences.reader.tabsTitle.titleCreatorYear;" value="titleCreatorYear"/>
<menuitem label="&zotero.preferences.reader.tabsTitle.creatorYearTitle;" value="creatorYearTitle"/>
<menuitem label="&zotero.preferences.reader.tabsTitle.filename;" value="filename"/>
</menupopup>
</menulist>
</hbox>
</groupbox>
<hbox align="center">
<label value="&zotero.preferences.reader.tabsTitle.label;" control="reader-tabs-title"/>
<menulist id="reader-tabs-title" preference="extensions.zotero.tabs.title.reader" native="true">
<menupopup>
<menuitem label="&zotero.preferences.reader.tabsTitle.titleCreatorYear;" value="titleCreatorYear"/>
<menuitem label="&zotero.preferences.reader.tabsTitle.creatorYearTitle;" value="creatorYearTitle"/>
<menuitem label="&zotero.preferences.reader.tabsTitle.filename;" value="filename"/>
</menupopup>
</menulist>
</hbox>
</groupbox>
<groupbox>
<label><html:h2>&zotero.preferences.groups;</html:h2></label>
<label value="&zotero.preferences.groups.whenCopyingInclude;"/>
<vbox style="margin-left: 2em">
<checkbox label="&zotero.preferences.groups.childNotes;" preference="extensions.zotero.groups.copyChildNotes" native="true"/>
<checkbox label="&zotero.preferences.groups.childFiles;" preference="extensions.zotero.groups.copyChildFileAttachments" native="true"/>
<checkbox label="&zotero.preferences.groups.annotations;" preference="extensions.zotero.groups.copyAnnotations" native="true"/>
<checkbox label="&zotero.preferences.groups.childLinks;" preference="extensions.zotero.groups.copyChildLinks" native="true"/>
<checkbox label="&zotero.preferences.groups.tags;" preference="extensions.zotero.groups.copyTags" native="true"/>
</vbox>
</groupbox>
<groupbox>
<label><html:h2>&zotero.preferences.groups;</html:h2></label>
<label value="&zotero.preferences.groups.whenCopyingInclude;"/>
<vbox style="margin-left: 2em">
<checkbox label="&zotero.preferences.groups.childNotes;" preference="extensions.zotero.groups.copyChildNotes" native="true"/>
<checkbox label="&zotero.preferences.groups.childFiles;" preference="extensions.zotero.groups.copyChildFileAttachments" native="true"/>
<checkbox label="&zotero.preferences.groups.annotations;" preference="extensions.zotero.groups.copyAnnotations" native="true"/>
<checkbox label="&zotero.preferences.groups.childLinks;" preference="extensions.zotero.groups.copyChildLinks" native="true"/>
<checkbox label="&zotero.preferences.groups.tags;" preference="extensions.zotero.groups.copyTags" native="true"/>
</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

@ -81,6 +81,15 @@ Zotero.PreferencePanes = {
scripts: ['chrome://zotero/content/preferences/preferences_sync.js'],
defaultXUL: true,
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 =
.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;
}
#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) {