mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 01:25:36 -05:00
Add IconPath type (#14420)
* Add IconPath type * Add ThemedIconPath subtype * Update type
This commit is contained in:
@@ -540,7 +540,7 @@ function createFromTabs(items: (azdata.Tab | azdata.TabGroup)[]): InternalItemCo
|
||||
return itemConfigs;
|
||||
}
|
||||
|
||||
function toTabItemConfig(content: azdata.Component, title: string, id?: string, group?: string, icon?: string | URI | { light: string | URI; dark: string | URI }): InternalItemConfig {
|
||||
function toTabItemConfig(content: azdata.Component, title: string, id?: string, group?: string, icon?: azdata.IconPath): InternalItemConfig {
|
||||
return new InternalItemConfig(content as ComponentWrapper, {
|
||||
title: title,
|
||||
group: group,
|
||||
@@ -860,10 +860,10 @@ class ComponentWithIconWrapper extends ComponentWrapper {
|
||||
super(proxy, handle, type, id);
|
||||
}
|
||||
|
||||
public get iconPath(): string | URI | { light: string | URI; dark: string | URI } {
|
||||
public get iconPath(): azdata.IconPath {
|
||||
return this.properties['iconPath'];
|
||||
}
|
||||
public set iconPath(v: string | URI | { light: string | URI; dark: string | URI }) {
|
||||
public set iconPath(v: azdata.IconPath) {
|
||||
this.setProperty('iconPath', v);
|
||||
}
|
||||
|
||||
@@ -927,10 +927,10 @@ class CardWrapper extends ComponentWrapper implements azdata.CardComponent {
|
||||
public set actions(a: azdata.ActionDescriptor[]) {
|
||||
this.setProperty('actions', a);
|
||||
}
|
||||
public get iconPath(): string | URI | { light: string | URI; dark: string | URI } {
|
||||
public get iconPath(): azdata.IconPath {
|
||||
return this.properties['iconPath'];
|
||||
}
|
||||
public set iconPath(v: string | URI | { light: string | URI; dark: string | URI }) {
|
||||
public set iconPath(v: azdata.IconPath) {
|
||||
this.setProperty('iconPath', v);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ import * as azdata from 'azdata';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { ModelComponentWrapper } from 'sql/workbench/browser/modelComponents/modelComponentWrapper.component';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import * as nls from 'vs/nls';
|
||||
import { EventType, addDisposableListener } from 'vs/base/browser/dom';
|
||||
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
||||
@@ -23,8 +22,6 @@ import { convertSize } from 'sql/base/browser/dom';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
|
||||
export type IUserFriendlyIcon = string | URI | { light: string | URI; dark: string | URI };
|
||||
|
||||
export class ItemDescriptor<T> {
|
||||
constructor(public descriptor: IComponentDescriptor, public config: T) { }
|
||||
}
|
||||
|
||||
@@ -6,9 +6,8 @@
|
||||
import { ChangeDetectorRef, ElementRef } from '@angular/core';
|
||||
import * as azdata from 'azdata';
|
||||
import { ComponentBase } from 'sql/workbench/browser/modelComponents/componentBase';
|
||||
import { createIconCssClass, IUserFriendlyIcon } from 'sql/workbench/browser/modelComponents/iconUtils';
|
||||
import { createIconCssClass, IconPath } from 'sql/workbench/browser/modelComponents/iconUtils';
|
||||
import { removeCSSRulesContainingSelector } from 'vs/base/browser/dom';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IComponentDescriptor } from 'sql/platform/dashboard/browser/interfaces';
|
||||
import { convertSize } from 'sql/base/browser/dom';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
@@ -20,7 +19,7 @@ export class ItemDescriptor<T> {
|
||||
export abstract class ComponentWithIconBase<T extends azdata.ComponentWithIconProperties> extends ComponentBase<T> {
|
||||
|
||||
protected _iconClass: string;
|
||||
protected _iconPath: IUserFriendlyIcon;
|
||||
protected _iconPath: IconPath;
|
||||
constructor(
|
||||
changeRef: ChangeDetectorRef,
|
||||
el: ElementRef,
|
||||
@@ -58,8 +57,8 @@ export abstract class ComponentWithIconBase<T extends azdata.ComponentWithIconPr
|
||||
return convertSize(this.iconHeight, `${this.defaultIconHeight}px`);
|
||||
}
|
||||
|
||||
public get iconPath(): string | URI | { light: string | URI; dark: string | URI } {
|
||||
return this.getPropertyOrDefault<IUserFriendlyIcon>((props) => props.iconPath, undefined);
|
||||
public get iconPath(): IconPath {
|
||||
return this.getPropertyOrDefault<IconPath>((props) => props.iconPath, undefined);
|
||||
}
|
||||
|
||||
public get iconHeight(): number | string {
|
||||
|
||||
@@ -9,7 +9,7 @@ import { URI } from 'vs/base/common/uri';
|
||||
|
||||
const ids = new IdGenerator('model-view-component-icon-');
|
||||
|
||||
export type IUserFriendlyIcon = string | URI | { light: string | URI; dark: string | URI };
|
||||
export type IconPath = string | URI | { light: string | URI; dark: string | URI };
|
||||
|
||||
/**
|
||||
* Create a CSS class for the specified icon, if a class with the name already exists, it will be deleted first.
|
||||
@@ -17,7 +17,7 @@ export type IUserFriendlyIcon = string | URI | { light: string | URI; dark: stri
|
||||
* @param className optional, the class name you want to reuse.
|
||||
* @returns the CSS class name
|
||||
*/
|
||||
export function createIconCssClass(iconPath: IUserFriendlyIcon, className?: string): string {
|
||||
export function createIconCssClass(iconPath: IconPath, className?: string): string {
|
||||
let iconClass = className;
|
||||
if (!iconClass) {
|
||||
iconClass = ids.nextId();
|
||||
@@ -30,7 +30,7 @@ export function createIconCssClass(iconPath: IUserFriendlyIcon, className?: stri
|
||||
return iconClass;
|
||||
}
|
||||
|
||||
function getLightIconUri(iconPath: IUserFriendlyIcon): URI {
|
||||
function getLightIconUri(iconPath: IconPath): URI {
|
||||
if (iconPath && iconPath['light']) {
|
||||
return getIconUri(iconPath['light']);
|
||||
} else {
|
||||
@@ -38,7 +38,7 @@ function getLightIconUri(iconPath: IUserFriendlyIcon): URI {
|
||||
}
|
||||
}
|
||||
|
||||
function getDarkIconUri(iconPath: IUserFriendlyIcon): URI {
|
||||
function getDarkIconUri(iconPath: IconPath): URI {
|
||||
if (iconPath && iconPath['dark']) {
|
||||
return getIconUri(iconPath['dark']);
|
||||
}
|
||||
@@ -53,6 +53,6 @@ function getIconUri(iconPath: string | URI): URI {
|
||||
}
|
||||
}
|
||||
|
||||
export function getIconKey(iconPath: IUserFriendlyIcon): string {
|
||||
export function getIconKey(iconPath: IconPath): string {
|
||||
return getLightIconUri(iconPath).toString(true) + getDarkIconUri(iconPath)?.toString(true);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { NavigationBarLayout, PanelComponent } from 'sql/base/browser/ui/panel/p
|
||||
import { TabType } from 'sql/base/browser/ui/panel/tab.component';
|
||||
import { ContainerBase, ItemDescriptor } from 'sql/workbench/browser/modelComponents/componentBase';
|
||||
import { ComponentEventType, IComponent, IComponentDescriptor, IModelStore, ModelViewAction } from 'sql/platform/dashboard/browser/interfaces';
|
||||
import { IUserFriendlyIcon, createIconCssClass } from 'sql/workbench/browser/modelComponents/iconUtils';
|
||||
import { IconPath, 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';
|
||||
@@ -18,7 +18,7 @@ export interface TabConfig {
|
||||
title: string;
|
||||
id?: string;
|
||||
group: string;
|
||||
icon?: IUserFriendlyIcon;
|
||||
icon?: IconPath;
|
||||
}
|
||||
|
||||
interface Tab {
|
||||
|
||||
@@ -28,7 +28,7 @@ import { isUndefinedOrNull } from 'vs/base/common/types';
|
||||
import { IComponent, IComponentDescriptor, IModelStore, ComponentEventType, ModelViewAction } from 'sql/platform/dashboard/browser/interfaces';
|
||||
import { convertSizeToNumber } from 'sql/base/browser/dom';
|
||||
import { ButtonCellValue, ButtonColumn } from 'sql/base/browser/ui/table/plugins/buttonColumn.plugin';
|
||||
import { IUserFriendlyIcon, createIconCssClass, getIconKey } from 'sql/workbench/browser/modelComponents/iconUtils';
|
||||
import { IconPath, createIconCssClass, getIconKey } from 'sql/workbench/browser/modelComponents/iconUtils';
|
||||
import { HeaderFilter } from 'sql/base/browser/ui/table/plugins/headerFilter.plugin';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
@@ -207,7 +207,7 @@ export default class TableComponent extends ComponentBase<azdata.TableComponentP
|
||||
}
|
||||
}
|
||||
|
||||
private createIconCssClassInternal(icon: IUserFriendlyIcon): string {
|
||||
private createIconCssClassInternal(icon: IconPath): string {
|
||||
const iconKey: string = getIconKey(icon);
|
||||
const iconCssClass = this._iconCssMap[iconKey] ?? createIconCssClass(icon);
|
||||
if (!this._iconCssMap[iconKey]) {
|
||||
@@ -430,7 +430,7 @@ export default class TableComponent extends ComponentBase<azdata.TableComponentP
|
||||
private createButtonPlugin(col: azdata.ButtonColumn) {
|
||||
let name = col.value;
|
||||
if (!this._buttonColumns[col.value]) {
|
||||
const icon = <IUserFriendlyIcon>(col.options ? (<any>col.options).icon : col.icon);
|
||||
const icon = <IconPath>(col.options ? (<any>col.options).icon : col.icon);
|
||||
this._buttonColumns[col.value] = new ButtonColumn({
|
||||
title: col.value,
|
||||
iconCssClass: icon ? this.createIconCssClassInternal(icon) : undefined,
|
||||
|
||||
Reference in New Issue
Block a user