Add doAction API call for ModelView (#10345)

* Add doAction API call for ModelView

* cleanup
This commit is contained in:
Charles Gagnon
2020-05-12 10:47:20 -07:00
committed by GitHub
parent ff848b5903
commit 3fa0deed71
13 changed files with 70 additions and 8 deletions

View File

@@ -266,6 +266,10 @@ export abstract class ComponentBase extends Disposable implements IComponent, On
(<HTMLElement>this._el.nativeElement).focus();
}
public doAction(action: string, ...args: any[]): void {
// no-op, components should override this if they want to handle actions
}
protected onkeydown(domNode: HTMLElement, listener: (e: StandardKeyboardEvent) => void): void {
this._register(addDisposableListener(domNode, EventType.KEY_DOWN, (e: KeyboardEvent) => listener(new StandardKeyboardEvent(e))));
}

View File

@@ -2,16 +2,17 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/tabbedPanel';
import { AfterViewInit, ChangeDetectorRef, Component, ElementRef, forwardRef, Inject, Input, OnDestroy, ViewChild } from '@angular/core';
import { NavigationBarLayout, PanelComponent } from 'sql/base/browser/ui/panel/panel.component';
import { TabType } from 'sql/base/browser/ui/panel/tab.component';
import { ContainerBase, ItemDescriptor } from 'sql/workbench/browser/modelComponents/componentBase';
import { ComponentEventType, IComponent, IComponentDescriptor, IModelStore } from 'sql/platform/dashboard/browser/interfaces';
import 'vs/css!./media/tabbedPanel';
import { ComponentEventType, IComponent, IComponentDescriptor, IModelStore, ModelViewAction } from 'sql/platform/dashboard/browser/interfaces';
import { IUserFriendlyIcon, createIconCssClass } from 'sql/workbench/browser/modelComponents/iconUtils';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { attachTabbedPanelStyler } from 'sql/workbench/common/styler';
import { TabbedPanelLayout } from 'azdata';
import { ILogService } from 'vs/platform/log/common/log';
export interface TabConfig {
title: string;
@@ -50,7 +51,8 @@ export default class TabbedPanelComponent extends ContainerBase<TabConfig> imple
constructor(
@Inject(forwardRef(() => ChangeDetectorRef)) changeRef: ChangeDetectorRef,
@Inject(forwardRef(() => ElementRef)) el: ElementRef,
@Inject(IWorkbenchThemeService) private themeService: IWorkbenchThemeService
@Inject(IWorkbenchThemeService) private themeService: IWorkbenchThemeService,
@Inject(ILogService) private logService: ILogService
) {
super(changeRef, el);
}
@@ -125,4 +127,19 @@ export default class TabbedPanelComponent extends ContainerBase<TabConfig> imple
onItemLayoutUpdated(item: ItemDescriptor<TabConfig>): void {
this._panel.updateTab(item.config.id, { title: item.config.title, iconClass: item.config.icon ? createIconCssClass(item.config.icon) : undefined });
}
public doAction(action: string, ...args: any[]): void {
switch (action) {
case ModelViewAction.SelectTab:
if (typeof args?.[0] !== 'string') {
this.logService.warn(`Got unknown arg type for SelectTab action ${args?.[0]}`);
return;
}
this.selectTab(args[0]);
}
}
public selectTab(id: string): void {
this._panel.selectTab(id);
}
}

View File

@@ -156,4 +156,8 @@ export abstract class ViewBase extends AngularDisposable implements IModelView {
public focus(componentId: string): void {
return this.queueAction(componentId, (component) => component.focus());
}
public doAction(componentId: string, action: string, ...args: any[]): void {
return this.queueAction(componentId, (component) => component.doAction(action, ...args));
}
}