Allow to use Quick Copy from PDF reader tab

Fixes #2023
This commit is contained in:
Martynas Bagdonas 2021-10-18 09:57:39 +03:00
parent 4e68b624f2
commit a07c052cf0
3 changed files with 48 additions and 10 deletions

View file

@ -54,6 +54,12 @@ const ZoteroStandalone = new function() {
{
notify: async (action, type, ids, extraData) => {
if (action == 'select') {
// Reader doesn't have tabID yet
setTimeout(async () => {
// Item and other things might not be loaded yet when reopening tabs
await Zotero.Schema.schemaUpdatePromise;
this.updateQuickCopyOptions();
}, 0);
// "library" or "reader"
this.switchMenuType(extraData[ids[0]].type);
setTimeout(() => ZoteroPane.updateToolbarPosition(), 0);
@ -283,13 +289,30 @@ const ZoteroStandalone = new function() {
this.updateQuickCopyOptions = function () {
var selected = false;
try {
selected = Zotero.getActiveZoteroPane()
.getSelectedItems()
.filter(item => item.isRegularItem())
.length;
let win = Zotero.getMainWindow();
if (win) {
if (win.Zotero_Tabs.selectedID == 'zotero-pane') {
try {
selected = win.ZoteroPane
.getSelectedItems()
.filter(item => item.isRegularItem())
.length;
}
catch (e) {
}
win.ZoteroPane.updateQuickCopyCommands(win.ZoteroPane.getSelectedItems());
}
else {
let reader = Zotero.Reader.getByTabID(win.Zotero_Tabs.selectedID);
if (reader) {
let item = Zotero.Items.get(reader.itemID);
selected = !!item.parentItemID;
item = item.parentItem || item;
win.ZoteroPane.updateQuickCopyCommands([item]);
}
}
}
catch (e) {}
var format = Zotero.QuickCopy.getFormatFromURL(Zotero.QuickCopy.lastActiveURL);
format = Zotero.QuickCopy.unserializeSetting(format);

View file

@ -183,13 +183,11 @@
<menuitem id="menu_cut"/>
<menuitem id="menu_copy"/>
<menuitem id="menu_copyCitation"
class="menu-type-library"
label="&copyCitationCmd.label;"
command="cmd_zotero_copyCitation"
key="key_copyCitation"
hidden="true"/>
<menuitem id="menu_copyBibliography"
class="menu-type-library"
label="&copyBibliographyCmd.label;"
command="cmd_zotero_copyBibliography"
key="key_copyBibliography"

View file

@ -1330,7 +1330,11 @@ var ZoteroPane = new function()
// selection hasn't changed, because the selected items might have been modified.
this.updateItemPaneButtons(selectedItems);
this.updateQuickCopyCommands(selectedItems);
// Tab selection observer in standalone.js makes sure that
// updateQuickCopyCommands is called
if (Zotero_Tabs.selectedID == 'zotero-pane') {
this.updateQuickCopyCommands(selectedItems);
}
// Check if selection has actually changed. The onselect event that calls this
// can be called in various situations where the selection didn't actually change,
@ -2069,7 +2073,20 @@ var ZoteroPane = new function()
this.copySelectedItemsToClipboard = function (asCitations) {
var items = this.getSelectedItems();
var items = [];
if (Zotero_Tabs.selectedID == 'zotero-pane') {
items = this.getSelectedItems();
}
else {
var reader = Zotero.Reader.getByTabID(Zotero_Tabs.selectedID);
if (reader) {
let item = Zotero.Items.get(reader.itemID);
if (item.parentItem) {
items = [item.parentItem];
}
}
}
if (!items.length) {
return;
}