Skip to content

Commit

Permalink
Merge branch 'master' into fix-encoding
Browse files Browse the repository at this point in the history
Signed-off-by: Cai Xuye <[email protected]>
  • Loading branch information
a1994846931931 committed Jun 13, 2019
2 parents 7e5671a + 741876b commit 3686967
Show file tree
Hide file tree
Showing 130 changed files with 3,261 additions and 3,522 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cache:
# All directories need to be listed here, because Travis does not support globs.
# Auto generated by scripts/prepare-travis
# start_cache_directories
- /tmp/vscode-ripgrep-cache-1.2.4
- dev-packages/application-manager/node_modules
- dev-packages/application-package/node_modules
- dev-packages/electron/node_modules
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Breaking changes:
- [plugin] 'Hosted mode' extracted in `plugin-dev` extension
- [core] `scheme` is mandatory for URI
- `URI.withoutScheme` is removed, in order to get a path use `URI.path`
- [debug] align commands with VS Code [#5102](https://github.com/theia-ide/theia/issues/5102)
- `debug.restart` renamed to `workbench.action.debug.restart`
- [preferences] renamed overridenPreferenceName to overriddenPreferenceName

## v0.7.0

Expand Down Expand Up @@ -69,6 +72,7 @@ Breaking changes:
- The CLEAR_BUTTON and OVERLAY constants are no longer available. Furthermore OutputChannelManager API has changed.
- [preferences] refactored to integrate launch configurations as preferences
- [scm] added Source Control Model
- [core] renamed the `src/electron-main` folder to `src/electron-node` in `@theia/core`. Removed `preventStop` from the `FrontendApplication` API. Move the `DefaultWindowService` class into its own module.

## v0.6.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,36 @@ const nativeKeymap = require('native-keymap');
const Storage = require('electron-store');
const electronStore = new Storage();
let canPreventStop = true;
const windows = [];
app.on('before-quit', async event => {
if (canPreventStop) {
// Pause the stop.
event.preventDefault();
let preventStop = false;
// Ask all opened windows whether they want to prevent the \`close\` event or not.
for (const window of windows) {
if (!preventStop) {
window.webContents.send('prevent-stop-request');
const preventStopPerWindow = await new Promise((resolve) => {
ipcMain.once('prevent-stop-response', (_, arg) => {
if (!!arg && 'preventStop' in arg && typeof arg.preventStop === 'boolean') {
resolve(arg.preventStop);
}
})
});
if (preventStopPerWindow) {
preventStop = true;
}
}
}
if (!preventStop) {
canPreventStop = false;
app.quit();
}
}
});
app.on('ready', () => {
const { screen } = electron;
Expand Down Expand Up @@ -213,6 +243,15 @@ app.on('ready', () => {
newWindow.on('close', saveWindowState);
newWindow.on('resize', saveWindowStateDelayed);
newWindow.on('move', saveWindowStateDelayed);
newWindow.on('closed', () => {
const index = windows.indexOf(newWindow);
if (index !== -1) {
windows.splice(index, 1);
}
if (windows.length === 0) {
app.quit();
}
});
// Notify the renderer process on keyboard layout change
nativeKeymap.onDidChangeKeyboardLayout(() => {
Expand All @@ -228,6 +267,7 @@ app.on('ready', () => {
if (!!theUrl) {
newWindow.loadURL(theUrl);
}
windows.push(newWindow);
return newWindow;
}
Expand Down
22 changes: 22 additions & 0 deletions dev-packages/application-package/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ class ElectronEnv {
&& ((process as any).defaultApp || /node_modules[/]electron[/]/.test(process.execPath)); // tslint:disable-line:no-any
}

/**
* Creates and return with a new environment object which always contains the `ELECTRON_RUN_AS_NODE: 1` property pair.
* This should be used to `spawn` and `fork` a new Node.js process from the Node.js shipped with Electron. Otherwise, a new Electron
* process will be spawned which [has side-effects](https://github.com/theia-ide/theia/issues/5385).
*
* If called from the backend and the `env` argument is not defined, it falls back to `process.env` such as Node.js behaves
* with the [`SpawnOptions`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options).
* If `env` is defined, it will be shallow-copied.
*
* Calling this function from the frontend does not make any sense, hence throw an error.
*/
// tslint:disable-next-line:no-any
runAsNodeEnv(env?: any): any & { ELECTRON_RUN_AS_NODE: 1 } {
if (typeof process === 'undefined') {
throw new Error("'process' cannot be undefined.");
}
return {
...(env === undefined ? process.env : env),
ELECTRON_RUN_AS_NODE: 1
};
}

}

const electron = new ElectronEnv();
Expand Down
7 changes: 6 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"typings": "lib/common/index.d.ts",
"dependencies": {
"@phosphor/widgets": "^1.5.0",
"@primer/octicons-react": "^9.0.0",
"@theia/application-package": "^0.7.0",
"@types/body-parser": "^1.16.4",
"@types/bunyan": "^1.8.0",
Expand All @@ -31,6 +32,7 @@
"nsfw": "^1.2.2",
"perfect-scrollbar": "^1.3.0",
"react": "^16.4.1",
"react-autosize-textarea": "^7.0.0",
"react-dom": "^16.4.1",
"react-virtualized": "^9.20.0",
"reconnecting-websocket": "^3.0.7",
Expand All @@ -57,7 +59,10 @@
{
"frontend": "lib/browser/keyboard/browser-keyboard-module",
"frontendElectron": "lib/electron-browser/keyboard/electron-keyboard-module",
"backendElectron": "lib/electron-main/keyboard/electron-backend-keyboard-module"
"backendElectron": "lib/electron-node/keyboard/electron-backend-keyboard-module"
},
{
"frontendElectron": "lib/electron-browser/shutdown-hook/electron-shutdown-hook-module"
}
],
"keywords": [
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { OS, isOSX } from '../common/os';
import { ResourceContextKey } from './resource-context-key';
import { UriSelection } from '../common/selection';
import { StorageService } from './storage-service';
import { Navigatable } from './navigatable';

export namespace CommonMenus {

Expand Down Expand Up @@ -245,7 +246,8 @@ export class CommonFrontendContribution implements FrontendApplicationContributi

protected initResourceContextKeys(): void {
const updateContextKeys = () => {
const resourceUri = UriSelection.getUri(this.selectionService.selection);
const selection = this.selectionService.selection;
const resourceUri = Navigatable.is(selection) && selection.getResourceUri() || UriSelection.getUri(selection);
this.resourceContextKey.set(resourceUri);
};
updateContextKeys();
Expand Down Expand Up @@ -634,7 +636,7 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
}

window.document.addEventListener('keydown', event => {
this.shouldPreventClose = isCtrlCmd(event) || event.code === 'KeyW';
this.shouldPreventClose = isCtrlCmd(event) && event.code === 'KeyW';
});

window.document.addEventListener('keyup', () => {
Expand Down
32 changes: 32 additions & 0 deletions packages/core/src/browser/context-menu-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

// tslint:disable:no-any

import { MenuPath } from '../common/menu';

export type Anchor = MouseEvent | { x: number, y: number };
Expand All @@ -24,5 +26,35 @@ export function toAnchor(anchor: HTMLElement | { x: number, y: number }): Anchor

export const ContextMenuRenderer = Symbol('ContextMenuRenderer');
export interface ContextMenuRenderer {
render(options: RenderContextMenuOptions): void;
/** @deprecated since 0.7.2 pass `RenderContextMenuOptions` instead */
render(menuPath: MenuPath, anchor: Anchor, onHide?: () => void): void;
}

export interface RenderContextMenuOptions {
menuPath: MenuPath
anchor: Anchor
args?: any[]
onHide?: () => void
}
export namespace RenderContextMenuOptions {
export function resolve(arg: MenuPath | RenderContextMenuOptions, anchor?: Anchor, onHide?: () => void): RenderContextMenuOptions {
let menuPath: MenuPath;
let args: any[];
if (Array.isArray(arg)) {
menuPath = arg;
args = [anchor!];
} else {
menuPath = arg.menuPath;
anchor = arg.anchor;
onHide = arg.onHide;
args = arg.args ? [...arg.args, anchor] : [anchor];
}
return {
menuPath,
anchor: anchor!,
onHide,
args
};
}
}
12 changes: 10 additions & 2 deletions packages/core/src/browser/diff-uris.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export namespace DiffUris {

export const DIFF_SCHEME = 'diff';

export function encode(left: URI, right: URI, name?: string): URI {
export function encode(left: URI, right: URI, label?: string): URI {
const diffUris = [
left.toString(),
right.toString()
];

const diffUriStr = JSON.stringify(diffUris);

return new URI(name || left.displayName).withScheme(DIFF_SCHEME).withQuery(diffUriStr);
return new URI().withScheme(DIFF_SCHEME).withPath(label || '').withQuery(diffUriStr);
}

export function decode(uri: URI): URI[] {
Expand Down Expand Up @@ -60,6 +60,10 @@ export class DiffUriLabelProviderContribution implements LabelProviderContributi
}

getLongName(uri: URI): string {
const label = uri.path.toString();
if (label) {
return label;
}
const [left, right] = DiffUris.decode(uri);
const leftLongName = this.labelProvider.getLongName(left);
const rightLongName = this.labelProvider.getLongName(right);
Expand All @@ -70,6 +74,10 @@ export class DiffUriLabelProviderContribution implements LabelProviderContributi
}

getName(uri: URI): string {
const label = uri.path.toString();
if (label) {
return label;
}
const [left, right] = DiffUris.decode(uri);

if (left.path.toString() === right.path.toString() && left.query && right.query) {
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/browser/frontend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo
bind(TabBarToolbarRegistry).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(TabBarToolbarRegistry);
bind(TabBarToolbarFactory).toFactory(context => () => {
const { container } = context;
const commandRegistry = container.get(CommandRegistry);
const labelParser = container.get(LabelParser);
return new TabBarToolbar(commandRegistry, labelParser);
const container = context.container.createChild();
container.bind(TabBarToolbar).toSelf().inSingletonScope();
return container.get(TabBarToolbar);
});

bind(DockPanelRendererFactory).toFactory(context => () => {
Expand Down
25 changes: 0 additions & 25 deletions packages/core/src/browser/frontend-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,6 @@ export class FrontendApplication {
* Register global event listeners.
*/
protected registerEventListeners(): void {
window.addEventListener('beforeunload', event => {
if (this.preventStop()) {
event.returnValue = '';
event.preventDefault();
return '';
}
});
window.addEventListener('unload', () => {
this.stateService.state = 'closing_window';
this.layoutRestorer.storeLayout(this);
Expand Down Expand Up @@ -248,24 +241,6 @@ export class FrontendApplication {
}
}

/**
* `beforeunload` listener implementation
*/
protected preventStop(): boolean {
const confirmExit = this.corePreferences['application.confirmExit'];
if (confirmExit === 'never') {
return false;
}
for (const contribution of this.contributions.getContributions()) {
if (contribution.onWillStop) {
if (!!contribution.onWillStop(this)) {
return true;
}
}
}
return confirmExit === 'always';
}

/**
* Initialize and start the frontend application contributions.
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/browser/icons/edit-json-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions packages/core/src/browser/icons/edit-json.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 8 additions & 5 deletions packages/core/src/browser/menu/browser-context-menu-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

// tslint:disable:no-any

import { inject, injectable } from 'inversify';
import { MenuPath } from '../../common/menu';
import { ContextMenuRenderer, Anchor } from '../context-menu-renderer';
import { ContextMenuRenderer, Anchor, RenderContextMenuOptions } from '../context-menu-renderer';
import { BrowserMainMenuFactory } from './browser-menu-plugin';

@injectable()
Expand All @@ -25,11 +27,12 @@ export class BrowserContextMenuRenderer implements ContextMenuRenderer {
constructor(@inject(BrowserMainMenuFactory) private menuFactory: BrowserMainMenuFactory) {
}

render(menuPath: MenuPath, anchor: Anchor, onHide?: () => void): void {
const contextMenu = this.menuFactory.createContextMenu(menuPath, anchor);
const { x, y } = anchor instanceof MouseEvent ? { x: anchor.clientX, y: anchor.clientY } : anchor;
render(arg: MenuPath | RenderContextMenuOptions, arg2?: Anchor, arg3?: () => void): void {
const { menuPath, anchor, args, onHide } = RenderContextMenuOptions.resolve(arg, arg2, arg3);
const contextMenu = this.menuFactory.createContextMenu(menuPath, args);
const { x, y } = anchor instanceof MouseEvent ? { x: anchor.clientX, y: anchor.clientY } : anchor!;
if (onHide) {
contextMenu.aboutToClose.connect(() => onHide());
contextMenu.aboutToClose.connect(() => onHide!());
}
contextMenu.open(x, y);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/browser/menu/browser-menu-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ import { BrowserContextMenuRenderer } from './browser-context-menu-renderer';
export default new ContainerModule(bind => {
bind(BrowserMainMenuFactory).toSelf().inSingletonScope();
bind(ContextMenuRenderer).to(BrowserContextMenuRenderer).inSingletonScope();
bind(FrontendApplicationContribution).to(BrowserMenuBarContribution).inSingletonScope();
bind(BrowserMenuBarContribution).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(BrowserMenuBarContribution);
});
Loading

0 comments on commit 3686967

Please sign in to comment.