Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/asl/icons_contibutions_draft' …
Browse files Browse the repository at this point in the history
…into icon-contributions
  • Loading branch information
vladarama committed Aug 11, 2023
2 parents 9d2684d + b8be503 commit fee1706
Show file tree
Hide file tree
Showing 12 changed files with 456 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/browser/icon-theme-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class IconThemeApplicationContribution implements FrontendApplicationCont
protected readonly iconThemeContributions: ContributionProvider<IconThemeContribution>;

async onStart(): Promise<void> {
console.log('**** alvs, IconThemeApplicationContribution onStart');

for (const contribution of this.iconThemeContributions.getContributions()) {
await contribution.registerIconThemes(this.iconThemes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class TabBarToolbarRegistry implements FrontendApplicationContribution {
throw new Error(`A toolbar item is already registered with the '${id}' ID.`);
}
this.items.set(id, item);
console.warn('***** alvs: registering tab item: ', item.id);
this.fireOnDidChange();
const toDispose = new DisposableCollection(
Disposable.create(() => this.fireOnDidChange()),
Expand Down
9 changes: 9 additions & 0 deletions packages/monaco/src/browser/monaco-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ import { MimeService } from '@theia/core/lib/browser/mime-service';
import { MonacoEditorServices } from './monaco-editor';
import { MonacoColorRegistry } from './monaco-color-registry';
import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
import { IconRegistry, IconStyleSheetService } from './monaco-icon-registry-types';
import { MonacoIconRegistry } from './monaco-icon-registry';
import { MonacoIconStyleSheetService } from './monaco-icon-style-sheet';
import { MonacoThemingService } from './monaco-theming-service';
import { bindContributionProvider } from '@theia/core';
import { WorkspaceSymbolCommand } from './workspace-symbol-command';
Expand Down Expand Up @@ -187,6 +190,12 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {

bind(ThemeServiceWithDB).toSelf().inSingletonScope();
rebind(ThemeService).toService(ThemeServiceWithDB);

bind(MonacoIconRegistry).toSelf().inSingletonScope();
bind(IconRegistry).toService(MonacoIconRegistry);

bind(MonacoIconStyleSheetService).toSelf().inSingletonScope();
bind(IconStyleSheetService).toService(MonacoIconStyleSheetService);
});

export const MonacoConfigurationService = Symbol('MonacoConfigurationService');
Expand Down
127 changes: 127 additions & 0 deletions packages/monaco/src/browser/monaco-icon-registry-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@

// *****************************************************************************
// Copyright (C) 2023 Ericsson and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************
import { Event } from '@theia/core';
import { IJSONSchema } from '@theia/core/lib/common/json-schema';
import { ThemeIcon } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';
import { URI } from '@theia/core/shared/vscode-uri';

// ------ API types

export type IconIdentifier = string;

// icon registry
export const Extensions = {
IconContribution: 'base.contributions.icons'
};

export type IconDefaults = ThemeIcon | IconDefinition;

export interface IconDefinition {
font?: IconFontContribution; // undefined for the default font (codicon)
fontCharacter: string;
}

export interface IconContribution {
readonly id: string;
description: string | undefined;
deprecationMessage?: string;
readonly defaults: IconDefaults;
}

export interface IconFontContribution {
readonly id: string;
readonly definition: IconFontDefinition;
}

export interface IconFontDefinition {
readonly weight?: string;
readonly style?: string;
readonly src: IconFontSource[];
}

export interface IconFontSource {
readonly location: URI;
readonly format: string;
}

export const IconRegistry = Symbol('IconRegistry');
export interface IconRegistry {

readonly onDidChange: Event<void>;

/**
* Register a icon to the registry.
* @param id The icon id
* @param defaults The default values
* @param description The description
*/
registerIcon(id: IconIdentifier, defaults: IconDefaults, description?: string): ThemeIcon;

/**
* Deregister a icon from the registry.
*/
deregisterIcon(id: IconIdentifier): void;

/**
* Get all icon contributions
*/
getIcons(): IconContribution[];

/**
* Get the icon for the given id
*/
getIcon(id: IconIdentifier): IconContribution | undefined;

/**
* JSON schema for an object to assign icon values to one of the icon contributions.
*/
getIconSchema(): IJSONSchema;

/**
* JSON schema to for a reference to a icon contribution.
*/
getIconReferenceSchema(): IJSONSchema;

/**
* Register a icon font to the registry.
* @param id The icon font id
* @param definition The icon font definition
*/
registerIconFont(id: string, definition: IconFontDefinition): IconFontDefinition;

/**
* Deregister an icon font to the registry.
*/
deregisterIconFont(id: string): void;

/**
* Get the icon font for the given id
*/
getIconFont(id: string): IconFontDefinition | undefined;
}

export const IconsStyleSheet = Symbol('IconsStyleSheet');
export interface IconsStyleSheet {
getCSS(): string;
readonly onDidChange: Event<void>;
}

export const IconStyleSheetService = Symbol('IconStyleSheetService');
export interface IconStyleSheetService {
getIconsStyleSheet(): IconsStyleSheet;
}

59 changes: 59 additions & 0 deletions packages/monaco/src/browser/monaco-icon-registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

// *****************************************************************************
// Copyright (C) 2023 Ericsson and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************

import { injectable } from '@theia/core/shared/inversify';
import * as monaco from '@theia/monaco-editor-core/esm/vs/platform/theme/common/iconRegistry';
import { IconContribution, IconDefaults, IconFontDefinition, IconRegistry } from './monaco-icon-registry-types';
import { Event } from '@theia/core';
import { IJSONSchema } from '@theia/core/lib/common/json-schema';
import { ThemeIcon } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';

@injectable()
export class MonacoIconRegistry implements IconRegistry {
protected readonly iconRegistry = monaco.getIconRegistry();

onDidChange: Event<void> = this.iconRegistry.onDidChange;

registerIcon(id: string, defaults: IconDefaults, description?: string | undefined): ThemeIcon {
return this.iconRegistry.registerIcon(id, defaults, description);
}
deregisterIcon(id: string): void {
return this.iconRegistry.deregisterIcon(id);
}
getIcons(): IconContribution[] {
return this.iconRegistry.getIcons();
}
getIcon(id: string): IconContribution | undefined {
return this.iconRegistry.getIcon(id);
}
getIconSchema(): IJSONSchema {
return this.iconRegistry.getIconSchema();
}
getIconReferenceSchema(): IJSONSchema {
return this.iconRegistry.getIconReferenceSchema();
}
registerIconFont(id: string, definition: IconFontDefinition): IconFontDefinition {
return this.iconRegistry.registerIconFont(id, definition);
}
deregisterIconFont(id: string): void {
return this.iconRegistry.deregisterIconFont(id);
}
getIconFont(id: string): IconFontDefinition | undefined {
return this.iconRegistry.getIconFont(id);
}

}
28 changes: 28 additions & 0 deletions packages/monaco/src/browser/monaco-icon-style-sheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

// *****************************************************************************
// Copyright (C) 2023 Ericsson and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************

import { injectable } from '@theia/core/shared/inversify';
import { getIconsStyleSheet } from '@theia/monaco-editor-core/esm/vs/platform/theme/browser/iconsStyleSheet';
import { IconsStyleSheet } from './monaco-icon-registry-types';

@injectable()
export class MonacoIconStyleSheetService {
protected getIconsStyleSheet(): IconsStyleSheet {
return getIconsStyleSheet(undefined);
}

}
31 changes: 30 additions & 1 deletion packages/plugin-ext/src/common/plugin-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { RpcServer } from '@theia/core/lib/common/messaging/proxy-factory';
import { RPCProtocol } from './rpc-protocol';
import { Disposable } from '@theia/core/lib/common/disposable';
import { LogPart, KeysToAnyValues, KeysToKeysToAnyValue } from './types';
import { CharacterPair, CommentRule, PluginAPIFactory, Plugin } from './plugin-api-rpc';
import { CharacterPair, CommentRule, PluginAPIFactory, Plugin, ThemeIcon } from './plugin-api-rpc';
import { ExtPluginApi } from './plugin-ext-api-contribution';
import { IJSONSchema, IJSONSchemaSnippet } from '@theia/core/lib/common/json-schema';
import { RecursivePartial } from '@theia/core/lib/common/types';
Expand Down Expand Up @@ -90,6 +90,7 @@ export interface PluginPackageContribution {
snippets?: PluginPackageSnippetsContribution[];
themes?: PluginThemeContribution[];
iconThemes?: PluginIconThemeContribution[];
icons?: PluginIconContribution[];
colors?: PluginColorContribution[];
taskDefinitions?: PluginTaskDefinitionContribution[];
problemMatchers?: PluginProblemMatcherContribution[];
Expand Down Expand Up @@ -253,6 +254,13 @@ export interface PluginIconThemeContribution {
uiTheme?: PluginUiTheme;
}

export interface PluginIconContribution {
[id: string]: {
description: string;
default: { fontPath: string; fontCharacter: string } | string;
};
}

export interface PlatformSpecificAdapterContribution {
program?: string;
args?: string[];
Expand Down Expand Up @@ -577,6 +585,7 @@ export interface PluginContribution {
snippets?: SnippetContribution[];
themes?: ThemeContribution[];
iconThemes?: IconThemeContribution[];
icons?: IconContribution[];
colors?: ColorDefinition[];
taskDefinitions?: TaskDefinition[];
problemMatchers?: ProblemMatcherContribution[];
Expand Down Expand Up @@ -644,6 +653,26 @@ export interface IconThemeContribution {
uiTheme?: UiTheme;
}

export interface IconDefinition {
fontCharacter: string;
location: string;
}

export type IconDefaults = ThemeIcon | IconDefinition;

export interface IconContribution {
id: string;
extensionId: string;
description: string | undefined;
defaults: IconDefaults;
}

export namespace IconContribution {
export function isIconDefinition(defaults: IconDefaults): defaults is IconDefinition {
return 'fontCharacter' in defaults;
}
}

export interface GrammarsContribution {
format: 'json' | 'plist';
language?: string;
Expand Down
Loading

0 comments on commit fee1706

Please sign in to comment.