mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-10 05:28:19 -05:00
git: basic status bar
This commit is contained in:
@@ -11,6 +11,7 @@ import { findGit, Git } from './git';
|
||||
import { Model } from './model';
|
||||
import { GitSCMProvider } from './scmProvider';
|
||||
import { registerCommands } from './commands';
|
||||
import { StatusBar } from './statusbar';
|
||||
import { filterEvent, anyEvent, throttle } from './util';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { decorate, debounce } from 'core-decorators';
|
||||
@@ -111,6 +112,8 @@ async function init(disposables: Disposable[]): Promise<void> {
|
||||
const watcher = new Watcher(model, onWorkspaceChange);
|
||||
const textDocumentContentProvider = new TextDocumentContentProvider(git, rootPath, onGitChange);
|
||||
|
||||
const statusBar = new StatusBar(model);
|
||||
|
||||
disposables.push(
|
||||
registerCommands(model),
|
||||
scm.registerSCMProvider('git', provider),
|
||||
@@ -118,7 +121,8 @@ async function init(disposables: Disposable[]): Promise<void> {
|
||||
textDocumentContentProvider,
|
||||
outputChannel,
|
||||
fsWatcher,
|
||||
watcher
|
||||
watcher,
|
||||
statusBar
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import { Uri, EventEmitter, Event, SCMResource, SCMResourceDecorations, SCMResourceGroup } from 'vscode';
|
||||
import { Repository, IRef, IRemote } from './git';
|
||||
import { throttle } from './util';
|
||||
import { decorate, debounce } from 'core-decorators';
|
||||
import { decorate } from 'core-decorators';
|
||||
import * as path from 'path';
|
||||
|
||||
const iconsRootPath = path.join(path.dirname(__dirname), 'resources', 'icons');
|
||||
|
||||
49
extensions/git/src/statusbar.ts
Normal file
49
extensions/git/src/statusbar.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { window, Disposable, StatusBarItem, StatusBarAlignment } from 'vscode';
|
||||
import { IRef, RefType } from './git';
|
||||
import { Model } from './model';
|
||||
|
||||
export class StatusBar {
|
||||
|
||||
private raw: StatusBarItem;
|
||||
private disposables: Disposable[] = [];
|
||||
|
||||
constructor(private model: Model) {
|
||||
this.raw = window.createStatusBarItem(StatusBarAlignment.Left);
|
||||
this.raw.show();
|
||||
|
||||
this.disposables.push(this.raw);
|
||||
model.onDidChange(this.update, this, this.disposables);
|
||||
this.update();
|
||||
}
|
||||
|
||||
private update(): void {
|
||||
const HEAD = this.model.HEAD;
|
||||
|
||||
if (!HEAD) {
|
||||
this.raw.color = 'rgb(100, 100, 100)';
|
||||
this.raw.text = 'unknown';
|
||||
return;
|
||||
}
|
||||
|
||||
const tag = this.model.refs.filter(iref => iref.type === RefType.Tag && iref.commit === HEAD.commit)[0];
|
||||
const tagName = tag && tag.name;
|
||||
const head = HEAD.name || tagName || (HEAD.commit || '').substr(0, 8);
|
||||
|
||||
this.raw.color = 'rgb(255, 255, 255)';
|
||||
this.raw.text = head +
|
||||
(this.model.workingTreeGroup.resources.length > 0 ? '*' : '') +
|
||||
(this.model.indexGroup.resources.length > 0 ? '+' : '') +
|
||||
(this.model.mergeGroup.resources.length > 0 ? '!' : '');
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.disposables.forEach(d => d.dispose());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user