Browse Source

Adds author toggle to commits view

main
Eric Amodio 4 years ago
parent
commit
98c7aeac6f
4 changed files with 69 additions and 1 deletions
  1. +30
    -0
      package.json
  2. +1
    -0
      src/constants.ts
  3. +35
    -1
      src/views/commitsView.ts
  4. +3
    -0
      src/views/nodes/branchNode.ts

+ 30
- 0
package.json View File

@ -3411,6 +3411,18 @@
"icon": "$(list-flat)"
},
{
"command": "gitlens.views.commits.setMyCommitsOnlyOn",
"title": "Toggle Authors (Everyone)",
"category": "GitLens",
"icon": "$(organization)"
},
{
"command": "gitlens.views.commits.setMyCommitsOnlyOff",
"title": "Toggle Authors (You)",
"category": "GitLens",
"icon": "$(person)"
},
{
"command": "gitlens.views.commits.setShowAvatarsOn",
"title": "Show Avatars",
"category": "GitLens"
@ -4630,6 +4642,14 @@
"when": "false"
},
{
"command": "gitlens.views.commits.setMyCommitsOnlyOn",
"when": "false"
},
{
"command": "gitlens.views.commits.setMyCommitsOnlyOff",
"when": "false"
},
{
"command": "gitlens.views.commits.setShowAvatarsOn",
"when": "false"
},
@ -5670,6 +5690,16 @@
"group": "navigation@13"
},
{
"command": "gitlens.views.commits.setMyCommitsOnlyOn",
"when": "view =~ /^gitlens\\.views\\.commits/ && !gitlens:views:commits:myCommitsOnly",
"group": "navigation@14"
},
{
"command": "gitlens.views.commits.setMyCommitsOnlyOff",
"when": "view =~ /^gitlens\\.views\\.commits/ && gitlens:views:commits:myCommitsOnly",
"group": "navigation@14"
},
{
"command": "gitlens.views.commits.refresh",
"when": "view =~ /^gitlens\\.views\\.commits/",
"group": "navigation@99"

+ 1
- 0
src/constants.ts View File

@ -40,6 +40,7 @@ export enum CommandContext {
Readonly = 'gitlens:readonly',
ViewsCanCompare = 'gitlens:views:canCompare',
ViewsCanCompareFile = 'gitlens:views:canCompare:file',
ViewsCommitsMyCommitsOnly = 'gitlens:views:commits:myCommitsOnly',
ViewsCompareKeepResults = 'gitlens:views:compare:keepResults',
ViewsFileHistoryCursorFollowing = 'gitlens:views:fileHistory:cursorFollowing',
ViewsFileHistoryEditorFollowing = 'gitlens:views:fileHistory:editorFollowing',

+ 35
- 1
src/views/commitsView.ts View File

@ -9,7 +9,7 @@ import {
window,
} from 'vscode';
import { CommitsViewConfig, configuration, ViewFilesLayout } from '../configuration';
import { GlyphChars } from '../constants';
import { CommandContext, GlyphChars, setCommandContext } from '../constants';
import { Container } from '../container';
import {
GitLogCommit,
@ -55,11 +55,20 @@ export class CommitsRepositoryNode extends SubscribeableViewNode {
const branch = await this.repo.getBranch();
if (branch == null) return [new MessageNode(this.view, this, 'No commits could be found.')];
let authors;
if (this.view.state.myCommitsOnly) {
const user = await Container.git.getCurrentUser(this.repo.path);
if (user != null) {
authors = [`^${user.name} <${user.email}>$`];
}
}
this.children = [
new BranchNode(this.uri, this.view, this, branch, true, {
expanded: true,
showCurrent: false,
showTracking: true,
authors: authors,
}),
];
@ -205,6 +214,10 @@ export class CommitsViewNode extends ViewNode {
}
}
interface CommitsViewState {
myCommitsOnly?: boolean;
}
export class CommitsView extends ViewBase<CommitsViewNode, CommitsViewConfig> {
protected readonly configKey = 'commits';
@ -212,6 +225,11 @@ export class CommitsView extends ViewBase {
super('gitlens.views.commits', 'Commits');
}
private readonly _state: CommitsViewState = {};
get state(): CommitsViewState {
return this._state;
}
getRoot() {
return new CommitsViewNode(this);
}
@ -240,6 +258,16 @@ export class CommitsView extends ViewBase {
() => this.setFilesLayout(ViewFilesLayout.Tree),
this,
);
commands.registerCommand(
this.getQualifiedCommand('setMyCommitsOnlyOn'),
() => this.setMyCommitsOnly(true),
this,
);
commands.registerCommand(
this.getQualifiedCommand('setMyCommitsOnlyOff'),
() => this.setMyCommitsOnly(false),
this,
);
commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this);
commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this);
}
@ -338,4 +366,10 @@ export class CommitsView extends ViewBase {
private setShowAvatars(enabled: boolean) {
return configuration.updateEffective('views', this.configKey, 'avatars', enabled);
}
private setMyCommitsOnly(enabled: boolean) {
void setCommandContext(CommandContext.ViewsCommitsMyCommitsOnly, enabled);
this.state.myCommitsOnly = enabled;
void this.refresh(true);
}
}

+ 3
- 0
src/views/nodes/branchNode.ts View File

@ -30,6 +30,7 @@ export class BranchNode
expanded: boolean;
showCurrent: boolean;
showTracking: boolean;
authors?: string[];
};
protected splatted = true;
@ -45,6 +46,7 @@ export class BranchNode
expanded?: boolean;
showCurrent?: boolean;
showTracking?: boolean;
authors?: string[];
},
) {
super(uri, view, parent);
@ -271,6 +273,7 @@ export class BranchNode
this._log = await Container.git.getLog(this.uri.repoPath!, {
limit: this.limit ?? this.view.config.defaultItemLimit,
ref: this.ref.ref,
authors: this.options?.authors,
});
}

Loading…
Cancel
Save