Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into offline-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Jul 24, 2018
2 parents 36d74df + 8e92f80 commit 23f3391
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 67 deletions.
2 changes: 1 addition & 1 deletion extensions/markdown-language-features/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function activate(context: vscode.ExtensionContext) {
const telemetryReporter = loadDefaultTelemetryReporter();
context.subscriptions.push(telemetryReporter);

const contributions = getMarkdownExtensionContributions();
const contributions = getMarkdownExtensionContributions(context);

const cspArbiter = new ExtensionContentSecurityPolicyArbiter(context.globalState, context.workspaceState);
const engine = new MarkdownEngine(contributions, githubSlugifier);
Expand Down
9 changes: 9 additions & 0 deletions extensions/markdown-language-features/src/features/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ export class MarkdownPreview {
this.editor.title = MarkdownPreview.getPreviewTitle(this._resource, this._locked);
}

private get iconPath() {
const root = path.join(this._contributions.extensionPath, 'media');
return {
light: vscode.Uri.file(path.join(root, 'Preview.svg')),
dark: vscode.Uri.file(path.join(root, 'Preview_inverse.svg'))
};
}

private isPreviewOf(resource: vscode.Uri): boolean {
return this._resource.fsPath === resource.fsPath;
}
Expand Down Expand Up @@ -327,6 +335,7 @@ export class MarkdownPreview {
const content = await this._contentProvider.provideTextDocumentContent(document, this._previewConfigurations, this.line, this.state);
if (this._resource === resource) {
this.editor.title = MarkdownPreview.getPreviewTitle(this._resource, this._locked);
this.editor.iconPath = this.iconPath;
this.editor.webview.options = MarkdownPreview.getWebviewOptions(resource, this._contributions);
this.editor.webview.html = content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const resolveExtensionResources = (extension: vscode.Extension<any>, resourcePat
};

export interface MarkdownContributions {
readonly extensionPath: string;
readonly previewScripts: vscode.Uri[];
readonly previewStyles: vscode.Uri[];
readonly markdownItPlugins: Thenable<(md: any) => any>[];
Expand All @@ -40,6 +41,10 @@ class MarkdownExtensionContributions implements MarkdownContributions {

private _loaded = false;

public constructor(
public readonly extensionPath: string,
) { }

public get previewScripts(): vscode.Uri[] {
this.ensureLoaded();
return this._scripts;
Expand Down Expand Up @@ -111,6 +116,6 @@ class MarkdownExtensionContributions implements MarkdownContributions {
}
}

export function getMarkdownExtensionContributions(): MarkdownContributions {
return new MarkdownExtensionContributions();
export function getMarkdownExtensionContributions(context: vscode.ExtensionContext): MarkdownContributions {
return new MarkdownExtensionContributions(context.extensionPath);
}
1 change: 1 addition & 0 deletions extensions/markdown-language-features/src/test/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MarkdownContributions } from '../markdownExtensions';
import { githubSlugifier } from '../slugify';

const emptyContributions = new class implements MarkdownContributions {
readonly extensionPath = '';
readonly previewScripts: vscode.Uri[] = [];
readonly previewStyles: vscode.Uri[] = [];
readonly previewResourceRoots: vscode.Uri[] = [];
Expand Down
3 changes: 1 addition & 2 deletions src/vs/platform/telemetry/common/telemetryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export interface ITelemetryServiceConfig {
appender: ITelemetryAppender;
commonProperties?: TPromise<{ [name: string]: any }>;
piiPaths?: string[];
userOptIn?: boolean;
}

export class TelemetryService implements ITelemetryService {
Expand All @@ -46,7 +45,7 @@ export class TelemetryService implements ITelemetryService {
this._appender = config.appender;
this._commonProperties = config.commonProperties || TPromise.as({});
this._piiPaths = config.piiPaths || [];
this._userOptIn = typeof config.userOptIn === 'undefined' ? true : config.userOptIn;
this._userOptIn = true;

// static cleanup pattern for: `file:///DANGEROUS/PATH/resources/app/Useful/Information`
this._cleanupPatterns = [/file:\/\/\/.*?\/resources\/app\//gi];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import * as Errors from 'vs/base/common/errors';
import * as sinon from 'sinon';
import { getConfigurationValue } from 'vs/platform/configuration/common/configuration';

const optInStatusEventName: string = 'optInStatus';

class TestTelemetryAppender implements ITelemetryAppender {

public events: any[];
Expand Down Expand Up @@ -719,29 +717,9 @@ suite('TelemetryService', () => {
}
}));

test('Telemetry Service respects user opt-in settings', sinon.test(function () {
let testAppender = new TestTelemetryAppender();
let service = new TelemetryService({ userOptIn: false, appender: testAppender }, undefined);

return service.publicLog('testEvent').then(() => {
assert.equal(testAppender.getEventsCount(), 0);
service.dispose();
});
}));

test('Telemetry Service does not sent optInStatus when user opted out', sinon.test(function () {
test('Telemetry Service sends events when enableTelemetry is on', sinon.test(function () {
let testAppender = new TestTelemetryAppender();
let service = new TelemetryService({ userOptIn: false, appender: testAppender }, undefined);

return service.publicLog(optInStatusEventName, { optIn: false }).then(() => {
assert.equal(testAppender.getEventsCount(), 0);
service.dispose();
});
}));

test('Telemetry Service sends events when enableTelemetry is on even user optin is on', sinon.test(function () {
let testAppender = new TestTelemetryAppender();
let service = new TelemetryService({ userOptIn: true, appender: testAppender }, undefined);
let service = new TelemetryService({ appender: testAppender }, undefined);

return service.publicLog('testEvent').then(() => {
assert.equal(testAppender.getEventsCount(), 1);
Expand Down
5 changes: 5 additions & 0 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5500,6 +5500,11 @@ declare module 'vscode' {
*/
title: string;

/**
* Icon for the panel shown in UI.
*/
iconPath?: Uri | { light: Uri; dark: Uri };

/**
* Webview belonging to the panel.
*/
Expand Down
71 changes: 65 additions & 6 deletions src/vs/workbench/api/electron-browser/mainThreadWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import * as dom from 'vs/base/browser/dom';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import * as map from 'vs/base/common/map';
import URI, { UriComponents } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { localize } from 'vs/nls';
import { EditorViewColumn, viewColumnToEditorGroup, editorGroupToViewColumn } from 'vs/workbench/api/shared/editor';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { ExtHostContext, ExtHostWebviewsShape, IExtHostContext, MainContext, MainThreadWebviewsShape, WebviewPanelHandle } from 'vs/workbench/api/node/extHost.protocol';
import { editorGroupToViewColumn, EditorViewColumn, viewColumnToEditorGroup } from 'vs/workbench/api/shared/editor';
import { WebviewEditor } from 'vs/workbench/parts/webview/electron-browser/webviewEditor';
import { WebviewEditorInput } from 'vs/workbench/parts/webview/electron-browser/webviewEditorInput';
import { IWebviewEditorService, WebviewInputOptions, WebviewReviver, ICreateWebViewShowOptions } from 'vs/workbench/parts/webview/electron-browser/webviewEditorService';
import { ICreateWebViewShowOptions, IWebviewEditorService, WebviewInputOptions, WebviewReviver } from 'vs/workbench/parts/webview/electron-browser/webviewEditorService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService';
import { extHostNamedCustomer } from './extHostCustomers';
import * as vscode from 'vscode';
import { extHostNamedCustomer } from './extHostCustomers';

@extHostNamedCustomer(MainContext.MainThreadWebviews)
export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviver {
Expand All @@ -29,6 +30,39 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv

private static revivalPool = 0;

private static _styleElement?: HTMLStyleElement;

private static _icons = new Map<number, { light: URI, dark: URI }>();

private static updateStyleElement(
webview: WebviewEditorInput,
iconPath: { light: URI, dark: URI } | undefined
) {
const id = webview.getId();
if (!this._styleElement) {
this._styleElement = dom.createStyleSheet();
this._styleElement.className = 'webview-icons';
}

if (!iconPath) {
this._icons.delete(id);
} else {
this._icons.set(id, iconPath);
}

const cssRules: string[] = [];
this._icons.forEach((value, key) => {
const webviewSelector = `.show-file-icons .webview-${key}-name-file-icon::before`;
if (URI.isUri(value)) {
cssRules.push(`${webviewSelector} { content: ""; background-image: url(${value.toString()}); }`);
} else {
cssRules.push(`${webviewSelector} { content: ""; background-image: url(${value.light.toString()}); }`);
cssRules.push(`.vs-dark ${webviewSelector} { content: ""; background-image: url(${value.dark.toString()}); }`);
}
});
this._styleElement.innerHTML = cssRules.join('\n');
}

private _toDispose: IDisposable[] = [];

private readonly _proxy: ExtHostWebviewsShape;
Expand Down Expand Up @@ -96,6 +130,11 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
webview.setName(value);
}

public $setIconPath(handle: WebviewPanelHandle, value: { light: UriComponents, dark: UriComponents } | undefined): void {
const webview = this.getWebview(handle);
MainThreadWebviews.updateStyleElement(webview, reviveWebviewIcon(value));
}

public $setHtml(handle: WebviewPanelHandle, value: string): void {
const webview = this.getWebview(handle);
webview.html = value;
Expand Down Expand Up @@ -185,9 +224,16 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
onDidClickLink: uri => this.onDidClickLink(handle, uri),
onMessage: message => this._proxy.$onMessage(handle, message),
onDispose: () => {
const cleanUp = () => {
const webview = this._webviews.get(handle);
if (webview) {
MainThreadWebviews.updateStyleElement(webview, undefined);
}
this._webviews.delete(handle);
};
this._proxy.$onDidDisposeWebviewPanel(handle).then(
() => this._webviews.delete(handle),
() => this._webviews.delete(handle));
cleanUp,
cleanUp);
}
};
}
Expand Down Expand Up @@ -297,3 +343,16 @@ function reviveWebviewOptions(options: WebviewInputOptions): WebviewInputOptions
localResourceRoots: Array.isArray(options.localResourceRoots) ? options.localResourceRoots.map(URI.revive) : undefined
};
}

function reviveWebviewIcon(
value: { light: UriComponents, dark: UriComponents } | undefined
): { light: URI, dark: URI } | undefined {
if (!value) {
return undefined;
}

return {
light: URI.revive(value.light),
dark: URI.revive(value.dark)
};
}
1 change: 1 addition & 0 deletions src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ export interface MainThreadWebviewsShape extends IDisposable {
$disposeWebview(handle: WebviewPanelHandle): void;
$reveal(handle: WebviewPanelHandle, viewColumn: EditorViewColumn | null, preserveFocus: boolean): void;
$setTitle(handle: WebviewPanelHandle, value: string): void;
$setIconPath(handle: WebviewPanelHandle, value: { light: UriComponents, dark: UriComponents } | undefined): void;
$setHtml(handle: WebviewPanelHandle, value: string): void;
$setOptions(handle: WebviewPanelHandle, options: vscode.WebviewOptions): void;
$postMessage(handle: WebviewPanelHandle, value: any): Thenable<boolean>;
Expand Down
28 changes: 23 additions & 5 deletions src/vs/workbench/api/node/extHostWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { MainContext, MainThreadWebviewsShape, IMainContext, ExtHostWebviewsShape, WebviewPanelHandle, WebviewPanelViewState } from './extHost.protocol';
import * as vscode from 'vscode';
import { Event, Emitter } from 'vs/base/common/event';
import { Emitter, Event } from 'vs/base/common/event';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import * as typeConverters from 'vs/workbench/api/node/extHostTypeConverters';
import { EditorViewColumn } from 'vs/workbench/api/shared/editor';
import { TPromise } from 'vs/base/common/winjs.base';
import * as vscode from 'vscode';
import { ExtHostWebviewsShape, IMainContext, MainContext, MainThreadWebviewsShape, WebviewPanelHandle, WebviewPanelViewState } from './extHost.protocol';
import { Disposable } from './extHostTypes';
import URI from 'vs/base/common/uri';


type IconPath = URI | { light: URI, dark: URI };

export class ExtHostWebview implements vscode.Webview {
private readonly _handle: WebviewPanelHandle;
Expand Down Expand Up @@ -78,6 +81,7 @@ export class ExtHostWebviewPanel implements vscode.WebviewPanel {
private readonly _proxy: MainThreadWebviewsShape;
private readonly _viewType: string;
private _title: string;
private _iconPath: IconPath;

private readonly _options: vscode.WebviewPanelOptions;
private readonly _webview: ExtHostWebview;
Expand Down Expand Up @@ -150,6 +154,20 @@ export class ExtHostWebviewPanel implements vscode.WebviewPanel {
}
}

get iconPath(): IconPath | undefined {
this.assertNotDisposed();
return this._iconPath;
}

set iconPath(value: IconPath | undefined) {
this.assertNotDisposed();
if (this._iconPath !== value) {
this._iconPath = value;

this._proxy.$setIconPath(this._handle, URI.isUri(value) ? { light: value, dark: value } : value);
}
}

get options() {
return this._options;
}
Expand Down
9 changes: 6 additions & 3 deletions src/vs/workbench/browser/parts/menubar/media/menubarpart.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
position: absolute;
left: 0px;
opacity: 1;
z-index: 2000;
}

.menubar-menu-items-holder.monaco-menu-container {
box-shadow: 0 2px 4px;
font-family: "Segoe WPC", "Segoe UI", ".SFNSDisplay-Light", "SFUIText-Light", "HelveticaNeue-Light", sans-serif, "Droid Sans Fallback";
outline: 0;
border: none;
}

.vs-dark .menubar-menu-items-holder.monaco-menu-container {
box-shadow: 0 2px 4px;
.menubar-menu-items-holder.monaco-menu-container :focus {
outline: 0;
}
2 changes: 0 additions & 2 deletions src/vs/workbench/browser/parts/menubar/menubarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,6 @@ export class MenubarPart extends Part {
let menuHolder = $(customMenu.buttonElement).div({ class: 'menubar-menu-items-holder' });

$(menuHolder.getHTMLElement().parentElement).addClass('open');

menuHolder.addClass('menubar-menu-items-holder-open context-view');
menuHolder.style({
'zoom': `${1 / browser.getZoomFactor()}`,
'top': `${this.container.getClientArea().height * browser.getZoomFactor()}px`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,15 @@ export class LocalizationWorkbenchContribution extends Disposable implements IWo
return;
}

const extensionIdPostfix = this.getPossibleChineseMapping(locale);
const ceintlExtensionSearch = this.galleryService.query({ names: [`MS-CEINTL.vscode-language-pack-${extensionIdPostfix}`], pageSize: 1 });
const tagSearch = this.galleryService.query({ text: `tag:lp-${locale}`, pageSize: 1 });

TPromise.join([ceintlExtensionSearch, tagSearch]).then(([ceintlResult, tagResult]) => {
if (ceintlResult.total === 0 && tagResult.total === 0) {
this.galleryService.query({ text: `tag:lp-${locale}` }).then(tagResult => {
if (tagResult.total === 0) {
return;
}

const extensionToInstall = ceintlResult.total === 1 ? ceintlResult.firstPage[0] : tagResult.total === 1 ? tagResult.firstPage[0] : null;
const extensionToFetchTranslationsFrom = extensionToInstall || (tagResult.total > 0 ? tagResult.firstPage[0] : null);
const extensionToInstall = tagResult.total === 1 ? tagResult.firstPage[0] : tagResult.firstPage.filter(e => e.publisher === 'MS-CEINTL' && e.name.indexOf('vscode-language-pack') === 0)[0];
const extensionToFetchTranslationsFrom = extensionToInstall || tagResult.firstPage[0];

if (!extensionToFetchTranslationsFrom || !extensionToFetchTranslationsFrom.assets.manifest) {
if (!extensionToFetchTranslationsFrom.assets.manifest) {
return;
}

Expand Down Expand Up @@ -236,11 +232,6 @@ export class LocalizationWorkbenchContribution extends Disposable implements IWo

}

private getPossibleChineseMapping(locale: string): string {
locale = locale.toLowerCase();
return locale === 'zh-cn' ? 'zh-hans' : locale === 'zh-tw' ? 'zh-hant' : locale;
}

private getLanguagePackExtension(language: string): TPromise<IGalleryExtension> {
return this.localizationService.getLanguageIds(LanguageType.Core)
.then(coreLanguages => {
Expand Down
Loading

0 comments on commit 23f3391

Please sign in to comment.