Skip to content

Commit

Permalink
Adds clear to branch compare node
Browse files Browse the repository at this point in the history
Adds hide menus for branch compare nodes
Moves branch comparison node under branch node
  • Loading branch information
eamodio committed Sep 12, 2020
1 parent 5626898 commit 95ede42
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 11 deletions.
61 changes: 57 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3169,7 +3169,7 @@
},
{
"command": "gitlens.views.setComparisonToTwoDot",
"title": "Switch to Two-dot Comparison",
"title": "Toggle Comparison Type (Two-dot)",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-compare-twodot.svg",
Expand All @@ -3178,7 +3178,7 @@
},
{
"command": "gitlens.views.setComparisonToThreeDot",
"title": "Switch to Three-dot Comparison",
"title": "Toggle Comparison Type (Three-dot)",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-compare-threedot.svg",
Expand Down Expand Up @@ -3262,7 +3262,7 @@
},
{
"command": "gitlens.views.setBranchComparisonToWorking",
"title": "Switch to Working Tree Comparison",
"title": "Toggle Comparison Source (Working Tree)",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-compare-ref-working.svg",
Expand All @@ -3271,10 +3271,16 @@
},
{
"command": "gitlens.views.setBranchComparisonToBranch",
"title": "Switch to Branch Comparison",
"title": "Toggle Comparison Source (Branch)",
"category": "GitLens",
"icon": "$(compare-changes)"
},
{
"command": "gitlens.views.clearNode",
"title": "Clear",
"category": "GitLens",
"icon": "$(close)"
},
{
"command": "gitlens.views.dismissNode",
"title": "Dismiss",
Expand Down Expand Up @@ -3414,6 +3420,16 @@
"title": "Hide Avatars",
"category": "GitLens"
},
{
"command": "gitlens.views.commits.setShowBranchComparisonOn",
"title": "Show Branch Comparison",
"category": "GitLens"
},
{
"command": "gitlens.views.commits.setShowBranchComparisonOff",
"title": "Hide Branch Comparison",
"category": "GitLens"
},
{
"command": "gitlens.views.compare.clear",
"title": "Clear Results",
Expand Down Expand Up @@ -4551,6 +4567,10 @@
"command": "gitlens.views.setBranchComparisonToBranch",
"when": "false"
},
{
"command": "gitlens.views.clearNode",
"when": "false"
},
{
"command": "gitlens.views.dismissNode",
"when": "false"
Expand Down Expand Up @@ -4643,6 +4663,14 @@
"command": "gitlens.views.commits.setShowAvatarsOff",
"when": "false"
},
{
"command": "gitlens.views.commits.setShowBranchComparisonOn",
"when": "false"
},
{
"command": "gitlens.views.commits.setShowBranchComparisonOff",
"when": "false"
},
{
"command": "gitlens.views.compare.clear",
"when": "false"
Expand Down Expand Up @@ -5700,6 +5728,16 @@
"when": "view =~ /^gitlens\\.views\\.commits/ && config.gitlens.views.commits.avatars",
"group": "1_gitlens@0"
},
{
"command": "gitlens.views.commits.setShowBranchComparisonOn",
"when": "view =~ /^gitlens\\.views\\.commits/ && !config.gitlens.views.commits.showBranchComparison",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.commits.setShowBranchComparisonOff",
"when": "view =~ /^gitlens\\.views\\.commits/ && config.gitlens.views.commits.showBranchComparison",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.contributors.setFilesLayoutToList",
"when": "view =~ /^gitlens\\.views\\.contributors/ && config.gitlens.views.contributors.files.layout == auto",
Expand Down Expand Up @@ -6554,6 +6592,11 @@
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+twodot\\b)/",
"group": "inline@1"
},
{
"command": "gitlens.views.clearNode",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)/",
"group": "inline@99"
},
{
"command": "gitlens.views.setBranchComparisonToWorking",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+branch\\b)/",
Expand Down Expand Up @@ -6584,6 +6627,16 @@
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+working\\b)/",
"group": "1_gitlens@2"
},
{
"command": "gitlens.views.commits.setShowBranchComparisonOff",
"when": "viewItem =~ /gitlens:compare:branch\\b/",
"group": "8_gitlens@1"
},
{
"command": "gitlens.views.clearNode",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)/",
"group": "9_gitlens@1"
},
{
"command": "gitlens.views.setComparisonToTwoDot",
"when": "viewItem =~ /gitlens:compare:results\\b(?=.*?\\b\\+threedot\\b)/",
Expand Down
28 changes: 22 additions & 6 deletions src/views/commitsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TreeItemCollapsibleState,
window,
} from 'vscode';
import { CommitsViewConfig, configuration, ViewFilesLayout } from '../configuration';
import { CommitsViewConfig, configuration, ViewFilesLayout, ViewShowBranchComparison } from '../configuration';
import { CommandContext, GlyphChars, setCommandContext } from '../constants';
import { Container } from '../container';
import {
Expand All @@ -22,6 +22,7 @@ import {
import { GitUri } from '../git/gitUri';
import {
BranchNode,
BranchTrackingStatusNode,
CompareBranchNode,
ContextValues,
MessageNode,
Expand All @@ -32,7 +33,6 @@ import {
} from './nodes';
import { debug, gate } from '../system';
import { ViewBase } from './viewBase';
import { BranchTrackingStatusNode } from './nodes/branchTrackingStatusNode';

export class CommitsRepositoryNode extends SubscribeableViewNode<CommitsView> {
protected splatted = true;
Expand Down Expand Up @@ -66,15 +66,12 @@ export class CommitsRepositoryNode extends SubscribeableViewNode<CommitsView> {
this.children = [
new BranchNode(this.uri, this.view, this, branch, true, {
expanded: true,
showComparison: this.view.config.showBranchComparison,
showCurrent: false,
showTracking: true,
authors: authors,
}),
];

if (this.view.config.showBranchComparison !== false) {
this.children.push(new CompareBranchNode(this.uri, this.view, this, branch));
}
}

const [branch, ...rest] = this.children;
Expand Down Expand Up @@ -271,6 +268,16 @@ export class CommitsView extends ViewBase<CommitsViewNode, CommitsViewConfig> {
);
commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this);
commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this);
commands.registerCommand(
this.getQualifiedCommand('setShowBranchComparisonOn'),
() => this.setShowBranchComparison(true),
this,
);
commands.registerCommand(
this.getQualifiedCommand('setShowBranchComparisonOff'),
() => this.setShowBranchComparison(false),
this,
);
}

protected filterConfigurationChanged(e: ConfigurationChangeEvent) {
Expand Down Expand Up @@ -367,6 +374,15 @@ export class CommitsView extends ViewBase<CommitsViewNode, CommitsViewConfig> {
return configuration.updateEffective('views', this.configKey, 'avatars', enabled);
}

private setShowBranchComparison(enabled: boolean) {
return configuration.updateEffective(
'views',
this.configKey,
'showBranchComparison',
enabled ? ViewShowBranchComparison.Working : false,
);
}

private setMyCommitsOnly(enabled: boolean) {
void setCommandContext(CommandContext.ViewsCommitsMyCommitsOnly, enabled);
this.state.myCommitsOnly = enabled;
Expand Down
10 changes: 9 additions & 1 deletion src/views/nodes/branchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { BranchTrackingStatusNode } from './branchTrackingStatusNode';
import { CommitNode } from './commitNode';
import { CommitsView } from '../commitsView';
import { LoadMoreNode, MessageNode } from './common';
import { ViewBranchesLayout } from '../../configuration';
import { CompareBranchNode } from './compareBranchNode';
import { ViewBranchesLayout, ViewShowBranchComparison } from '../../configuration';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { BranchDateFormatting, GitBranch, GitBranchReference, GitLog, GitRemoteType } from '../../git/git';
Expand All @@ -28,6 +29,7 @@ export class BranchNode
private _children: ViewNode[] | undefined;
private readonly options: {
expanded: boolean;
showComparison: false | ViewShowBranchComparison;
showCurrent: boolean;
showTracking: boolean;
authors?: string[];
Expand All @@ -44,6 +46,7 @@ export class BranchNode

options?: {
expanded?: boolean;
showComparison?: false | ViewShowBranchComparison;
showCurrent?: boolean;
showTracking?: boolean;
authors?: string[];
Expand All @@ -53,6 +56,7 @@ export class BranchNode

this.options = {
expanded: false,
showComparison: false,
// Hide the current branch checkmark when the node is displayed as a root under the repository node
showCurrent: !this.root,
// Don't show tracking info the node is displayed as a root under the repository node
Expand Down Expand Up @@ -131,6 +135,10 @@ export class BranchNode
new BranchTrackingStatusNode(this.view, this, this.branch, status, 'none', this.root),
);
}

if (this.options.showComparison !== false && this.view instanceof CommitsView) {
children.push(new CompareBranchNode(this.uri, this.view, this, this.branch));
}
}

const log = await this.getLog();
Expand Down
11 changes: 11 additions & 0 deletions src/views/nodes/compareBranchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ export class CompareBranchNode extends ViewNode<CommitsView | RepositoriesView>
return item;
}

@log()
async clear() {
if (this._compareWith == null) return;

this._compareWith = undefined;
await this.updateCompareWith(undefined);

this._children = undefined;
this.view.triggerNodeChange(this);
}

@log()
async setComparisonNotation(comparisonNotation: '...' | '..') {
if (this._compareWith !== undefined) {
Expand Down
4 changes: 4 additions & 0 deletions src/views/nodes/viewNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ export abstract class ViewRefFileNode<TView extends View = View> extends ViewRef
}
}

export function nodeSupportsClearing(node: ViewNode): node is ViewNode & { clear(): void | Promise<void> } {
return typeof (node as ViewNode & { clear(): void | Promise<void> }).clear === 'function';
}

export function nodeSupportsConditionalDismissal(node: ViewNode): node is ViewNode & { canDismiss(): boolean } {
return typeof (node as ViewNode & { canDismiss(): boolean }).canDismiss === 'function';
}
Expand Down
6 changes: 6 additions & 0 deletions src/views/viewCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
FileHistoryNode,
FolderNode,
LineHistoryNode,
nodeSupportsClearing,
PageableViewNode,
PagerNode,
RemoteNode,
Expand Down Expand Up @@ -84,6 +85,11 @@ export class ViewCommands {
(node: ViewNode) => node.view.reveal(node, { select: false, focus: false, expand: 3 }),
this,
);
commands.registerCommand(
'gitlens.views.clearNode',
(node: ViewNode) => nodeSupportsClearing(node) && node.clear(),
this,
);
commands.registerCommand(
'gitlens.views.dismissNode',
(node: ViewNode) => viewSupportsNodeDismissal(node.view) && node.view.dismissNode(node),
Expand Down

0 comments on commit 95ede42

Please sign in to comment.