mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
fix task icon in dashboard (#1174)
This commit is contained in:
@@ -52,6 +52,7 @@ export class TasksWidget extends DashboardWidget implements IDashboardWidget, On
|
|||||||
private _profile: IConnectionProfile;
|
private _profile: IConnectionProfile;
|
||||||
private _scrollableElement: ScrollableElement;
|
private _scrollableElement: ScrollableElement;
|
||||||
private $container: Builder;
|
private $container: Builder;
|
||||||
|
static readonly ICON_PATH_TO_CSS_RULES: Map<string /* path*/, string /* CSS rule */> = new Map<string, string>();
|
||||||
|
|
||||||
private _inited = false;
|
private _inited = false;
|
||||||
|
|
||||||
@@ -131,9 +132,9 @@ export class TasksWidget extends DashboardWidget implements IDashboardWidget, On
|
|||||||
let tile = $('div.task-tile').style('height', this._size + 'px').style('width', this._size + 'px');
|
let tile = $('div.task-tile').style('height', this._size + 'px').style('width', this._size + 'px');
|
||||||
let innerTile = $('div');
|
let innerTile = $('div');
|
||||||
|
|
||||||
// @SQLTODO - iconPath shouldn't be used as a CSS class
|
let iconClassName = TaskRegistry.getOrCreateTaskIconClassName(action);
|
||||||
if (action.iconPath && action.iconPath.dark) {
|
if (iconClassName) {
|
||||||
let icon = $('span.icon').addClass(action.iconPath.dark);
|
let icon = $('span.icon').addClass(iconClassName);
|
||||||
innerTile.append(icon);
|
innerTile.append(icon);
|
||||||
}
|
}
|
||||||
innerTile.append(label);
|
innerTile.append(label);
|
||||||
|
|||||||
@@ -238,7 +238,8 @@ export class NewProfilerAction extends Task {
|
|||||||
super({
|
super({
|
||||||
id: NewProfilerAction.ID,
|
id: NewProfilerAction.ID,
|
||||||
title: NewProfilerAction.LABEL,
|
title: NewProfilerAction.LABEL,
|
||||||
iconPath: { dark: NewProfilerAction.ICON, light: NewProfilerAction.ICON }
|
iconPath: { dark: NewProfilerAction.ICON, light: NewProfilerAction.ICON },
|
||||||
|
iconClass: NewProfilerAction.ICON
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
|
||||||
|
|
||||||
import * as types from 'vs/base/common/types';
|
import * as types from 'vs/base/common/types';
|
||||||
import { TPromise } from 'vs/base/common/winjs.base';
|
import { TPromise } from 'vs/base/common/winjs.base';
|
||||||
@@ -14,9 +15,10 @@ import { ILocalizedString, IMenuItem, MenuRegistry, ICommandAction } from 'vs/pl
|
|||||||
import Event, { Emitter } from 'vs/base/common/event';
|
import Event, { Emitter } from 'vs/base/common/event';
|
||||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||||
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
|
|
||||||
import { LinkedList } from 'vs/base/common/linkedList';
|
import { LinkedList } from 'vs/base/common/linkedList';
|
||||||
|
import { IdGenerator } from 'vs/base/common/idGenerator';
|
||||||
|
import { createCSSRule } from 'vs/base/browser/dom';
|
||||||
|
import URI from 'vs/base/common/uri';
|
||||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||||
|
|
||||||
export interface ITaskOptions {
|
export interface ITaskOptions {
|
||||||
@@ -24,6 +26,7 @@ export interface ITaskOptions {
|
|||||||
title: string;
|
title: string;
|
||||||
iconPath: { dark: string; light: string; };
|
iconPath: { dark: string; light: string; };
|
||||||
description?: ITaskHandlerDescription;
|
description?: ITaskHandlerDescription;
|
||||||
|
iconClass?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class Task {
|
export abstract class Task {
|
||||||
@@ -31,12 +34,14 @@ export abstract class Task {
|
|||||||
public readonly title: string;
|
public readonly title: string;
|
||||||
public readonly iconPathDark: string;
|
public readonly iconPathDark: string;
|
||||||
public readonly iconPath: { dark: string; light: string; };
|
public readonly iconPath: { dark: string; light: string; };
|
||||||
|
private readonly _iconClass: string;
|
||||||
private readonly _description: ITaskHandlerDescription;
|
private readonly _description: ITaskHandlerDescription;
|
||||||
|
|
||||||
constructor(opts: ITaskOptions) {
|
constructor(opts: ITaskOptions) {
|
||||||
this.id = opts.id;
|
this.id = opts.id;
|
||||||
this.title = opts.title;
|
this.title = opts.title;
|
||||||
this.iconPath = opts.iconPath;
|
this.iconPath = opts.iconPath;
|
||||||
|
this._iconClass = opts.iconClass;
|
||||||
this._description = opts.description;
|
this._description = opts.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +49,8 @@ export abstract class Task {
|
|||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
handler: (accessor, profile, args) => this.runTask(accessor, profile, args),
|
handler: (accessor, profile, args) => this.runTask(accessor, profile, args),
|
||||||
description: this._description
|
description: this._description,
|
||||||
|
iconClass: this._iconClass
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,20 +97,25 @@ export interface ITask {
|
|||||||
handler: ITaskHandler;
|
handler: ITaskHandler;
|
||||||
precondition?: ContextKeyExpr;
|
precondition?: ContextKeyExpr;
|
||||||
description?: ITaskHandlerDescription;
|
description?: ITaskHandlerDescription;
|
||||||
|
iconClass?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITaskRegistry {
|
export interface ITaskRegistry {
|
||||||
registerTask(id: string, command: ITaskHandler): IDisposable;
|
registerTask(id: string, command: ITaskHandler): IDisposable;
|
||||||
registerTask(command: ITask): IDisposable;
|
registerTask(command: ITask): IDisposable;
|
||||||
getTasks(): string[];
|
getTasks(): string[];
|
||||||
|
getOrCreateTaskIconClassName(item: ICommandAction): string;
|
||||||
onTaskRegistered: Event<string>;
|
onTaskRegistered: Event<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ids = new IdGenerator('task-icon-');
|
||||||
|
|
||||||
export const TaskRegistry: ITaskRegistry = new class implements ITaskRegistry {
|
export const TaskRegistry: ITaskRegistry = new class implements ITaskRegistry {
|
||||||
|
|
||||||
private _tasks = new Array<string>();
|
private _tasks = new Array<string>();
|
||||||
private _onTaskRegistered = new Emitter<string>();
|
private _onTaskRegistered = new Emitter<string>();
|
||||||
public readonly onTaskRegistered: Event<string> = this._onTaskRegistered.event;
|
public readonly onTaskRegistered: Event<string> = this._onTaskRegistered.event;
|
||||||
|
private taskIdToIconClassNameMap: Map<string /* task id */, string /* CSS rule */> = new Map<string, string>();
|
||||||
|
|
||||||
registerTask(idOrTask: string | ITask, handler?: ITaskHandler): IDisposable {
|
registerTask(idOrTask: string | ITask, handler?: ITaskHandler): IDisposable {
|
||||||
let disposable: IDisposable;
|
let disposable: IDisposable;
|
||||||
@@ -113,6 +124,9 @@ export const TaskRegistry: ITaskRegistry = new class implements ITaskRegistry {
|
|||||||
disposable = CommandsRegistry.registerCommand(idOrTask, handler);
|
disposable = CommandsRegistry.registerCommand(idOrTask, handler);
|
||||||
id = idOrTask;
|
id = idOrTask;
|
||||||
} else {
|
} else {
|
||||||
|
if (idOrTask.iconClass) {
|
||||||
|
this.taskIdToIconClassNameMap.set(idOrTask.id, idOrTask.iconClass);
|
||||||
|
}
|
||||||
disposable = CommandsRegistry.registerCommand(idOrTask);
|
disposable = CommandsRegistry.registerCommand(idOrTask);
|
||||||
id = idOrTask.id;
|
id = idOrTask.id;
|
||||||
}
|
}
|
||||||
@@ -131,6 +145,19 @@ export const TaskRegistry: ITaskRegistry = new class implements ITaskRegistry {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getOrCreateTaskIconClassName(item: ICommandAction): string {
|
||||||
|
let iconClass = null;
|
||||||
|
if (this.taskIdToIconClassNameMap.has(item.id)) {
|
||||||
|
iconClass = this.taskIdToIconClassNameMap.get(item.id);
|
||||||
|
} else if (item.iconPath) {
|
||||||
|
iconClass = ids.nextId();
|
||||||
|
createCSSRule(`.icon.${iconClass}`, `background-image: url("${URI.file(item.iconPath.light || item.iconPath.dark).toString()}")`);
|
||||||
|
createCSSRule(`.vs-dark .icon.${iconClass}, .hc-black .icon.${iconClass}`, `background-image: url("${URI.file(item.iconPath.dark).toString()}")`);
|
||||||
|
this.taskIdToIconClassNameMap.set(item.id, iconClass);
|
||||||
|
}
|
||||||
|
return iconClass;
|
||||||
|
}
|
||||||
|
|
||||||
getTasks(): string[] {
|
getTasks(): string[] {
|
||||||
return this._tasks.slice(0);
|
return this._tasks.slice(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ export class NewQueryAction extends Task {
|
|||||||
super({
|
super({
|
||||||
id: NewQueryAction.ID,
|
id: NewQueryAction.ID,
|
||||||
title: NewQueryAction.LABEL,
|
title: NewQueryAction.LABEL,
|
||||||
iconPath: { dark: NewQueryAction.ICON, light: NewQueryAction.ICON }
|
iconPath: { dark: NewQueryAction.ICON, light: NewQueryAction.ICON },
|
||||||
|
iconClass: NewQueryAction.ICON
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +293,8 @@ export class BackupAction extends Task {
|
|||||||
super({
|
super({
|
||||||
id: BackupAction.ID,
|
id: BackupAction.ID,
|
||||||
title: BackupAction.LABEL,
|
title: BackupAction.LABEL,
|
||||||
iconPath: { dark: BackupAction.ICON, light: BackupAction.ICON }
|
iconPath: { dark: BackupAction.ICON, light: BackupAction.ICON },
|
||||||
|
iconClass: BackupAction.ICON
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,7 +324,8 @@ export class RestoreAction extends Task {
|
|||||||
super({
|
super({
|
||||||
id: RestoreAction.ID,
|
id: RestoreAction.ID,
|
||||||
title: RestoreAction.LABEL,
|
title: RestoreAction.LABEL,
|
||||||
iconPath: { dark: RestoreAction.ICON, light: RestoreAction.ICON }
|
iconPath: { dark: RestoreAction.ICON, light: RestoreAction.ICON },
|
||||||
|
iconClass: RestoreAction.ICON
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,7 +424,8 @@ export class ConfigureDashboardAction extends Task {
|
|||||||
super({
|
super({
|
||||||
id: ConfigureDashboardAction.ID,
|
id: ConfigureDashboardAction.ID,
|
||||||
title: ConfigureDashboardAction.LABEL,
|
title: ConfigureDashboardAction.LABEL,
|
||||||
iconPath: { dark: ConfigureDashboardAction.ICON, light: ConfigureDashboardAction.ICON }
|
iconPath: { dark: ConfigureDashboardAction.ICON, light: ConfigureDashboardAction.ICON },
|
||||||
|
iconClass: ConfigureDashboardAction.ICON
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user