|
@@ -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()
|