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.

89 lines
3.1 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';
2024-11-20 18:12:20 +00:00
import { ExampleViewContainer } from './views/exampleViewContainer.js';
import { ExampleView } from './views/exampleView.js';
2024-11-15 06:29:18 +00:00
import { IViewPaneOptions } from '../../../browser/parts/views/viewPane.js';
2024-11-20 18:12:20 +00:00
import { EditorPaneDescriptor, IEditorPaneRegistry } from '../../../browser/editor.js';
import { EditorExtensions } from '../../../common/editor.js';
2024-11-21 08:39:15 +00:00
import { StockDetailsEditor } from './editors/StockDetailsEditor.js';
import { StockDetailsInput } from './editors/StockDetailsInput.js';
2024-11-20 18:12:20 +00:00
2024-11-15 06:29:18 +00:00
// 如果需要为 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',
2024-11-20 18:12:20 +00:00
title: { value: localize('example', '侧边栏'), original: 'Example' },
2024-11-15 06:29:18 +00:00
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
);
2024-11-20 18:12:20 +00:00
// 注册 EditorPane
Registry.as<IEditorPaneRegistry>(EditorExtensions.EditorPane).registerEditorPane(
EditorPaneDescriptor.create(
StockDetailsEditor, // 编辑器的类
StockDetailsEditor.ID, // 编辑器唯一标识符
localize('stockDetails', 'Stock Details') // 编辑器的本地化名称
),
[new SyncDescriptor(StockDetailsInput)] // 绑定的 EditorInput 类型
);
console.log('StockDetailsEditor 注册完成');
2024-11-15 06:29:18 +00:00
console.log('初始化完成');