Skip to content

Commit

Permalink
Avoid empty or ambiguous repository label in Repositories submenu (fix
Browse files Browse the repository at this point in the history
…#196613) (#196623)

Co-authored-by: Ladislau Szomoru <[email protected]>
  • Loading branch information
gjsjohnmurray and lszomoru authored Nov 21, 2023
1 parent 4eef9f9 commit 1817634
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
24 changes: 20 additions & 4 deletions src/vs/workbench/api/browser/mainThreadSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { ISCMHistoryItem, ISCMHistoryItemChange, ISCMHistoryItemGroup, ISCMHisto
import { ResourceTree } from 'vs/base/common/resourceTree';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { Codicon } from 'vs/base/common/codicons';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { basename } from 'vs/base/common/resources';

function getSCMInputBoxActionButtonIcon(actionButton: SCMInputActionButtonDto): URI | { light: URI; dark: URI } | ThemeIcon | undefined {
if (!actionButton.icon) {
Expand Down Expand Up @@ -257,6 +259,9 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
get statusBarCommands(): Command[] | undefined { return this.features.statusBarCommands; }
get count(): number | undefined { return this.features.count; }

private readonly _name: string | undefined;
get name(): string { return this._name ?? this._label; }

private readonly _onDidChangeCommitTemplate = new Emitter<string>();
readonly onDidChangeCommitTemplate: Event<string> = this._onDidChangeCommitTemplate.event;

Expand All @@ -282,8 +287,18 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
private readonly _rootUri: URI | undefined,
private readonly _inputBoxDocumentUri: URI,
private readonly _quickDiffService: IQuickDiffService,
private readonly _uriIdentService: IUriIdentityService
) { }
private readonly _uriIdentService: IUriIdentityService,
private readonly _workspaceContextService: IWorkspaceContextService
) {
if (_rootUri) {
const folder = this._workspaceContextService.getWorkspaceFolder(_rootUri);
if (folder?.uri.toString() === _rootUri.toString()) {
this._name = folder.name;
} else if (_rootUri.path !== '/') {
this._name = basename(_rootUri);
}
}
}

$updateSourceControl(features: SCMProviderFeatures): void {
this.features = { ...this.features, ...features };
Expand Down Expand Up @@ -483,7 +498,8 @@ export class MainThreadSCM implements MainThreadSCMShape {
@ISCMService private readonly scmService: ISCMService,
@ISCMViewService private readonly scmViewService: ISCMViewService,
@IQuickDiffService private readonly quickDiffService: IQuickDiffService,
@IUriIdentityService private readonly _uriIdentService: IUriIdentityService
@IUriIdentityService private readonly _uriIdentService: IUriIdentityService,
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService
) {
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostSCM);
}
Expand All @@ -500,7 +516,7 @@ export class MainThreadSCM implements MainThreadSCMShape {
}

$registerSourceControl(handle: number, id: string, label: string, rootUri: UriComponents | undefined, inputBoxDocumentUri: UriComponents): void {
const provider = new MainThreadSCMProvider(this._proxy, handle, id, label, rootUri ? URI.revive(rootUri) : undefined, URI.revive(inputBoxDocumentUri), this.quickDiffService, this._uriIdentService);
const provider = new MainThreadSCMProvider(this._proxy, handle, id, label, rootUri ? URI.revive(rootUri) : undefined, URI.revive(inputBoxDocumentUri), this.quickDiffService, this._uriIdentService, this.workspaceContextService);
const repository = this.scmService.registerSCMProvider(provider);
this._repositories.set(handle, repository);

Expand Down
15 changes: 2 additions & 13 deletions src/vs/workbench/contrib/scm/browser/scmRepositoryRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import { ICompressibleTreeRenderer } from 'vs/base/browser/ui/tree/objectTree';
import { FuzzyScore } from 'vs/base/common/filters';
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
import { IListRenderer } from 'vs/base/browser/ui/list/list';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { basename } from 'vs/base/common/resources';
import { IActionViewItemProvider } from 'vs/base/browser/ui/actionbar/actionbar';
import { defaultCountBadgeStyles } from 'vs/platform/theme/browser/defaultStyles';

Expand All @@ -42,8 +40,7 @@ export class RepositoryRenderer implements ICompressibleTreeRenderer<ISCMReposit
private actionViewItemProvider: IActionViewItemProvider,
@ISCMViewService private scmViewService: ISCMViewService,
@ICommandService private commandService: ICommandService,
@IContextMenuService private contextMenuService: IContextMenuService,
@IWorkspaceContextService private workspaceContextService: IWorkspaceContextService,
@IContextMenuService private contextMenuService: IContextMenuService
) { }

renderTemplate(container: HTMLElement): RepositoryTemplate {
Expand All @@ -70,20 +67,12 @@ export class RepositoryRenderer implements ICompressibleTreeRenderer<ISCMReposit
renderElement(arg: ISCMRepository | ITreeNode<ISCMRepository, FuzzyScore>, index: number, templateData: RepositoryTemplate, height: number | undefined): void {
const repository = isSCMRepository(arg) ? arg : arg.element;

templateData.name.textContent = repository.provider.name;
if (repository.provider.rootUri) {
const folder = this.workspaceContextService.getWorkspaceFolder(repository.provider.rootUri);

if (folder?.uri.toString() === repository.provider.rootUri.toString()) {
templateData.name.textContent = folder.name;
} else {
templateData.name.textContent = basename(repository.provider.rootUri);
}

templateData.label.title = `${repository.provider.label}: ${repository.provider.rootUri.fsPath}`;
templateData.description.textContent = repository.provider.label;
} else {
templateData.label.title = repository.provider.label;
templateData.name.textContent = repository.provider.label;
templateData.description.textContent = '';
}

Expand Down
19 changes: 3 additions & 16 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ import { LabelFuzzyScore } from 'vs/base/browser/ui/tree/abstractTree';
import { Selection } from 'vs/editor/common/core/selection';
import { API_OPEN_DIFF_EDITOR_COMMAND_ID, API_OPEN_EDITOR_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { MarkdownRenderer, openLinkFromMarkdown } from 'vs/editor/contrib/markdownRenderer/browser/markdownRenderer';
import { Button, ButtonWithDescription, ButtonWithDropdown } from 'vs/base/browser/ui/button/button';
import { INotificationService } from 'vs/platform/notification/common/notification';
Expand Down Expand Up @@ -1261,8 +1260,7 @@ class SCMResourceIdentityProvider implements IIdentityProvider<TreeElement> {
export class SCMAccessibilityProvider implements IListAccessibilityProvider<TreeElement> {

constructor(
@ILabelService private readonly labelService: ILabelService,
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService
@ILabelService private readonly labelService: ILabelService
) { }

getWidgetAriaLabel(): string {
Expand All @@ -1273,17 +1271,7 @@ export class SCMAccessibilityProvider implements IListAccessibilityProvider<Tree
if (ResourceTree.isResourceNode(element)) {
return this.labelService.getUriLabel(element.uri, { relative: true, noPrefix: true }) || element.name;
} else if (isSCMRepository(element)) {
let folderName = '';
if (element.provider.rootUri) {
const folder = this.workspaceContextService.getWorkspaceFolder(element.provider.rootUri);

if (folder?.uri.toString() === element.provider.rootUri.toString()) {
folderName = folder.name;
} else {
folderName = basename(element.provider.rootUri);
}
}
return `${folderName} ${element.provider.label}`;
return `${element.provider.name} ${element.provider.label}`;
} else if (isSCMInput(element)) {
return localize('input', "Source Control Input");
} else if (isSCMActionButton(element)) {
Expand Down Expand Up @@ -1374,10 +1362,9 @@ class RepositoryVisibilityAction extends Action2 {
private repository: ISCMRepository;

constructor(repository: ISCMRepository) {
const title = repository.provider.rootUri ? basename(repository.provider.rootUri) : repository.provider.label;
super({
id: `workbench.scm.action.toggleRepositoryVisibility.${repository.provider.id}`,
title,
title: repository.provider.name,
f1: false,
precondition: ContextKeyExpr.or(ContextKeys.RepositoryVisibilityCount.notEqualsTo(1), ContextKeys.RepositoryVisibility(repository).isEqualTo(false)),
toggled: ContextKeys.RepositoryVisibility(repository).isEqualTo(true),
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/scm/common/scm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface ISCMProvider extends IDisposable {
readonly id: string;
readonly label: string;
readonly contextValue: string;
readonly name: string;

readonly groups: readonly ISCMResourceGroup[];
readonly onDidChangeResourceGroups: Event<void>;
Expand Down

0 comments on commit 1817634

Please sign in to comment.