Skip to content

Commit

Permalink
[shell] restore current view container part on activation when possible
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 Jul 15, 2019
1 parent 3cdd3b5 commit 02acfac
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions packages/core/src/browser/view-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { interfaces, injectable, inject, postConstruct } from 'inversify';
import { IIterator, toArray, find, some, every, map } from '@phosphor/algorithm';
import {
Widget, EXPANSION_TOGGLE_CLASS, COLLAPSED_CLASS, MessageLoop, Message, SplitPanel, BaseWidget,
addEventListener, SplitLayout, LayoutItem, PanelLayout, addKeyListener
addEventListener, SplitLayout, LayoutItem, PanelLayout, addKeyListener, FocusTracker
} from './widgets';
import { Event, Emitter } from '../common/event';
import { Deferred } from '../common/promise-util';
Expand All @@ -33,6 +33,7 @@ import { parseCssMagnitude } from './browser';
import { WidgetManager } from './widget-manager';
import { TabBarToolbarRegistry, TabBarToolbarFactory, TabBarToolbar } from './shell/tab-bar-toolbar';
import { Key } from './keys';
import { Slot } from '@phosphor/signaling';

export interface ViewContainerTitleOptions {
label: string;
Expand All @@ -57,6 +58,11 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
protected panel: SplitPanel;
protected attached = new Deferred<void>();

protected currentPart: ViewContainerPart | undefined;

@inject(ApplicationShell)
protected readonly shell: ApplicationShell;

@inject(FrontendApplicationStateService)
protected readonly applicationStateService: FrontendApplicationStateService;

Expand Down Expand Up @@ -134,6 +140,23 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
Disposable.create(() => commandRegistry.unregisterCommand(this.globalHideCommandId)),
Disposable.create(() => menuRegistry.unregisterMenuAction(this.globalHideCommandId))
]);
this.shell.currentChanged.connect(this.updateCurrentPart);
this.toDispose.push(Disposable.create(() => this.shell.currentChanged.disconnect(this.updateCurrentPart)));
}

protected readonly toDisposeOnCurrentPart = new DisposableCollection();

protected updateCurrentPart = (): void => {
const widget = this.shell.currentWidget;
if (widget instanceof ViewContainerPart && this.containerLayout.widgets.indexOf(widget) !== -1) {
this.currentPart = widget;
}
if (this.currentPart && !this.currentPart.isDisposed && !this.currentPart.isHidden) {
return;
}
const visibleParts = this.containerLayout.widgets.filter(p => !p.isHidden);
const expandedParts = visibleParts.filter(p => !p.collapsed);
this.currentPart = expandedParts[0] || visibleParts[0];
}

protected titleOptions: ViewContainerTitleOptions | undefined;
Expand All @@ -145,8 +168,7 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica

protected readonly toDisposeOnUpdateTitle = new DisposableCollection();

// should be a property to preserve fn identity
protected updateTitle = (): void => {
protected updateTitle(): void {
this.toDisposeOnUpdateTitle.dispose();
this.toDispose.push(this.toDisposeOnUpdateTitle);
const title = this.titleOptions;
Expand All @@ -157,7 +179,7 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
this.title.label = title.label;
if (visibleParts.length === 1) {
const part = visibleParts[0];
this.toDisposeOnUpdateTitle.push(part.onTitleChanged(this.updateTitle));
this.toDisposeOnUpdateTitle.push(part.onTitleChanged(() => this.updateTitle()));
const partLabel = part.wrapped.title.label;
if (partLabel) {
this.title.label += ': ' + partLabel;
Expand Down Expand Up @@ -244,6 +266,7 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
}
this.refreshMenu(newPart);
this.updateTitle();
this.updateCurrentPart();
this.update();
toRemoveWidget.pushAll([
newPart,
Expand All @@ -255,10 +278,17 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
if (!this.isDisposed) {
this.update();
this.updateTitle();
this.updateCurrentPart();
}
}),
newPart.onVisibilityChanged(this.updateTitle),
newPart.onCollapsed(() => this.containerLayout.updateCollapsed(newPart, this.enableAnimation)),
newPart.onVisibilityChanged(() => {
this.updateTitle();
this.updateCurrentPart();
}),
newPart.onCollapsed(() => {
this.containerLayout.updateCollapsed(newPart, this.enableAnimation);
this.updateCurrentPart();
}),
newPart.onMoveBefore(toMoveId => this.moveBefore(toMoveId, newPart.id)),
newPart.onContextMenu(event => {
if (event.button === 2) {
Expand Down Expand Up @@ -454,11 +484,8 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica

protected onActivateRequest(msg: Message): void {
super.onActivateRequest(msg);
const visibleParts = this.containerLayout.widgets.filter(p => !p.isHidden);
const expandedParts = visibleParts.filter(p => !p.collapsed);
const part = expandedParts[0] || visibleParts[0];
if (part) {
part.activate();
if (this.currentPart) {
this.currentPart.activate();
} else {
this.panel.node.focus();
}
Expand Down

0 comments on commit 02acfac

Please sign in to comment.