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

Workbench - add activeRepositoryName and activeRepositoryBranchName variables #204393

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export class SettingsDocument {
completions.push(this.newSimpleCompletionItem(getText('appName'), range, vscode.l10n.t("e.g. VS Code")));
completions.push(this.newSimpleCompletionItem(getText('remoteName'), range, vscode.l10n.t("e.g. SSH")));
completions.push(this.newSimpleCompletionItem(getText('dirty'), range, vscode.l10n.t("an indicator for when the active editor has unsaved changes")));
completions.push(this.newSimpleCompletionItem(getText('activeRepositoryName'), range, vscode.l10n.t("the name of the active repository (e.g. vscode)")));
completions.push(this.newSimpleCompletionItem(getText('activeRepositoryBranchName'), range, vscode.l10n.t("the name of the active branch in the active repository (e.g. main)")));
completions.push(this.newSimpleCompletionItem(getText('separator'), range, vscode.l10n.t("a conditional separator (' - ') that only shows when surrounded by variables with values")));

return completions;
Expand Down
15 changes: 15 additions & 0 deletions src/vs/workbench/browser/parts/titlebar/windowTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { getVirtualWorkspaceLocation } from 'vs/platform/workspace/common/virtua
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
import { IViewsService } from 'vs/workbench/services/views/common/viewsService';
import { ICodeEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';

const enum WindowSettingNames {
titleSeparator = 'window.titleSeparator',
Expand Down Expand Up @@ -66,6 +67,7 @@ export class WindowTitle extends Disposable {
private readonly targetWindow: Window,
editorGroupsContainer: IEditorGroupsContainer | 'main',
@IConfigurationService protected readonly configurationService: IConfigurationService,
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IEditorService editorService: IEditorService,
@IBrowserWorkbenchEnvironmentService protected readonly environmentService: IBrowserWorkbenchEnvironmentService,
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
Expand Down Expand Up @@ -95,6 +97,13 @@ export class WindowTitle extends Disposable {
this.titleUpdater.schedule();
}
}));

const scmContextKeys = new Set(['scmActiveRepositoryName', 'scmActiveRepositoryBranchName']);
this._register(this.contextKeyService.onDidChangeContext(e => {
if (e.affectsSome(scmContextKeys)) {
this.titleUpdater.schedule();
}
}));
}

private onConfigurationChanged(event: IConfigurationChangeEvent): void {
Expand Down Expand Up @@ -240,6 +249,8 @@ export class WindowTitle extends Disposable {
* {remoteName}: e.g. SSH
* {dirty}: indicator
* {focusedView}: e.g. Terminal
* {activeRepositoryName}: e.g. vscode
* {activeRepositoryBranchName}: e.g. main
* {separator}: conditional separator
*/
getWindowTitle(): string {
Expand Down Expand Up @@ -302,6 +313,8 @@ export class WindowTitle extends Disposable {
const separator = this.configurationService.getValue<string>(WindowSettingNames.titleSeparator);
const titleTemplate = this.configurationService.getValue<string>(WindowSettingNames.title);
const focusedView: string = this.viewsService.getFocusedViewName();
const activeRepositoryName = this.contextKeyService.getContextKeyValue<string>('scmActiveRepositoryName') ?? '';
const activeRepositoryBranchName = this.contextKeyService.getContextKeyValue<string>('scmActiveRepositoryBranchName') ?? '';

return template(titleTemplate, {
activeEditorShort,
Expand All @@ -320,6 +333,8 @@ export class WindowTitle extends Disposable {
remoteName,
profileName,
focusedView,
activeRepositoryName,
activeRepositoryBranchName,
separator: { label: separator }
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/browser/workbench.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
localize('remoteName', "`${remoteName}`: e.g. SSH"),
localize('dirty', "`${dirty}`: an indicator for when the active editor has unsaved changes."),
localize('focusedView', "`${focusedView}`: the name of the view that is currently focused."),
localize('activeRepositoryName', "`${activeRepositoryName}`: the name of the active repository (e.g. vscode)."),
localize('activeRepositoryBranchName', "`${activeRepositoryBranchName}`: the name of the active branch in the active repository (e.g. main)."),
localize('separator', "`${separator}`: a conditional separator (\" - \") that only shows when surrounded by variables with values or static text.")
].join('\n- '); // intentionally concatenated to not produce a string that is too long for translations

Expand Down
11 changes: 11 additions & 0 deletions src/vs/workbench/contrib/scm/browser/scmViewService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function getRepositoryName(workspaceContextService: IWorkspaceContextService, re
}

export const RepositoryContextKeys = {
ActiveRepositoryName: new RawContextKey<string>('scmActiveRepositoryName', ''),
ActiveRepositoryBranchName: new RawContextKey<string>('scmActiveRepositoryBranchName', ''),
RepositorySortKey: new RawContextKey<ISCMRepositorySortKey>('scmRepositorySortKey', ISCMRepositorySortKey.DiscoveryTime),
};

Expand Down Expand Up @@ -156,6 +158,9 @@ export class SCMViewService implements ISCMViewService {
private _repositoriesSortKey: ISCMRepositorySortKey;
private _sortKeyContextKey: IContextKey<ISCMRepositorySortKey>;

private _activeRepositoryNameContextKey: IContextKey<string>;
private _activeRepositoryBranchNameContextKey: IContextKey<string>;

constructor(
@ISCMService scmService: ISCMService,
@IContextKeyService contextKeyService: IContextKeyService,
Expand All @@ -176,6 +181,9 @@ export class SCMViewService implements ISCMViewService {
this._sortKeyContextKey = RepositoryContextKeys.RepositorySortKey.bindTo(contextKeyService);
this._sortKeyContextKey.set(this._repositoriesSortKey);

this._activeRepositoryNameContextKey = RepositoryContextKeys.ActiveRepositoryName.bindTo(contextKeyService);
this._activeRepositoryBranchNameContextKey = RepositoryContextKeys.ActiveRepositoryBranchName.bindTo(contextKeyService);

scmService.onDidAddRepository(this.onDidAddRepository, this, this.disposables);
scmService.onDidRemoveRepository(this.onDidRemoveRepository, this, this.disposables);

Expand Down Expand Up @@ -317,6 +325,9 @@ export class SCMViewService implements ISCMViewService {
this._repositories.forEach(r => r.focused = r.repository === repository);

if (this._repositories.find(r => r.focused)) {
this._activeRepositoryNameContextKey.set(repository?.provider.name ?? '');
this._activeRepositoryBranchNameContextKey.set(repository?.provider.historyProvider?.currentHistoryItemGroup?.label ?? '');

this._onDidFocusRepository.fire(repository);
}
}
Expand Down
Loading