提交 a10fc279 编写于 作者: B Benjamin Pasero

notifications - scaffold a notification service

上级 7410a0ea
......@@ -39,6 +39,7 @@ import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKe
import { OS } from 'vs/base/common/platform';
import { IRange } from 'vs/editor/common/core/range';
import { ITextModel } from 'vs/editor/common/model';
import { INotificationService, INotification } from 'vs/platform/notification/common/notification';
export class SimpleEditor implements IEditor {
......@@ -280,6 +281,30 @@ export class SimpleMessageService implements IMessageService {
}
}
export class SimpleNotificationService implements INotificationService {
public _serviceBrand: any;
private static readonly Empty: INotification = { dispose: () => undefined };
public notify(sev: Severity, message: string): INotification {
switch (sev) {
case Severity.Error:
console.error(message);
break;
case Severity.Warning:
console.warn(message);
break;
default:
console.log(message);
break;
}
return SimpleNotificationService.Empty;
}
}
export class StandaloneCommandService implements ICommandService {
_serviceBrand: any;
......
......@@ -33,7 +33,7 @@ import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { CodeEditorServiceImpl } from 'vs/editor/browser/services/codeEditorServiceImpl';
import {
SimpleConfigurationService, SimpleResourceConfigurationService, SimpleMenuService, SimpleMessageService,
SimpleProgressService, StandaloneCommandService, StandaloneKeybindingService,
SimpleProgressService, StandaloneCommandService, StandaloneKeybindingService, SimpleNotificationService,
StandaloneTelemetryService, SimpleWorkspaceContextService
} from 'vs/editor/standalone/browser/simpleServices';
import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService';
......@@ -41,6 +41,7 @@ import { IMenuService } from 'vs/platform/actions/common/actions';
import { IStandaloneThemeService } from 'vs/editor/standalone/common/standaloneThemeService';
import { StandaloneThemeServiceImpl } from 'vs/editor/standalone/browser/standaloneThemeServiceImpl';
import { ILogService, NullLogService } from 'vs/platform/log/common/log';
import { INotificationService } from 'vs/platform/notification/common/notification';
export interface IEditorContextViewService extends IContextViewService {
dispose(): void;
......@@ -127,6 +128,8 @@ export module StaticServices {
export const messageService = define(IMessageService, () => new SimpleMessageService());
export const notificationService = define(INotificationService, () => new SimpleNotificationService());
export const markerService = define(IMarkerService, () => new MarkerService());
export const modeService = define(IModeService, (o) => new ModeServiceImpl());
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Severity } from 'vs/platform/message/common/message';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IDisposable } from 'vs/base/common/lifecycle';
export const INotificationService = createDecorator<INotificationService>('notificationService');
export interface INotification extends IDisposable {
}
export interface INotificationService {
_serviceBrand: any;
notify(sev: Severity, message: string): INotification;
// notify(sev: Severity, message: Error): () => void;
// notify(sev: Severity, message: string[]): () => void;
// notify(sev: Severity, message: Error[]): () => void;
// notify(sev: Severity, message: IMessageWithAction): () => void;
}
\ No newline at end of file
......@@ -51,6 +51,7 @@ import { getDomNodePagePosition, createStyleSheet, createCSSRule } from 'vs/base
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { Context } from 'vs/platform/contextkey/browser/contextKeyService';
import { IWorkbenchIssueService } from 'vs/workbench/services/issue/common/issue';
import { INotificationService } from 'vs/platform/notification/common/notification';
// --- actions
......@@ -1571,13 +1572,15 @@ export class ShowAboutDialogAction extends Action {
constructor(
id: string,
label: string,
@IWindowsService private windowsService: IWindowsService
@INotificationService private notificationService: INotificationService
) {
super(id, label);
}
run(): TPromise<void> {
return this.windowsService.openAboutDialog();
this.notificationService.notify(Severity.Info, 'This is a message with a [link](https://code.visualstudio.com).');
return TPromise.as(undefined);
}
}
......
......@@ -94,6 +94,8 @@ import { ILocalizationsChannel, LocalizationsChannelClient } from 'vs/platform/l
import { ILocalizationsService } from 'vs/platform/localizations/common/localizations';
import { IWorkbenchIssueService } from 'vs/workbench/services/issue/common/issue';
import { WorkbenchIssueService } from 'vs/workbench/services/issue/electron-browser/workbenchIssueService';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { NotificationService } from 'vs/workbench/services/notification/browser/notificationService';
/**
* Services that we require for the Shell
......@@ -401,6 +403,8 @@ export class WorkbenchShell {
serviceCollection.set(IMessageService, this.messageService);
serviceCollection.set(IChoiceService, this.messageService);
serviceCollection.set(INotificationService, new SyncDescriptor(NotificationService, container));
const lifecycleService = instantiationService.createInstance(LifecycleService);
this.toUnbind.push(lifecycleService.onShutdown(reason => this.dispose(reason)));
serviceCollection.set(ILifecycleService, lifecycleService);
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Severity } from 'vs/platform/message/common/message';
export class NotificationList {
constructor(
private container: HTMLElement
) {
}
public show(severity: Severity, notification: string): void {
console.log(this.container);
}
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { INotificationService, INotification } from 'vs/platform/notification/common/notification';
import { Severity } from 'vs/platform/message/common/message';
import { NotificationList } from 'vs/workbench/services/notification/browser/notificationList';
export class NotificationService implements INotificationService {
public _serviceBrand: any;
private handler: NotificationList;
constructor(
container: HTMLElement
) {
this.handler = new NotificationList(container);
}
public notify(sev: Severity, message: string): INotification {
this.handler.show(sev, message);
return { dispose: () => void 0 };
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册