Skip to content

Commit a632505

Browse files
committed
add open file action button
- created an icon for opening a file - switch diff action button for open file action button when doubleClickDiff is true.
1 parent 9403cee commit a632505

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

src/components/FileList.tsx

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
346346
key={file.to}
347347
actions={
348348
<React.Fragment>
349-
{this._createDiffButton(file, 'INDEX')}
349+
{this._maybeCreateDiffButton(file, 'INDEX')}
350350
<ActionButton
351351
className={hiddenButtonStyle}
352352
iconName={'git-remove'}
@@ -410,7 +410,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
410410
this.discardChanges(file.to);
411411
}}
412412
/>
413-
{this._createDiffButton(file, 'WORKING')}
413+
{this._maybeCreateDiffButton(file, 'WORKING')}
414414
<ActionButton
415415
className={hiddenButtonStyle}
416416
iconName={'git-add'}
@@ -505,12 +505,12 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
505505
this.discardChanges(file.to);
506506
}}
507507
/>
508-
{this._createDiffButton(file, 'WORKING')}
508+
{this._maybeCreateDiffButton(file, 'WORKING')}
509509
</React.Fragment>
510510
);
511511
onDoubleClick = this._onDoubleClickFactory(file, 'WORKING');
512512
} else if (file.status === 'staged') {
513-
actions = this._createDiffButton(file, 'INDEX');
513+
actions = this._maybeCreateDiffButton(file, 'INDEX');
514514
onDoubleClick = this._onDoubleClickFactory(file, 'INDEX');
515515
}
516516

@@ -530,27 +530,47 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
530530
}
531531

532532
/**
533-
* Creates a button element which is used to request diff of a file.
533+
* Creates a button element which, depending on the settings, is used
534+
* to either request a diff of the file, or open the file
534535
*
535536
* @param path File path of interest
536537
* @param currentRef the ref to diff against the git 'HEAD' ref
537538
*/
538-
private _createDiffButton(
539+
private _maybeCreateDiffButton(
539540
file: Git.IStatusFile,
540541
currentRef: ISpecialRef['specialRef']
541542
): JSX.Element {
542-
return (
543-
(isDiffSupported(file.to) || !file.is_binary) && (
543+
if (this.props.settings.composite['doubleClickDiff']) {
544+
return (
544545
<ActionButton
545546
className={hiddenButtonStyle}
546-
iconName={'git-diff'}
547-
title={'Diff this file'}
548-
onClick={this._openDiffViewFactory(file, currentRef)}
547+
iconName={'open-file'}
548+
title={'Open this file'}
549+
onClick={async () => {
550+
openListedFile(file, this.props.model);
551+
}}
549552
/>
550-
)
551-
);
553+
);
554+
} else {
555+
return (
556+
(isDiffSupported(file.to) || !file.is_binary) && (
557+
<ActionButton
558+
className={hiddenButtonStyle}
559+
iconName={'git-diff'}
560+
title={'Diff this file'}
561+
onClick={this._openDiffViewFactory(file, currentRef)}
562+
/>
563+
)
564+
);
565+
}
552566
}
553567

568+
/**
569+
* Returns a callback which opens a diff of the file
570+
*
571+
* @param file
572+
* @param currentRef the ref to diff against the git 'HEAD' ref
573+
*/
554574
private _openDiffViewFactory(
555575
file: Git.IStatusFile,
556576
currentRef: ISpecialRef['specialRef']
@@ -576,6 +596,12 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
576596
}
577597
}
578598

599+
/**
600+
* Returns a callback which is invoked upon double clicking a file
601+
*
602+
* @param file
603+
* @param currentRef the ref to diff against the current git 'HEAD' ref
604+
*/
579605
private _onDoubleClickFactory(
580606
file: Git.IStatusFile,
581607
currentRef: ISpecialRef['specialRef']

src/style/icons.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import insertionsMadeSvg from '../../style/images/insertions-made-icon.svg';
99
import addSvg from '../../style/images/move-file-up.svg';
1010
import removeSvg from '../../style/images/move-file-down.svg';
1111
import rewindSvg from '../../style/images/rewind.svg';
12+
import openSvg from '../../style/images/open-file.svg';
1213

1314
export const gitIcon = new LabIcon({ name: 'git', svgstr: gitSvg });
1415
export const deletionsMadeIcon = new LabIcon({
@@ -40,3 +41,7 @@ export const rewindIcon = new LabIcon({
4041
name: 'git-rewind',
4142
svgstr: rewindSvg
4243
});
44+
export const openIcon = new LabIcon({
45+
name: 'open-file',
46+
svgstr: openSvg
47+
});

style/images/open-file.svg

Lines changed: 14 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)