Skip to content
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

rework scm, recover git extension #5416

Merged
merged 8 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 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 Down
4 changes: 3 additions & 1 deletion 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
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;
akosyakov marked this conversation as resolved.
Show resolved Hide resolved
/** @deprecated since 0.7.2 pass `RenderContextMenuOptions` instead */
render(menuPath: MenuPath, anchor: Anchor, onHide?: () => void): void;
akosyakov marked this conversation as resolved.
Show resolved Hide resolved
}

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
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!());
akosyakov marked this conversation as resolved.
Show resolved Hide resolved
}
contextMenu.open(x, y);
}
Expand Down
22 changes: 11 additions & 11 deletions packages/core/src/browser/menu/browser-menu-plugin.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 { injectable, inject } from 'inversify';
import { MenuBar as MenuBarWidget, Menu as MenuWidget, Widget } from '@phosphor/widgets';
import { CommandRegistry as PhosphorCommandRegistry } from '@phosphor/commands';
Expand All @@ -24,7 +26,6 @@ import {
import { KeybindingRegistry } from '../keybinding';
import { FrontendApplicationContribution, FrontendApplication } from '../frontend-application';
import { ContextKeyService } from '../context-key-service';
import { Anchor } from '../context-menu-renderer';

@injectable()
export class BrowserMainMenuFactory {
Expand Down Expand Up @@ -67,31 +68,31 @@ export class BrowserMainMenuFactory {
}
}

createContextMenu(path: MenuPath, anchor?: Anchor): MenuWidget {
createContextMenu(path: MenuPath, args?: any[]): MenuWidget {
const menuModel = this.menuProvider.getMenu(path);
const phosphorCommands = this.createPhosphorCommands(menuModel, anchor);
const phosphorCommands = this.createPhosphorCommands(menuModel, args);

const contextMenu = new DynamicMenuWidget(menuModel, { commands: phosphorCommands }, this.contextKeyService);
return contextMenu;
}

protected createPhosphorCommands(menu: CompositeMenuNode, anchor?: Anchor): PhosphorCommandRegistry {
protected createPhosphorCommands(menu: CompositeMenuNode, args: any[] = []): PhosphorCommandRegistry {
const commands = new PhosphorCommandRegistry();
this.addPhosphorCommands(commands, menu, anchor);
this.addPhosphorCommands(commands, menu, args);
return commands;
}

protected addPhosphorCommands(commands: PhosphorCommandRegistry, menu: CompositeMenuNode, anchor?: Anchor): void {
protected addPhosphorCommands(commands: PhosphorCommandRegistry, menu: CompositeMenuNode, args: any[]): void {
for (const child of menu.children) {
if (child instanceof ActionMenuNode) {
this.addPhosphorCommand(commands, child, anchor);
this.addPhosphorCommand(commands, child, args);
} else if (child instanceof CompositeMenuNode) {
this.addPhosphorCommands(commands, child, anchor);
this.addPhosphorCommands(commands, child, args);
}
}
}

protected addPhosphorCommand(commands: PhosphorCommandRegistry, menu: ActionMenuNode, anchor?: Anchor): void {
protected addPhosphorCommand(commands: PhosphorCommandRegistry, menu: ActionMenuNode, args: any[]): void {
const command = this.commandRegistry.getCommand(menu.action.commandId);
if (!command) {
return;
Expand All @@ -100,14 +101,13 @@ export class BrowserMainMenuFactory {
// several menu items can be registered for the same command in different contexts
return;
}
const args = anchor ? [anchor] : [];
commands.addCommand(command.id, {
execute: () => this.commandRegistry.executeCommand(command.id, ...args),
label: menu.label,
icon: menu.icon,
isEnabled: () => this.commandRegistry.isEnabled(command.id, ...args),
isVisible: () => this.commandRegistry.isVisible(command.id, ...args),
isToggled: () => this.commandRegistry.isToggled(command.id)
isToggled: () => this.commandRegistry.isToggled(command.id, ...args)
});

const bindings = this.keybindingRegistry.getKeybindingsForCommand(command.id);
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/browser/resource-context-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { injectable, inject, postConstruct } from 'inversify';
import URI from '../common/uri';
import Uri from 'vscode-uri';
import { ContextKeyService, ContextKey } from './context-key-service';

@injectable()
Expand All @@ -24,20 +25,28 @@ export class ResourceContextKey {
@inject(ContextKeyService)
protected readonly contextKeyService: ContextKeyService;

protected resource: ContextKey<Uri>;
protected resourceSchemeKey: ContextKey<string>;
protected resourceFileName: ContextKey<string>;
protected resourceExtname: ContextKey<string>;
protected resourceLangId: ContextKey<string>;

@postConstruct()
protected init(): void {
this.resource = this.contextKeyService.createKey<Uri>('resource', undefined);
this.resourceSchemeKey = this.contextKeyService.createKey<string>('resourceScheme', undefined);
this.resourceFileName = this.contextKeyService.createKey<string>('resourceFilename', undefined);
this.resourceExtname = this.contextKeyService.createKey<string>('resourceExtname', undefined);
this.resourceLangId = this.contextKeyService.createKey<string>('resourceLangId', undefined);
}

get(): URI | undefined {
const codeUri = this.resource.get();
return codeUri && new URI(codeUri);
}

set(resourceUri: URI | undefined): void {
this.resource.set(resourceUri && resourceUri['codeUri']);
this.resourceSchemeKey.set(resourceUri && resourceUri.scheme);
this.resourceFileName.set(resourceUri && resourceUri.path.base);
this.resourceExtname.set(resourceUri && resourceUri.path.ext);
Expand Down
Loading