Skip to content

Commit

Permalink
Merge branch 'master' into az/sym
Browse files Browse the repository at this point in the history
  • Loading branch information
azatsarynnyy committed Nov 21, 2018
2 parents ecc44ec + ac97c73 commit 344ae6a
Show file tree
Hide file tree
Showing 150 changed files with 5,104 additions and 1,550 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cache:
- packages/cpp/node_modules
- packages/debug-nodejs/node_modules
- packages/debug/node_modules
- packages/editor-preview/node_modules
- packages/editor/node_modules
- packages/editorconfig/node_modules
- packages/extension-manager/node_modules
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [plug-in] added `languages.registerCodeLensProvider` Plug-in API
- [plug-in] added `languages.registerDocumentSymbolProvider` Plug-in API
- [core] `ctrl+alt+a` and `ctrl+alt+d` to switch tabs left/right
- [core] added `theia.applicationName` to application `package.json` and improved window title


## v0.3.16
Expand Down
116 changes: 75 additions & 41 deletions dev-packages/application-manager/src/generator/frontend-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ module.exports = Promise.resolve()${this.compileFrontendModuleImports(frontendMo
protected compileElectronMain(): string {
return `// @ts-check
// Useful for Electron/NW.js apps as GUI apps on macOS doesn't inherit the \`$PATH\` define
// in your dotfiles (.bashrc/.bash_profile/.zshrc/etc).
// https://github.com/electron/electron/issues/550#issuecomment-162037357
// https://github.com/theia-ide/theia/pull/3534#issuecomment-439689082
require('fix-path')();
// Workaround for https://github.com/electron/electron/issues/9225. Chrome has an issue where
// in certain locales (e.g. PL), image metrics are wrongly computed. We explicitly set the
// LC_NUMERIC to prevent this from happening (selects the numeric formatting category of the
Expand All @@ -101,59 +107,87 @@ if (process.env.LC_ALL) {
}
process.env.LC_NUMERIC = 'C';
const { join } = require('path');
const electron = require('electron');
const { join, resolve } = require('path');
const { isMaster } = require('cluster');
const { fork } = require('child_process');
const { app, BrowserWindow, ipcMain } = require('electron');
const windows = [];
function createNewWindow(theUrl) {
const newWindow = new BrowserWindow({ width: 1024, height: 728, show: !!theUrl });
if (windows.length === 0) {
newWindow.webContents.on('new-window', (event, url, frameName, disposition, options) => {
// If the first electron window isn't visible, then all other new windows will remain invisible.
// https://github.com/electron/electron/issues/3751
options.show = true;
options.width = 1024;
options.height = 728;
});
}
windows.push(newWindow);
if (!!theUrl) {
newWindow.loadURL(theUrl);
} else {
newWindow.on('ready-to-show', () => newWindow.show());
}
newWindow.on('closed', () => {
const index = windows.indexOf(newWindow);
if (index !== -1) {
windows.splice(index, 1);
}
if (windows.length === 0) {
app.exit(0);
}
});
return newWindow;
}
const { app, BrowserWindow, ipcMain, Menu } = electron;
const applicationName = \`${this.pck.props.frontend.config.applicationName}\`;
if (isMaster) {
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
ipcMain.on('create-new-window', (event, url) => {
createNewWindow(url);
});
app.on('ready', () => {
const { screen } = electron;
// Remove the default electron menus, waiting for the application to set its own.
Menu.setApplicationMenu(Menu.buildFromTemplate([]));
// Window list tracker.
const windows = [];
function createNewWindow(theUrl) {
// We must center by hand because \`browserWindow.center()\` fails on multi-screen setups
// See: https://github.com/electron/electron/issues/3490
const { bounds } = screen.getDisplayNearestPoint(screen.getCursorScreenPoint());
const height = Math.floor(bounds.height * (2/3));
const width = Math.floor(bounds.width * (2/3));
const y = Math.floor(bounds.y + (bounds.height - height) / 2);
const x = Math.floor(bounds.x + (bounds.width - width) / 2);
const newWindow = new BrowserWindow({ width, height, x, y, show: !!theUrl, title: applicationName });
if (windows.length === 0) {
newWindow.webContents.on('new-window', (event, url, frameName, disposition, options) => {
// If the first electron window isn't visible, then all other new windows will remain invisible.
// https://github.com/electron/electron/issues/3751
options.show = true;
options.width = width;
options.height = height;
options.title = applicationName;
});
}
windows.push(newWindow);
if (!!theUrl) {
newWindow.loadURL(theUrl);
} else {
newWindow.on('ready-to-show', () => newWindow.show());
}
newWindow.on('closed', () => {
const index = windows.indexOf(newWindow);
if (index !== -1) {
windows.splice(index, 1);
}
if (windows.length === 0) {
app.exit(0);
}
});
return newWindow;
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
ipcMain.on('create-new-window', (event, url) => {
createNewWindow(url);
});
// Check whether we are in bundled application or development mode.
// @ts-ignore
const devMode = process.defaultApp || /node_modules[\/]electron[\/]/.test(process.execPath);
const mainWindow = createNewWindow();
const loadMainWindow = (port) => {
mainWindow.loadURL('file://' + join(__dirname, '../../lib/index.html') + '?port=' + port);
};
// We cannot use the \`process.cwd()\` as the application project path (the location of the \`package.json\` in other words)
// in a bundled electron application because it depends on the way we start it. For instance, on OS X, these are a differences:
// https://github.com/theia-ide/theia/issues/3297#issuecomment-439172274
process.env.THEIA_APP_PROJECT_PATH = resolve(__dirname, '..', '..');
const mainPath = join(__dirname, '..', 'backend', 'main');
// We need to distinguish between bundled application and development mode when starting the clusters.
// See: https://github.com/electron/electron/issues/6337#issuecomment-230183287
Expand Down
9 changes: 8 additions & 1 deletion dev-packages/application-package/src/application-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export namespace ApplicationProps {
config: {}
},
frontend: {
config: {}
config: {
applicationName: 'Theia'
}
}
};

Expand All @@ -93,6 +95,11 @@ export interface FrontendApplicationConfig extends ApplicationConfig {
*/
readonly defaultTheme?: string;

/**
* The name of the application. `Theia` by default.
*/
readonly applicationName: string;

}

/**
Expand Down
3 changes: 2 additions & 1 deletion dev-packages/application-package/src/json-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
********************************************************************************/

import * as fs from 'fs';

import writeJsonFile = require('write-json-file');

// tslint:disable-next-line:no-any
function readJsonFile(path: string): any {
return JSON.parse(fs.readFileSync(path, { encoding: 'utf-8' }));
}
Expand Down
1 change: 1 addition & 0 deletions dev-packages/cli/src/theia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function rebuildCommand(command: string, target: ApplicationProps.Target): yargs
.command(rebuildCommand('rebuild:electron', 'electron'));

// see https://github.com/yargs/yargs/issues/287#issuecomment-314463783
// tslint:disable-next-line:no-any
const commands = (yargs as any).getCommandInstance().getCommands();
const argv = yargs.demandCommand(1).argv;
const command = argv._[0];
Expand Down
8 changes: 8 additions & 0 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"private": true,
"name": "@theia/example-browser",
"version": "0.3.16",
"theia": {
"frontend": {
"config": {
"applicationName": "Theia Browser Example"
}
}
},
"dependencies": {
"@theia/callhierarchy": "^0.3.16",
"@theia/console": "^0.3.16",
Expand All @@ -10,6 +17,7 @@
"@theia/debug": "^0.3.16",
"@theia/debug-nodejs": "^0.3.16",
"@theia/editor": "^0.3.16",
"@theia/editor-preview": "^0.3.16",
"@theia/editorconfig": "^0.3.16",
"@theia/extension-manager": "^0.3.16",
"@theia/file-search": "^0.3.16",
Expand Down
8 changes: 7 additions & 1 deletion examples/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"name": "@theia/example-electron",
"version": "0.3.16",
"theia": {
"target": "electron"
"target": "electron",
"frontend": {
"config": {
"applicationName": "Theia Electron Example"
}
}
},
"dependencies": {
"@theia/callhierarchy": "^0.3.16",
Expand All @@ -13,6 +18,7 @@
"@theia/debug": "^0.3.16",
"@theia/debug-nodejs": "^0.3.16",
"@theia/editor": "^0.3.16",
"@theia/editor-preview": "^0.3.16",
"@theia/editorconfig": "^0.3.16",
"@theia/extension-manager": "^0.3.16",
"@theia/file-search": "^0.3.16",
Expand Down
3 changes: 2 additions & 1 deletion examples/electron/test/basic-example.espec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ const { app } = require('electron');

describe('basic-example-spec', () => {
describe('01 #start example app', () => {
it('should start the electron example app', (done) => {
it('should start the electron example app', done => {
if (app.isReady()) {
require('../src-gen/backend/main'); // start the express server

mainWindow.webContents.openDevTools();
mainWindow.loadURL(`file://${path.join(__dirname, 'index.html')}`);
}
// tslint:disable-next-line:no-unused-expression
expect(mainWindow.isVisible()).to.be.true;
done();
});
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"es6-promise": "^4.2.4",
"express": "^4.16.3",
"file-icons-js": "^1.0.3",
"fix-path": "^2.1.0",
"font-awesome": "^4.7.0",
"fuzzy": "^0.1.3",
"inversify": "^4.14.0",
Expand Down
52 changes: 52 additions & 0 deletions packages/core/src/browser/core-preferences.ts
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});
}
9 changes: 5 additions & 4 deletions packages/core/src/browser/frontend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import { EnvVariablesServer, envVariablesPath } from './../common/env-variables'
import { FrontendApplicationStateService } from './frontend-application-state';
import { JsonSchemaStore } from './json-schema-store';
import { TabBarToolbarRegistry, TabBarToolbarContribution, TabBarToolbarFactory, TabBarToolbar } from './shell/tab-bar-toolbar';
import { WidgetTracker } from './widgets';
import { bindCorePreferences } from './core-preferences';

export const frontendApplicationModule = new ContainerModule((bind, unbind, isBound, rebind) => {
const themeService = ThemeService.get();
Expand All @@ -76,7 +76,6 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo

bind(ApplicationShellOptions).toConstantValue({});
bind(ApplicationShell).toSelf().inSingletonScope();
bind(WidgetTracker).toService(ApplicationShell);
bind(SidePanelHandlerFactory).toAutoFactory(SidePanelHandler);
bind(SidePanelHandler).toSelf();
bind(SplitPositionHandler).toSelf().inSingletonScope();
Expand All @@ -91,12 +90,12 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo
return new TabBarToolbar(commandRegistry, labelParser);
});

bind(DockPanelRendererFactory).toFactory(context => (widgetTracker: WidgetTracker) => {
bind(DockPanelRendererFactory).toFactory(context => () => {
const { container } = context;
const tabBarToolbarRegistry = container.get(TabBarToolbarRegistry);
const tabBarRendererFactory: () => TabBarRenderer = container.get(TabBarRendererFactory);
const tabBarToolbarFactory: () => TabBarToolbar = container.get(TabBarToolbarFactory);
return new DockPanelRenderer(tabBarRendererFactory, tabBarToolbarRegistry, widgetTracker, tabBarToolbarFactory);
return new DockPanelRenderer(tabBarRendererFactory, tabBarToolbarRegistry, tabBarToolbarFactory);
});
bind(DockPanelRenderer).toSelf();
bind(TabBarRendererFactory).toFactory(context => () => {
Expand Down Expand Up @@ -217,4 +216,6 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo
[CommandContribution, MenuContribution].forEach(serviceIdentifier =>
bind(serviceIdentifier).toService(ThemingCommandContribution),
);

bindCorePreferences(bind);
});
1 change: 1 addition & 0 deletions packages/core/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ export * from './label-provider';
export * from './widget-open-handler';
export * from './navigatable';
export * from './diff-uris';
export * from './core-preferences';
4 changes: 2 additions & 2 deletions packages/core/src/browser/label-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/

import { expect } from 'chai';
import { DefaultUriLabelProviderContribution } from './label-provider';
import { DefaultUriLabelProviderContribution, FOLDER_ICON } from './label-provider';
import URI from '../common/uri';

describe('DefaultUriLabelProviderContribution', function () {
Expand Down Expand Up @@ -45,6 +45,6 @@ describe('DefaultUriLabelProviderContribution', function () {
const prov = new DefaultUriLabelProviderContribution();
const icon = prov.getIcon(new URI('file:///tmp/hello'));

expect(icon).eq('fa fa-folder');
expect(icon).eq(FOLDER_ICON);
});
});
Loading

0 comments on commit 344ae6a

Please sign in to comment.