vscode/src/vs/workbench/contrib/example/browser/example.contribution.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
2.4 KiB
TypeScript
Raw Normal View History

2024-11-15 06:29:18 +00:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Registry } from '../../../../platform/registry/common/platform.js';
import {
ViewContainerLocation,
IViewContainersRegistry,
IViewsRegistry,
Extensions
} from '../../../common/views.js';
import { ILocalizedString, localize } from '../../../../nls.js';
import { SyncDescriptor } from '../../../../platform/instantiation/common/descriptors.js';
import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js';
import { Codicon } from '../../../../base/common/codicons.js';
import { ExampleViewContainer } from './exampleViewContainer.js';
import { ExampleView } from './exampleView.js';
import { IViewPaneOptions } from '../../../browser/parts/views/viewPane.js';
// 如果需要为 Extensions 使用别名,可以在此处赋值
const ViewContainerExtensions = Extensions;
const ViewExtensions = Extensions;
// 注册图标
const exampleIcon = registerIcon(
'example-view-icon',
Codicon.beaker,
localize('exampleViewIcon', 'Example View 的图标')
);
// 注册视图容器
const viewContainer = Registry.as<IViewContainersRegistry>(ViewContainerExtensions.ViewContainersRegistry).registerViewContainer(
{
id: 'workbench.view.example',
title: { value: localize('example', '示例'), original: 'Example' },
ctorDescriptor: new SyncDescriptor(ExampleViewContainer),
icon: exampleIcon,
order: 6,
},
ViewContainerLocation.Sidebar
);
// 定义视图选项
const exampleViewOptions: IViewPaneOptions = {
id: 'exampleView',
title: '示例视图',
};
function localizedString(key: string, defaultMessage: string, original: string): ILocalizedString {
console.log('Registering Example View Container...');
// eslint-disable-next-line local/code-no-unexternalized-strings
return { value: localize(key, defaultMessage), original };
}
// 注册视图
Registry.as<IViewsRegistry>(ViewExtensions.ViewsRegistry).registerViews(
[
{
id: 'exampleView',
name: localizedString('exampleView', '示例视图', 'Example View'),
ctorDescriptor: new SyncDescriptor(ExampleView, [exampleViewOptions]),
},
],
viewContainer
);
console.log('初始化完成');