From d3c6036fcc5785fd368526d575a8760f2bc134b7 Mon Sep 17 00:00:00 2001 From: kieferrm Date: Sat, 21 Jan 2017 16:55:26 -0800 Subject: [PATCH] show notification --- .../electron-browser/workbench.main.ts | 2 + .../electron-browser/trust.contribution.ts | 64 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/vs/workbench/parts/trust/electron-browser/trust.contribution.ts diff --git a/src/vs/workbench/electron-browser/workbench.main.ts b/src/vs/workbench/electron-browser/workbench.main.ts index 7540d06d5dc..d5e22d521d2 100644 --- a/src/vs/workbench/electron-browser/workbench.main.ts +++ b/src/vs/workbench/electron-browser/workbench.main.ts @@ -80,6 +80,8 @@ import 'vs/workbench/parts/terminal/electron-browser/terminalPanel'; // can be p import 'vs/workbench/electron-browser/workbench'; +import 'vs/workbench/parts/trust/electron-browser/trust.contribution'; + import 'vs/workbench/parts/tasks/electron-browser/task.contribution'; import 'vs/workbench/parts/emmet/browser/emmet.browser.contribution'; diff --git a/src/vs/workbench/parts/trust/electron-browser/trust.contribution.ts b/src/vs/workbench/parts/trust/electron-browser/trust.contribution.ts new file mode 100644 index 00000000000..72d3c5e1219 --- /dev/null +++ b/src/vs/workbench/parts/trust/electron-browser/trust.contribution.ts @@ -0,0 +1,64 @@ +/*--------------------------------------------------------------------------------------------- + * 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 * as nls from 'vs/nls'; +import { IDisposable, dispose } from 'vs/base/common/lifecycle'; +import { Action } from 'vs/base/common/actions'; +import { IWorkbenchContributionsRegistry, IWorkbenchContribution, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions'; +import { Registry } from 'vs/platform/platform'; +import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle'; +import { IMessageService, Severity, CloseAction } from 'vs/platform/message/common/message'; +import { IPreferencesService } from 'vs/workbench/parts/preferences/common/preferences'; +import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration'; + +class TrustContribution implements IWorkbenchContribution { + + private toDispose: IDisposable[] = []; + private isUntrusted = false; + + constructor( + @ILifecycleService lifecycleService: ILifecycleService, + @IWorkspaceConfigurationService private workspaceConfigurationService: IWorkspaceConfigurationService, + @IPreferencesService private preferencesService: IPreferencesService, + @IMessageService private messageService: IMessageService, + ) { + lifecycleService.onShutdown(this.dispose, this); + this.toDispose.push(this.workspaceConfigurationService.onDidUpdateConfiguration(e => this.checkWorkspaceTrust())); + this.checkWorkspaceTrust(); + } + + getId(): string { + return 'trust'; + } + + public dispose(): void { + this.toDispose = dispose(this.toDispose); + } + + private checkWorkspaceTrust(): void { + const wasUntrusted = this.isUntrusted; + this.isUntrusted = this.workspaceConfigurationService.hasUntrustedConfigurations(); + if (this.isUntrusted && !wasUntrusted) { + this.showTrustWarning(); + } + } + + private showTrustWarning(): void { + const message = nls.localize('untrustedWorkspace', "This workspace specifies executables. While the workspace is untrusted, these settings are being ignored."); + + const openWorkspaceSettings = new Action('trust.openWorkspaceSettings', nls.localize('openWorkspaceSettings', "Review Workspace Settings"), '', true, () => { + return this.preferencesService.openWorkspaceSettings(); + }); + + + const actions = [openWorkspaceSettings, CloseAction]; + this.messageService.show(Severity.Warning, { message, actions }); + } +} + +const workbenchRegistry = Registry.as(WorkbenchExtensions.Workbench); +workbenchRegistry.registerWorkbenchContribution(TrustContribution); -- GitLab