Browse Source

ted2 cleanups.

Mark Sibly 9 years ago
parent
commit
6c78ff079f

+ 21 - 21
src/ted2/audiodocument.monkey2

@@ -3,27 +3,6 @@ Namespace ted2
 
 
 Private
 Private
 
 
-Class AudioDocumentType Extends Ted2DocumentType
-
-	Protected
-	
-	Method New()
-		AddPlugin( Self )
-		
-		Extensions=New String[]( ".wav",".ogg" )
-	End
-	
-	Method OnCreateDocument:Ted2Document( path:String ) Override
-	
-		Return New AudioDocument( path )
-	End
-	
-	Private
-	
-	Global _instance:=New AudioDocumentType
-	
-End
-
 Class AudioDocumentView Extends View
 Class AudioDocumentView Extends View
 
 
 	Method New( doc:AudioDocument )
 	Method New( doc:AudioDocument )
@@ -183,3 +162,24 @@ Class AudioDocument Extends Ted2Document
 	Field _sound:Sound
 	Field _sound:Sound
 	
 	
 End
 End
+
+Class AudioDocumentType Extends Ted2DocumentType
+
+	Protected
+	
+	Method New()
+		AddPlugin( Self )
+		
+		Extensions=New String[]( ".wav",".ogg" )
+	End
+	
+	Method OnCreateDocument:Ted2Document( path:String ) Override
+	
+		Return New AudioDocument( path )
+	End
+	
+	Private
+	
+	Global _instance:=New AudioDocumentType
+	
+End

+ 62 - 22
src/ted2/buildactions.monkey2

@@ -33,8 +33,7 @@ Class BuildActions
 	Field moduleManager:Action
 	Field moduleManager:Action
 	Field rebuildHelp:Action
 	Field rebuildHelp:Action
 	
 	
-	Field configMenu:Menu
-	Field targetMenu:Menu
+	Field settingsMenu:Menu
 	
 	
 	Method New( docs:DocumentManager,console:Console,debugView:DebugView )
 	Method New( docs:DocumentManager,console:Console,debugView:DebugView )
 	
 	
@@ -56,11 +55,6 @@ Class BuildActions
 #Endif
 #Endif
 		_mx2cc=RealPath( _mx2cc )
 		_mx2cc=RealPath( _mx2cc )
 		
 		
-#if __HOSTOS__="macos"
-		Local menuCmd:=Modifier.Gui
-#else		
-		Local menuCmd:=Modifier.Control
-#endif
 		buildAndRun=New Action( "Build And Run" )
 		buildAndRun=New Action( "Build And Run" )
 		buildAndRun.Triggered=OnBuildAndRun
 		buildAndRun.Triggered=OnBuildAndRun
 		buildAndRun.HotKey=Key.F5
 		buildAndRun.HotKey=Key.F5
@@ -76,17 +70,17 @@ Class BuildActions
 		lockBuildFile=New Action( "Lock Build File" )
 		lockBuildFile=New Action( "Lock Build File" )
 		lockBuildFile.Triggered=OnLockBuildFile
 		lockBuildFile.Triggered=OnLockBuildFile
 		lockBuildFile.HotKey=Key.L
 		lockBuildFile.HotKey=Key.L
-		lockBuildFile.HotKeyModifiers=menuCmd
+		lockBuildFile.HotKeyModifiers=Modifier.Menu
 		
 		
 		updateModules=New Action( "Update Modules" )
 		updateModules=New Action( "Update Modules" )
 		updateModules.Triggered=OnUpdateModules
 		updateModules.Triggered=OnUpdateModules
 		updateModules.HotKey=Key.U
 		updateModules.HotKey=Key.U
-		updateModules.HotKeyModifiers=menuCmd
+		updateModules.HotKeyModifiers=Modifier.Menu
 		
 		
 		rebuildModules=New Action( "Rebuild Modules" )
 		rebuildModules=New Action( "Rebuild Modules" )
 		rebuildModules.Triggered=OnRebuildModules
 		rebuildModules.Triggered=OnRebuildModules
 		rebuildModules.HotKey=Key.U
 		rebuildModules.HotKey=Key.U
-		rebuildModules.HotKeyModifiers=menuCmd|Modifier.Shift
+		rebuildModules.HotKeyModifiers=Modifier.Menu|Modifier.Shift
 		
 		
 		moduleManager=New Action( "Module Manager" )
 		moduleManager=New Action( "Module Manager" )
 		moduleManager.Triggered=OnModuleManager
 		moduleManager.Triggered=OnModuleManager
@@ -106,9 +100,6 @@ Class BuildActions
 			_buildConfig="release"
 			_buildConfig="release"
 		End
 		End
 		_buildConfig="debug"
 		_buildConfig="debug"
-		configMenu=New Menu( "Config..." )
-		configMenu.AddView( _debugConfig )
-		configMenu.AddView( _releaseConfig )
 		
 		
 		group=New CheckGroup
 		group=New CheckGroup
 		_desktopTarget=New CheckButton( "Desktop",,group )
 		_desktopTarget=New CheckButton( "Desktop",,group )
@@ -116,7 +107,11 @@ Class BuildActions
 		_consoleTarget=New CheckButton( "Console",,group )
 		_consoleTarget=New CheckButton( "Console",,group )
 		_consoleTarget.Layout="fill-x"
 		_consoleTarget.Layout="fill-x"
 		_emscriptenTarget=New CheckButton( "Emscripten",,group )
 		_emscriptenTarget=New CheckButton( "Emscripten",,group )
-		_desktopTarget.Layout="fill-x"
+		_emscriptenTarget.Layout="fill-x"
+		_androidTarget=New CheckButton( "Android",,group )
+		_androidTarget.Layout="fill-x"
+		_iosTarget=New CheckButton( "iOS",,group )
+		_iosTarget.Layout="fill-x"
 		_desktopTarget.Clicked+=Lambda()
 		_desktopTarget.Clicked+=Lambda()
 			_buildTarget="desktop"
 			_buildTarget="desktop"
 		End
 		End
@@ -126,11 +121,23 @@ Class BuildActions
 		_emscriptenTarget.Clicked+=Lambda()
 		_emscriptenTarget.Clicked+=Lambda()
 			_buildTarget="emscripten"
 			_buildTarget="emscripten"
 		End
 		End
+		_androidTarget.Clicked+=Lambda()
+			_buildTarget="android"
+		End
+		_iosTarget.Clicked+=Lambda()
+			_buildTarget="ios"
+		End
 		_buildTarget="desktop"
 		_buildTarget="desktop"
-		targetMenu=New Menu( "Target..." )
-		targetMenu.AddView( _desktopTarget )
-		targetMenu.AddView( _consoleTarget )
-		targetMenu.AddView( _emscriptenTarget )
+		
+		settingsMenu=New Menu( "Build Settings..." )
+		settingsMenu.AddView( _debugConfig )
+		settingsMenu.AddView( _releaseConfig )
+		settingsMenu.AddSeparator()
+		settingsMenu.AddView( _desktopTarget )
+		settingsMenu.AddView( _consoleTarget )
+		settingsMenu.AddView( _emscriptenTarget )
+		settingsMenu.AddView( _androidTarget )
+		settingsMenu.AddView( _iosTarget )
 
 
 	End
 	End
 	
 	
@@ -169,6 +176,10 @@ Class BuildActions
 				_consoleTarget.Checked=True
 				_consoleTarget.Checked=True
 			Case "emscripten"
 			Case "emscripten"
 				_emscriptenTarget.Checked=True
 				_emscriptenTarget.Checked=True
+			Case "android"
+				_androidTarget.Checked=True
+			Case "ios"
+				_iosTarget.Checked=True
 			Default
 			Default
 				_desktopTarget.Checked=True
 				_desktopTarget.Checked=True
 				_buildTarget="desktop"
 				_buildTarget="desktop"
@@ -214,6 +225,8 @@ Class BuildActions
 	Field _consoleTarget:CheckButton
 	Field _consoleTarget:CheckButton
 	Field _desktopTarget:CheckButton
 	Field _desktopTarget:CheckButton
 	Field _emscriptenTarget:CheckButton
 	Field _emscriptenTarget:CheckButton
+	Field _androidTarget:CheckButton
+	Field _iosTarget:CheckButton
 	
 	
 	Field _appFile:String
 	Field _appFile:String
 	
 	
@@ -331,17 +344,26 @@ Class BuildActions
 	
 	
 	Method BuildModules:Bool( clean:Bool )
 	Method BuildModules:Bool( clean:Bool )
 	
 	
+		Local target:=""
+		
+		Select TextDialog.Run( "Build Modules","Select target...",New String[]( "Desktop","Emscripten","Android","Cancel" ),0,3 )
+		Case 0 target="desktop"
+		Case 1 target="emscripten"
+		Case 2 target="android"
+		Default Return False
+		End
+	
 		Local n:=clean ? "Rebuilding" Else "Updating"
 		Local n:=clean ? "Rebuilding" Else "Updating"
 		
 		
 		For Local config:=0 Until 2
 		For Local config:=0 Until 2
 		
 		
 			Local t:=(config ? "debug" Else "release")
 			Local t:=(config ? "debug" Else "release")
 			
 			
-			Local cmd:=_mx2cc+" makemods"
+			Local cmd:=_mx2cc+" makemods -target="+target
 			If clean cmd+=" -clean"
 			If clean cmd+=" -clean"
 			cmd+=" -config="+t
 			cmd+=" -config="+t
 			
 			
-			If Not BuildMx2( cmd,n+" "+t+" modules..." ) Return False
+			If Not BuildMx2( cmd,n+" "+target+" "+t+" modules..." ) Return False
 
 
 		Next
 		Next
 		
 		
@@ -370,11 +392,29 @@ Class BuildActions
 		cmd+=" -target="+target
 		cmd+=" -target="+target
 		cmd+=" ~q"+buildDoc.Path+"~q"
 		cmd+=" ~q"+buildDoc.Path+"~q"
 		
 		
-		If Not BuildMx2( cmd,"Building "+buildDoc.Path+"..." ) Return False
+		Local msg:="Building "+StripDir( buildDoc.Path )+" for "+target+" "+config
+		
+		If Not BuildMx2( cmd,msg ) Return False
 		
 		
 		If Not run Or Not _appFile Return True
 		If Not run Or Not _appFile Return True
 		
 		
-		_debugView.DebugApp( _appFile,config )
+		Select target
+		Case "desktop"
+			_debugView.DebugApp( _appFile,config )
+
+		Case "emscripten"	'cheese it for now...
+
+			Local mserver:=""
+
+#if __HOSTOS__="windows"
+			mserver="~q"+RealPath( "devtools/MonkeyXFree86c/bin/mserver_winnt.exe" )+"~q"
+#else if __HOSTOS__="linux"
+			mserver="~q"+RealPath( "devtools/MonkeyXFree86c/bin/mserver_linux" )+"~q"
+#else if __HOSTOS__="macos"
+			mserver="open ~q"+RealPath( "devtools/MonkeyXFree86c/bin/mserver_macos.app" )+"~q --args"
+#endif
+			_console.Run( mserver+" ~q"+_appFile+"~q" )
+		End
 		
 		
 		Return True
 		Return True
 	End
 	End

+ 91 - 84
src/ted2/documentmanager.monkey2

@@ -91,52 +91,7 @@ Class DocumentManager
 		Return _openDocs.ToArray()
 		Return _openDocs.ToArray()
 	End
 	End
 	
 	
-	Method AddDocument( doc:Ted2Document,index:Int=-1 )
-	
-		doc.DirtyChanged+=Lambda()
-			UpdateTabLabel( doc )
-		End
-		
-		doc.StateChanged+=Lambda()
-			UpdateTabLabel( doc )
-		End
-
-		doc.Closed+=Lambda()
-		
-			Local index:=_tabView.TabIndex( doc.View )
-
-			_tabView.RemoveTab( index )
-			_openDocs.Remove( doc )
-			
-			If doc=_currentDoc
-				If _tabView.NumTabs
-					If index=_tabView.NumTabs index-=1
-					CurrentDocument=FindDocument( _tabView.TabView( index ) )
-				Else
-					CurrentDocument=Null
-				Endif
-			Endif
-			
-			DocumentRemoved( doc )
-		End
-		
-		If index=-1
-		
-			_tabView.AddTab( DocumentTabLabel( doc ),doc.View )
-			
-			_openDocs.Add( doc )
-		
-		Else
-			_tabView.SetTabView( index,doc.View )
-			
-			_openDocs.Insert( index,doc )
-			
-		Endif
-		
-		DocumentAdded( doc )
-	End
-	
-	Method OpenDocument:Ted2Document( path:String,makeCurrent:Bool=False,index:Int=-1 )
+	Method OpenDocument:Ted2Document( path:String,makeCurrent:Bool=False )
 	
 	
 		path=RealPath( path )
 		path=RealPath( path )
 		
 		
@@ -146,46 +101,68 @@ Class DocumentManager
 			Return doc
 			Return doc
 		Endif
 		Endif
 		
 		
-		Local ext:=ExtractExt( path ).ToLower()
-			
-		Select ext
-		Case ".monkey2"
-		Case ".png",".jpg",".bmp"
-		Case ".wav",".ogg"
-		Case ".h",".hpp",".hxx",".c",".cpp",".cxx",".m",".mm",".s",".asm"
-		Case ".html",".js",".css",".php",".md",".json",".xml",".ini"
-		Case ".sh",".bat"
-		Case ".glsl"
-		Case ".txt"
-		Default
-			Alert( "Unrecognized file type extension for file '"+path+"'" )
-			Return Null
-		End
+		If GetFileType( path )<>FileType.File Return Null
 		
 		
-		Select ext
-		Case ".monkey2"
-			doc=New Monkey2Document( path )
-		Case ".png",".jpg"
-			doc=New ImageDocument( path )
-		Case ".wav",".ogg"
-			doc=Ted2DocumentType.CreateDocument( path )
-		Case ".json"
-			doc=New JsonDocument( path )
-		Default
-			doc=New PlainTextDocument( path )
-		End
+		Local docType:=Ted2DocumentType.ForExtension( ExtractExt( path ) )
+		If Not docType Return Null
 		
 		
-		If GetFileType( path )<>FileType.File Or Not doc.Load()
-			Return Null
-		End
+		doc=docType.CreateDocument( path )
+		If Not doc.Load() Return Null
+
+		InitDoc( doc )
+	
+		_openDocs.Add( doc )
+		_tabView.AddTab( TabText( doc ),doc.View )
 		
 		
-		AddDocument( doc,index )
+		DocumentAdded( doc )
 		
 		
 		If makeCurrent CurrentDocument=doc
 		If makeCurrent CurrentDocument=doc
 		
 		
 		Return doc
 		Return doc
 	End
 	End
 	
 	
+	'Currently also saves doc.
+	'
+	Method RenameDocument:Ted2Document( doc:Ted2Document,newPath:String )
+	
+		For Local i:=0 Until _openDocs.Length
+			If doc<>_openDocs[i] Continue
+			
+			Local newType:=Ted2DocumentType.ForExtension( ExtractExt( newPath ) )
+			If Not newType Return Null
+
+			Local oldPath:=doc.Path
+			doc.Rename( newPath )
+			If Not doc.Save()
+				doc.Rename( oldPath )
+				Return Null
+			Endif
+			
+			If newType=Ted2DocumentType.ForExtension( ExtractExt( oldPath ) ) Return doc
+			
+			Local newDoc:=newType.CreateDocument( newPath )
+			If Not newDoc.Load() Return Null
+			
+			InitDoc( newDoc )
+			
+			_openDocs[i]=newDoc
+			_tabView.SetTabText( i,TabText( newDoc ) )
+			_tabView.SetTabView( i,newDoc.View )
+			
+			doc.Close()
+			
+			DocumentRemoved( doc )
+			
+			DocumentAdded( newDoc )
+			
+			If doc=_currentDoc CurrentDocument=newDoc
+
+			Return newDoc
+		Next
+		
+		Return Null
+	End
+	
 	Method FindDocument:Ted2Document( path:String )
 	Method FindDocument:Ted2Document( path:String )
 	
 	
 		For Local doc:=Eachin _openDocs
 		For Local doc:=Eachin _openDocs
@@ -208,9 +185,6 @@ Class DocumentManager
 		
 		
 		Local docs:=New JsonArray
 		Local docs:=New JsonArray
 		For Local doc:=Eachin _openDocs
 		For Local doc:=Eachin _openDocs
-
-			If MainWindow.IsTmpPath( doc.Path ) And Not doc.Dirty Continue
-			
 			docs.Add( New JsonString( doc.Path ) )
 			docs.Add( New JsonString( doc.Path ) )
 		Next
 		Next
 		jobj["openDocuments"]=docs
 		jobj["openDocuments"]=docs
@@ -256,14 +230,46 @@ Class DocumentManager
 	
 	
 	Field _openDocs:=New Stack<Ted2Document>
 	Field _openDocs:=New Stack<Ted2Document>
 	
 	
-	Method DocumentTabLabel:String( doc:Ted2Document )
+	Method InitDoc( doc:Ted2Document )
+	
+		doc.DirtyChanged+=Lambda()
+		
+			UpdateTabLabel( doc )
+		End
+		
+		doc.StateChanged+=Lambda()
+		
+			UpdateTabLabel( doc )
+		End
+
+		doc.Closed+=Lambda()
+		
+			Local index:=_tabView.TabIndex( doc.View )
+			If index=-1 Return	'in case doc already removed via Rename.
+
+			_tabView.RemoveTab( index )
+			_openDocs.Remove( doc )
+			
+			If doc=_currentDoc
+				If _tabView.NumTabs
+					If index=_tabView.NumTabs index-=1
+					CurrentDocument=FindDocument( _tabView.TabView( index ) )
+				Else
+					CurrentDocument=Null
+				Endif
+			Endif
+			
+			DocumentRemoved( doc )
+		End
+		
+	End
+	
+	Method TabText:String( doc:Ted2Document )
 	
 	
 		Local label:=StripDir( doc.Path )
 		Local label:=StripDir( doc.Path )
 		
 		
 		If ExtractExt( doc.Path ).ToLower()=".monkey2"  label=StripExt( label )
 		If ExtractExt( doc.Path ).ToLower()=".monkey2"  label=StripExt( label )
 		
 		
-		'If IsTmpPath( doc.Path ) label="<"+label+">"
-		
 		label=doc.State+label
 		label=doc.State+label
 		
 		
 		If doc.Dirty label+="*"
 		If doc.Dirty label+="*"
@@ -272,7 +278,8 @@ Class DocumentManager
 	End
 	End
 	
 	
 	Method UpdateTabLabel( doc:Ted2Document )
 	Method UpdateTabLabel( doc:Ted2Document )
-		If doc _tabView.SetTabText( doc.View,DocumentTabLabel( doc ) )
+	
+		If doc _tabView.SetTabText( doc.View,TabText( doc ) )
 	End
 	End
 	
 	
 	Method OnNextDocument()
 	Method OnNextDocument()

+ 38 - 79
src/ted2/fileactions.monkey2

@@ -17,29 +17,23 @@ Class FileActions
 	
 	
 		_docs=docs
 		_docs=docs
 		
 		
-#if __HOSTOS__="macos"
-		Local menuCmd:=Modifier.Gui
-#else		
-		Local menuCmd:=Modifier.Control
-#endif
-
 		new_=New Action( "New" )
 		new_=New Action( "New" )
 		new_.HotKey=Key.N
 		new_.HotKey=Key.N
-		new_.HotKeyModifiers=menuCmd
+		new_.HotKeyModifiers=Modifier.Menu
 		new_.Triggered=OnNew
 		new_.Triggered=OnNew
 		
 		
 		open=New Action( "Open" )
 		open=New Action( "Open" )
 		open.HotKey=Key.O
 		open.HotKey=Key.O
-		open.HotKeyModifiers=menuCmd
+		open.HotKeyModifiers=Modifier.Menu
 		open.Triggered=OnOpen
 		open.Triggered=OnOpen
 		
 		
 		close=New Action( "Close" )
 		close=New Action( "Close" )
 #if __HOSTOS__="macos"
 #if __HOSTOS__="macos"
 		close.HotKey=Key.W
 		close.HotKey=Key.W
-		close.HotKeyModifiers=menuCmd
+		close.HotKeyModifiers=Modifier.Menu
 #else
 #else
 		close.HotKey=Key.F4
 		close.HotKey=Key.F4
-		close.HotKeyModifiers=menuCmd
+		close.HotKeyModifiers=Modifier.Menu
 #endif		
 #endif		
 		close.Triggered=OnClose
 		close.Triggered=OnClose
 		
 		
@@ -51,10 +45,12 @@ Class FileActions
 		
 		
 		save=New Action( "Save" )
 		save=New Action( "Save" )
 		save.HotKey=Key.S
 		save.HotKey=Key.S
-		save.HotKeyModifiers=menuCmd
+		save.HotKeyModifiers=Modifier.Menu
 		save.Triggered=OnSave
 		save.Triggered=OnSave
 
 
 		saveAs=New Action( "Save As" )
 		saveAs=New Action( "Save As" )
+		saveAs.HotKey=Key.S
+		saveAs.HotKeyModifiers=Modifier.Menu|Modifier.Shift
 		saveAs.Triggered=OnSaveAs
 		saveAs.Triggered=OnSaveAs
 
 
 		saveAll=New Action( "Save All" )
 		saveAll=New Action( "Save All" )
@@ -62,7 +58,6 @@ Class FileActions
 		
 		
 		quit=New Action( "Quit" )
 		quit=New Action( "Quit" )
 		quit.Triggered=OnQuit
 		quit.Triggered=OnQuit
-		
 	End
 	End
 	
 	
 	Method Update()
 	Method Update()
@@ -88,73 +83,52 @@ Class FileActions
 	
 	
 	Field _docs:DocumentManager
 	Field _docs:DocumentManager
 	
 	
-	Method IsTmpPath:Bool( path:String )
+	Method SaveAs:Ted2Document()
 	
 	
-		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
+		Local doc:=_docs.CurrentDocument
+		If Not doc Return Null
 		
 		
-		If reopen And ExtractExt( tpath ).ToLower()<>ExtractExt( path ).ToLower()
-			doc.Close()
-			Return _docs.OpenDocument( path,makeCurrent )
-		Endif
+		Local path:=MainWindow.RequestFile( "Save As","",True )
+		If Not path Return Null
+				
+		If Not ExtractExt( path ) path+=ExtractExt( doc.Path )
 		
 		
-		Return doc
+		Return _docs.RenameDocument( doc,path )
 	End
 	End
+
+	Method CanClose:Ted2Document( doc:Ted2Document )
 	
 	
-	Method CanClose:Bool( doc:Ted2Document )
-	
-		If Not doc.Dirty Return True
+		If Not doc.Dirty Return doc
 		
 		
 		_docs.CurrentDocument=doc
 		_docs.CurrentDocument=doc
 				
 				
 		Local buttons:=New String[]( "Save","Discard Changes","Cancel" )
 		Local buttons:=New String[]( "Save","Discard Changes","Cancel" )
 			
 			
-		Select TextDialog.Run( "Close All","File '"+doc.Path+"' has been modified.",buttons )
+		Select TextDialog.Run( "Close File","File '"+doc.Path+"' has been modified.",buttons )
 		Case 0
 		Case 0
 			If MainWindow.IsTmpPath( doc.Path )
 			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
+				Return SaveAs()
 			Else
 			Else
- 
-				If Not doc.Save() Return False
+				If Not doc.Save() Return Null
 			Endif
 			Endif
-		Case 2 
-			Return False
+		Case 2
+			Return Null
 		End
 		End
 		
 		
-		Return True
+		Return doc
 	End
 	End
 	
 	
 	Method CloseAll:Bool( except:Ted2Document )
 	Method CloseAll:Bool( except:Ted2Document )
 
 
-		Local close:=New Stack<Ted2Document>
-	
 		For Local doc:=Eachin _docs.OpenDocuments
 		For Local doc:=Eachin _docs.OpenDocuments
 			If doc=except Continue
 			If doc=except Continue
-		
-			If Not CanClose( doc ) Return False
 			
 			
-			close.Add( doc )
+			If Not CanClose( doc ) Return False
 		Next
 		Next
 		
 		
-		For Local doc:=Eachin close
+		For Local doc:=Eachin _docs.OpenDocuments
+			If doc=except Continue
+			
 			doc.Close()
 			doc.Close()
 		Next
 		Next
 		
 		
@@ -176,7 +150,7 @@ Class FileActions
 		
 		
 	Method OnOpen()
 	Method OnOpen()
 	
 	
-		Local path:=MainWindow.RequestFile( "Open file...","",False )
+		Local path:=MainWindow.RequestFile( "Open File","",False )
 		If Not path Return
 		If Not path Return
 		
 		
 		path=RealPath( path )
 		path=RealPath( path )
@@ -189,19 +163,20 @@ Class FileActions
 		Local doc:=_docs.CurrentDocument
 		Local doc:=_docs.CurrentDocument
 		If Not doc Return
 		If Not doc Return
 		
 		
-		If Not CanClose( doc ) Return
+		doc=CanClose( doc )
+		If Not doc return
 		
 		
 		doc.Close()
 		doc.Close()
 	End
 	End
 	
 	
 	Method OnCloseOthers()
 	Method OnCloseOthers()
 	
 	
-		If Not CloseAll( _docs.CurrentDocument ) Return
+		CloseAll( _docs.CurrentDocument )
 	End
 	End
 	
 	
 	Method OnCloseAll()
 	Method OnCloseAll()
 	
 	
-		If Not CloseAll( Null ) Return
+		CloseAll( Null )
 	End
 	End
 	
 	
 	Method OnSave()
 	Method OnSave()
@@ -210,26 +185,15 @@ Class FileActions
 		If Not doc Return
 		If Not doc Return
 		
 		
 		If MainWindow.IsTmpPath( doc.Path )
 		If MainWindow.IsTmpPath( doc.Path )
-
-			Local path:=MainWindow.RequestFile( "Save As","",True )
-			If Not path Return
-			
-			Rename( doc,path,True,True )
+			SaveAs()
 		Else
 		Else
-		
 			doc.Save()
 			doc.Save()
 		Endif
 		Endif
 	End
 	End
 	
 	
 	Method OnSaveAs()
 	Method OnSaveAs()
 	
 	
-		Local doc:=_docs.CurrentDocument
-		If Not doc Return
-	
-		Local path:=MainWindow.RequestFile( "Save As","",True )
-		If Not path Return 
-		
-		Rename( doc,path,True,True )
+		SaveAs()
 	End
 	End
 	
 	
 	Method OnSaveAll()
 	Method OnSaveAll()
@@ -237,13 +201,9 @@ Class FileActions
 		For Local doc:=Eachin _docs.OpenDocuments
 		For Local doc:=Eachin _docs.OpenDocuments
 
 
 			If MainWindow.IsTmpPath( doc.Path )
 			If MainWindow.IsTmpPath( doc.Path )
-	
-				Local path:=MainWindow.RequestFile( "Save As","",True )
-				If Not path Return
-				
-				Rename( doc,path,True,False )
+				_docs.CurrentDocument=doc
+				If Not SaveAs() Return
 			Else
 			Else
-			
 				doc.Save()
 				doc.Save()
 			Endif
 			Endif
 		Next
 		Next
@@ -254,13 +214,12 @@ Class FileActions
 		For Local doc:=Eachin _docs.OpenDocuments
 		For Local doc:=Eachin _docs.OpenDocuments
 		
 		
 			If MainWindow.IsTmpPath( doc.Path )
 			If MainWindow.IsTmpPath( doc.Path )
-			
 				If Not doc.Save() Return
 				If Not doc.Save() Return
 			Else
 			Else
 				If Not CanClose( doc ) Return
 				If Not CanClose( doc ) Return
 			Endif
 			Endif
 		Next
 		Next
 		
 		
-		App.Terminate()
+		MainWindow.Terminate()
 	End
 	End
 End
 End

+ 1 - 6
src/ted2/findactions.monkey2

@@ -13,15 +13,10 @@ Class FindActions
 		
 		
 		_docs=docs
 		_docs=docs
 		
 		
-#if __HOSTOS__="macos"
-		Local menuCmd:=Modifier.Gui
-#else		
-		Local menuCmd:=Modifier.Control
-#endif
 		find=New Action( "Find" )
 		find=New Action( "Find" )
 		find.Triggered=OnFind
 		find.Triggered=OnFind
 		find.HotKey=Key.F
 		find.HotKey=Key.F
-		find.HotKeyModifiers=menuCmd
+		find.HotKeyModifiers=Modifier.Menu
 		
 		
 		findNext=New Action( "Find Next" )
 		findNext=New Action( "Find Next" )
 		findNext.Triggered=OnFindNext
 		findNext.Triggered=OnFindNext

+ 21 - 0
src/ted2/imagedocument.monkey2

@@ -101,3 +101,24 @@ Class ImageDocument Extends Ted2Document
 	Field _view:ImageDocumentView
 	Field _view:ImageDocumentView
 	
 	
 End
 End
+
+Class ImageDocumentType Extends Ted2DocumentType
+
+	Protected
+	
+	Method New()
+		AddPlugin( Self )
+		
+		Extensions=New String[]( ".png",".jpg",".bmp" )
+	End
+	
+	Method OnCreateDocument:Ted2Document( path:String ) Override
+	
+		Return New ImageDocument( path )
+	End
+	
+	Private
+	
+	Global _instance:=New ImageDocumentType
+	
+End

+ 21 - 0
src/ted2/jsondocument.monkey2

@@ -165,3 +165,24 @@ Class JsonDocument Extends Ted2Document
 	
 	
 	Field _view:JsonDocumentView
 	Field _view:JsonDocumentView
 End
 End
+
+Class JsonDocumentType Extends Ted2DocumentType
+
+	Protected
+	
+	Method New()
+		AddPlugin( Self )
+		
+		Extensions=New String[]( ".json" )
+	End
+	
+	Method OnCreateDocument:Ted2Document( path:String ) Override
+	
+		Return New JsonDocument( path )
+	End
+	
+	Private
+	
+	Global _instance:=New JsonDocumentType
+	
+End

+ 22 - 20
src/ted2/mainwindow.monkey2

@@ -147,9 +147,7 @@ Class MainWindowInstance Extends Window
 		_buildMenu=New Menu( "Build" )
 		_buildMenu=New Menu( "Build" )
 		_buildMenu.AddAction( _buildActions.buildAndRun )
 		_buildMenu.AddAction( _buildActions.buildAndRun )
 		_buildMenu.AddAction( _buildActions.build )
 		_buildMenu.AddAction( _buildActions.build )
-		_buildMenu.AddSeparator()
-		_buildMenu.AddSubMenu( _buildActions.configMenu )
-		_buildMenu.AddSubMenu( _buildActions.targetMenu )
+		_buildMenu.AddSubMenu( _buildActions.settingsMenu )
 		_buildMenu.AddSeparator()
 		_buildMenu.AddSeparator()
 		_buildMenu.AddAction( _buildActions.nextError )
 		_buildMenu.AddAction( _buildActions.nextError )
 		_buildMenu.AddSeparator()
 		_buildMenu.AddSeparator()
@@ -197,6 +195,13 @@ Class MainWindowInstance Extends Window
 
 
 		App.Idle+=OnAppIdle
 		App.Idle+=OnAppIdle
 	End
 	End
+	
+	Method Terminate()
+	
+		SaveState()
+		
+		App.Terminate()
+	End
 
 
 	'Use these as macos still seems to have problems running requesters on a fiber - stacksize?
 	'Use these as macos still seems to have problems running requesters on a fiber - stacksize?
 	'
 	'
@@ -330,27 +335,24 @@ Class MainWindowInstance Extends Window
 	
 	
 	Method LoadState( jobj:JsonObject )
 	Method LoadState( jobj:JsonObject )
 	
 	
+		'for 'reload' later...
 		_projectView.ProjectOpened-=UpdateCloseProjectMenu
 		_projectView.ProjectOpened-=UpdateCloseProjectMenu
 		
 		
-		If jobj
-		
-	'		If jobj.Contains( "windowRect" ) Frame=ToRecti( jobj["windowRect"] )
-			If jobj.Contains( "browserSize" ) _contentView.SetViewSize( _browsersTabView,jobj["browserSize"].ToNumber() )
-			If jobj.Contains( "consoleSize" ) _contentView.SetViewSize( _consolesTabView,jobj["consoleSize"].ToNumber() )
+'		If jobj.Contains( "windowRect" ) Frame=ToRecti( jobj["windowRect"] )
+		If jobj.Contains( "browserSize" ) _contentView.SetViewSize( _browsersTabView,jobj["browserSize"].ToNumber() )
+		If jobj.Contains( "consoleSize" ) _contentView.SetViewSize( _consolesTabView,jobj["consoleSize"].ToNumber() )
 			
 			
-			If jobj.Contains( "recentFiles" )
-				For Local file:=Eachin jobj["recentFiles"].ToArray()
-					Local path:=file.ToString()
-					If GetFileType( path )<>FileType.File Continue
-					_recentFiles.Push( path )
-				Next
-			End
+		If jobj.Contains( "recentFiles" )
+			For Local file:=Eachin jobj["recentFiles"].ToArray()
+				Local path:=file.ToString()
+				If GetFileType( path )<>FileType.File Continue
+				_recentFiles.Push( path )
+			Next
+		End
 			
 			
-			_docsManager.LoadState( jobj )
-			_buildActions.LoadState( jobj )
-			_projectView.LoadState( jobj )
-		
-		Endif
+		_docsManager.LoadState( jobj )
+		_buildActions.LoadState( jobj )
+		_projectView.LoadState( jobj )
 		
 		
 		If Not _projectView.OpenProjects _projectView.OpenProject( CurrentDir() )
 		If Not _projectView.OpenProjects _projectView.OpenProject( CurrentDir() )
 		
 		

+ 22 - 0
src/ted2/monkey2document.monkey2

@@ -401,3 +401,25 @@ Class Monkey2Document Extends Ted2Document
 	End
 	End
 	
 	
 End
 End
+
+Class Monkey2DocumentType Extends Ted2DocumentType
+
+	Protected
+	
+	Method New()
+		AddPlugin( Self )
+		
+		Extensions=New String[]( ".monkey2",".ogg" )
+	End
+	
+	Method OnCreateDocument:Ted2Document( path:String ) Override
+	
+		Return New Monkey2Document( path )
+	End
+	
+	Private
+	
+	Global _instance:=New Monkey2DocumentType
+	
+End
+

+ 20 - 0
src/ted2/plaintextdocument.monkey2

@@ -74,3 +74,23 @@ Class PlainTextDocument Extends Ted2Document
 
 
 End
 End
 
 
+Class PlainTextDocumentType Extends Ted2DocumentType
+
+	Protected
+	
+	Method New()
+		AddPlugin( Self )
+		
+		Extensions=New String[]( ".h",".hpp",".hxx",".c",".cpp",".cxx",".m",".mm",".s",".asm",".html",".js",".css",".php",".md",".xml",".ini",".sh",".bat",".glsl",".txt" )
+	End
+	
+	Method OnCreateDocument:Ted2Document( path:String ) Override
+	
+		Return New PlainTextDocument( path )
+	End
+	
+	Private
+	
+	Global _instance:=New PlainTextDocumentType
+	
+End

+ 8 - 3
src/ted2/ted2.monkey2

@@ -1,5 +1,5 @@
 
 
-#If __HOSTOS__="windows"
+#If __TARGET__="desktop" and __HOSTOS__="windows"
 #Import "bin/wget.exe"
 #Import "bin/wget.exe"
 #End
 #End
 
 
@@ -40,8 +40,10 @@ Using mojox..
 
 
 Function Main()
 Function Main()
 
 
-	ChangeDir( AppDir() )
+#if __TARGET__="desktop"
 		
 		
+	ChangeDir( AppDir() )
+	
 	While GetFileType( "bin" )<>FileType.Directory Or GetFileType( "modules" )<>FileType.Directory
 	While GetFileType( "bin" )<>FileType.Directory Or GetFileType( "modules" )<>FileType.Directory
 
 
 		If IsRootDir( CurrentDir() )
 		If IsRootDir( CurrentDir() )
@@ -52,10 +54,13 @@ Function Main()
 		ChangeDir( ExtractDir( CurrentDir() ) )
 		ChangeDir( ExtractDir( CurrentDir() ) )
 	Wend
 	Wend
 	
 	
+#endif
+	
 	Local jobj:=JsonObject.Load( "bin/ted2.state.json" )
 	Local jobj:=JsonObject.Load( "bin/ted2.state.json" )
+	If Not jobj jobj=New JsonObject
 	
 	
 	Local rect:=New Recti( 64,64,64+960,64+800 )
 	Local rect:=New Recti( 64,64,64+960,64+800 )
-	If jobj And jobj.Contains( "windowRect" ) rect=ToRecti( jobj["windowRect"] )
+	If jobj.Contains( "windowRect" ) rect=ToRecti( jobj["windowRect"] )
 	
 	
 	New AppInstance
 	New AppInstance
 	
 	

+ 52 - 47
src/ted2/ted2document.monkey2

@@ -1,53 +1,6 @@
 
 
 Namespace ted2
 Namespace ted2
 
 
-Class Ted2DocumentType Extends Plugin
-
-	Function CreateDocument:Ted2Document( path:String )
-	
-		Local ext:=ExtractExt( path ).ToLower()
-	
-		Local types:=Plugin.PluginsOfType<Ted2DocumentType>()
-
-		For Local type:=Eachin types
-		
-			For Local ext2:=Eachin type.Extensions	'Array.Contains() would be nice!
-			
-				If ext=ext2 Return type.OnCreateDocument( path )
-			
-			Next
-			
-		Next
-		
-		Return Null
-	End
-	
-	Protected
-	
-	Method New()
-		AddPlugin( Self )
-	
-	End
-	
-	Property Extensions:String[]()
-	
-		Return _exts
-	
-	Setter( exts:String[] )
-	
-		_exts=exts
-	End
-	
-	Method OnCreateDocument:Ted2Document( path:String ) Virtual
-	
-		Return Null	'should return hex editor!
-	End
-	
-	Private
-	
-	Field _exts:String[]
-End
-
 Class Ted2Document
 Class Ted2Document
 
 
 	Field DirtyChanged:Void()
 	Field DirtyChanged:Void()
@@ -187,3 +140,55 @@ Class Ted2Document
 	Field _view:View
 	Field _view:View
 	
 	
 End
 End
+
+Class Ted2DocumentType Extends Plugin
+
+	Function ForExtension:Ted2DocumentType( ext:String )
+	
+		ext=ext.ToLower()
+
+		Local types:=Plugin.PluginsOfType<Ted2DocumentType>()
+
+		For Local type:=Eachin types
+		
+			For Local ext2:=Eachin type.Extensions	'Array.Contains() would be nice!
+			
+				If ext=ext2 Return type
+			
+			Next
+			
+		Next
+		
+		Return Null
+	End
+	
+	Method CreateDocument:Ted2Document( path:String )
+	
+		Return OnCreateDocument( path )
+	End
+
+	Protected
+	
+	Method New()
+
+		AddPlugin( Self )
+	End
+	
+	Property Extensions:String[]()
+	
+		Return _exts
+	
+	Setter( exts:String[] )
+	
+		_exts=exts
+	End
+	
+	Method OnCreateDocument:Ted2Document( path:String ) Virtual
+	
+		Return Null	'should return hex editor!
+	End
+	
+	Private
+	
+	Field _exts:String[]
+End