Browse Source

Added 'close tabs to the right' to Ted2.

Mark Sibly 9 years ago
parent
commit
542389905f
2 changed files with 60 additions and 23 deletions
  1. 58 23
      src/ted2/fileactions.monkey2
  2. 2 0
      src/ted2/mainwindow.monkey2

+ 58 - 23
src/ted2/fileactions.monkey2

@@ -7,6 +7,7 @@ Class FileActions
 	Field open:Action
 	Field close:Action
 	Field closeOthers:Action
+	Field closeToRight:Action
 	Field closeAll:Action
 	Field save:Action
 	Field saveAs:Action
@@ -37,9 +38,12 @@ Class FileActions
 #endif		
 		close.Triggered=OnClose
 		
-		closeOthers=New Action( "Close Others" )
+		closeOthers=New Action( "Close Other Tabs" )
 		closeOthers.Triggered=OnCloseOthers
-
+		
+		closeToRight=New Action( "Close Tabs To The Right" )
+		closeToRight.Triggered=OnCloseToRight
+		
 		closeAll=New Action( "Close All" )
 		closeAll.Triggered=OnCloseAll
 		
@@ -65,10 +69,12 @@ Class FileActions
 	End
 	
 	Method Update()
+	
+		Local docs:=_docs.OpenDocuments
 
 		Local n:=0
 		Local anyDirty:Bool
-		For Local doc:=Eachin _docs.OpenDocuments
+		For Local doc:=Eachin docs
 			If doc.Dirty anyDirty=True
 			n+=1
 		Next
@@ -77,6 +83,7 @@ Class FileActions
 
 		close.Enabled=doc
 		closeOthers.Enabled=n>1
+		closeToRight.Enabled=doc And doc<>docs[docs.Length-1]
 		closeAll.Enabled=n>0
 		save.Enabled=doc And doc.Dirty
 		saveAs.Enabled=doc
@@ -122,23 +129,6 @@ Class FileActions
 		Return doc
 	End
 	
-	Method CloseAll:Bool( except:Ted2Document )
-
-		For Local doc:=Eachin _docs.OpenDocuments
-			If doc=except Continue
-			
-			If Not CanClose( doc ) Return False
-		Next
-		
-		For Local doc:=Eachin _docs.OpenDocuments
-			If doc=except Continue
-			
-			doc.Close()
-		Next
-		
-		Return True
-	End
-	
 	Method OnNew()
 	
 		Local path:=MainWindow.AllocTmpPath( ".monkey2" )
@@ -175,12 +165,57 @@ Class FileActions
 	
 	Method OnCloseOthers()
 	
-		CloseAll( _docs.CurrentDocument )
+		If Not _docs.CurrentDocument Return
+	
+		Local docs:=_docs.OpenDocuments
+		
+		For Local doc:=Eachin docs
+			If doc<>_docs.CurrentDocument And Not CanClose( doc ) Return
+		Next
+		
+		For Local doc:=Eachin docs
+			If doc<>_docs.CurrentDocument doc.Close()
+		Next
+	End
+	
+	Method OnCloseToRight()
+	
+		If Not _docs.CurrentDocument Return
+	
+		Local docs:=_docs.OpenDocuments
+		
+		Local close:=False
+		For Local doc:=Eachin docs
+			If close
+				If Not CanClose( doc ) Return
+			Else
+				If doc=_docs.CurrentDocument close=True
+			Endif
+		Next
+		
+		close=False
+		For Local doc:=Eachin docs
+			If close
+				doc.Close()
+			Else
+				If doc=_docs.CurrentDocument close=True
+			Endif
+		Next
+		
 	End
 	
 	Method OnCloseAll()
-	
-		CloseAll( Null )
+
+		Local docs:=_docs.OpenDocuments
+		
+		For Local doc:=Eachin docs
+			If Not CanClose( doc ) Return
+		Next
+		
+		For Local doc:=Eachin docs
+			doc.Close()
+		Next
+		
 	End
 	
 	Method OnSave()

+ 2 - 0
src/ted2/mainwindow.monkey2

@@ -65,6 +65,7 @@ Class MainWindowInstance Extends Window
 		_tabMenu=New Menu
 		_tabMenu.AddAction( _fileActions.close )
 		_tabMenu.AddAction( _fileActions.closeOthers )
+		_tabMenu.AddAction( _fileActions.closeToRight )
 		_tabMenu.AddSeparator()
 		_tabMenu.AddAction( _fileActions.save )
 		_tabMenu.AddAction( _fileActions.saveAs )
@@ -109,6 +110,7 @@ Class MainWindowInstance Extends Window
 		_fileMenu.AddSeparator()
 		_fileMenu.AddAction( _fileActions.close )
 		_fileMenu.AddAction( _fileActions.closeOthers )
+		_fileMenu.AddAction( _fileActions.closeToRight )
 		_fileMenu.AddAction( _fileActions.closeAll )
 		_fileMenu.AddSeparator()
 		_fileMenu.AddAction( _fileActions.save )