Skip to content

Commit

Permalink
Added version to the workbench layout interface
Browse files Browse the repository at this point in the history
- The initial step that resolves #1075

Signed-off-by: elaihau <liang.huang@ericsson.com>
  • Loading branch information
elaihau authored and elaihau committed Mar 29, 2018
1 parent 4641151 commit cd757db
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/core/src/browser/shell/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const MAIN_AREA_CLASS = 'theia-app-main';
/** The class name added to the bottom area panel. */
const BOTTOM_AREA_CLASS = 'theia-app-bottom';

const LAYOUT_DATA_VERSION = '2.0';

export const ApplicationShellOptions = Symbol('ApplicationShellOptions');
export const DockPanelRendererFactory = Symbol('DockPanelRendererFactory');

Expand Down Expand Up @@ -463,6 +465,7 @@ export class ApplicationShell extends Widget {
*/
getLayoutData(): ApplicationShell.LayoutData {
return {
version: LAYOUT_DATA_VERSION,
mainPanel: this.mainPanel.saveLayout(),
bottomPanel: {
config: this.bottomPanel.saveLayout(),
Expand Down Expand Up @@ -507,7 +510,8 @@ export class ApplicationShell extends Widget {
/**
* Apply a shell layout that has been previously created with `getLayoutData`.
*/
setLayoutData({ mainPanel, bottomPanel, leftPanel, rightPanel, statusBar, activeWidgetId }: ApplicationShell.LayoutData): void {
setLayoutData(layoutData: ApplicationShell.LayoutData): void {
const { mainPanel, bottomPanel, leftPanel, rightPanel, statusBar, activeWidgetId } = this.getValidatedLayoutData(layoutData);
if (mainPanel) {
this.mainPanel.restoreLayout(mainPanel);
this.registerWithFocusTracker(mainPanel.main);
Expand Down Expand Up @@ -542,6 +546,13 @@ export class ApplicationShell extends Widget {
}
}

protected getValidatedLayoutData(layoutData: ApplicationShell.LayoutData) {
if (layoutData.version !== LAYOUT_DATA_VERSION) {
throw new Error(`Saved workbench layout (version ${layoutData.version || 'unknown'}) is incompatible with the current (${LAYOUT_DATA_VERSION})`);
}
return layoutData;
}

/**
* Modify the height of the bottom panel. This implementation assumes that the container of the
* bottom panel is a `SplitPanel`.
Expand Down Expand Up @@ -1244,6 +1255,7 @@ export namespace ApplicationShell {
* Data to save and load the application shell layout.
*/
export interface LayoutData {
version?: string,
mainPanel?: DockPanel.ILayoutConfig;
bottomPanel?: BottomPanelLayoutData;
leftPanel?: SidePanel.LayoutData;
Expand Down

0 comments on commit cd757db

Please sign in to comment.