Citation Explorer: Disable buttons when no selection

This commit is contained in:
Adomas Venčkauskas 2025-09-29 16:11:11 +03:00
parent 4fd753f822
commit 68b9499bc0
7 changed files with 47 additions and 29 deletions

View file

@ -190,6 +190,7 @@ window.ZoteroDocumentCitations = {
regularOnly: true,
columns: itemColumns,
shouldListenForNotifications: false,
autoSelect: false,
onSelectionChange: this.onItemSelectionChange.bind(this),
onActivate: this.onItemActivate.bind(this),
emptyMessage: Zotero.getString('pane.items.loading'),
@ -272,7 +273,7 @@ window.ZoteroDocumentCitations = {
// check if all citation items are linked
for (let citationItem of citation.citationItems) {
itemMap[citationItem.id].citedIn.push(citationIndex);
isLinked = typeof citationItem.id == 'number';
isLinked = isLinked && typeof citationItem.id == 'number';
}
let title = await citation.field.getText();
if (citation.properties.plainCitation != title) {
@ -343,6 +344,9 @@ window.ZoteroDocumentCitations = {
}
}
itemList.setHighlightedRows(highlightedItems);
const noneSelected = citationList.selection.selected.size === 0;
document.querySelector('#button-show-in-document').disabled = noneSelected;
document.querySelector('#button-edit-citation').disabled = noneSelected;
},
onCitationEdit: async function () {
@ -366,22 +370,22 @@ window.ZoteroDocumentCitations = {
}
const item = itemList.getRow(itemList.selection.focused).ref;
const isUnlinked = typeof item.id != 'number';
const isMultiple = itemList.selection.selected.size > 1;
document.querySelector('#button-show-in-zotero').hidden = isMultiple || isUnlinked;
document.querySelector('#button-relink-item').hidden = isMultiple || !isUnlinked;
document.querySelector('#button-addTo-library').style.display = (isMultiple || !isUnlinked) ? 'none' : 'inherit';
const noneSelected = itemList.selection.selected.size === 0;
document.querySelector('#button-show-in-zotero').disabled = noneSelected || isUnlinked;
document.querySelector('#button-relink-item').disabled = noneSelected || !isUnlinked;
document.querySelector('#button-addTo-library').disabled = noneSelected || !isUnlinked;
await this.refreshCitationList();
},
onItemActivate: async function () {
if (itemList.selection.selected.size > 1) return;
const item = itemList.getRow(itemList.selection.focused).ref;
if (typeof item.id != 'number') {
this.onItemRelink();
}
else {
await Zotero.Utilities.Internal.showInLibrary(item);
await Zotero.Utilities.Internal.showInLibrary(
Array.from(itemList.selection.selected).map(index => itemList.getRow(index).ref));
}
},

View file

@ -78,9 +78,8 @@
</div>
<div class="button-container citation-explorer-grid-left grid-padded-section">
<input type="button" id="button-show-in-document" value="Show in Document"/>
<div class="spacer"></div>
<input type="button" id="button-edit-citation" value="Edit Citation"/>
<input type="button" id="button-show-in-document" value="Show in Document" disabled="true"/>
<input type="button" id="button-edit-citation" class="right" value="Edit Citation" disabled="true"/>
</div>
<!-- Right Column -->
@ -95,12 +94,11 @@
</div>
<div class="button-container grid-padded-section">
<input type="button" id="button-show-in-zotero" value="Show in Zotero"/>
<div class="spacer"></div>
<input type="button" id="button-relink-item" value="Relink Item" hidden="true"/>
<input type="button" id="button-show-in-zotero" value="Show in Zotero" disabled="true"/>
<input type="button" id="button-relink-item" class="right" value="Relink Item" disabled="true"/>
<button is="split-menu-button" id="button-addTo-library"
onclick="ZoteroDocumentCitations.addToLibraryAndLink()"
popup="item-addTo-menu" style="display: none"/>
popup="item-addTo-menu" disabled="true"/>
<xul:popupset>
<xul:menupopup id="item-addTo-menu" onpopupshowing="ZoteroDocumentCitations.buildAddToLibraryContextMenu(event);"/>
</xul:popupset>

View file

@ -923,6 +923,7 @@ var ItemTree = class ItemTree extends LibraryTree {
regularOnly: false,
multiSelect: true,
shouldListenForNotifications: true,
autoSelect: true,
columns: COLUMNS,
onContextMenu: noop,
onActivate: noop,
@ -940,6 +941,8 @@ var ItemTree = class ItemTree extends LibraryTree {
regularOnly: PropTypes.bool,
multiSelect: PropTypes.bool,
shouldListenForNotifications: PropTypes.bool,
// Whether to automatically select the focused row when the tree is focused via tab key
autoSelect: PropTypes.bool,
columns: PropTypes.array,
onSelectionChange: PropTypes.func,
onContextMenu: PropTypes.func,
@ -1409,7 +1412,7 @@ var ItemTree = class ItemTree extends LibraryTree {
* Select the first row when the tree is tabbed into with no selection.
*/
handleKeyUp = (event) => {
if (!Zotero.locked && event.code === 'Tab' && this.selection.count == 0) {
if (!Zotero.locked && this.props.autoSelect && (event.code === 'Tab' || event.key.includes("Arrow")) && this.selection.count == 0) {
this.selection.select(this.selection.focused);
}
};

View file

@ -2041,9 +2041,12 @@ Zotero.Utilities.Internal = {
/**
* Select an object in the library tab of the main window
*
* @param {Zotero.DataObject} - Data object (e.g., Zotero.Item) to select
* @param {Zotero.DataObject[]} - Data objects (e.g., Zotero.Item) to select
*/
showInLibrary: async function (dataObject) {
showInLibrary: async function (dataObjects) {
if (!Array.isArray(dataObjects)) {
dataObjects = [dataObjects];
}
var pane = Zotero.getActiveZoteroPane();
// Open main window if it's not open (Mac)
if (!pane) {
@ -2057,12 +2060,12 @@ Zotero.Utilities.Internal = {
});
pane = win.ZoteroPane;
}
if (dataObject instanceof Zotero.Item) {
pane.selectItem(dataObject.id);
}
else {
throw new Error("Unimplemented");
}
pane.selectItems(dataObjects.map(dataObject => {
if (dataObject instanceof Zotero.Item) {
return dataObject.id;
}
throw new Error(`Unsupported data object: ${dataObject}`);
}));
// Pull window to foreground
Zotero.Utilities.Internal.activate(pane.document.defaultView);

View file

@ -17,6 +17,6 @@
flex: 1
}
.spacer {
flex: 1;
.right {
margin-left: auto !important;
}

View file

@ -1,5 +1,6 @@
#zotero-citation-explorer-dialog {
min-height: 500px;
min-width: 600px;
--split-button-icon-color: var(--accent-blue);
dialog {
@ -10,10 +11,6 @@
search-textbox, input, button {
margin: 0;
}
input + button {
margin-left: 8px;
}
.citation-explorer-grid {
display: grid;
@ -77,7 +74,19 @@
.button-container {
border-bottom: var(--material-border-quarternary);
display: flex;
gap: 8px;
padding: 8px 16px;
min-width: 0;
.split-menu-button {
min-width: 0;
flex: 0 1 auto;
[anonid="button-image-and-text-box"] {
min-width: 0;
width: auto;
}
}
}
.diff-deleted {

View file

@ -34,6 +34,7 @@
display: flex;
align-items: center;
overflow: hidden;
min-width: 8px;
}
& [anonid="dropmarker-separator"] {