Skip to content
This repository has been archived by the owner on Nov 6, 2019. It is now read-only.

Commit

Permalink
GH-223 Enable / Disable Tab Dragging in DockPanel
Browse files Browse the repository at this point in the history
Allow user to enable / disable tab dragging at runtime.

Fixes GH-223

Signed-off-by: Gordon Smith <gordonjsmith@gmail.com>
  • Loading branch information
GordonSmith committed Nov 6, 2019
1 parent 5eea83b commit 80e7073
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions packages/widgets/src/dockpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ class DockPanel extends Widget {
this._mode = options.mode || 'multiple-document';
this._renderer = options.renderer || DockPanel.defaultRenderer;
this._edges = options.edges || Private.DEFAULT_EDGES;
if (options.tabsMovable !== undefined) {
this._tabsMovable = options.tabsMovable;
}

// Toggle the CSS mode attribute.
this.dataset['mode'] = this._mode;

// Create the delegate renderer for the layout.
let renderer: DockPanel.IRenderer = {
createTabBar: () => this._createTabBar(),
createTabBar: () => this._createTabBar(this._tabsMovable),
createHandle: () => this._createHandle()
};

Expand Down Expand Up @@ -190,6 +193,21 @@ class DockPanel extends Widget {
MessageLoop.postMessage(this, Private.LayoutModified);
}

/**
* Whether the tabs are movable.
*/
get tabsMovable(): boolean {
return this._tabsMovable;
}

/**
* Enable / Disable movable tabs.
*/
set tabsMovable(value: boolean) {
this._tabsMovable = value;
each(this.tabBars(), (tabbar) => tabbar.tabsMovable = value);
}

/**
* Whether the dock panel is empty.
*/
Expand Down Expand Up @@ -829,7 +847,7 @@ class DockPanel extends Widget {
/**
* Create a new tab bar for use by the panel.
*/
private _createTabBar(): TabBar<Widget> {
private _createTabBar(tabsMovable: boolean): TabBar<Widget> {
// Create the tab bar.
let tabBar = this._renderer.createTabBar();

Expand All @@ -843,7 +861,7 @@ class DockPanel extends Widget {

// Enforce necessary tab bar behavior.
// TODO do we really want to enforce *all* of these?
tabBar.tabsMovable = true;
tabBar.tabsMovable = tabsMovable;
tabBar.allowDeselect = false;
tabBar.removeBehavior = 'select-previous-tab';
tabBar.insertBehavior = 'select-tab-if-needed';
Expand Down Expand Up @@ -960,6 +978,7 @@ class DockPanel extends Widget {
private _mode: DockPanel.Mode;
private _drag: Drag | null = null;
private _renderer: DockPanel.IRenderer;
private _tabsMovable: boolean = true;
private _pressData: Private.IPressData | null = null;
private _layoutModified = new Signal<this, void>(this);
}
Expand Down Expand Up @@ -1003,11 +1022,19 @@ namespace DockPanel {
*/
mode?: DockPanel.Mode;


/**
* The sizes of the edge drop zones, in pixels.
* If not given, default values will be used.
*/
edges?: IEdges;

/**
* Allow user tab placement.
*
* The deafult is `'true'`.
*/
tabsMovable?: boolean;
}

/**
Expand Down

0 comments on commit 80e7073

Please sign in to comment.