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

SCM - ActionBar rendering optimization #180712

Merged
merged 2 commits into from
Apr 24, 2023
Merged
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
36 changes: 22 additions & 14 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { IContextViewService, IContextMenuService } from 'vs/platform/contextvie
import { IContextKeyService, IContextKey, ContextKeyExpr, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { MenuItemAction, IMenuService, registerAction2, MenuId, IAction2Options, MenuRegistry, Action2 } from 'vs/platform/actions/common/actions';
import { MenuItemAction, IMenuService, registerAction2, MenuId, IAction2Options, MenuRegistry, Action2, IMenu } from 'vs/platform/actions/common/actions';
import { IAction, ActionRunner, Action, Separator } from 'vs/base/common/actions';
import { ActionBar, IActionViewItemProvider } from 'vs/base/browser/ui/actionbar/actionbar';
import { IThemeService, IFileIconTheme } from 'vs/platform/theme/common/themeService';
Expand Down Expand Up @@ -356,6 +356,7 @@ interface ResourceTemplate {
fileLabel: IResourceLabel;
decorationIcon: HTMLElement;
actionBar: ActionBar;
actionBarMenu: IMenu | undefined;
readonly elementDisposables: DisposableStore;
readonly disposables: IDisposable;
}
Expand Down Expand Up @@ -419,7 +420,7 @@ class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IReso
const decorationIcon = append(element, $('.decoration-icon'));
const disposables = combinedDisposable(actionBar, fileLabel);

return { element, name, fileLabel, decorationIcon, actionBar, elementDisposables: new DisposableStore(), disposables };
return { element, name, fileLabel, decorationIcon, actionBar, actionBarMenu: undefined, elementDisposables: new DisposableStore(), disposables };
}

renderElement(node: ITreeNode<ISCMResource, FuzzyScore | LabelFuzzyScore> | ITreeNode<ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>, FuzzyScore | LabelFuzzyScore>, index: number, template: ResourceTemplate): void {
Expand All @@ -430,29 +431,29 @@ class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IReso
const viewModel = this.viewModelProvider();
const tooltip = !ResourceTree.isResourceNode(resourceOrFolder) && resourceOrFolder.decorations.tooltip || '';

template.actionBar.clear();
template.actionBar.context = resourceOrFolder;

let matches: IMatch[] | undefined;
let descriptionMatches: IMatch[] | undefined;
let strikethrough: boolean | undefined;

if (ResourceTree.isResourceNode(resourceOrFolder)) {
if (resourceOrFolder.element) {
const menus = this.scmViewService.menus.getRepositoryMenus(resourceOrFolder.element.resourceGroup.provider);
template.elementDisposables.add(connectPrimaryMenuToInlineActionBar(menus.getResourceMenu(resourceOrFolder.element), template.actionBar));
this._renderActionBar(template, resourceOrFolder, menus.getResourceMenu(resourceOrFolder.element));

template.element.classList.toggle('faded', resourceOrFolder.element.decorations.faded);
strikethrough = resourceOrFolder.element.decorations.strikeThrough;
} else {
matches = createMatches(node.filterData as FuzzyScore | undefined);
const menus = this.scmViewService.menus.getRepositoryMenus(resourceOrFolder.context.provider);
template.elementDisposables.add(connectPrimaryMenuToInlineActionBar(menus.getResourceFolderMenu(resourceOrFolder.context), template.actionBar));
this._renderActionBar(template, resourceOrFolder, menus.getResourceFolderMenu(resourceOrFolder.context));

matches = createMatches(node.filterData as FuzzyScore | undefined);
template.element.classList.remove('faded');
}
} else {
[matches, descriptionMatches] = this._processFilterData(uri, node.filterData);
const menus = this.scmViewService.menus.getRepositoryMenus(resourceOrFolder.resourceGroup.provider);
template.elementDisposables.add(connectPrimaryMenuToInlineActionBar(menus.getResourceMenu(resourceOrFolder), template.actionBar));
this._renderActionBar(template, resourceOrFolder, menus.getResourceMenu(resourceOrFolder));

[matches, descriptionMatches] = this._processFilterData(uri, node.filterData);
template.element.classList.toggle('faded', resourceOrFolder.decorations.faded);
strikethrough = resourceOrFolder.decorations.strikeThrough;
}
Expand Down Expand Up @@ -497,11 +498,8 @@ class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IReso
separator: this.labelService.getSeparator(folder.uri.scheme)
});

template.actionBar.clear();
template.actionBar.context = folder;

const menus = this.scmViewService.menus.getRepositoryMenus(folder.context.provider);
template.elementDisposables.add(connectPrimaryMenuToInlineActionBar(menus.getResourceFolderMenu(folder.context), template.actionBar));
this._renderActionBar(template, folder, menus.getResourceFolderMenu(folder.context));

template.name.classList.remove('strike-through');
template.element.classList.remove('faded');
Expand All @@ -520,6 +518,16 @@ class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IReso
template.disposables.dispose();
}

private _renderActionBar(template: ResourceTemplate, resourceOrFolder: ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>, menu: IMenu): void {
if (!template.actionBarMenu || template.actionBarMenu !== menu) {
template.actionBar.clear();
template.elementDisposables.add(connectPrimaryMenuToInlineActionBar(menu, template.actionBar));
template.actionBarMenu = menu;
}

template.actionBar.context = resourceOrFolder;
}

private _processFilterData(uri: URI, filterData: FuzzyScore | LabelFuzzyScore | undefined): [IMatch[] | undefined, IMatch[] | undefined] {
if (!filterData) {
return [undefined, undefined];
Expand Down