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.state = state;
|
||||||
this._itemID = item.id;
|
this._itemID = item.id;
|
||||||
// Set `ReaderTab` title as fast as possible
|
// Set `ReaderTab` title as fast as possible
|
||||||
this.updateTitle();
|
await this.updateTitle();
|
||||||
let path = await item.getFilePathAsync();
|
let path = await item.getFilePathAsync();
|
||||||
// Check file size, otherwise we get uncatchable error:
|
// Check file size, otherwise we get uncatchable error:
|
||||||
// JavaScript error: resource://gre/modules/osfile/osfile_native.jsm, line 60: RangeError: invalid array length
|
// JavaScript error: resource://gre/modules/osfile/osfile_native.jsm, line 60: RangeError: invalid array length
|
||||||
|
@ -151,10 +151,11 @@ class ReaderInstance {
|
||||||
}
|
}
|
||||||
}, [buf]);
|
}, [buf]);
|
||||||
// Set title once again, because `ReaderWindow` isn't loaded the first time
|
// Set title once again, because `ReaderWindow` isn't loaded the first time
|
||||||
this.updateTitle();
|
await this.updateTitle();
|
||||||
|
|
||||||
this._prefObserverIDs = [
|
this._prefObserverIDs = [
|
||||||
Zotero.Prefs.registerObserver('fontSize', this._handleFontSizeChange)
|
Zotero.Prefs.registerObserver('fontSize', this._handleFontSizePrefChange),
|
||||||
|
Zotero.Prefs.registerObserver('tabs.title', this._handleTabTitlePrefChange)
|
||||||
];
|
];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -170,32 +171,34 @@ class ReaderInstance {
|
||||||
return this._itemID;
|
return this._itemID;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTitle() {
|
async updateTitle() {
|
||||||
let item = Zotero.Items.get(this._itemID);
|
let item = Zotero.Items.get(this._itemID);
|
||||||
let title = item.getDisplayTitle();
|
let readerTitle = item.getDisplayTitle();
|
||||||
let parentItem = item.parentItem;
|
let parentItem = item.parentItem;
|
||||||
if (parentItem) {
|
if (parentItem) {
|
||||||
let parts = [];
|
let attachment = await parentItem.getBestAttachment();
|
||||||
let displayTitle = parentItem.getDisplayTitle();
|
if (attachment && attachment.id === this._itemID) {
|
||||||
if (displayTitle) {
|
let parts = [];
|
||||||
parts.push(displayTitle);
|
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 = readerTitle;
|
||||||
this._title = title;
|
this._setTitleValue(readerTitle);
|
||||||
this._setTitleValue(title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async setAnnotations(items) {
|
async setAnnotations(items) {
|
||||||
|
@ -598,10 +601,14 @@ class ReaderInstance {
|
||||||
|| item.parentItem && item.parentItem.deleted;
|
|| item.parentItem && item.parentItem.deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
_handleFontSizeChange = () => {
|
_handleFontSizePrefChange = () => {
|
||||||
this._postMessage({ action: 'setFontSize', fontSize: Zotero.Prefs.get('fontSize') });
|
this._postMessage({ action: 'setFontSize', fontSize: Zotero.Prefs.get('fontSize') });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_handleTabTitlePrefChange = async () => {
|
||||||
|
await this.updateTitle();
|
||||||
|
};
|
||||||
|
|
||||||
_dataURLtoBlob(dataurl) {
|
_dataURLtoBlob(dataurl) {
|
||||||
let parts = dataurl.split(',');
|
let parts = dataurl.split(',');
|
||||||
let mime = parts[0].match(/:(.*?);/)[1];
|
let mime = parts[0].match(/:(.*?);/)[1];
|
||||||
|
|
|
@ -211,3 +211,6 @@ pref("extensions.zotero.annotations.noteTemplates.note", "<p>{{citation}} {{comm
|
||||||
|
|
||||||
// Scaffold
|
// Scaffold
|
||||||
pref("extensions.zotero.scaffold.eslint.enabled", true);
|
pref("extensions.zotero.scaffold.eslint.enabled", true);
|
||||||
|
|
||||||
|
// Tabs
|
||||||
|
pref("extensions.zotero.tabs.title", "titleCreatorYear");
|
||||||
|
|
Loading…
Reference in a new issue