提交 0282585d 编写于 作者: S Sandeep Somavarapu

Fix #83171

上级 0e3a2cc6
...@@ -37,7 +37,6 @@ import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; ...@@ -37,7 +37,6 @@ import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions'; import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions'; import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { createCSSRule, asCSSUrl } from 'vs/base/browser/dom';
export interface IUserFriendlyViewsContainerDescriptor { export interface IUserFriendlyViewsContainerDescriptor {
id: string; id: string;
...@@ -254,10 +253,9 @@ class ViewsExtensionHandler implements IWorkbenchContribution { ...@@ -254,10 +253,9 @@ class ViewsExtensionHandler implements IWorkbenchContribution {
private registerTestViewContainer(): void { private registerTestViewContainer(): void {
const title = localize('test', "Test"); const title = localize('test', "Test");
const cssClass = `extensionViewlet-test`;
const icon = URI.parse(require.toUrl('./media/test.svg')); const icon = URI.parse(require.toUrl('./media/test.svg'));
this.registerCustomViewContainer(TEST_VIEW_CONTAINER_ID, title, icon, TEST_VIEW_CONTAINER_ORDER, cssClass, undefined); this.registerCustomViewContainer(TEST_VIEW_CONTAINER_ID, title, icon, TEST_VIEW_CONTAINER_ORDER, undefined);
} }
private isValidViewsContainer(viewsContainersDescriptors: IUserFriendlyViewsContainerDescriptor[], collector: ExtensionMessageCollector): boolean { private isValidViewsContainer(viewsContainersDescriptors: IUserFriendlyViewsContainerDescriptor[], collector: ExtensionMessageCollector): boolean {
...@@ -290,10 +288,9 @@ class ViewsExtensionHandler implements IWorkbenchContribution { ...@@ -290,10 +288,9 @@ class ViewsExtensionHandler implements IWorkbenchContribution {
private registerCustomViewContainers(containers: IUserFriendlyViewsContainerDescriptor[], extension: IExtensionDescription, order: number, existingViewContainers: ViewContainer[]): number { private registerCustomViewContainers(containers: IUserFriendlyViewsContainerDescriptor[], extension: IExtensionDescription, order: number, existingViewContainers: ViewContainer[]): number {
containers.forEach(descriptor => { containers.forEach(descriptor => {
const cssClass = `extensionViewlet-${descriptor.id}`;
const icon = resources.joinPath(extension.extensionLocation, descriptor.icon); const icon = resources.joinPath(extension.extensionLocation, descriptor.icon);
const id = `workbench.view.extension.${descriptor.id}`; const id = `workbench.view.extension.${descriptor.id}`;
const viewContainer = this.registerCustomViewContainer(id, descriptor.title, icon, order++, cssClass, extension.identifier); const viewContainer = this.registerCustomViewContainer(id, descriptor.title, icon, order++, extension.identifier);
// Move those views that belongs to this container // Move those views that belongs to this container
if (existingViewContainers.length) { if (existingViewContainers.length) {
...@@ -311,7 +308,7 @@ class ViewsExtensionHandler implements IWorkbenchContribution { ...@@ -311,7 +308,7 @@ class ViewsExtensionHandler implements IWorkbenchContribution {
return order; return order;
} }
private registerCustomViewContainer(id: string, title: string, icon: URI, order: number, cssClass: string, extensionId: ExtensionIdentifier | undefined): ViewContainer { private registerCustomViewContainer(id: string, title: string, icon: URI, order: number, extensionId: ExtensionIdentifier | undefined): ViewContainer {
let viewContainer = this.viewContainersRegistry.get(id); let viewContainer = this.viewContainersRegistry.get(id);
if (!viewContainer) { if (!viewContainer) {
...@@ -339,7 +336,7 @@ class ViewsExtensionHandler implements IWorkbenchContribution { ...@@ -339,7 +336,7 @@ class ViewsExtensionHandler implements IWorkbenchContribution {
CustomViewlet, CustomViewlet,
id, id,
title, title,
cssClass, undefined,
order, order,
icon icon
); );
...@@ -363,15 +360,6 @@ class ViewsExtensionHandler implements IWorkbenchContribution { ...@@ -363,15 +360,6 @@ class ViewsExtensionHandler implements IWorkbenchContribution {
`View: Show ${title}`, `View: Show ${title}`,
localize('view', "View") localize('view', "View")
); );
// Generate CSS to show the icon in the activity bar
const iconClass = `.monaco-workbench .activitybar .monaco-action-bar .action-label.${cssClass}`;
createCSSRule(iconClass, `
mask: ${asCSSUrl(icon)} no-repeat 50% 50%;
mask-size: 24px;
-webkit-mask: ${asCSSUrl(icon)} no-repeat 50% 50%;
-webkit-mask-size: 24px;`
);
} }
return viewContainer; return viewContainer;
......
...@@ -33,15 +33,45 @@ export class ViewletActivityAction extends ActivityAction { ...@@ -33,15 +33,45 @@ export class ViewletActivityAction extends ActivityAction {
private static readonly preventDoubleClickDelay = 300; private static readonly preventDoubleClickDelay = 300;
private lastRun: number = 0; private readonly viewletService: IViewletService;
private readonly layoutService: IWorkbenchLayoutService;
private readonly telemetryService: ITelemetryService;
private lastRun: number;
constructor( constructor(
activity: IActivity, activity: IActivity,
@IViewletService private readonly viewletService: IViewletService, @IViewletService viewletService: IViewletService,
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService, @IWorkbenchLayoutService layoutService: IWorkbenchLayoutService,
@ITelemetryService private readonly telemetryService: ITelemetryService @ITelemetryService telemetryService: ITelemetryService
) { ) {
ViewletActivityAction.generateIconCSS(activity);
super(activity); super(activity);
this.lastRun = 0;
this.viewletService = viewletService;
this.layoutService = layoutService;
this.telemetryService = telemetryService;
}
private static generateIconCSS(activity: IActivity): void {
if (activity.iconUrl) {
activity.cssClass = activity.cssClass || `activity-${activity.id.replace(/\./g, '-')}`;
const iconClass = `.monaco-workbench .activitybar .monaco-action-bar .action-label.${activity.cssClass}`;
DOM.createCSSRule(iconClass, `
mask: ${DOM.asCSSUrl(activity.iconUrl)} no-repeat 50% 50%;
mask-size: 24px;
-webkit-mask: ${DOM.asCSSUrl(activity.iconUrl)} no-repeat 50% 50%;
-webkit-mask-size: 24px;
`);
}
}
setActivity(activity: IActivity): void {
if (activity.iconUrl && this.activity.cssClass !== activity.cssClass) {
ViewletActivityAction.generateIconCSS(activity);
}
this.activity = activity;
} }
async run(event: any): Promise<any> { async run(event: any): Promise<any> {
...@@ -170,21 +200,7 @@ export class PlaceHolderViewletActivityAction extends ViewletActivityAction { ...@@ -170,21 +200,7 @@ export class PlaceHolderViewletActivityAction extends ViewletActivityAction {
@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService, @IWorkbenchLayoutService layoutService: IWorkbenchLayoutService,
@ITelemetryService telemetryService: ITelemetryService @ITelemetryService telemetryService: ITelemetryService
) { ) {
super({ id, name: id, cssClass: `extensionViewlet-placeholder-${id.replace(/\./g, '-')}` }, viewletService, layoutService, telemetryService); super({ id, name: id, iconUrl }, viewletService, layoutService, telemetryService);
if (iconUrl) {
const iconClass = `.monaco-workbench .activitybar .monaco-action-bar .action-label.${this.class}`; // Generate Placeholder CSS to show the icon in the activity bar
DOM.createCSSRule(iconClass, `
mask: ${DOM.asCSSUrl(iconUrl)} no-repeat 50% 50%;
mask-size: 24px;
-webkit-mask: ${DOM.asCSSUrl(iconUrl)} no-repeat 50% 50%;
-webkit-mask-size: 24px;
`);
}
}
setActivity(activity: IActivity): void {
this.activity = activity;
} }
} }
......
...@@ -158,15 +158,12 @@ export class ActivityActionViewItem extends BaseActionViewItem { ...@@ -158,15 +158,12 @@ export class ActivityActionViewItem extends BaseActionViewItem {
if (this.label) { if (this.label) {
if (this.options.icon) { if (this.options.icon) {
const foreground = this._action.checked ? colors.activeBackgroundColor || colors.activeForegroundColor : colors.inactiveBackgroundColor || colors.inactiveForegroundColor; const foreground = this._action.checked ? colors.activeBackgroundColor || colors.activeForegroundColor : colors.inactiveBackgroundColor || colors.inactiveForegroundColor;
// TODO @misolori find a cleaner way to do this if (this.activity.iconUrl) {
const isExtension = this.activity.cssClass?.indexOf('extensionViewlet') === 0; // Apply background color to activity bar item provided with iconUrls
if (!isExtension) {
// Apply foreground color to activity bar items (codicons)
this.label.style.color = foreground ? foreground.toString() : '';
} else {
// Apply background color to extensions + remote explorer (svgs)
this.label.style.backgroundColor = foreground ? foreground.toString() : ''; this.label.style.backgroundColor = foreground ? foreground.toString() : '';
} else {
// Apply foreground color to activity bar items provided with codicons
this.label.style.color = foreground ? foreground.toString() : '';
} }
} else { } else {
const foreground = this._action.checked ? colors.activeForegroundColor : colors.inactiveForegroundColor; const foreground = this._action.checked ? colors.activeForegroundColor : colors.inactiveForegroundColor;
...@@ -242,6 +239,7 @@ export class ActivityActionViewItem extends BaseActionViewItem { ...@@ -242,6 +239,7 @@ export class ActivityActionViewItem extends BaseActionViewItem {
this.updateLabel(); this.updateLabel();
this.updateTitle(this.activity.name); this.updateTitle(this.activity.name);
this.updateBadge(); this.updateBadge();
this.updateStyles();
} }
protected updateBadge(): void { protected updateBadge(): void {
...@@ -319,15 +317,14 @@ export class ActivityActionViewItem extends BaseActionViewItem { ...@@ -319,15 +317,14 @@ export class ActivityActionViewItem extends BaseActionViewItem {
this.label.className = 'action-label'; this.label.className = 'action-label';
if (this.activity.cssClass) { if (this.activity.cssClass) {
// TODO @misolori find a cleaner way to do this
const isExtension = this.activity.cssClass?.indexOf('extensionViewlet') === 0;
if (this.options.icon && !isExtension) {
// Only apply icon class to activity bar items (exclude extensions + remote explorer)
dom.addClass(this.label, 'codicon');
}
dom.addClass(this.label, this.activity.cssClass); dom.addClass(this.label, this.activity.cssClass);
} }
if (this.options.icon && !this.activity.iconUrl) {
// Only apply codicon class to activity bar icon items without iconUrl
dom.addClass(this.label, 'codicon');
}
if (!this.options.icon) { if (!this.options.icon) {
this.label.textContent = this.getAction().label; this.label.textContent = this.getAction().label;
} }
...@@ -496,11 +493,7 @@ export class CompositeActionViewItem extends ActivityActionViewItem { ...@@ -496,11 +493,7 @@ export class CompositeActionViewItem extends ActivityActionViewItem {
activityName = this.compositeActivityAction.activity.name; activityName = this.compositeActivityAction.activity.name;
} }
this.compositeActivity = { this.compositeActivity = { ...this.compositeActivityAction.activity, ... { name: activityName } };
id: this.compositeActivityAction.activity.id,
cssClass: this.compositeActivityAction.activity.cssClass,
name: activityName
};
} }
return this.compositeActivity; return this.compositeActivity;
......
...@@ -73,14 +73,10 @@ export class ViewletDescriptor extends CompositeDescriptor<Viewlet> { ...@@ -73,14 +73,10 @@ export class ViewletDescriptor extends CompositeDescriptor<Viewlet> {
name: string, name: string,
cssClass?: string, cssClass?: string,
order?: number, order?: number,
private _iconUrl?: URI readonly iconUrl?: URI
) { ) {
super(ctor, id, name, cssClass, order, id); super(ctor, id, name, cssClass, order, id);
} }
get iconUrl(): URI | undefined {
return this._iconUrl;
}
} }
export const Extensions = { export const Extensions = {
......
...@@ -3,11 +3,14 @@ ...@@ -3,11 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { URI } from 'vs/base/common/uri';
export interface IActivity { export interface IActivity {
id: string; id: string;
name: string; name: string;
keybindingId?: string; keybindingId?: string;
cssClass?: string; cssClass?: string;
iconUrl?: URI;
} }
export const GLOBAL_ACTIVITY_ID = 'workbench.action.globalActivity'; export const GLOBAL_ACTIVITY_ID = 'workbench.action.globalActivity';
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册