Skip to content

Commit

Permalink
Merge from vscode f5d3ffa (microsoft#7929)
Browse files Browse the repository at this point in the history
* Merge from vscode f5d3ffa

* fix launch script

* add missing files
  • Loading branch information
Anthony Dresser authored Oct 23, 2019
1 parent 4a68ab4 commit a94cbb5
Show file tree
Hide file tree
Showing 189 changed files with 1,973 additions and 1,538 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: CI

on: [push, pull_request]

jobs:
linux:
runs-on: ubuntu-latest
env:
CHILD_CONCURRENCY: "1"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v1
# TODO: rename azure-pipelines/linux/xvfb.init to github-actions
- run: |
sudo apt-get update
sudo apt-get install -y libxkbfile-dev pkg-config libsecret-1-dev libxss1 dbus xvfb libgtk-3-0
sudo cp build/azure-pipelines/linux/xvfb.init /etc/init.d/xvfb
sudo chmod +x /etc/init.d/xvfb
sudo update-rc.d xvfb defaults
sudo service xvfb start
name: Setup Build Environment
- uses: actions/setup-node@v1
with:
node-version: 10
# TODO: cache node modules
- run: yarn --frozen-lockfile
name: Install Dependencies
- run: yarn electron x64
name: Download Electron
- run: yarn gulp hygiene --skip-tslint
name: Run Hygiene Checks
- run: yarn gulp tslint
name: Run TSLint Checks
- run: yarn monaco-compile-check
name: Run Monaco Editor Checks
- run: yarn compile
name: Compile Sources
- run: yarn download-builtin-extensions
name: Download Built-in Extensions
- run: DISPLAY=:10 ./scripts/test.sh --tfs "Unit Tests"
name: Run Unit Tests
- run: DISPLAY=:10 ./scripts/test-integration.sh --tfs "Integration Tests"
name: Run Integration Tests

windows:
runs-on: windows-2016
env:
CHILD_CONCURRENCY: "1"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 10
- uses: actions/setup-python@v1
with:
python-version: '2.x'
- run: yarn --frozen-lockfile
name: Install Dependencies
- run: yarn electron
name: Download Electron
- run: yarn gulp hygiene --skip-tslint
name: Run Hygiene Checks
- run: yarn gulp tslint
name: Run TSLint Checks
- run: yarn monaco-compile-check
name: Run Monaco Editor Checks
- run: yarn compile
name: Compile Sources
- run: yarn download-builtin-extensions
name: Download Built-in Extensions
- run: .\scripts\test.bat --tfs "Unit Tests"
name: Run Unit Tests
- run: .\scripts\test-integration.bat --tfs "Integration Tests"
name: Run Integration Tests

darwin:
runs-on: macos-latest
env:
CHILD_CONCURRENCY: "1"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 10
- run: yarn --frozen-lockfile
name: Install Dependencies
- run: yarn electron x64
name: Download Electron
- run: yarn gulp hygiene --skip-tslint
name: Run Hygiene Checks
- run: yarn gulp tslint
name: Run TSLint Checks
- run: yarn monaco-compile-check
name: Run Monaco Editor Checks
- run: yarn compile
name: Compile Sources
- run: yarn download-builtin-extensions
name: Download Built-in Extensions
- run: ./scripts/test.sh --tfs "Unit Tests"
name: Run Unit Tests
- run: ./scripts/test-integration.sh --tfs "Integration Tests"
name: Run Integration Tests
2 changes: 1 addition & 1 deletion build/azure-pipelines/darwin/continuous-build-darwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ steps:
inputs:
versionSpec: "1.x"
- script: |
yarn --frozen-lockfile
CHILD_CONCURRENCY=1 yarn --frozen-lockfile
displayName: Install Dependencies
condition: and(succeeded(), ne(variables['CacheRestored'], 'true'))
- task: 1ESLighthouseEng.PipelineArtifactCaching.SaveCacheV1.SaveCache@1
Expand Down
2 changes: 1 addition & 1 deletion build/azure-pipelines/linux/continuous-build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ steps:
inputs:
versionSpec: "1.x"
- script: |
yarn --frozen-lockfile
CHILD_CONCURRENCY=1 yarn --frozen-lockfile
displayName: Install Dependencies
condition: and(succeeded(), ne(variables['CacheRestored'], 'true'))
- task: 1ESLighthouseEng.PipelineArtifactCaching.SaveCacheV1.SaveCache@1
Expand Down
2 changes: 2 additions & 0 deletions build/azure-pipelines/win32/continuous-build-win32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ steps:
vstsFeed: '$(ArtifactFeed)'
- powershell: |
yarn --frozen-lockfile
env:
CHILD_CONCURRENCY: "1"
displayName: Install Dependencies
condition: and(succeeded(), ne(variables['CacheRestored'], 'true'))
- task: 1ESLighthouseEng.PipelineArtifactCaching.SaveCacheV1.SaveCache@1
Expand Down
56 changes: 39 additions & 17 deletions extensions/image-preview/media/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,34 @@
updateScale(scale);
}

function zoomIn() {
if (scale === 'fit') {
firstZoom();
}

let i = 0;
for (; i < zoomLevels.length; ++i) {
if (zoomLevels[i] > scale) {
break;
}
}
updateScale(zoomLevels[i] || MAX_SCALE);
}

function zoomOut() {
if (scale === 'fit') {
firstZoom();
}

let i = zoomLevels.length - 1;
for (; i >= 0; --i) {
if (zoomLevels[i] < scale) {
break;
}
}
updateScale(zoomLevels[i] || MIN_SCALE);
}

window.addEventListener('keydown', (/** @type {KeyboardEvent} */ e) => {
if (!image || !hasLoadedImage) {
return;
Expand Down Expand Up @@ -204,21 +232,9 @@
}

if (!(isMac ? altPressed : ctrlPressed)) { // zoom in
let i = 0;
for (; i < zoomLevels.length; ++i) {
if (zoomLevels[i] > scale) {
break;
}
}
updateScale(zoomLevels[i] || MAX_SCALE);
zoomIn();
} else {
let i = zoomLevels.length - 1;
for (; i >= 0; --i) {
if (zoomLevels[i] < scale) {
break;
}
}
updateScale(zoomLevels[i] || MIN_SCALE);
zoomOut();
}
});

Expand All @@ -232,9 +248,6 @@
return;
}

e.preventDefault();
e.stopPropagation();

if (scale === 'fit') {
firstZoom();
}
Expand Down Expand Up @@ -290,9 +303,18 @@
case 'setScale':
updateScale(e.data.scale);
break;

case 'setActive':
changeActive(e.data.value);
break;

case 'zoomIn':
zoomIn();
break;

case 'zoomOut':
zoomOut();
break;
}
});
}());
32 changes: 30 additions & 2 deletions extensions/image-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"Other"
],
"activationEvents": [
"onWebviewEditor:imagePreview.previewEditor"
"onWebviewEditor:imagePreview.previewEditor",
"onCommand:imagePreview.zoomIn",
"onCommand:imagePreview.zoomOut"
],
"contributes": {
"webviewEditors": [
Expand All @@ -32,7 +34,33 @@
}
]
}
]
],
"commands": [
{
"command": "imagePreview.zoomIn",
"title": "%command.zoomIn%",
"category": "Image Preview"
},
{
"command": "imagePreview.zoomOut",
"title": "%command.zoomOut%",
"category": "Image Preview"
}
],
"menus": {
"commandPalette": [
{
"command": "imagePreview.zoomIn",
"when": "imagePreviewFocus",
"group": "1_imagePreview"
},
{
"command": "imagePreview.zoomOut",
"when": "imagePreviewFocus",
"group": "1_imagePreview"
}
]
}
},
"scripts": {
"compile": "gulp compile-extension:image-preview",
Expand Down
4 changes: 3 additions & 1 deletion extensions/image-preview/package.nls.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"displayName": "Image Preview",
"description": "Provides VS Code's built-in image preview",
"webviewEditors.displayName": "Image Preview"
"webviewEditors.displayName": "Image Preview",
"command.zoomIn": "Zoom in",
"command.zoomOut": "Zoom out"
}
18 changes: 14 additions & 4 deletions extensions/image-preview/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { Preview } from './preview';
import { PreviewManager } from './preview';
import { SizeStatusBarEntry } from './sizeStatusBarEntry';
import { ZoomStatusBarEntry } from './zoomStatusBarEntry';

Expand All @@ -17,12 +17,22 @@ export function activate(context: vscode.ExtensionContext) {
const zoomStatusBarEntry = new ZoomStatusBarEntry();
context.subscriptions.push(zoomStatusBarEntry);

const previewManager = new PreviewManager(extensionRoot, sizeStatusBarEntry, zoomStatusBarEntry);

context.subscriptions.push(vscode.window.registerWebviewEditorProvider(
Preview.viewType,
PreviewManager.viewType,
{
async resolveWebviewEditor(resource: vscode.Uri, editor: vscode.WebviewEditor): Promise<void> {
// tslint:disable-next-line: no-unused-expression
new Preview(extensionRoot, resource, editor, sizeStatusBarEntry, zoomStatusBarEntry);
previewManager.resolve(resource, editor);
}
}));

context.subscriptions.push(vscode.commands.registerCommand('imagePreview.zoomIn', () => {
previewManager.activePreview?.zoomIn();
}));

context.subscriptions.push(vscode.commands.registerCommand('imagePreview.zoomOut', () => {
previewManager.activePreview?.zoomOut();
}));
}

61 changes: 58 additions & 3 deletions extensions/image-preview/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,58 @@ import { Scale, ZoomStatusBarEntry } from './zoomStatusBarEntry';

const localize = nls.loadMessageBundle();


export class PreviewManager {

public static readonly viewType = 'imagePreview.previewEditor';

private readonly _previews = new Set<Preview>();
private _activePreview: Preview | undefined;

constructor(
private readonly extensionRoot: vscode.Uri,
private readonly sizeStatusBarEntry: SizeStatusBarEntry,
private readonly zoomStatusBarEntry: ZoomStatusBarEntry,
) { }

public resolve(
resource: vscode.Uri,
webviewEditor: vscode.WebviewEditor,
) {
const preview = new Preview(this.extensionRoot, resource, webviewEditor, this.sizeStatusBarEntry, this.zoomStatusBarEntry);
this._previews.add(preview);
this.setActivePreview(preview);

webviewEditor.onDidDispose(() => { this._previews.delete(preview); });

webviewEditor.onDidChangeViewState(() => {
if (webviewEditor.active) {
this.setActivePreview(preview);
} else if (this._activePreview === preview && !webviewEditor.active) {
this.setActivePreview(undefined);
}
});
}

public get activePreview() { return this._activePreview; }

private setActivePreview(value: Preview | undefined): void {
this._activePreview = value;
this.setPreviewActiveContext(!!value);
}

private setPreviewActiveContext(value: boolean) {
vscode.commands.executeCommand('setContext', 'imagePreviewFocus', value);
}
}

const enum PreviewState {
Disposed,
Visible,
Active,
}

export class Preview extends Disposable {

public static readonly viewType = 'imagePreview.previewEditor';
class Preview extends Disposable {

private readonly id: string = `${Date.now()}-${Math.random().toString()}`;

Expand Down Expand Up @@ -98,6 +141,18 @@ export class Preview extends Disposable {
this.update();
}

public zoomIn() {
if (this._previewState === PreviewState.Active) {
this.webviewEditor.webview.postMessage({ type: 'zoomIn' });
}
}

public zoomOut() {
if (this._previewState === PreviewState.Active) {
this.webviewEditor.webview.postMessage({ type: 'zoomOut' });
}
}

private render() {
if (this._previewState !== PreviewState.Disposed) {
this.webviewEditor.webview.html = this.getWebiewContents();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"native-keymap": "2.0.0",
"native-watchdog": "1.2.0",
"ng2-charts": "^1.6.0",
"node-pty": "0.9.0-beta19",
"node-pty": "0.9.0",
"nsfw": "1.2.5",
"onigasm-umd": "^2.2.2",
"plotly.js-dist": "^1.48.3",
Expand Down
Loading

0 comments on commit a94cbb5

Please sign in to comment.