Add a hidden pref for tab title with support for Creator-Year-Title option (#2985)
This commit is contained in:
parent
87fbf3c7fb
commit
a5fb64f295
2 changed files with 35 additions and 25 deletions
|
@ -105,7 +105,7 @@ class ReaderInstance {
|
|||
this.state = state;
|
||||
this._itemID = item.id;
|
||||
// Set `ReaderTab` title as fast as possible
|
||||
this.updateTitle();
|
||||
await this.updateTitle();
|
||||
let path = await item.getFilePathAsync();
|
||||
// Check file size, otherwise we get uncatchable error:
|
||||
// JavaScript error: resource://gre/modules/osfile/osfile_native.jsm, line 60: RangeError: invalid array length
|
||||
|
@ -151,10 +151,11 @@ class ReaderInstance {
|
|||
}
|
||||
}, [buf]);
|
||||
// Set title once again, because `ReaderWindow` isn't loaded the first time
|
||||
this.updateTitle();
|
||||
await this.updateTitle();
|
||||
|
||||
this._prefObserverIDs = [
|
||||
Zotero.Prefs.registerObserver('fontSize', this._handleFontSizeChange)
|
||||
Zotero.Prefs.registerObserver('fontSize', this._handleFontSizePrefChange),
|
||||
Zotero.Prefs.registerObserver('tabs.title', this._handleTabTitlePrefChange)
|
||||
];
|
||||
|
||||
return true;
|
||||
|
@ -170,32 +171,34 @@ class ReaderInstance {
|
|||
return this._itemID;
|
||||
}
|
||||
|
||||
updateTitle() {
|
||||
async updateTitle() {
|
||||
let item = Zotero.Items.get(this._itemID);
|
||||
let title = item.getDisplayTitle();
|
||||
let readerTitle = item.getDisplayTitle();
|
||||
let parentItem = item.parentItem;
|
||||
if (parentItem) {
|
||||
let parts = [];
|
||||
let displayTitle = parentItem.getDisplayTitle();
|
||||
if (displayTitle) {
|
||||
parts.push(displayTitle);
|
||||
let attachment = await parentItem.getBestAttachment();
|
||||
if (attachment && attachment.id === this._itemID) {
|
||||
let parts = [];
|
||||
let type = Zotero.Prefs.get('tabs.title');
|
||||
let creator = parentItem.getField('firstCreator');
|
||||
let year = parentItem.getField('year');
|
||||
let title = parentItem.getDisplayTitle();
|
||||
// If creator is missing fall back to titleCreatorYear
|
||||
if (type === 'creatorYearTitle' && creator) {
|
||||
parts = [creator, year, title];
|
||||
}
|
||||
else if (type === 'title') {
|
||||
parts = [title];
|
||||
}
|
||||
// If type is titleCreatorYear, or is missing, or another type falls back
|
||||
else {
|
||||
parts = [title, creator, year];
|
||||
}
|
||||
readerTitle = parts.filter(x => x).join(' - ');
|
||||
}
|
||||
|
||||
let firstCreator = parentItem.getField('firstCreator');
|
||||
if (firstCreator) {
|
||||
parts.push(firstCreator);
|
||||
}
|
||||
|
||||
let year = parentItem.getField('year');
|
||||
if (year) {
|
||||
parts.push(year);
|
||||
}
|
||||
|
||||
title = parts.join(' - ');
|
||||
}
|
||||
|
||||
this._title = title;
|
||||
this._setTitleValue(title);
|
||||
this._title = readerTitle;
|
||||
this._setTitleValue(readerTitle);
|
||||
}
|
||||
|
||||
async setAnnotations(items) {
|
||||
|
@ -598,10 +601,14 @@ class ReaderInstance {
|
|||
|| item.parentItem && item.parentItem.deleted;
|
||||
}
|
||||
|
||||
_handleFontSizeChange = () => {
|
||||
_handleFontSizePrefChange = () => {
|
||||
this._postMessage({ action: 'setFontSize', fontSize: Zotero.Prefs.get('fontSize') });
|
||||
};
|
||||
|
||||
_handleTabTitlePrefChange = async () => {
|
||||
await this.updateTitle();
|
||||
};
|
||||
|
||||
_dataURLtoBlob(dataurl) {
|
||||
let parts = dataurl.split(',');
|
||||
let mime = parts[0].match(/:(.*?);/)[1];
|
||||
|
|
|
@ -211,3 +211,6 @@ pref("extensions.zotero.annotations.noteTemplates.note", "<p>{{citation}} {{comm
|
|||
|
||||
// Scaffold
|
||||
pref("extensions.zotero.scaffold.eslint.enabled", true);
|
||||
|
||||
// Tabs
|
||||
pref("extensions.zotero.tabs.title", "titleCreatorYear");
|
||||
|
|
Loading…
Reference in a new issue