|
|
@ -1,32 +1,39 @@ |
|
|
|
'use strict'; |
|
|
|
import { TreeItem, TreeItemCollapsibleState } from 'vscode'; |
|
|
|
import { NamedRef, PinnedComparisons, WorkspaceState } from '../../constants'; |
|
|
|
import { Container } from '../../container'; |
|
|
|
import { GitService, GitUri } from '../../git/gitService'; |
|
|
|
import { Strings } from '../../system'; |
|
|
|
import { ViewWithFiles } from '../viewBase'; |
|
|
|
import { log, Strings } from '../../system'; |
|
|
|
import { CompareView } from '../compareView'; |
|
|
|
import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode'; |
|
|
|
import { ResultsFilesNode } from './resultsFilesNode'; |
|
|
|
import { NamedRef, ResourceType, ViewNode } from './viewNode'; |
|
|
|
import { ResourceType, ViewNode } from './viewNode'; |
|
|
|
|
|
|
|
export class CompareResultsNode extends ViewNode<ViewWithFiles> { |
|
|
|
export class CompareResultsNode extends ViewNode<CompareView> { |
|
|
|
constructor( |
|
|
|
view: ViewWithFiles, |
|
|
|
view: CompareView, |
|
|
|
public readonly repoPath: string, |
|
|
|
ref1: NamedRef, |
|
|
|
ref2: NamedRef |
|
|
|
private _ref1: NamedRef, |
|
|
|
private _ref2: NamedRef, |
|
|
|
private _pinned: boolean = false |
|
|
|
) { |
|
|
|
super(GitUri.fromRepoPath(repoPath), view); |
|
|
|
} |
|
|
|
|
|
|
|
get label() { |
|
|
|
return `Comparing ${this._ref1.label || |
|
|
|
GitService.shortenSha(this._ref1.ref, { working: 'Working Tree' })} to ${this._ref2.label || |
|
|
|
GitService.shortenSha(this._ref2.ref, { working: 'Working Tree' })}`;
|
|
|
|
} |
|
|
|
|
|
|
|
this._ref1 = ref1; |
|
|
|
this._ref2 = ref2; |
|
|
|
get pinned(): boolean { |
|
|
|
return this._pinned; |
|
|
|
} |
|
|
|
|
|
|
|
private _ref1: NamedRef; |
|
|
|
get ref1(): NamedRef { |
|
|
|
return this._ref1; |
|
|
|
} |
|
|
|
|
|
|
|
private _ref2: NamedRef; |
|
|
|
get ref2(): NamedRef { |
|
|
|
return this._ref2; |
|
|
|
} |
|
|
@ -45,23 +52,69 @@ export class CompareResultsNode extends ViewNode { |
|
|
|
description = (repo && repo.formattedName) || this.uri.repoPath; |
|
|
|
} |
|
|
|
|
|
|
|
const item = new TreeItem( |
|
|
|
`Comparing ${this._ref1.label || |
|
|
|
GitService.shortenSha(this._ref1.ref, { working: 'Working Tree' })} to ${this._ref2.label || |
|
|
|
GitService.shortenSha(this._ref2.ref, { working: 'Working Tree' })}`,
|
|
|
|
TreeItemCollapsibleState.Collapsed |
|
|
|
); |
|
|
|
const item = new TreeItem(this.label, TreeItemCollapsibleState.Collapsed); |
|
|
|
item.contextValue = ResourceType.CompareResults; |
|
|
|
if (this._pinned) { |
|
|
|
item.contextValue += '+pinned'; |
|
|
|
} |
|
|
|
item.description = description; |
|
|
|
if (this._pinned) { |
|
|
|
item.iconPath = { |
|
|
|
dark: Container.context.asAbsolutePath(`images/dark/icon-pinned.svg`), |
|
|
|
light: Container.context.asAbsolutePath(`images/light/icon-pinned.svg`) |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
return item; |
|
|
|
} |
|
|
|
|
|
|
|
swap() { |
|
|
|
canDismiss(): boolean { |
|
|
|
return !this._pinned; |
|
|
|
} |
|
|
|
|
|
|
|
@log() |
|
|
|
async pin() { |
|
|
|
if (this._pinned) return; |
|
|
|
|
|
|
|
await this.view.updatePinnedComparison(this.getPinnableId(), { |
|
|
|
path: this.repoPath, |
|
|
|
ref1: this.ref1, |
|
|
|
ref2: this.ref2 |
|
|
|
}); |
|
|
|
|
|
|
|
this._pinned = true; |
|
|
|
void this.triggerChange(); |
|
|
|
} |
|
|
|
|
|
|
|
@log() |
|
|
|
async unpin() { |
|
|
|
if (!this._pinned) return; |
|
|
|
|
|
|
|
await this.view.updatePinnedComparison(this.getPinnableId()); |
|
|
|
|
|
|
|
this._pinned = false; |
|
|
|
void this.triggerChange(); |
|
|
|
} |
|
|
|
|
|
|
|
@log() |
|
|
|
async swap() { |
|
|
|
// Save the current id so we can update it later
|
|
|
|
const currentId = this.getPinnableId(); |
|
|
|
|
|
|
|
const ref1 = this._ref1; |
|
|
|
this._ref1 = this._ref2; |
|
|
|
this._ref2 = ref1; |
|
|
|
|
|
|
|
// If we were pinned, remove the existing pin and save a new one
|
|
|
|
if (this._pinned) { |
|
|
|
await this.view.updatePinnedComparison(currentId); |
|
|
|
await this.view.updatePinnedComparison(this.getPinnableId(), { |
|
|
|
path: this.repoPath, |
|
|
|
ref1: this.ref1, |
|
|
|
ref2: this.ref2 |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
this.view.triggerNodeChange(this); |
|
|
|
} |
|
|
|
|
|
|
@ -81,4 +134,8 @@ export class CompareResultsNode extends ViewNode { |
|
|
|
log: log |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private getPinnableId() { |
|
|
|
return Strings.sha1(`${this.repoPath}|${this.ref1.ref}|${this.ref2.ref}`); |
|
|
|
} |
|
|
|
} |