-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editor preview #3373
Merged
svenefftinge
merged 1 commit into
eclipse-theia:master
from
caseyflynn-google:editor-preview
Nov 20, 2018
Merged
Editor preview #3373
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 Google and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { interfaces } from 'inversify'; | ||
import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceContribution, PreferenceSchema } from './preferences'; | ||
|
||
export const corePreferenceSchema: PreferenceSchema = { | ||
'type': 'object', | ||
properties: { | ||
'list.openMode': { | ||
type: 'string', | ||
enum: [ | ||
'singleClick', | ||
'doubleClick' | ||
], | ||
default: 'singleClick', | ||
description: 'Controls how to open items in trees using the mouse.' | ||
} | ||
} | ||
}; | ||
|
||
export interface CoreConfiguration { | ||
'list.openMode': string; | ||
} | ||
|
||
export const CorePreferences = Symbol('CorePreferences'); | ||
export type CorePreferences = PreferenceProxy<CoreConfiguration>; | ||
|
||
export function createCorePreferences(preferences: PreferenceService): CorePreferences { | ||
return createPreferenceProxy(preferences, corePreferenceSchema); | ||
} | ||
|
||
export function bindCorePreferences(bind: interfaces.Bind): void { | ||
bind(CorePreferences).toDynamicValue(ctx => { | ||
const preferences = ctx.container.get<PreferenceService>(PreferenceService); | ||
return createCorePreferences(preferences); | ||
}).inSingletonScope(); | ||
bind(PreferenceContribution).toConstantValue({ schema: corePreferenceSchema}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Theia - Editor Preview Extension | ||
|
||
See [here](https://www.theia-ide.org/doc/index.html) for a detailed documentation. | ||
|
||
## License | ||
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/) | ||
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../configs/base.tsconfig", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "@theia/editor-preview", | ||
"version": "0.3.16", | ||
"description": "Theia - Editor Preview Extension", | ||
"dependencies": { | ||
"@theia/core": "^0.3.16", | ||
"@theia/editor": "^0.3.16", | ||
"@theia/navigator": "^0.3.16" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"theiaExtensions": [ | ||
{ | ||
"frontend": "lib/browser/editor-preview-frontend-module" | ||
} | ||
], | ||
"keywords": [ | ||
"theia-extension" | ||
], | ||
"license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/theia-ide/theia.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/theia-ide/theia/issues" | ||
}, | ||
"homepage": "https://github.com/theia-ide/theia", | ||
"files": [ | ||
"lib", | ||
"src" | ||
], | ||
"scripts": { | ||
"prepare": "yarn run clean && yarn run build", | ||
"clean": "theiaext clean", | ||
"build": "theiaext build", | ||
"watch": "theiaext watch", | ||
"test": "theiaext test", | ||
"docs": "theiaext docs" | ||
}, | ||
"devDependencies": { | ||
"@theia/ext-scripts": "^0.3.16" | ||
}, | ||
"nyc": { | ||
"extends": "../../configs/nyc.json" | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
packages/editor-preview/src/browser/editor-preview-factory.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 Google and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
// This file is strictly for testing; disable no-any so we can mock out objects not under test | ||
// disable no-unused-expression for chai. | ||
// tslint:disable:no-any no-unused-expression | ||
|
||
import {enableJSDOM} from '@theia/core/lib/browser/test/jsdom'; | ||
const disableJsDom = enableJSDOM(); | ||
|
||
import { Container } from 'inversify'; | ||
import { WidgetFactory, WidgetManager } from '@theia/core/lib/browser'; | ||
import { EditorWidget, EditorManager } from '@theia/editor/lib/browser'; | ||
import { EditorPreviewWidgetFactory, EditorPreviewWidgetOptions } from './editor-preview-factory'; | ||
import { expect } from 'chai'; | ||
import * as sinon from 'sinon'; | ||
import * as previewFrontEndModule from './editor-preview-frontend-module'; | ||
|
||
const mockEditorWidget = sinon.createStubInstance(EditorWidget); | ||
const mockEditorManager = { | ||
getOrCreateByUri: () => {} | ||
}; | ||
const getOrCreateStub = sinon.stub(mockEditorManager, 'getOrCreateByUri').returns(mockEditorWidget); | ||
|
||
let testContainer: Container; | ||
|
||
before(() => { | ||
testContainer = new Container(); | ||
// Mock out injected dependencies. | ||
testContainer.bind(WidgetManager).toDynamicValue(ctx => ({} as any)); | ||
testContainer.bind(EditorManager).toDynamicValue(ctx => (mockEditorManager as any)); | ||
testContainer.load(previewFrontEndModule.default); | ||
}); | ||
|
||
after(() => { | ||
disableJsDom(); | ||
}); | ||
|
||
describe('editor-preview-factory', () => { | ||
let widgetFactory: EditorPreviewWidgetFactory; | ||
|
||
beforeEach(() => { | ||
widgetFactory = testContainer.get<EditorPreviewWidgetFactory>(WidgetFactory); | ||
getOrCreateStub.resetHistory(); | ||
}); | ||
|
||
it('should create a new editor widget via editor manager if same session', async () => { | ||
const opts: EditorPreviewWidgetOptions = { | ||
kind: 'editor-preview-widget', | ||
id: '1', | ||
initialUri: 'file://a/b/c', | ||
session: EditorPreviewWidgetFactory.sessionId | ||
}; | ||
const widget = await widgetFactory.createWidget(opts); | ||
expect((mockEditorManager.getOrCreateByUri as sinon.SinonStub).calledOnce).to.be.true; | ||
expect(widget.id).to.equal(opts.id); | ||
expect(widget.editorWidget).to.equal(mockEditorWidget); | ||
}); | ||
|
||
it('should not create a widget if restoring from previous session', async () => { | ||
const opts: EditorPreviewWidgetOptions = { | ||
kind: 'editor-preview-widget', | ||
id: '2', | ||
initialUri: 'file://a/b/c', | ||
session: 'session-mismatch' | ||
}; | ||
const widget = await widgetFactory.createWidget(opts); | ||
expect((mockEditorManager.getOrCreateByUri as sinon.SinonStub).called).to.be.false; | ||
expect(widget.id).to.equal(opts.id); | ||
expect(widget.editorWidget).to.be.undefined; | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
packages/editor-preview/src/browser/editor-preview-factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 Google and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import URI from '@theia/core/lib/common/uri'; | ||
import { WidgetFactory, WidgetManager } from '@theia/core/lib/browser'; | ||
import { MaybePromise } from '@theia/core/lib/common/types'; | ||
import { EditorPreviewWidget } from './editor-preview-widget'; | ||
import { inject, injectable } from 'inversify'; | ||
import { EditorManager } from '@theia/editor/lib/browser'; | ||
import { UUID } from '@phosphor/coreutils'; | ||
|
||
export interface EditorPreviewWidgetOptions { | ||
kind: 'editor-preview-widget', | ||
id: string, | ||
initialUri: string, | ||
session: string, | ||
} | ||
|
||
@injectable() | ||
export class EditorPreviewWidgetFactory implements WidgetFactory { | ||
|
||
static ID: string = 'editor-preview-widget'; | ||
|
||
static generateUniqueId(): string { | ||
return UUID.uuid4(); | ||
} | ||
|
||
readonly id = EditorPreviewWidgetFactory.ID; | ||
static readonly sessionId = EditorPreviewWidgetFactory.generateUniqueId(); | ||
|
||
@inject(WidgetManager) | ||
protected readonly widgetManager: WidgetManager; | ||
|
||
@inject(EditorManager) | ||
protected readonly editorManager: EditorManager; | ||
|
||
createWidget(options: EditorPreviewWidgetOptions): MaybePromise<EditorPreviewWidget> { | ||
return this.doCreate(options); | ||
} | ||
|
||
protected async doCreate(options: EditorPreviewWidgetOptions): Promise<EditorPreviewWidget> { | ||
const widget = (options.session === EditorPreviewWidgetFactory.sessionId) ? | ||
await this.editorManager.getOrCreateByUri(new URI(options.initialUri)) : undefined; | ||
const previewWidget = new EditorPreviewWidget(this.widgetManager, widget); | ||
previewWidget.id = options.id; | ||
return previewWidget; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/editor-preview/src/browser/editor-preview-frontend-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 Google and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public Liffcense, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { OpenHandler, WidgetFactory } from '@theia/core/lib/browser'; | ||
import {ContainerModule} from 'inversify'; | ||
import { EditorPreviewManager } from './editor-preview-manager'; | ||
import { EditorPreviewWidgetFactory } from './editor-preview-factory'; | ||
import { bindEditorPreviewPreferences } from './editor-preview-preferences'; | ||
|
||
import '../../src/browser/style/index.css'; | ||
|
||
export default new ContainerModule(bind => { | ||
|
||
bind(WidgetFactory).to(EditorPreviewWidgetFactory).inSingletonScope(); | ||
|
||
bind(EditorPreviewManager).toSelf().inSingletonScope(); | ||
bind(OpenHandler).to(EditorPreviewManager); | ||
|
||
bindEditorPreviewPreferences(bind); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have a description of what this extension brings. Maybe some bits from the overview part from this comment could be copied: #1252 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#3561