Skip to content

Commit 50f41c5

Browse files
committed
bubbling up context menu invocation from list row in changes list
1 parent b0c4b63 commit 50f41c5

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

app/src/ui/changes/changed-file.tsx

+1-11
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ interface IChangedFileProps {
1515
readonly disableSelection: boolean
1616
readonly checkboxTooltip?: string
1717
readonly onIncludeChanged: (path: string, include: boolean) => void
18-
19-
/** Callback called when user right-clicks on an item */
20-
readonly onContextMenu: (
21-
file: WorkingDirectoryFileChange,
22-
event: React.MouseEvent<HTMLDivElement>
23-
) => void
2418
}
2519

2620
/** a changed file in the working directory for a given repository */
@@ -59,7 +53,7 @@ export class ChangedFile extends React.Component<IChangedFileProps, {}> {
5953
statusWidth
6054

6155
return (
62-
<div className="file" onContextMenu={this.onContextMenu}>
56+
<div className="file">
6357
<TooltippedContent
6458
tooltip={checkboxTooltip}
6559
direction={TooltipDirection.EAST}
@@ -91,8 +85,4 @@ export class ChangedFile extends React.Component<IChangedFileProps, {}> {
9185
</div>
9286
)
9387
}
94-
95-
private onContextMenu = (event: React.MouseEvent<HTMLDivElement>) => {
96-
this.props.onContextMenu(this.props.file, event)
97-
}
9888
}

app/src/ui/changes/changes-list.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ export class ChangesList extends React.Component<
318318
file={file}
319319
include={isPartiallyCommittableSubmodule && include ? null : include}
320320
key={file.id}
321-
onContextMenu={this.onItemContextMenu}
322321
onIncludeChanged={onIncludeChanged}
323322
availableWidth={availableWidth}
324323
disableSelection={disableSelection}
@@ -671,9 +670,12 @@ export class ChangesList extends React.Component<
671670
}
672671

673672
private onItemContextMenu = (
674-
file: WorkingDirectoryFileChange,
673+
row: number,
675674
event: React.MouseEvent<HTMLDivElement>
676675
) => {
676+
const { workingDirectory } = this.props
677+
const file = workingDirectory.files[row]
678+
677679
if (this.props.isCommitting) {
678680
return
679681
}
@@ -957,10 +959,12 @@ export class ChangesList extends React.Component<
957959
onScroll={this.onScroll}
958960
setScrollTop={this.props.changesListScrollTop}
959961
onRowKeyDown={this.onRowKeyDown}
962+
onRowContextMenu={this.onItemContextMenu}
960963
/>
961964
{this.renderStashedChanges()}
962965
{this.renderCommitMessageForm()}
963966
</div>
964967
)
965968
}
966969
}
970+

app/src/ui/lib/list/list-row.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ interface IListRowProps {
5353
e: React.FocusEvent<HTMLDivElement>
5454
) => void
5555

56+
/** Called back for when the context menu is invoked (user right clicks of
57+
* uses keyboard shortcuts) */
58+
readonly onContextMenu?: (
59+
index: number,
60+
e: React.MouseEvent<HTMLDivElement>
61+
) => void
62+
5663
/**
5764
* Whether or not this list row is going to be selectable either through
5865
* keyboard navigation, pointer clicks, or both. This is used to determine
@@ -97,6 +104,11 @@ export class ListRow extends React.Component<IListRowProps, {}> {
97104
this.props.onRowBlur?.(this.props.rowIndex, e)
98105
}
99106

107+
private onContextMenu = (e: React.MouseEvent<HTMLDivElement>) => {
108+
console.log(this.props.rowIndex)
109+
this.props.onContextMenu?.(this.props.rowIndex, e)
110+
}
111+
100112
public render() {
101113
const selected = this.props.selected
102114
const className = classNames(
@@ -135,6 +147,7 @@ export class ListRow extends React.Component<IListRowProps, {}> {
135147
style={style}
136148
onFocus={this.onFocus}
137149
onBlur={this.onBlur}
150+
onContextMenu={this.onContextMenu}
138151
>
139152
{this.props.children}
140153
</div>

app/src/ui/lib/list/list.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ interface IListProps {
188188
*/
189189
readonly onRowMouseDown?: (row: number, event: React.MouseEvent<any>) => void
190190

191+
/**
192+
* A handler called whenever a context menu event is received on the
193+
* row container element.
194+
*
195+
* The context menu is invoked when a user right clicks the row or
196+
* uses keyboard shortcut.
197+
*/
198+
readonly onRowContextMenu?: (
199+
row: number,
200+
event: React.MouseEvent<HTMLDivElement>
201+
) => void
202+
191203
/**
192204
* A handler called whenever the user drops items on the list to be inserted.
193205
*
@@ -607,6 +619,13 @@ export class List extends React.Component<IListProps, IListState> {
607619
}
608620
}
609621

622+
private onRowContextMenu = (
623+
row: number,
624+
e: React.MouseEvent<HTMLDivElement>
625+
) => {
626+
this.props.onRowContextMenu?.(row, e)
627+
}
628+
610629
private onRowMouseOver = (row: number, event: React.MouseEvent<any>) => {
611630
if (this.props.selectOnHover && this.canSelectRow(row)) {
612631
if (!this.props.selectedRows.includes(row)) {
@@ -914,6 +933,7 @@ export class List extends React.Component<IListProps, IListState> {
914933
onRowMouseOver={this.onRowMouseOver}
915934
onRowFocus={this.onRowFocus}
916935
onRowBlur={this.onRowBlur}
936+
onContextMenu={this.onRowContextMenu}
917937
style={params.style}
918938
tabIndex={tabIndex}
919939
children={element}

0 commit comments

Comments
 (0)