提交 50bd9c27 编写于 作者: E Eric Amodio

Fixes repo events not updating action button

上级 48017a0d
......@@ -106,9 +106,6 @@ class ActionButtonRenderer implements ICompressibleTreeRenderer<ISCMActionButton
static readonly TEMPLATE_ID = 'actionButton';
get templateId(): string { return ActionButtonRenderer.TEMPLATE_ID; }
private readonly _onDidChange = new Emitter<void>();
readonly onDidChange: Event<void> = this._onDidChange.event;
constructor(
@ICommandService private commandService: ICommandService,
@IThemeService private themeService: IThemeService,
......@@ -118,15 +115,14 @@ class ActionButtonRenderer implements ICompressibleTreeRenderer<ISCMActionButton
renderTemplate(container: HTMLElement): ActionButtonTemplate {
const buttonContainer = append(container, $('.button-container'));
const actionButton = new ScmActionButton(buttonContainer, this.commandService, this.themeService, this.notificationService);
const disposable = actionButton.onDidChange(this._onDidChange.fire, this);
return { actionButton, disposable: Disposable.None, templateDisposable: combinedDisposable(disposable, actionButton) };
return { actionButton, disposable: Disposable.None, templateDisposable: actionButton };
}
renderElement(node: ITreeNode<ISCMActionButton, FuzzyScore>, index: number, templateData: ActionButtonTemplate, height: number | undefined): void {
templateData.disposable.dispose();
templateData.actionButton.setCommand(node.element.repository, node.element.button);
templateData.actionButton.setButton(node.element.button);
}
renderCompressedElements(): void {
......@@ -1070,7 +1066,6 @@ class ViewModel {
constructor(
private tree: WorkbenchCompressibleObjectTree<TreeElement, FuzzyScore>,
private inputRenderer: InputRenderer,
actionButtonRenderer: ActionButtonRenderer,
private _mode: ViewModelMode,
private _treeViewState: ITreeViewState | undefined,
@IInstantiationService protected instantiationService: IInstantiationService,
......@@ -1097,7 +1092,6 @@ class ViewModel {
(this.updateRepositoryCollapseAllContextKeys, this, this.disposables);
this.disposables.add(this.tree.onDidChangeCollapseState(() => this._treeViewStateIsStale = true));
this.disposables.add(actionButtonRenderer.onDidChange(() => this.refresh()));
}
private onDidChangeConfiguration(e?: IConfigurationChangeEvent): void {
......@@ -1112,7 +1106,12 @@ class ViewModel {
for (const repository of added) {
const disposable = combinedDisposable(
repository.provider.groups.onDidSplice(splice => this._onDidSpliceGroups(item, splice)),
repository.input.onDidChangeVisibility(() => this.refresh(item))
repository.input.onDidChangeVisibility(() => this.refresh(item)),
repository.provider.onDidChange(() => {
if (this.showActionButtons) {
this.refresh(item);
}
})
);
const groupItems = repository.provider.groups.elements.map(group => this.createGroupItem(group));
const item: IRepositoryItem = {
......@@ -2048,11 +2047,10 @@ export class SCMViewPane extends ViewPane {
this._register(actionRunner);
this._register(actionRunner.onBeforeRun(() => this.tree.domFocus()));
const actionButtonRenderer = this.instantiationService.createInstance(ActionButtonRenderer);
const renderers: ICompressibleTreeRenderer<any, any, any>[] = [
this.instantiationService.createInstance(RepositoryRenderer, getActionViewItemProvider(this.instantiationService)),
this.inputRenderer,
actionButtonRenderer,
this.instantiationService.createInstance(ActionButtonRenderer),
this.instantiationService.createInstance(ResourceGroupRenderer, getActionViewItemProvider(this.instantiationService)),
this.instantiationService.createInstance(ResourceRenderer, () => this._viewModel, this.listLabels, getActionViewItemProvider(this.instantiationService), actionRunner)
];
......@@ -2108,7 +2106,7 @@ export class SCMViewPane extends ViewPane {
this._register(this.instantiationService.createInstance(RepositoryVisibilityActionController));
this._viewModel = this.instantiationService.createInstance(ViewModel, this.tree, this.inputRenderer, actionButtonRenderer, viewMode, viewState);
this._viewModel = this.instantiationService.createInstance(ViewModel, this.tree, this.inputRenderer, viewMode, viewState);
this._register(this._viewModel);
this.listContainer.classList.add('file-icon-themable-tree');
......@@ -2400,9 +2398,6 @@ registerThemingParticipant((theme, collector) => {
});
export class ScmActionButton implements IDisposable {
private readonly _onDidChange = new Emitter<void>();
readonly onDidChange: Event<void> = this._onDidChange.event;
private button: Button | undefined;
private readonly disposables = new MutableDisposable<DisposableStore>();
......@@ -2419,18 +2414,18 @@ export class ScmActionButton implements IDisposable {
}
setCommand(repository: ISCMRepository, command: Command | undefined): void {
setButton(button: Command | undefined): void {
// Clear old button
this.clear();
if (!command) {
if (!button) {
return;
}
this.button = new Button(this.container, { title: command.tooltip, supportIcons: true });
this.button.label = command.title;
this.button = new Button(this.container, { title: button.tooltip, supportIcons: true });
this.button.label = button.title;
this.button.onDidClick(async () => {
try {
await this.commandService.executeCommand(command!.id, ...(command!.arguments || []));
await this.commandService.executeCommand(button!.id, ...(button!.arguments || []));
} catch (ex) {
this.notificationService.error(ex);
}
......@@ -2438,7 +2433,6 @@ export class ScmActionButton implements IDisposable {
this.disposables.value!.add(this.button);
this.disposables.value!.add(attachButtonStyler(this.button, this.themeService));
this.disposables.value!.add(repository.provider.onDidChange(this._onDidChange.fire, this));
}
private clear(): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册