Skip to content

Commit

Permalink
[scm][plugin] restore view containers and view laout
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Aug 3, 2019
1 parent 2f593e3 commit 9320510
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 148 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/browser/frontend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import { ResourceContextKey } from './resource-context-key';
import { KeyboardLayoutService } from './keyboard/keyboard-layout-service';
import { MimeService } from './mime-service';
import { ApplicationShellMouseTracker } from './shell/application-shell-mouse-tracker';
import { ViewContainer, ViewContainerOptions } from './view-container';
import { ViewContainer, ViewContainerIdentifier } from './view-container';

export const frontendApplicationModule = new ContainerModule((bind, unbind, isBound, rebind) => {
const themeService = ThemeService.get();
Expand Down Expand Up @@ -241,9 +241,9 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo
bind(ApplicationShellMouseTracker).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(ApplicationShellMouseTracker);

bind(ViewContainer.Factory).toFactory(context => (options: ViewContainerOptions) => {
bind(ViewContainer.Factory).toFactory(context => (options: ViewContainerIdentifier) => {
const container = context.container.createChild();
container.bind(ViewContainerOptions).toConstantValue(options);
container.bind(ViewContainerIdentifier).toConstantValue(options);
container.bind(ViewContainer).toSelf().inSingletonScope();
return container.get(ViewContainer);
});
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/browser/shell/shell-layout-restorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export namespace StatefulWidget {

interface WidgetDescription {
constructionOptions: WidgetConstructionOptions,
innerWidgetState?: object
innerWidgetState?: string | object
}

@injectable()
Expand Down Expand Up @@ -111,7 +111,7 @@ export class ShellLayoutRestorer implements CommandContribution {
/**
* Turns the layout data to a string representation.
*/
protected deflate(data: ApplicationShell.LayoutData): string {
protected deflate(data: object): string {
return JSON.stringify(data, (property: string, value) => {
if (this.isWidgetProperty(property)) {
const description = this.convertToDescription(value as Widget);
Expand Down Expand Up @@ -139,7 +139,7 @@ export class ShellLayoutRestorer implements CommandContribution {
}
return {
constructionOptions: desc,
innerWidgetState: innerState
innerWidgetState: innerState && this.deflate(innerState)
};
}
}
Expand Down Expand Up @@ -185,10 +185,11 @@ export class ShellLayoutRestorer implements CommandContribution {
private convertToWidget(desc: WidgetDescription): Promise<Widget | undefined> {
if (desc.constructionOptions) {
return this.widgetManager.getOrCreateWidget(desc.constructionOptions.factoryId, desc.constructionOptions.options)
.then(widget => {
.then(async widget => {
if (StatefulWidget.is(widget) && desc.innerWidgetState !== undefined) {
try {
widget.restoreState(desc.innerWidgetState);
const oldState = typeof desc.innerWidgetState === 'string' ? await this.inflate(desc.innerWidgetState) : desc.innerWidgetState;
widget.restoreState(oldState);
} catch (err) {
this.logger.warn(`Couldn't restore widget state for ${widget.id}. Error: ${err} `);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/browser/shell/view-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface OpenViewArguments extends ApplicationShell.WidgetOptions {
reveal?: boolean;
}

export interface ViewContributionOptions<T extends Widget> {
export interface ViewContributionOptions {
widgetId: string;
widgetName: string;
defaultWidgetOptions: ApplicationShell.WidgetOptions;
Expand Down Expand Up @@ -61,7 +61,7 @@ export abstract class AbstractViewContribution<T extends Widget> implements Comm
readonly toggleCommand?: Command;

constructor(
protected readonly options: ViewContributionOptions<T>
protected readonly options: ViewContributionOptions
) {
if (options.toggleCommandId) {
this.toggleCommand = {
Expand Down
Loading

0 comments on commit 9320510

Please sign in to comment.