diff --git a/src/sql/azdata.d.ts b/src/sql/azdata.d.ts index cb9b3e3628..ecc368a0a4 100644 --- a/src/sql/azdata.d.ts +++ b/src/sql/azdata.d.ts @@ -2471,6 +2471,7 @@ declare module 'azdata' { editor(): ComponentBuilder; diffeditor(): ComponentBuilder; text(): ComponentBuilder; + image(): ComponentBuilder; button(): ComponentBuilder; dropDown(): ComponentBuilder; tree(): ComponentBuilder>; @@ -3057,6 +3058,12 @@ declare module 'azdata' { CSSStyles?: { [key: string]: string }; } + export interface ImageComponentProperties { + src: string; + alt?: string; + height?: number | string; + width?: number | string; + } export interface LinkArea { text: string; url: string; @@ -3092,7 +3099,6 @@ declare module 'azdata' { export interface ListBoxProperties { selectedRow?: number; values?: string[]; - } export interface WebViewProperties extends ComponentProperties { @@ -3136,10 +3142,25 @@ declare module 'azdata' { } export interface ButtonProperties extends ComponentProperties, ComponentWithIcon { + /** + * The label for the button + */ label?: string; + /** + * Whether the button opens the file browser dialog + */ isFile?: boolean; + /** + * The content of the currently selected file + */ fileContent?: string; + /** + * The title for the button. This title will show when hovered over + */ title?: string; + /** + * The accessibility aria label for this component + */ ariaLabel?: string; } @@ -3182,9 +3203,10 @@ declare module 'azdata' { onDidClick: vscode.Event; } + export interface ImageComponent extends Component, ImageComponentProperties { + } + export interface HyperlinkComponent extends Component, HyperlinkComponentProperties { - label: string; - url: string; } export interface InputBoxComponent extends Component, InputBoxProperties { @@ -3205,8 +3227,6 @@ declare module 'azdata' { } export interface DropDownComponent extends Component, DropDownProperties { - value: string | CategoryValue; - values: string[] | CategoryValue[]; onValueChanged: vscode.Event; } @@ -3221,8 +3241,6 @@ declare module 'azdata' { } export interface ListBoxComponent extends Component, ListBoxProperties { - selectedRow?: number; - values: string[]; onRowSelected: vscode.Event; } @@ -3343,19 +3361,6 @@ declare module 'azdata' { } export interface ButtonComponent extends Component, ButtonProperties { - /** - * The label for the button - */ - label: string; - /** - * The title for the button. This title will show when it hovers - */ - title: string; - /** - * Icon Path for the button. - */ - iconPath: string | vscode.Uri | { light: string | vscode.Uri; dark: string | vscode.Uri }; - /** * An event called when the button is clicked */ diff --git a/src/sql/sqlops.proposed.d.ts b/src/sql/sqlops.proposed.d.ts index a23600d50d..f4414d87fc 100644 --- a/src/sql/sqlops.proposed.d.ts +++ b/src/sql/sqlops.proposed.d.ts @@ -627,9 +627,21 @@ declare module 'sqlops' { } export interface ButtonProperties extends ComponentProperties, ComponentWithIcon { + /** + * The label for the button + */ label?: string; + /** + * Whether the button opens the file browser dialog + */ isFile?: boolean; + /** + * The content of the currently selected file + */ fileContent?: string; + /** + * The title for the button. This title will show when hovered over + */ title?: string; fileType?: string; } @@ -665,8 +677,6 @@ declare module 'sqlops' { } export interface HyperlinkComponent extends Component, HyperlinkComponentProperties { - label: string; - url: string; } export interface InputBoxComponent extends Component, InputBoxProperties { @@ -684,8 +694,6 @@ declare module 'sqlops' { } export interface DropDownComponent extends Component, DropDownProperties { - value: string | CategoryValue; - values: string[] | CategoryValue[]; onValueChanged: vscode.Event; } @@ -700,8 +708,6 @@ declare module 'sqlops' { } export interface ListBoxComponent extends Component, ListBoxProperties { - selectedRow?: number; - values: string[]; onRowSelected: vscode.Event; } @@ -765,19 +771,6 @@ declare module 'sqlops' { } export interface ButtonComponent extends Component, ButtonProperties { - /** - * The label for the button - */ - label: string; - /** - * The title for the button. This title will show when it hovers - */ - title: string; - /** - * Icon Path for the button. - */ - iconPath: string | vscode.Uri | { light: string | vscode.Uri; dark: string | vscode.Uri }; - /** * An event called when the button is clicked */ diff --git a/src/sql/workbench/api/common/extHostModelView.ts b/src/sql/workbench/api/common/extHostModelView.ts index 722fd22910..5b8c3e7d84 100644 --- a/src/sql/workbench/api/common/extHostModelView.ts +++ b/src/sql/workbench/api/common/extHostModelView.ts @@ -107,6 +107,13 @@ class ModelBuilderImpl implements azdata.ModelBuilder { return builder; } + image(): azdata.ComponentBuilder { + let id = this.getNextComponentId(); + let builder: ComponentBuilderImpl = this.getComponentBuilder(new ImageComponentWrapper(this._proxy, this._handle, id), id); + this._componentBuilders.set(id, builder); + return builder; + } + radioButton(): azdata.ComponentBuilder { let id = this.getNextComponentId(); let builder: ComponentBuilderImpl = this.getComponentBuilder(new RadioButtonWrapper(this._proxy, this._handle, id), id); @@ -1118,6 +1125,42 @@ class TextComponentWrapper extends ComponentWrapper implements azdata.TextCompon } } +class ImageComponentWrapper extends ComponentWrapper implements azdata.ImageComponentProperties { + + constructor(proxy: MainThreadModelViewShape, handle: number, id: string) { + super(proxy, handle, ModelComponentTypes.Image, id); + this.properties = {}; + } + + public get src(): string { + return this.properties['src']; + } + public set src(v: string) { + this.setProperty('src', v); + } + + public get alt(): string { + return this.properties['alt']; + } + public set alt(v: string) { + this.setProperty('alt', v); + } + + public get height(): number | string { + return this.properties['height']; + } + public set height(v: number | string) { + this.setProperty('height', v); + } + + public get width(): number | string { + return this.properties['width']; + } + public set width(v: number | string) { + this.setProperty('width', v); + } +} + class TableComponentWrapper extends ComponentWrapper implements azdata.TableComponent { constructor(proxy: MainThreadModelViewShape, handle: number, id: string) { diff --git a/src/sql/workbench/api/common/sqlExtHostTypes.ts b/src/sql/workbench/api/common/sqlExtHostTypes.ts index 6d195fd3ac..99f3eef8e1 100644 --- a/src/sql/workbench/api/common/sqlExtHostTypes.ts +++ b/src/sql/workbench/api/common/sqlExtHostTypes.ts @@ -166,7 +166,8 @@ export enum ModelComponentTypes { Editor, DiffEditor, Dom, - Hyperlink + Hyperlink, + Image } export enum ColumnSizingMode { diff --git a/src/sql/workbench/browser/modelComponents/components.contribution.ts b/src/sql/workbench/browser/modelComponents/components.contribution.ts index 53eba6f630..281a582d74 100644 --- a/src/sql/workbench/browser/modelComponents/components.contribution.ts +++ b/src/sql/workbench/browser/modelComponents/components.contribution.ts @@ -19,6 +19,7 @@ import RadioButtonComponent from './radioButton.component'; import WebViewComponent from './webview.component'; import TableComponent from './table.component'; import TextComponent from './text.component'; +import ImageComponent from './image.component'; import LoadingComponent from './loadingComponent.component'; import FileBrowserTreeComponent from './fileBrowserTree.component'; import EditorComponent from './editor.component'; @@ -78,6 +79,9 @@ registerComponentType(WEBVIEW_COMPONENT, ModelComponentTypes.WebView, WebViewCom export const TEXT_COMPONENT = 'text-component'; registerComponentType(TEXT_COMPONENT, ModelComponentTypes.Text, TextComponent); +export const IMAGE_COMPONENT = 'image-component'; +registerComponentType(IMAGE_COMPONENT, ModelComponentTypes.Image, ImageComponent); + export const TABLE_COMPONENT = 'table-component'; registerComponentType(TABLE_COMPONENT, ModelComponentTypes.Table, TableComponent); diff --git a/src/sql/workbench/browser/modelComponents/image.component.ts b/src/sql/workbench/browser/modelComponents/image.component.ts new file mode 100644 index 0000000000..e39b3740fc --- /dev/null +++ b/src/sql/workbench/browser/modelComponents/image.component.ts @@ -0,0 +1,63 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { + Component, Input, Inject, ChangeDetectorRef, forwardRef, + OnDestroy, AfterViewInit, ElementRef +} from '@angular/core'; + +import * as azdata from 'azdata'; + +import { ComponentBase } from 'sql/workbench/browser/modelComponents/componentBase'; +import { IComponent, IComponentDescriptor, IModelStore } from 'sql/workbench/browser/modelComponents/interfaces'; + +@Component({ + selector: 'modelview-image', + template: ` + ` +}) +export default class ImageComponent extends ComponentBase implements IComponent, OnDestroy, AfterViewInit { + @Input() descriptor: IComponentDescriptor; + @Input() modelStore: IModelStore; + + constructor( + @Inject(forwardRef(() => ChangeDetectorRef)) changeRef: ChangeDetectorRef, + @Inject(forwardRef(() => ElementRef)) el: ElementRef) { + super(changeRef, el); + } + + ngOnInit(): void { + this.baseInit(); + } + + ngAfterViewInit(): void { + } + + ngOnDestroy(): void { + this.baseDestroy(); + } + + /// IComponent implementation + + public setLayout(layout: any): void { + this.layout(); + } + + public set src(newValue: string) { + this.setPropertyFromUI((properties, value) => { properties.src = value; }, newValue); + } + + public get src(): string { + return this.getPropertyOrDefault((props) => props.src, ''); + } + + public set alt(newValue: string) { + this.setPropertyFromUI((properties, value) => { properties.alt = value; }, newValue); + } + + public get alt(): string { + return this.getPropertyOrDefault((props) => props.alt, ''); + } +}