@@ -79,6 +79,20 @@ module.exports = ext.register("ext/tabbehaviors/tabbehaviors", {
7979 } ,
8080 disabled : "{!!!tabEditors.activepage}"
8181 } ) ) ,
82+ mnuTabs . appendChild ( new apf . item ( {
83+ caption : "Close Tabs to the Right" ,
84+ onclick : function ( ) {
85+ _self . closealltotheright ( ) ;
86+ } ,
87+ disabled : "{!!!tabEditors.activepage}"
88+ } ) ) ,
89+ mnuTabs . appendChild ( new apf . item ( {
90+ caption : "Close Tabs to the Left" ,
91+ onclick : function ( ) {
92+ _self . closealltotheleft ( ) ;
93+ } ,
94+ disabled : "{!!!tabEditors.activepage}"
95+ } ) ) ,
8296 //mnuTabs.appendChild(new apf.divider()),
8397 apf . document . body . appendChild ( new apf . menu ( {
8498 id : "mnuContextTabs" ,
@@ -104,18 +118,50 @@ module.exports = ext.register("ext/tabbehaviors/tabbehaviors", {
104118 onclick : function ( ) {
105119 _self . closeallbutme ( tabEditors . contextPage ) ;
106120 }
121+ } ) ,
122+ new apf . item ( {
123+ caption : "Close Tabs to the Right" ,
124+ onclick : function ( ) {
125+ _self . closealltotheright ( ) ;
126+ }
127+ } ) ,
128+ new apf . item ( {
129+ caption : "Close Tabs to the Left" ,
130+ onclick : function ( ) {
131+ _self . closealltotheleft ( ) ;
132+ }
107133 } )
108134 ]
109135 } ) )
110136 ) ;
111-
137+
112138 this . hotitems . revealtab = [ this . nodes [ 0 ] , mnuContextTabs . childNodes [ 0 ] ] ;
113139 this . hotitems . closetab = [ this . nodes [ 1 ] , mnuContextTabs . childNodes [ 1 ] ] ;
114140 this . hotitems . closealltabs = [ this . nodes [ 2 ] , mnuContextTabs . childNodes [ 2 ] ] ;
115141 this . hotitems . closeallbutme = [ this . nodes [ 3 ] , mnuContextTabs . childNodes [ 3 ] ] ;
116-
142+ this . hotitems . closealltotheright = [ this . nodes [ 4 ] , mnuContextTabs . childNodes [ 4 ] ] ;
143+ this . hotitems . closealltotheleftt = [ this . nodes [ 5 ] , mnuContextTabs . childNodes [ 5 ] ] ;
144+
117145 tabEditors . setAttribute ( "contextmenu" , "mnuContextTabs" ) ;
118146
147+ mnuContextTabs . addEventListener ( "prop.visible" , function ( e ) {
148+ var page = tabEditors . getPage ( ) ;
149+ var pages = tabEditors . getPages ( ) ;
150+
151+ // be optimistic, reset menu items to disabled
152+ mnuContextTabs . childNodes [ 4 ] . setAttribute ( 'disabled' , false ) ;
153+ mnuContextTabs . childNodes [ 5 ] . setAttribute ( 'disabled' , false ) ;
154+
155+ // if last tab, remove "close to the right"
156+ if ( page . nextSibling . localName !== "page" ) {
157+ mnuContextTabs . childNodes [ 4 ] . setAttribute ( 'disabled' , true ) ;
158+ }
159+ // if first tab, remove "close to the left"
160+ else if ( pages . indexOf ( page ) == 0 ) {
161+ mnuContextTabs . childNodes [ 5 ] . setAttribute ( 'disabled' , true ) ;
162+ }
163+ } ) ;
164+
119165 tabEditors . addEventListener ( "close" , function ( e ) {
120166 if ( ! e || ! e . htmlEvent )
121167 return ;
@@ -231,8 +277,9 @@ module.exports = ext.register("ext/tabbehaviors/tabbehaviors", {
231277 for ( var i = 0 , l = pages . length ; i < l ; i ++ ) {
232278 page = pages [ i ] ;
233279
234- if ( ignore && page == ignore )
280+ if ( ignore && ( page == ignore || ignore . hasOwnProperty ( i ) ) ) {
235281 continue ;
282+ }
236283
237284 if ( page . $doc . getNode ( ) . getAttribute ( "changed" ) == "1" ) {
238285 page . noAnim = true ; // turn off animation on closing tab
@@ -282,6 +329,34 @@ module.exports = ext.register("ext/tabbehaviors/tabbehaviors", {
282329 callback ( ) ;
283330 } ,
284331
332+ closealltotheright : function ( ) {
333+ var page = tabEditors . getPage ( ) ;
334+ var pages = tabEditors . getPages ( ) ;
335+
336+ var currIdx = pages . indexOf ( page ) ;
337+ var ignore = { } ;
338+
339+ for ( var j = 0 ; j <= currIdx ; j ++ ) {
340+ ignore [ j ] = page ;
341+ }
342+
343+ this . closeallbutme ( ignore ) ;
344+ } ,
345+
346+ closealltotheleft : function ( ) {
347+ var page = tabEditors . getPage ( ) ;
348+ var pages = tabEditors . getPages ( ) ;
349+
350+ var currIdx = pages . indexOf ( page ) ;
351+ var ignore = { } ;
352+
353+ for ( var j = pages . length - 1 ; j >= currIdx ; j -- ) {
354+ ignore [ j ] = page ;
355+ }
356+
357+ this . closeallbutme ( ignore ) ;
358+ } ,
359+
285360 nexttab : function ( ) {
286361 var n = this . accessed . length - this . $tabAccessCycle ++ ;
287362 if ( n < 0 ) {
0 commit comments