소스 검색

Ted2 tweaks and cleanups.

Mark Sibly 9 년 전
부모
커밋
3372c7e117
5개의 변경된 파일99개의 추가작업 그리고 70개의 파일을 삭제
  1. 11 21
      src/ted2/documentmanager.monkey2
  2. 58 36
      src/ted2/fileactions.monkey2
  3. 25 1
      src/ted2/mainwindow.monkey2
  4. 2 9
      src/ted2/projectview.monkey2
  5. 3 3
      src/ted2/ted2document.monkey2

+ 11 - 21
src/ted2/documentmanager.monkey2

@@ -92,7 +92,7 @@ Class DocumentManager
 	End
 	
 	Method AddDocument( doc:Ted2Document,index:Int=-1 )
-		
+	
 		doc.DirtyChanged+=Lambda()
 			UpdateTabLabel( doc )
 		End
@@ -176,7 +176,6 @@ Class DocumentManager
 		End
 		
 		If GetFileType( path )<>FileType.File Or Not doc.Load()
-			MainWindow.ReadError( path )
 			Return Null
 		End
 		
@@ -209,6 +208,9 @@ Class DocumentManager
 		
 		Local docs:=New JsonArray
 		For Local doc:=Eachin _openDocs
+
+			If MainWindow.IsTmpPath( doc.Path ) And Not doc.Dirty Continue
+			
 			docs.Add( New JsonString( doc.Path ) )
 		Next
 		jobj["openDocuments"]=docs
@@ -221,16 +223,21 @@ Class DocumentManager
 		If Not jobj.Contains( "openDocuments" ) Return
 		
 		For Local doc:=Eachin jobj["openDocuments"].ToArray()
+		
 			Local path:=doc.ToString()
 			If GetFileType( path )<>FileType.File Continue
-			OpenDocument( doc.ToString() )
+			
+			Local tdoc:=OpenDocument( doc.ToString() )
+			If tdoc And MainWindow.IsTmpPath( path ) tdoc.Dirty=True
 		Next
 		
 		If jobj.Contains( "currentDocument" )
 			Local path:=jobj["currentDocument"].ToString()
 			Local doc:=FindDocument( path )
 			If doc CurrentDocument=doc
-		Else If _openDocs.Length
+		Endif
+		
+		If Not _currentDoc And _openDocs.Length
 			CurrentDocument=_openDocs[0]
 		Endif
 		
@@ -249,23 +256,6 @@ Class DocumentManager
 	
 	Field _openDocs:=New Stack<Ted2Document>
 	
-	Field _tmp:String
-	
-	Method AllocTmpPath:String()
-	
-		For Local i:=1 Until 10
-			Local path:=_tmp+"untitled"+i+".monkey2"
-			If GetFileType( path )=FileType.None Return path
-		Next
-
-		Return ""
-	End
-	
-	Method IsTmpPath:Bool( path:String )
-
-		Return path.StartsWith( _tmp )
-	End
-	
 	Method DocumentTabLabel:String( doc:Ted2Document )
 	
 		Local label:=StripDir( doc.Path )

+ 58 - 36
src/ted2/fileactions.monkey2

@@ -88,6 +88,33 @@ Class FileActions
 	
 	Field _docs:DocumentManager
 	
+	Method IsTmpPath:Bool( path:String )
+	
+		Return MainWindow.IsTmpPath( path )
+	End
+	
+	'Ok, pretty ugly - changing doc type is tricky.
+	'
+	'Wait until we have a propery DocumentType class before getting too carried away...
+	'
+	Method Rename:Ted2Document( doc:Ted2Document,path:String,reopen:Bool,makeCurrent:Bool )
+		
+		Local tpath:=doc.Path
+
+		doc.Rename( path )
+		If Not doc.Save()
+			doc.Rename( tpath )
+			Return Null
+		Endif
+		
+		If reopen And ExtractExt( tpath ).ToLower()<>ExtractExt( path ).ToLower()
+			doc.Close()
+			Return _docs.OpenDocument( path,makeCurrent )
+		Endif
+		
+		Return doc
+	End
+	
 	Method CanClose:Bool( doc:Ted2Document )
 	
 		If Not doc.Dirty Return True
@@ -97,8 +124,17 @@ Class FileActions
 		Local buttons:=New String[]( "Save","Discard Changes","Cancel" )
 			
 		Select TextDialog.Run( "Close All","File '"+doc.Path+"' has been modified.",buttons )
-		Case 0 
-			If Not doc.Save() Return False
+		Case 0
+			If MainWindow.IsTmpPath( doc.Path )
+			
+				Local path:=MainWindow.RequestFile( "Save As","",True )
+				If Not path Return False
+				
+				If Not Rename( doc,path,False,False ) Return False
+			Else
+ 
+				If Not doc.Save() Return False
+			Endif
 		Case 2 
 			Return False
 		End
@@ -129,7 +165,7 @@ Class FileActions
 	
 		Local path:=MainWindow.AllocTmpPath( ".monkey2" )
 		If Not path
-			Alert( "Can't create temporary file" )
+			Alert( "Can't allocate temporary file" )
 			Return
 		Endif
 
@@ -143,7 +179,7 @@ Class FileActions
 		Local future:=New Future<String>
 		
 		App.Idle+=Lambda()
-			Local path:=RequestFile( "Open file...","",False )
+			Local path:=MainWindow.RequestFile( "Open file...","",False )
 			future.Set( path )
 		End
 		
@@ -182,37 +218,25 @@ Class FileActions
 		
 		If MainWindow.IsTmpPath( doc.Path )
 
-			Local path:=RequestFile( "Save As","",True )
+			Local path:=MainWindow.RequestFile( "Save As","",True )
 			If Not path Return
 			
-			doc.Rename( path )
-		Endif
+			Rename( doc,path,True,True )
+		Else
 		
-		doc.Save()
+			doc.Save()
+		Endif
 	End
 	
 	Method OnSaveAs()
-
+	
 		Local doc:=_docs.CurrentDocument
 		If Not doc Return
-			
-		Local path:=RequestFile( "Save As","",True )
-		If Not path Return
-		
-		Local index:=0
-		For Local doc2:=Eachin _docs.OpenDocuments
-			If doc=doc2 Exit
-			index+=1
-		Next
-
-		doc.Rename( path )
-		
-		doc.Save()
-		
-		doc.Close()
-		
-		_docs.OpenDocument( path,True )
+	
+		Local path:=MainWindow.RequestFile( "Save As","",True )
+		If Not path Return 
 		
+		Rename( doc,path,True,True )
 	End
 	
 	Method OnSaveAll()
@@ -221,17 +245,10 @@ Class FileActions
 
 			If MainWindow.IsTmpPath( doc.Path )
 	
-				Local path:=RequestFile( "Save As","",True )
+				Local path:=MainWindow.RequestFile( "Save As","",True )
 				If Not path Return
 				
-				doc.Rename( path )
-				
-				doc.Save()
-				
-				doc.Close()
-				
-				_docs.OpenDocument( path,True )
-				
+				Rename( doc,path,True,False )
 			Else
 			
 				doc.Save()
@@ -243,7 +260,12 @@ Class FileActions
 	
 		For Local doc:=Eachin _docs.OpenDocuments
 		
-			If Not CanClose( doc ) Return
+			If MainWindow.IsTmpPath( doc.Path )
+			
+				If Not doc.Save() Return
+			Else
+				If Not CanClose( doc ) Return
+			Endif
 		Next
 		
 		App.Terminate()

+ 25 - 1
src/ted2/mainwindow.monkey2

@@ -73,7 +73,7 @@ Class MainWindowInstance Extends Window
 		_docsTabView.CloseClicked+=Lambda( index:Int )
 
 			Local doc:=_docsManager.FindDocument( _docsTabView.TabView( index ) )
-			If Not doc.Dirty
+			If Not doc.Dirty And Not IsTmpPath( doc.Path )
 				doc.Close()
 				Return
 			Endif
@@ -197,6 +197,30 @@ Class MainWindowInstance Extends Window
 
 		App.Idle+=OnAppIdle
 	End
+
+	'Use these as macos still seems to have problems running requesters on a fiber - stacksize?
+	'
+	Method RequestFile:String( title:String,path:String,save:Bool )
+	
+		Local future:=New Future<String>
+		
+		App.Idle+=Lambda()
+			future.Set( requesters.RequestFile( "Save As","",True ) )
+		End
+		
+		Return future.Get()
+	End
+
+	Method RequestDir:String( title:String,dir:String )
+		
+		Local future:=New Future<String>
+		
+		App.Idle+=Lambda()
+			future.Set( requesters.RequestDir( "Select Project Directory...","" ) )
+		End
+		
+		Return future.Get()
+	End
 	
 	Method AllocTmpPath:String( ext:String )
 	

+ 2 - 9
src/ted2/projectview.monkey2

@@ -202,17 +202,10 @@ Class ProjectView Extends ScrollView
 
 	Method OnOpenProject()
 	
-		Local future:=New Future<String>
-		
-		App.Idle+=Lambda()
-			Local dir:=RequestDir( "Select Project Directory...","" )
-			future.Set( dir )
-		End
-		
-		Local dir:=future.Get()
+		Local dir:=MainWindow.RequestDir( "Select Project Directory...","" )
 		If Not dir Return
 		
-		If Not OpenProject( dir ) Return
+		OpenProject( dir )
 	End
 	
 End

+ 3 - 3
src/ted2/ted2document.monkey2

@@ -3,7 +3,7 @@ Namespace ted2
 
 Class Ted2Document
 
-	Field DirtyChanged:Void()	'also triggered by save/rename
+	Field DirtyChanged:Void()
 	
 	Field StateChanged:Void()
 
@@ -91,9 +91,9 @@ Class Ted2Document
 
 		Return True
 	End
-	
+
+	'DON'T USE YET!	
 	Method Rename( path:String )
-	
 		_path=path
 		
 		Dirty=True