diff --git a/examples/browser/package.json b/examples/browser/package.json index 2fa43a2721bf0..dc638c99a5746 100644 --- a/examples/browser/package.json +++ b/examples/browser/package.json @@ -26,7 +26,6 @@ "@theia/file-search": "^0.10.0", "@theia/filesystem": "^0.10.0", "@theia/getting-started": "^0.10.0", - "@theia/git": "^0.10.0", "@theia/java": "^0.10.0", "@theia/java-debug": "^0.10.0", "@theia/json": "^0.10.0", diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index c1a2cace8f09e..432cf762d4451 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -565,6 +565,7 @@ export interface ScmExt { $updateInputBox(sourceControlHandle: number, message: string): Promise; $executeResourceCommand(sourceControlHandle: number, groupHandle: number, resourceHandle: number): Promise; $provideOriginalResource(sourceControlHandle: number, uri: string, token: CancellationToken): Promise; + $setSourceControlSelection(sourceControlHandle: number, selected: boolean): Promise; } export interface DecorationsExt { diff --git a/packages/plugin-ext/src/main/browser/scm-main.ts b/packages/plugin-ext/src/main/browser/scm-main.ts index 2e4bbc525a548..cbe4ef8f9dff9 100644 --- a/packages/plugin-ext/src/main/browser/scm-main.ts +++ b/packages/plugin-ext/src/main/browser/scm-main.ts @@ -37,12 +37,32 @@ export class ScmMainImpl implements ScmMain { private readonly scmService: ScmService; private readonly scmRepositoryMap: Map; private readonly labelProvider: LabelProvider; + private lastSelectedSourceControlHandle: number | undefined; constructor(rpc: RPCProtocol, container: interfaces.Container) { this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.SCM_EXT); this.scmService = container.get(ScmService); this.scmRepositoryMap = new Map(); this.labelProvider = container.get(LabelProvider); + this.scmService.onDidChangeSelectedRepository(repository => this.updateSelectedRepository(repository)); + } + + protected updateSelectedRepository(repository: ScmRepository | undefined): void { + const sourceControlHandle = repository ? this.getSourceControlHandle(repository) : undefined; + if (sourceControlHandle !== undefined) { + this.proxy.$setSourceControlSelection(sourceControlHandle, true); + } + if (this.lastSelectedSourceControlHandle !== undefined && this.lastSelectedSourceControlHandle !== sourceControlHandle) { + this.proxy.$setSourceControlSelection(this.lastSelectedSourceControlHandle, false); + } + this.lastSelectedSourceControlHandle = sourceControlHandle; + } + + protected getSourceControlHandle(repository: ScmRepository): number | undefined { + return Array.from(this.scmRepositoryMap.keys()).find(key => { + const scmRepository = this.scmRepositoryMap.get(key); + return scmRepository !== undefined && scmRepository.provider.rootUri === repository.provider.rootUri; + }); } async $registerSourceControl(sourceControlHandle: number, id: string, label: string, rootUri: string): Promise { @@ -52,6 +72,9 @@ export class ScmMainImpl implements ScmMain { this.proxy.$updateInputBox(sourceControlHandle, repository.input.value) ); this.scmRepositoryMap.set(sourceControlHandle, repository); + if (this.scmService.repositories.length === 1) { + this.updateSelectedRepository(repository); + } } async $updateSourceControl(sourceControlHandle: number, features: SourceControlProviderFeatures): Promise { diff --git a/packages/plugin-ext/src/plugin/scm.ts b/packages/plugin-ext/src/plugin/scm.ts index eeb2a2005451c..0214df40710bd 100644 --- a/packages/plugin-ext/src/plugin/scm.ts +++ b/packages/plugin-ext/src/plugin/scm.ts @@ -23,6 +23,7 @@ import { UriComponents } from '../common/uri-components'; import URI from '@theia/core/lib/common/uri'; import { CommandRegistryImpl } from './command-registry'; import { ScmCommand } from '@theia/scm/lib/browser/scm-provider'; +import { Emitter } from '@theia/core/lib/common/event'; export class ScmExtImpl implements ScmExt { private handle: number = 0; @@ -97,6 +98,13 @@ export class ScmExtImpl implements ScmExt { sourceControl.inputBox.$updateValue(value); } } + + async $setSourceControlSelection(sourceControlHandle: number, selected: boolean): Promise { + const sourceControl = this.sourceControlMap.get(sourceControlHandle); + if (sourceControl) { + sourceControl.selected = selected; + } + } } class InputBoxImpl implements theia.SourceControlInputBox { @@ -142,9 +150,13 @@ class SourceControlImpl implements theia.SourceControl { private _commitTemplate: string | undefined; private _acceptInputCommand: theia.Command | undefined; private _statusBarCommands: theia.Command[] | undefined; + private _selected: boolean = false; private readonly toDispose = new DisposableCollection(); + private readonly onDidChangeSelectionEmitter = new Emitter(); + readonly onDidChangeSelection: theia.Event = this.onDidChangeSelectionEmitter.event; + constructor( private proxy: ScmMain, private commands: CommandRegistryImpl, @@ -254,6 +266,15 @@ class SourceControlImpl implements theia.SourceControl { getResourceGroup(handle: number): SourceControlResourceGroupImpl | undefined { return this.resourceGroupsMap.get(handle); } + + get selected(): boolean { + return this._selected; + } + + set selected(selected: boolean) { + this._selected = selected; + this.onDidChangeSelectionEmitter.fire(selected); + } } class SourceControlResourceGroupImpl implements theia.SourceControlResourceGroup { diff --git a/packages/plugin/src/theia-proposed.d.ts b/packages/plugin/src/theia-proposed.d.ts index 010cee6f60a88..1175ab7c90304 100644 --- a/packages/plugin/src/theia-proposed.d.ts +++ b/packages/plugin/src/theia-proposed.d.ts @@ -131,12 +131,6 @@ declare module '@theia/plugin' { value: string; } - export interface SourceControlResourceDecorations { - source?: string; - letter?: string; - color?: ThemeColor; - } - /** * Enumeration of the supported operating systems. */ @@ -172,6 +166,19 @@ declare module '@theia/plugin' { source?: string; } + export interface SourceControl { + + /** + * Whether the source control is selected. + */ + readonly selected: boolean; + + /** + * An event signaling when the selection state changes. + */ + readonly onDidChangeSelection: Event; + } + export interface SourceControlResourceDecorations { source?: string; letter?: string;