Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract stash explorer #94

Merged
merged 2 commits into from Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -1370,6 +1370,10 @@
{
"id": "gitlens-explorer",
"name": "GitLens Explorer"
},
{
"id": "gitstash-explorer",
"name": "Git Stashes"
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/showStashList.ts
@@ -1,14 +1,14 @@
'use strict';
import { TextEditor, TextEditorEdit, Uri, window } from 'vscode';
import { Commands, EditorCommand, getCommandUri } from './common';
import { GitExplorer } from '../views/gitExplorer';
import { StashExplorer } from '../views/stashExplorer';
import { GitService, GitUri } from '../gitService';
import { Messages } from '../messages';
import { Logger } from '../logger';

export class ShowStashListCommand extends EditorCommand {

constructor(private git: GitService, private explorer: GitExplorer) {
constructor(private git: GitService, private explorer: StashExplorer) {
super(Commands.ShowStashList);
}

Expand All @@ -19,7 +19,7 @@ export class ShowStashListCommand extends EditorCommand {
const repoPath = await this.git.getRepoPathFromUri(uri);
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to show stashed changes`);

this.explorer.addStash(new GitUri(uri, { repoPath: repoPath, fileName: uri!.fsPath }));
this.explorer.update(new GitUri(uri, { repoPath: repoPath, fileName: uri!.fsPath }));
return undefined;
}
catch (ex) {
Expand Down
10 changes: 7 additions & 3 deletions src/extension.ts
Expand Up @@ -20,6 +20,7 @@ import { ApplicationInsightsKey, CommandContext, ExtensionKey, QualifiedExtensio
import { CurrentLineController, LineAnnotationType } from './currentLineController';
import { GitContentProvider } from './gitContentProvider';
import { GitExplorer } from './views/gitExplorer';
import { StashExplorer } from './views/stashExplorer';
import { GitRevisionCodeLensProvider } from './gitRevisionCodeLensProvider';
import { GitContextTracker, GitService } from './gitService';
import { Keyboard } from './keyboard';
Expand Down Expand Up @@ -93,6 +94,12 @@ export async function activate(context: ExtensionContext) {
explorer = new GitExplorer(context, git);
context.subscriptions.push(window.registerTreeDataProvider('gitlens-explorer', explorer));
}
let stashExplorer;
if (cfg.insiders) {
stashExplorer = new StashExplorer(context, git);
context.subscriptions.push(window.registerTreeDataProvider('gitstash-explorer', stashExplorer));
context.subscriptions.push(new ShowStashListCommand(git, stashExplorer!));
}

context.subscriptions.push(new CloseUnchangedFilesCommand(git));
context.subscriptions.push(new OpenChangedFilesCommand(git));
Expand Down Expand Up @@ -127,9 +134,6 @@ export async function activate(context: ExtensionContext) {
context.subscriptions.push(new ShowQuickFileHistoryCommand(git));
context.subscriptions.push(new ShowQuickRepoStatusCommand(git));
context.subscriptions.push(new ShowQuickStashListCommand(git));
if (cfg.insiders) {
context.subscriptions.push(new ShowStashListCommand(git, explorer!));
}
context.subscriptions.push(new StashApplyCommand(git));
context.subscriptions.push(new StashDeleteCommand(git));
context.subscriptions.push(new StashSaveCommand(git));
Expand Down
2 changes: 0 additions & 2 deletions src/views/repositoryNode.ts
Expand Up @@ -5,7 +5,6 @@ import { CommitNode } from './commitNode';
import { GlyphChars } from '../constants';
import { ExplorerNode, ResourceType } from './explorerNode';
import { GitBranch, GitService, GitUri } from '../gitService';
import { StashNode } from './stashNode';

export class RepositoryNode extends ExplorerNode {

Expand All @@ -19,7 +18,6 @@ export class RepositoryNode extends ExplorerNode {
async getChildren(): Promise<ExplorerNode[]> {
return [
new StatusNode(this.uri, this.context, this.git),
new StashNode(this.uri, this.context, this.git),
new BranchesNode(this.uri, this.context, this.git)
];
}
Expand Down
43 changes: 43 additions & 0 deletions src/views/stashExplorer.ts
@@ -0,0 +1,43 @@
'use strict';
import { Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri, window } from 'vscode';
import { ExplorerNode, StashNode } from './gitExplorerNodes';
import { GitService, GitUri } from '../gitService';
import { StashCommitNode } from './stashCommitNode';

export * from './gitExplorerNodes';

export class StashExplorer implements TreeDataProvider<ExplorerNode> {
private _node: ExplorerNode;
private _onDidChangeTreeData = new EventEmitter<ExplorerNode>();
public get onDidChangeTreeData(): Event<StashCommitNode> {
return this._onDidChangeTreeData.event;
}

constructor(private context: ExtensionContext, private git: GitService) {
const editor = window.activeTextEditor;

const uri = (editor !== undefined && editor.document !== undefined)
? new GitUri(editor.document.uri, { repoPath: git.repoPath, fileName: editor.document.uri.fsPath })
: new GitUri(Uri.file(git.repoPath), { repoPath: git.repoPath, fileName: git.repoPath });

this._node = new StashNode(uri, this.context, this.git);
}

async getTreeItem(node: ExplorerNode): Promise<TreeItem> {
return node.getTreeItem();
}

async getChildren(node?: ExplorerNode): Promise<ExplorerNode[]> {
if (node === undefined) return this._node.getChildren();
return node.getChildren();
}

update(uri: GitUri) {
this._node = new StashNode(uri, this.context, this.git);
this.refresh();
}

refresh() {
this._onDidChangeTreeData.fire();
}
}