File tree Expand file tree Collapse file tree 3 files changed +24
-5
lines changed
Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,19 @@ export class GlueSessionSharedModel
111111 this . _contents . set ( key , value ) ;
112112 }
113113
114+ addTab ( ) : void {
115+ let idx = 1 ;
116+ let tabName = 'Tab 1' ;
117+ while ( this . _tabs . has ( tabName ) ) {
118+ idx += 1 ;
119+ tabName = `Tab ${ idx } ` ;
120+ }
121+ const newTab = new Y . Map < IDict > ( ) ;
122+ this . transact ( ( ) => {
123+ this . _tabs . set ( tabName , newTab ) ;
124+ } , false ) ;
125+ }
126+
114127 getTabNames ( ) : string [ ] {
115128 return [ ...this . _tabs . keys ( ) ] ;
116129 }
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ export interface IGlueSessionSharedModel
5151 tabChanged : ISignal < IGlueSessionSharedModel , IDict > ;
5252 tabsChanged : ISignal < IGlueSessionSharedModel , IDict > ;
5353
54+ addTab ( ) : void ;
5455 getTabNames ( ) : string [ ] ;
5556 getTabData ( tabName : string ) : IDict < IGlueSessionViewerTypes > | undefined ;
5657
Original file line number Diff line number Diff line change @@ -46,7 +46,9 @@ export class SessionWidget extends BoxPanel {
4646 addButtonEnabled : true
4747 }
4848 } ) ;
49-
49+ this . _tabPanel . topBar . addRequested . connect ( ( ) => {
50+ this . _model . addTab ( ) ;
51+ } ) ;
5052 if ( this . _model ) {
5153 this . _linkWidget = new LinkEditor ( { sharedModel : this . _model } ) ;
5254 this . _tabPanel . addTab ( this . _linkWidget , 0 ) ;
@@ -145,15 +147,16 @@ export class SessionWidget extends BoxPanel {
145147
146148 private async _onTabsChanged ( ) {
147149 await this . _pythonSessionCreated . promise ;
148-
150+ let newTabIndex = 1 ;
151+ const currentIndex = this . _tabPanel . topBar . currentIndex ;
149152 const tabNames = this . _model . getTabNames ( ) ;
150153
151154 tabNames . forEach ( ( tabName , idx ) => {
152155 // Tab already exists, we don't do anything
153156 if ( tabName in this . _tabViews ) {
154157 return ;
155158 }
156-
159+ newTabIndex = idx ;
157160 // Tab does not exist, we create it
158161 const tabWidget = ( this . _tabViews [ tabName ] = new TabView ( {
159162 tabName,
@@ -173,8 +176,10 @@ export class SessionWidget extends BoxPanel {
173176 // todo
174177 // }
175178 // }
176-
177- this . _tabPanel . activateTab ( 1 ) ;
179+ if ( currentIndex === 0 ) {
180+ newTabIndex = 0 ;
181+ }
182+ this . _tabPanel . activateTab ( newTabIndex + 1 ) ;
178183 }
179184
180185 private _onFocusedTabChanged (
You can’t perform that action at this time.
0 commit comments