Selaa lähdekoodia

Reworks viewItem contextValues to make is easier to have multiple states

main
Eric Amodio 5 vuotta sitten
vanhempi
commit
fbe0c7c203
7 muutettua tiedostoa jossa 71 lisäystä ja 69 poistoa
  1. +39
    -39
      package.json
  2. +13
    -8
      src/views/nodes/branchNode.ts
  3. +5
    -4
      src/views/nodes/branchesNode.ts
  4. +2
    -2
      src/views/nodes/commitFileNode.ts
  5. +4
    -2
      src/views/nodes/commitNode.ts
  6. +7
    -5
      src/views/nodes/statusFileNode.ts
  7. +1
    -9
      src/views/nodes/viewNode.ts

+ 39
- 39
package.json Näytä tiedosto

@ -3789,58 +3789,58 @@
"view/item/context": [
{
"command": "gitlens.openBranchesInRemote",
"when": "viewItem == gitlens:branches:remotes",
"when": "viewItem =~ /gitlens:branches\\b.*?\\+remotes\\b.*?/",
"group": "inline@98"
},
{
"command": "gitlens.openBranchesInRemote",
"when": "viewItem == gitlens:branches:remotes",
"when": "viewItem =~ /gitlens:branches\\b.*?\\+remotes\\b.*?/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.checkout",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!:current)\\b/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\+current\\b.*?)/",
"group": "inline@10"
},
{
"command": "gitlens.views.compareWithRemote",
"when": "viewItem =~ /gitlens:branch\\b.*?:tracking/",
"when": "viewItem =~ /gitlens:branch\\b.*?\\+tracking\\b.*?/",
"group": "inline@96"
},
{
"command": "gitlens.views.compareWithHead",
"when": "viewItem =~ /gitlens:(branch(?!:current)|commit|stash|tag)\\b/",
"when": "viewItem =~ /gitlens:(branch\\b(?!.*?\\+current\\b.*?)|commit\\b|stash\\b|tag\\b)/",
"group": "inline@97",
"alt": "gitlens.views.compareWithWorking"
},
{
"command": "gitlens.views.compareWithWorking",
"when": "viewItem =~ /gitlens:branch:current\\b/",
"when": "viewItem =~ /gitlens:branch\\b.*?\\+current\\b.*?/",
"group": "inline@97"
},
{
"command": "gitlens.openBranchInRemote",
"when": "viewItem =~ /gitlens:branch\\b(.*?:tracking|:remote)/",
"when": "viewItem =~ /gitlens:branch\\b.*?\\+(tracking|remote)\\b.*?/",
"group": "inline@98"
},
{
"command": "gitlens.views.checkout",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!:current)\\b/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\+current\\b.*?)/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.openBranchInRemote",
"when": "viewItem =~ /gitlens:branch\\b(.*?:tracking|:remote)/",
"when": "viewItem =~ /gitlens:branch\\b.*?\\+(tracking|remote)\\b.*?/",
"group": "2_gitlens@1"
},
{
"command": "gitlens.views.compareWithRemote",
"when": "viewItem =~ /gitlens:(branch\\b.*?:tracking)/",
"when": "viewItem =~ /gitlens:branch\\b.*?\\+tracking\\b.*?/",
"group": "7_gitlens@1"
},
{
"command": "gitlens.views.compareWithHead",
"when": "viewItem =~ /gitlens:(branch(?!:current)|commit|stash|tag)\\b/",
"when": "viewItem =~ /gitlens:(branch\\b(?!.*?\\+current\\b.*?)|commit\\b|stash\\b|tag\\b)/",
"group": "7_gitlens@2"
},
{
@ -3850,7 +3850,7 @@
},
{
"command": "gitlens.views.compareAncestryWithWorking",
"when": "viewItem =~ /gitlens:branch(?!:current)\\b/",
"when": "viewItem =~ /gitlens:branch\\b(?!.*?\\+current\\b.*?)/",
"group": "7_gitlens@4"
},
{
@ -3880,27 +3880,27 @@
},
{
"command": "gitlens.views.terminalCheckoutBranch",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!:current)/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\+current\\b.*?)//",
"group": "8_gitlens@1"
},
{
"command": "gitlens.views.terminalRebaseBranchToRemote",
"when": "!gitlens:readonly && viewItem =~ /gitlens:(branch:current:tracking)\\b/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b.*?\\+current\\b.*?\\+tracking\\b.*?/",
"group": "8_gitlens@1"
},
{
"command": "gitlens.views.terminalMergeBranch",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!:current)/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\+current\\b.*?)/",
"group": "8_gitlens@2"
},
{
"command": "gitlens.views.terminalRebaseBranch",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!:current)/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\+current\\b.*?)/",
"group": "8_gitlens@3"
},
{
"command": "gitlens.views.terminalSquashBranchIntoCommit",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!:current)/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\+current\\b.*?)/",
"group": "8_gitlens@4"
},
{
@ -3910,7 +3910,7 @@
},
{
"command": "gitlens.views.terminalDeleteBranch",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!:current)/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b(?!.*?\\+current\\b.*?)/",
"group": "8_gitlens@6"
},
{
@ -3981,12 +3981,12 @@
},
{
"command": "gitlens.views.terminalPushCommit",
"when": "!gitlens:readonly && viewItem == gitlens:commit:current",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b.*?\\+current\\b.*?/",
"group": "8_gitlens@2"
},
{
"command": "gitlens.views.terminalRevertCommit",
"when": "!gitlens:readonly && viewItem == gitlens:commit:current",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b.*?\\+current\\b.*?/",
"group": "8_gitlens@3"
},
{
@ -4011,27 +4011,27 @@
},
{
"command": "gitlens.views.stageFile",
"when": "viewItem =~ /gitlens:file\\b.*:unstaged\\b/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b.*?\\+unstaged\\b.*?/",
"group": "inline@1"
},
{
"command": "gitlens.views.unstageFile",
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b.*:staged\\b/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b.*?\\+staged\\b.*?/",
"group": "inline@1"
},
{
"command": "gitlens.views.stageFile",
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b.*:unstaged\\b/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b.*?\\+unstaged\\b.*?/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.unstageFile",
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b.*:staged\\b/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b.*?\\+staged\\b.*?/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.stashSaveFiles",
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b.*:(un)?staged\\b/",
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b.*?\\+(un)?staged\\b.*?/",
"group": "1_gitlens@2"
},
{
@ -4061,7 +4061,7 @@
},
{
"command": "gitlens.openFileInRemote",
"when": "viewItem =~ /gitlens:(file(?!:(un)?staged)|history:(file|line))\\b/ && gitlens:hasRemotes",
"when": "viewItem =~ /gitlens:(file\\b(?!.*?\\+(un)?staged\\b.*?)|history:(file|line))\\b/ && gitlens:hasRemotes",
"group": "inline@99",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
},
@ -4152,43 +4152,43 @@
},
{
"command": "gitlens.showCommitSearch",
"when": "viewItem == gitlens:repository",
"when": "viewItem =~ /gitlens:repository\\b/",
"group": "inline@1"
},
{
"command": "gitlens.views.push",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem == gitlens:repository",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repository\\b/",
"group": "inline@97",
"alt": "gitlens.views.pushWithForce"
},
{
"command": "gitlens.views.pull",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem == gitlens:repository",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repository\\b/",
"group": "inline@98"
},
{
"command": "gitlens.views.fetch",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem == gitlens:repository",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repository\\b/",
"group": "inline@99"
},
{
"command": "gitlens.views.fetch",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem == gitlens:repository",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repository\\b/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.pull",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem == gitlens:repository",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repository\\b/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.push",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem == gitlens:repository",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repository\\b/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.pushWithForce",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem == gitlens:repository",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repository\\b/",
"group": "1_gitlens@2"
},
{
@ -4219,27 +4219,27 @@
},
{
"command": "gitlens.showCommitSearch",
"when": "viewItem == gitlens:repository",
"when": "viewItem =~ /gitlens:repository\\b/",
"group": "2_gitlens@1"
},
{
"command": "gitlens.stashApply",
"when": "!gitlens:readonly && viewItem == gitlens:repository",
"when": "!gitlens:readonly && viewItem =~ /gitlens:repository\\b/",
"group": "3_gitlens@1"
},
{
"command": "gitlens.stashSave",
"when": "!gitlens:readonly && viewItem == gitlens:repository",
"when": "!gitlens:readonly && viewItem =~ /gitlens:repository\\b/",
"group": "3_gitlens@2"
},
{
"command": "gitlens.openRepoInRemote",
"when": "viewItem == gitlens:repository && gitlens:hasRemotes",
"when": "viewItem =~ /gitlens:repository\\b/ && gitlens:hasRemotes",
"group": "4_gitlens@1"
},
{
"command": "gitlens.views.closeRepository",
"when": "viewItem == gitlens:repository",
"when": "viewItem =~ /gitlens:repository\\b/",
"group": "8_gitlens@1"
},
{

+ 13
- 8
src/views/nodes/branchNode.ts Näytä tiedosto

@ -4,7 +4,7 @@ import { ViewBranchesLayout } from '../../configuration';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { GitBranch, GitUri } from '../../git/gitService';
import { Iterables } from '../../system';
import { debug, gate, Iterables } from '../../system';
import { RepositoriesView } from '../repositoriesView';
import { BranchTrackingStatusNode } from './branchTrackingStatusNode';
import { CommitNode } from './commitNode';
@ -129,30 +129,35 @@ export class BranchNode extends ViewRefNode implements Pageabl
`${!this._root && this.current ? `${GlyphChars.Check} ${GlyphChars.Space}` : ''}${name}`,
TreeItemCollapsibleState.Collapsed
);
item.description = description;
item.id = this.id;
item.tooltip = tooltip;
item.contextValue = ResourceType.Branch;
if (this.current) {
item.contextValue += '+current';
}
if (this.branch.remote) {
item.contextValue = ResourceType.RemoteBranch;
item.contextValue += '+remote';
}
else if (this.current) {
item.contextValue = this.branch.tracking
? ResourceType.CurrentBranchWithTracking
: ResourceType.CurrentBranch;
}
else {
item.contextValue = this.branch.tracking ? ResourceType.BranchWithTracking : ResourceType.Branch;
if (this.branch.tracking) {
item.contextValue += '+tracking';
}
item.description = description;
item.iconPath = {
dark: Container.context.asAbsolutePath(`images/dark/icon-branch${iconSuffix}.svg`),
light: Container.context.asAbsolutePath(`images/light/icon-branch${iconSuffix}.svg`)
};
item.id = this.id;
item.tooltip = tooltip;
return item;
}
@gate()
@debug()
refresh() {
this._children = undefined;
}

+ 5
- 4
src/views/nodes/branchesNode.ts Näytä tiedosto

@ -57,14 +57,15 @@ export class BranchesNode extends ViewNode {
const remotes = await this.repo.getRemotes();
const item = new TreeItem(`Branches`, TreeItemCollapsibleState.Collapsed);
item.id = this.id;
item.contextValue =
remotes !== undefined && remotes.length > 0 ? ResourceType.BranchesWithRemotes : ResourceType.Branches;
item.contextValue = ResourceType.Branches;
if (remotes !== undefined && remotes.length > 0) {
item.contextValue += '+remotes';
}
item.iconPath = {
dark: Container.context.asAbsolutePath('images/dark/icon-branch.svg'),
light: Container.context.asAbsolutePath('images/light/icon-branch.svg')
};
item.id = this.id;
return item;
}

+ 2
- 2
src/views/nodes/commitFileNode.ts Näytä tiedosto

@ -151,10 +151,10 @@ export class CommitFileNode extends ViewRefNode {
this._tooltip = undefined;
}
protected get resourceType(): ResourceType {
protected get resourceType(): string {
if (!this.commit.isUncommitted) return ResourceType.CommitFile;
return this.commit.isStagedUncommitted ? ResourceType.FileStaged : ResourceType.FileUnstaged;
return this.commit.isStagedUncommitted ? `${ResourceType.File}+staged` : `${ResourceType.File}+unstaged`;
}
private _tooltip: string | undefined;

+ 4
- 2
src/views/nodes/commitNode.ts Näytä tiedosto

@ -69,8 +69,10 @@ export class CommitNode extends ViewRefNode {
}
const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed);
item.contextValue =
this.branch === undefined || this.branch.current ? ResourceType.CommitOnCurrentBranch : ResourceType.Commit;
item.contextValue = ResourceType.Commit;
if (this.branch === undefined || this.branch.current) {
item.contextValue += '+current';
}
item.description = CommitFormatter.fromTemplate(this.view.config.commitDescriptionFormat, this.commit, {
truncateMessageAtNewLine: true,
dateFormat: Container.config.defaultDateFormat

+ 7
- 5
src/views/nodes/statusFileNode.ts Näytä tiedosto

@ -62,15 +62,16 @@ export class StatusFileNode extends ViewNode {
item.description = this.description;
if ((this._hasStagedChanges || this._hasUnstagedChanges) && this.commits.length === 1) {
item.contextValue = ResourceType.File;
if (this._hasStagedChanges) {
item.contextValue = ResourceType.FileStaged;
item.contextValue += '+staged';
item.tooltip = StatusFileFormatter.fromTemplate(
'${file}\n${directory}/\n\n${status} in Index (staged)',
this.file
);
}
else {
item.contextValue = ResourceType.FileUnstaged;
item.contextValue += '+unstaged';
item.tooltip = StatusFileFormatter.fromTemplate(
'${file}\n${directory}/\n\n${status} in Working Tree',
this.file
@ -86,14 +87,15 @@ export class StatusFileNode extends ViewNode {
else {
item.collapsibleState = TreeItemCollapsibleState.Collapsed;
if (this._hasStagedChanges || this._hasUnstagedChanges) {
item.contextValue = ResourceType.File;
if (this._hasStagedChanges && this._hasUnstagedChanges) {
item.contextValue = ResourceType.FileStagedAndUnstaged;
item.contextValue += '+staged+unstaged';
}
else if (this._hasStagedChanges) {
item.contextValue = ResourceType.FileStaged;
item.contextValue += '+staged';
}
else {
item.contextValue = ResourceType.FileUnstaged;
item.contextValue += '+unstaged';
}
// Use the file icon and decorations

+ 1
- 9
src/views/nodes/viewNode.ts Näytä tiedosto

@ -10,25 +10,17 @@ export enum ResourceType {
ActiveLineHistory = 'gitlens:history:active:line',
Branch = 'gitlens:branch',
Branches = 'gitlens:branches',
BranchesWithRemotes = 'gitlens:branches:remotes',
BranchStatusAheadOfUpstream = 'gitlens:branch-status:upstream:ahead',
BranchStatusBehindUpstream = 'gitlens:branch-status:upstream:behind',
BranchWithTracking = 'gitlens:branch:tracking',
CurrentBranch = 'gitlens:branch:current',
CurrentBranchWithTracking = 'gitlens:branch:current:tracking',
RemoteBranch = 'gitlens:branch:remote',
Commit = 'gitlens:commit',
CommitOnCurrentBranch = 'gitlens:commit:current',
CommitFile = 'gitlens:file:commit',
Commits = 'gitlens:commits',
Compare = 'gitlens:compare',
ComparePicker = 'gitlens:compare:picker',
ComparePickerWithRef = 'gitlens:compare:picker:ref',
CompareResults = 'gitlens:compare:results',
File = 'gitlens:file',
FileHistory = 'gitlens:history:file',
FileStaged = 'gitlens:file:staged',
FileStagedAndUnstaged = 'gitlens:file:staged:unstaged',
FileUnstaged = 'gitlens:file:unstaged',
Folder = 'gitlens:folder',
LineHistory = 'gitlens:history:line',
Message = 'gitlens:message',

Ladataan…
Peruuta
Tallenna