|
@@ -3,7 +3,7 @@
|
|
|
|
|
|
import { ArrayExt, find, IIterator, iter, toArray } from '@phosphor/algorithm';
|
|
|
|
|
|
-import { PromiseDelegate } from '@phosphor/coreutils';
|
|
|
+import { PromiseDelegate, Token } from '@phosphor/coreutils';
|
|
|
|
|
|
import { Message, MessageLoop, IMessageHandler } from '@phosphor/messaging';
|
|
|
|
|
@@ -57,6 +57,126 @@ const MODE_ATTRIBUTE = 'data-shell-mode';
|
|
|
|
|
|
const ACTIVITY_CLASS = 'jp-Activity';
|
|
|
|
|
|
+/* tslint:disable */
|
|
|
+/**
|
|
|
+ * The layout restorer token.
|
|
|
+ */
|
|
|
+export const IApplicationShell = new Token<IApplicationShell>(
|
|
|
+ '@jupyterlab/application:IApplicationShell'
|
|
|
+);
|
|
|
+/* tslint:enable */
|
|
|
+
|
|
|
+/**
|
|
|
+ * The JupyterLab application shell.
|
|
|
+ */
|
|
|
+export interface IApplicationShell extends ApplicationShell {}
|
|
|
+
|
|
|
+/**
|
|
|
+ * The namespace for `IApplicationShell` type information.
|
|
|
+ */
|
|
|
+export namespace IApplicationShell {
|
|
|
+ /**
|
|
|
+ * The areas of the application shell where widgets can reside.
|
|
|
+ */
|
|
|
+ export type Area = 'main' | 'top' | 'left' | 'right' | 'bottom';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The restorable description of an area within the main dock panel.
|
|
|
+ */
|
|
|
+ export type AreaConfig = DockLayout.AreaConfig;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * An arguments object for the changed signals.
|
|
|
+ */
|
|
|
+ export type IChangedArgs = FocusTracker.IChangedArgs<Widget>;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A description of the application's user interface layout.
|
|
|
+ */
|
|
|
+ export interface ILayout {
|
|
|
+ /**
|
|
|
+ * Indicates whether fetched session restore data was actually retrieved
|
|
|
+ * from the state database or whether it is a fresh blank slate.
|
|
|
+ *
|
|
|
+ * #### Notes
|
|
|
+ * This attribute is only relevant when the layout data is retrieved via a
|
|
|
+ * `fetch` call. If it is set when being passed into `save`, it will be
|
|
|
+ * ignored.
|
|
|
+ */
|
|
|
+ readonly fresh?: boolean;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The main area of the user interface.
|
|
|
+ */
|
|
|
+ readonly mainArea: IMainArea | null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The left area of the user interface.
|
|
|
+ */
|
|
|
+ readonly leftArea: ISideArea | null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The right area of the user interface.
|
|
|
+ */
|
|
|
+ readonly rightArea: ISideArea | null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The restorable description of the main application area.
|
|
|
+ */
|
|
|
+ export interface IMainArea {
|
|
|
+ /**
|
|
|
+ * The current widget that has application focus.
|
|
|
+ */
|
|
|
+ readonly currentWidget: Widget | null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The contents of the main application dock panel.
|
|
|
+ */
|
|
|
+ readonly dock: DockLayout.ILayoutConfig | null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The document mode (i.e., multiple/single) of the main dock panel.
|
|
|
+ */
|
|
|
+ readonly mode: DockPanel.Mode | null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The restorable description of a sidebar in the user interface.
|
|
|
+ */
|
|
|
+ export interface ISideArea {
|
|
|
+ /**
|
|
|
+ * A flag denoting whether the sidebar has been collapsed.
|
|
|
+ */
|
|
|
+ readonly collapsed: boolean;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The current widget that has side area focus.
|
|
|
+ */
|
|
|
+ readonly currentWidget: Widget | null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The collection of widgets held by the sidebar.
|
|
|
+ */
|
|
|
+ readonly widgets: Array<Widget> | null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The options for adding a widget to a side area of the shell.
|
|
|
+ */
|
|
|
+ export interface ISideAreaOptions {
|
|
|
+ /**
|
|
|
+ * The rank order of the widget among its siblings.
|
|
|
+ */
|
|
|
+ rank?: number;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The options for adding a widget to a side area of the shell.
|
|
|
+ */
|
|
|
+ export interface IMainAreaOptions extends DocumentRegistry.IOpenOptions {}
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* The application shell for JupyterLab.
|
|
|
*/
|
|
@@ -169,7 +289,7 @@ export class ApplicationShell extends Widget {
|
|
|
/**
|
|
|
* A signal emitted when main area's active focus changes.
|
|
|
*/
|
|
|
- get activeChanged(): ISignal<this, ApplicationShell.IChangedArgs> {
|
|
|
+ get activeChanged(): ISignal<this, IApplicationShell.IChangedArgs> {
|
|
|
return this._activeChanged;
|
|
|
}
|
|
|
|
|
@@ -183,7 +303,7 @@ export class ApplicationShell extends Widget {
|
|
|
/**
|
|
|
* A signal emitted when main area's current focus changes.
|
|
|
*/
|
|
|
- get currentChanged(): ISignal<this, ApplicationShell.IChangedArgs> {
|
|
|
+ get currentChanged(): ISignal<this, IApplicationShell.IChangedArgs> {
|
|
|
return this._currentChanged;
|
|
|
}
|
|
|
|
|
@@ -301,7 +421,7 @@ export class ApplicationShell extends Widget {
|
|
|
* Promise that resolves when state is first restored, returning layout
|
|
|
* description.
|
|
|
*/
|
|
|
- get restored(): Promise<ApplicationShell.ILayout> {
|
|
|
+ get restored(): Promise<IApplicationShell.ILayout> {
|
|
|
return this._restored.promise;
|
|
|
}
|
|
|
|
|
@@ -402,7 +522,7 @@ export class ApplicationShell extends Widget {
|
|
|
*/
|
|
|
addToLeftArea(
|
|
|
widget: Widget,
|
|
|
- options?: ApplicationShell.ISideAreaOptions
|
|
|
+ options?: IApplicationShell.ISideAreaOptions
|
|
|
): void {
|
|
|
if (!widget.id) {
|
|
|
console.error('Widgets added to app shell must have unique id property.');
|
|
@@ -428,7 +548,7 @@ export class ApplicationShell extends Widget {
|
|
|
*/
|
|
|
addToMainArea(
|
|
|
widget: Widget,
|
|
|
- options: ApplicationShell.IMainAreaOptions = {}
|
|
|
+ options: IApplicationShell.IMainAreaOptions = {}
|
|
|
): void {
|
|
|
if (!widget.id) {
|
|
|
console.error('Widgets added to app shell must have unique id property.');
|
|
@@ -467,7 +587,7 @@ export class ApplicationShell extends Widget {
|
|
|
*/
|
|
|
addToRightArea(
|
|
|
widget: Widget,
|
|
|
- options?: ApplicationShell.ISideAreaOptions
|
|
|
+ options?: IApplicationShell.ISideAreaOptions
|
|
|
): void {
|
|
|
if (!widget.id) {
|
|
|
console.error('Widgets added to app shell must have unique id property.');
|
|
@@ -488,7 +608,7 @@ export class ApplicationShell extends Widget {
|
|
|
*/
|
|
|
addToTopArea(
|
|
|
widget: Widget,
|
|
|
- options: ApplicationShell.ISideAreaOptions = {}
|
|
|
+ options: IApplicationShell.ISideAreaOptions = {}
|
|
|
): void {
|
|
|
if (!widget.id) {
|
|
|
console.error('Widgets added to app shell must have unique id property.');
|
|
@@ -508,7 +628,7 @@ export class ApplicationShell extends Widget {
|
|
|
|
|
|
addToBottomArea(
|
|
|
widget: Widget,
|
|
|
- options: ApplicationShell.ISideAreaOptions = {}
|
|
|
+ options: IApplicationShell.ISideAreaOptions = {}
|
|
|
): void {
|
|
|
if (!widget.id) {
|
|
|
console.error('Widgets added to app shell must have unique id property.');
|
|
@@ -576,7 +696,7 @@ export class ApplicationShell extends Widget {
|
|
|
/**
|
|
|
* True if the given area is empty.
|
|
|
*/
|
|
|
- isEmpty(area: ApplicationShell.Area): boolean {
|
|
|
+ isEmpty(area: IApplicationShell.Area): boolean {
|
|
|
switch (area) {
|
|
|
case 'left':
|
|
|
return this._leftHandler.stackedPanel.widgets.length === 0;
|
|
@@ -596,7 +716,7 @@ export class ApplicationShell extends Widget {
|
|
|
/**
|
|
|
* Restore the layout state for the application shell.
|
|
|
*/
|
|
|
- restoreLayout(layout: ApplicationShell.ILayout): void {
|
|
|
+ restoreLayout(layout: IApplicationShell.ILayout): void {
|
|
|
const { mainArea, leftArea, rightArea } = layout;
|
|
|
|
|
|
// Rehydrate the main area.
|
|
@@ -636,7 +756,7 @@ export class ApplicationShell extends Widget {
|
|
|
/**
|
|
|
* Save the dehydrated state of the application shell.
|
|
|
*/
|
|
|
- saveLayout(): ApplicationShell.ILayout {
|
|
|
+ saveLayout(): IApplicationShell.ILayout {
|
|
|
// If the application is in single document mode, use the cached layout if
|
|
|
// available. Otherwise, default to querying the dock panel for layout.
|
|
|
return {
|
|
@@ -656,7 +776,7 @@ export class ApplicationShell extends Widget {
|
|
|
/**
|
|
|
* Returns the widgets for an application area.
|
|
|
*/
|
|
|
- widgets(area: ApplicationShell.Area): IIterator<Widget> {
|
|
|
+ widgets(area: IApplicationShell.Area): IIterator<Widget> {
|
|
|
switch (area) {
|
|
|
case 'main':
|
|
|
return this._dockPanel.widgets();
|
|
@@ -796,18 +916,18 @@ export class ApplicationShell extends Widget {
|
|
|
return true;
|
|
|
};
|
|
|
|
|
|
- private _activeChanged = new Signal<this, ApplicationShell.IChangedArgs>(
|
|
|
+ private _activeChanged = new Signal<this, IApplicationShell.IChangedArgs>(
|
|
|
this
|
|
|
);
|
|
|
private _cachedLayout: DockLayout.ILayoutConfig | null = null;
|
|
|
- private _currentChanged = new Signal<this, ApplicationShell.IChangedArgs>(
|
|
|
+ private _currentChanged = new Signal<this, IApplicationShell.IChangedArgs>(
|
|
|
this
|
|
|
);
|
|
|
private _dockPanel: DockPanel;
|
|
|
private _isRestored = false;
|
|
|
private _layoutModified = new Signal<this, void>(this);
|
|
|
private _leftHandler: Private.SideBarHandler;
|
|
|
- private _restored = new PromiseDelegate<ApplicationShell.ILayout>();
|
|
|
+ private _restored = new PromiseDelegate<IApplicationShell.ILayout>();
|
|
|
private _rightHandler: Private.SideBarHandler;
|
|
|
private _tracker = new FocusTracker<Widget>();
|
|
|
private _topPanel: Panel;
|
|
@@ -815,120 +935,14 @@ export class ApplicationShell extends Widget {
|
|
|
private _debouncer = 0;
|
|
|
private _addOptionsCache = new Map<
|
|
|
Widget,
|
|
|
- ApplicationShell.IMainAreaOptions
|
|
|
+ IApplicationShell.IMainAreaOptions
|
|
|
>();
|
|
|
private _sideOptionsCache = new Map<
|
|
|
Widget,
|
|
|
- ApplicationShell.ISideAreaOptions
|
|
|
+ IApplicationShell.ISideAreaOptions
|
|
|
>();
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * The namespace for `ApplicationShell` class statics.
|
|
|
- */
|
|
|
-export namespace ApplicationShell {
|
|
|
- /**
|
|
|
- * The areas of the application shell where widgets can reside.
|
|
|
- */
|
|
|
- export type Area = 'main' | 'top' | 'left' | 'right' | 'bottom';
|
|
|
-
|
|
|
- /**
|
|
|
- * The restorable description of an area within the main dock panel.
|
|
|
- */
|
|
|
- export type AreaConfig = DockLayout.AreaConfig;
|
|
|
-
|
|
|
- /**
|
|
|
- * An arguments object for the changed signals.
|
|
|
- */
|
|
|
- export type IChangedArgs = FocusTracker.IChangedArgs<Widget>;
|
|
|
-
|
|
|
- /**
|
|
|
- * A description of the application's user interface layout.
|
|
|
- */
|
|
|
- export interface ILayout {
|
|
|
- /**
|
|
|
- * Indicates whether fetched session restore data was actually retrieved
|
|
|
- * from the state database or whether it is a fresh blank slate.
|
|
|
- *
|
|
|
- * #### Notes
|
|
|
- * This attribute is only relevant when the layout data is retrieved via a
|
|
|
- * `fetch` call. If it is set when being passed into `save`, it will be
|
|
|
- * ignored.
|
|
|
- */
|
|
|
- readonly fresh?: boolean;
|
|
|
-
|
|
|
- /**
|
|
|
- * The main area of the user interface.
|
|
|
- */
|
|
|
- readonly mainArea: IMainArea | null;
|
|
|
-
|
|
|
- /**
|
|
|
- * The left area of the user interface.
|
|
|
- */
|
|
|
- readonly leftArea: ISideArea | null;
|
|
|
-
|
|
|
- /**
|
|
|
- * The right area of the user interface.
|
|
|
- */
|
|
|
- readonly rightArea: ISideArea | null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * The restorable description of the main application area.
|
|
|
- */
|
|
|
- export interface IMainArea {
|
|
|
- /**
|
|
|
- * The current widget that has application focus.
|
|
|
- */
|
|
|
- readonly currentWidget: Widget | null;
|
|
|
-
|
|
|
- /**
|
|
|
- * The contents of the main application dock panel.
|
|
|
- */
|
|
|
- readonly dock: DockLayout.ILayoutConfig | null;
|
|
|
-
|
|
|
- /**
|
|
|
- * The document mode (i.e., multiple/single) of the main dock panel.
|
|
|
- */
|
|
|
- readonly mode: DockPanel.Mode | null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * The restorable description of a sidebar in the user interface.
|
|
|
- */
|
|
|
- export interface ISideArea {
|
|
|
- /**
|
|
|
- * A flag denoting whether the sidebar has been collapsed.
|
|
|
- */
|
|
|
- readonly collapsed: boolean;
|
|
|
-
|
|
|
- /**
|
|
|
- * The current widget that has side area focus.
|
|
|
- */
|
|
|
- readonly currentWidget: Widget | null;
|
|
|
-
|
|
|
- /**
|
|
|
- * The collection of widgets held by the sidebar.
|
|
|
- */
|
|
|
- readonly widgets: Array<Widget> | null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * The options for adding a widget to a side area of the shell.
|
|
|
- */
|
|
|
- export interface ISideAreaOptions {
|
|
|
- /**
|
|
|
- * The rank order of the widget among its siblings.
|
|
|
- */
|
|
|
- rank?: number;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * The options for adding a widget to a side area of the shell.
|
|
|
- */
|
|
|
- export interface IMainAreaOptions extends DocumentRegistry.IOpenOptions {}
|
|
|
-}
|
|
|
-
|
|
|
namespace Private {
|
|
|
/**
|
|
|
* An object which holds a widget and its sort rank.
|
|
@@ -1083,7 +1097,7 @@ namespace Private {
|
|
|
/**
|
|
|
* Dehydrate the side bar data.
|
|
|
*/
|
|
|
- dehydrate(): ApplicationShell.ISideArea {
|
|
|
+ dehydrate(): IApplicationShell.ISideArea {
|
|
|
let collapsed = this._sideBar.currentTitle === null;
|
|
|
let widgets = toArray(this._stackedPanel.widgets);
|
|
|
let currentWidget = widgets[this._sideBar.currentIndex];
|
|
@@ -1093,7 +1107,7 @@ namespace Private {
|
|
|
/**
|
|
|
* Rehydrate the side bar.
|
|
|
*/
|
|
|
- rehydrate(data: ApplicationShell.ISideArea): void {
|
|
|
+ rehydrate(data: IApplicationShell.ISideArea): void {
|
|
|
if (data.currentWidget) {
|
|
|
this.activate(data.currentWidget.id);
|
|
|
} else if (data.collapsed) {
|