Browse Source

WORK IN PROGRESS ted2 tweaks.

Mark Sibly 9 years ago
parent
commit
e0739f6bf3

+ 9 - 2
src/ted2/documentmanager.monkey2

@@ -11,9 +11,10 @@ Class DocumentManager
 	Field DocumentAdded:Void( doc:Ted2Document )
 	Field DocumentAdded:Void( doc:Ted2Document )
 	Field DocumentRemoved:Void( doc:Ted2Document )
 	Field DocumentRemoved:Void( doc:Ted2Document )
 
 
-	Method New( tabView:TabView )
+	Method New( tabView:TabView,browser:DockingView )
 	
 	
 		_tabView=tabView
 		_tabView=tabView
+		_browser=browser
 		
 		
 		_tabView.CurrentChanged+=Lambda()
 		_tabView.CurrentChanged+=Lambda()
 			CurrentDocument=FindDocument( _tabView.CurrentView )
 			CurrentDocument=FindDocument( _tabView.CurrentView )
@@ -57,7 +58,12 @@ Class DocumentManager
 		
 		
 		_currentDoc=doc
 		_currentDoc=doc
 		
 		
-		If doc _tabView.CurrentView=CurrentView
+		If _currentDoc
+			_tabView.CurrentView=CurrentView
+			_browser.ContentView=_currentDoc.BrowserView
+		Else
+			_browser.ContentView=Null
+		Endif
 		
 		
 		'Can't change window title on a fiber on at least windows!
 		'Can't change window title on a fiber on at least windows!
 		'
 		'
@@ -225,6 +231,7 @@ Class DocumentManager
 	Private
 	Private
 	
 	
 	Field _tabView:TabView
 	Field _tabView:TabView
+	Field _browser:DockingView
 	
 	
 	Field _currentDoc:Ted2Document
 	Field _currentDoc:Ted2Document
 	
 	

+ 1 - 1
src/ted2/fileactions.monkey2

@@ -131,7 +131,7 @@ Class FileActions
 	
 	
 	Method OnNew()
 	Method OnNew()
 	
 	
-		Local path:=MainWindow.AllocTmpPath( ".monkey2" )
+		Local path:=MainWindow.AllocTmpPath( "untitled",".monkey2" )
 		If Not path
 		If Not path
 			Alert( "Can't allocate temporary file" )
 			Alert( "Can't allocate temporary file" )
 			Return
 			Return

+ 16 - 42
src/ted2/jsondocument.monkey2

@@ -1,41 +1,6 @@
 
 
 Namespace ted2
 Namespace ted2
 
 
-Class JsonDocumentView Extends DockingView
-
-	Method New( doc:TextDocument )
-	
-		_textView=New TextView( doc )
-		
-		doc.TextChanged+=Lambda()
-		
-			_jsonTree.Value=JsonValue.Parse( _textView.Text )
-		End
-
-		_jsonTree=New JsonTreeView
-				
-		AddView( _jsonTree,"right",300,True )
-		
-		ContentView=_textView
-	End
-	
-	Property TextView:TextView()
-	
-		Return _textView
-	End
-	
-	Property JsonTree:JsonTreeView()
-	
-		Return _jsonTree
-	End
-	
-	Private
-	
-	Field _textView:TextView
-	Field _jsonTree:JsonTreeView
-
-End
-
 Class JsonDocument Extends Ted2Document
 Class JsonDocument Extends Ted2Document
 
 
 	Method New( path:String )
 	Method New( path:String )
@@ -43,11 +8,17 @@ Class JsonDocument Extends Ted2Document
 		
 		
 		_doc=New TextDocument
 		_doc=New TextDocument
 		
 		
+		_view=New TextView( _doc )
+		
+		_browser=New JsonTreeView
+
 		_doc.TextChanged+=Lambda()
 		_doc.TextChanged+=Lambda()
+		
+			_browser.Value=JsonValue.Parse( _doc.Text )
+			
 			Dirty=True
 			Dirty=True
 		End
 		End
 		
 		
-		_view=New JsonDocumentView( _doc )
 	End
 	End
 
 
 	Protected
 	Protected
@@ -58,10 +29,6 @@ Class JsonDocument Extends Ted2Document
 		
 		
 		_doc.Text=json
 		_doc.Text=json
 		
 		
-		Local jval:=JsonValue.Parse( json )
-		
-		_view.JsonTree.Value=jval
-		
 		Return True
 		Return True
 	End
 	End
 	
 	
@@ -77,16 +44,23 @@ Class JsonDocument Extends Ted2Document
 		Return _view
 		Return _view
 	End
 	End
 	
 	
+	Method OnCreateBrowser:View() Override
+	
+		Return _browser
+	End
+	
 	Method OnGetTextView:TextView( view:View ) Override
 	Method OnGetTextView:TextView( view:View ) Override
 	
 	
-		Return Cast<JsonDocumentView>( view ).TextView
+		Return Cast<TextView>( view )
 	End
 	End
 	
 	
 	Private
 	Private
 	
 	
 	Field _doc:TextDocument
 	Field _doc:TextDocument
 	
 	
-	Field _view:JsonDocumentView
+	Field _view:TextView
+	
+	Field _browser:JsonTreeView
 End
 End
 
 
 Class JsonDocumentType Extends Ted2DocumentType
 Class JsonDocumentType Extends Ted2DocumentType

+ 9 - 5
src/ted2/jsontreeview.monkey2

@@ -57,10 +57,7 @@ Class JsonTreeView Extends TreeView
 	End
 	End
 	
 	
 	Method New()
 	Method New()
-	
-		RootNodeVisible=False
-		
-		RootNode.Expanded=True
+		RootNode.Text="[No Data]"
 	End
 	End
 	
 	
 	Method New( value:JsonValue )
 	Method New( value:JsonValue )
@@ -77,7 +74,14 @@ Class JsonTreeView Extends TreeView
 	
 	
 		RootNode.RemoveAllChildren()
 		RootNode.RemoveAllChildren()
 		
 		
-		If Not value Return
+		If Not value 
+			RootNodeVisible=True
+			RootNode.Text="[No Data]"
+			Return
+		End
+		
+		RootNodeVisible=False
+		RootNode.Expanded=True
 		
 		
 		New Node( value,RootNode )
 		New Node( value,RootNode )
 	End
 	End

+ 11 - 7
src/ted2/mainwindow.monkey2

@@ -36,12 +36,13 @@ Class MainWindowInstance Extends Window
 		_recentFilesMenu=New Menu( "Recent files..." )
 		_recentFilesMenu=New Menu( "Recent files..." )
 		_closeProjectMenu=New Menu( "Close project..." )
 		_closeProjectMenu=New Menu( "Close project..." )
 		
 		
-		_docsManager=New DocumentManager( _docsTabView )
+		_docBrowser=New DockingView
+		
+		_docsManager=New DocumentManager( _docsTabView,_docBrowser )
 
 
 		_docsManager.CurrentDocumentChanged+=UpdateKeyView
 		_docsManager.CurrentDocumentChanged+=UpdateKeyView
 		
 		
 		App.FileDropped+=Lambda( path:String )
 		App.FileDropped+=Lambda( path:String )
-			Print "Dropped:"+path
 			_docsManager.OpenDocument( path,True )
 			_docsManager.OpenDocument( path,True )
 		End
 		End
 
 
@@ -107,7 +108,7 @@ Class MainWindowInstance Extends Window
 		For Local f:=Eachin LoadDir( p )
 		For Local f:=Eachin LoadDir( p )
 			Local src:=stringio.LoadString( p+f )
 			Local src:=stringio.LoadString( p+f )
 			_newFiles.AddAction( StripExt( f.Replace( "_"," " ) ) ).Triggered=Lambda()
 			_newFiles.AddAction( StripExt( f.Replace( "_"," " ) ) ).Triggered=Lambda()
-				Local path:=AllocTmpPath( ExtractExt( f ) )
+				Local path:=AllocTmpPath( "untitled",ExtractExt( f ) )
 				If Not path Return
 				If Not path Return
 				SaveString( src,path )
 				SaveString( src,path )
 				Local doc:=_docsManager.OpenDocument( path,True )
 				Local doc:=_docsManager.OpenDocument( path,True )
@@ -216,6 +217,7 @@ Class MainWindowInstance Extends Window
 		_menuBar.AddMenu( _helpMenu )
 		_menuBar.AddMenu( _helpMenu )
 		
 		
 		_browsersTabView.AddTab( "Files",_projectView,True )
 		_browsersTabView.AddTab( "Files",_projectView,True )
+		_browsersTabView.AddTab( "Source",_docBrowser,False )
 		_browsersTabView.AddTab( "Debug",_debugView,False )
 		_browsersTabView.AddTab( "Debug",_debugView,False )
 		_browsersTabView.AddTab( "Help",_helpTree,False )
 		_browsersTabView.AddTab( "Help",_helpTree,False )
 		
 		
@@ -279,11 +281,12 @@ Class MainWindowInstance Extends Window
 		Return future.Get()
 		Return future.Get()
 	End
 	End
 	
 	
-	Method AllocTmpPath:String( ext:String )
+	Method AllocTmpPath:String( ident:String,ext:String )
 	
 	
-		For Local i:=1 Until 10
-			Local path:=_tmp+"untitled"+i+ext
-			If GetFileType( path )=FileType.None Return path
+		For Local i:=1 Until 100
+			Local path:=_tmp+ident+i+ext
+			If GetFileType( path )<>FileType.None Continue
+			If CreateFile( path ) Return path
 		Next
 		Next
 
 
 		Return ""
 		Return ""
@@ -483,6 +486,7 @@ Class MainWindowInstance Extends Window
 	Field _helpView:HtmlView
 	Field _helpView:HtmlView
 
 
 	Field _projectView:ProjectView
 	Field _projectView:ProjectView
+	Field _docBrowser:DockingView
 	Field _debugView:DebugView
 	Field _debugView:DebugView
 	Field _helpTree:HelpTree
 	Field _helpTree:HelpTree
 
 

+ 22 - 12
src/ted2/monkey2document.monkey2

@@ -436,12 +436,14 @@ Class Monkey2Document Extends Ted2Document
 		
 		
 		_doc=New TextDocument
 		_doc=New TextDocument
 		
 		
-		_doc.TextChanged=Lambda()
+		_doc.TextHighlighter=Monkey2TextHighlighter
+		
+		_browser=New Monkey2TreeView( _doc )
+		
+		_doc.TextChanged+=Lambda()
 			Dirty=True
 			Dirty=True
 		End
 		End
 		
 		
-		_doc.TextHighlighter=Monkey2TextHighlighter
-		
 		_doc.LinesModified=Lambda( first:Int,removed:Int,inserted:Int )
 		_doc.LinesModified=Lambda( first:Int,removed:Int,inserted:Int )
 			Local put:=0
 			Local put:=0
 			For Local get:=0 Until _errors.Length
 			For Local get:=0 Until _errors.Length
@@ -486,15 +488,7 @@ Class Monkey2Document Extends Ted2Document
 		Return _errors
 		Return _errors
 	End
 	End
 	
 	
-	Private
-
-	Field _doc:TextDocument
-
-	Field _view:Monkey2DocumentView
-
-	Field _errors:=New Stack<BuildError>
-
-	Field _debugLine:Int=-1
+	Protected
 	
 	
 	Method OnLoad:Bool() Override
 	Method OnLoad:Bool() Override
 	
 	
@@ -518,6 +512,22 @@ Class Monkey2Document Extends Ted2Document
 		Return _view
 		Return _view
 	End
 	End
 	
 	
+	Method OnCreateBrowser:View() Override
+	
+		Return _browser
+	End
+	
+	Private
+
+	Field _doc:TextDocument
+
+	Field _view:Monkey2DocumentView
+	
+	Field _browser:Monkey2TreeView
+
+	Field _errors:=New Stack<BuildError>
+
+	Field _debugLine:Int=-1
 End
 End
 
 
 Class Monkey2DocumentType Extends Ted2DocumentType
 Class Monkey2DocumentType Extends Ted2DocumentType

+ 59 - 0
src/ted2/monkey2treeview.monkey2

@@ -0,0 +1,59 @@
+
+Namespace ted2
+
+Class Monkey2TreeView Extends JsonTreeView
+
+	Method New( doc:TextDocument )
+	
+		_doc=doc
+	
+		_doc.TextChanged+=OnTextChanged
+
+	End
+	
+	Private
+	
+	Field _doc:TextDocument
+	
+	Field _timer:Timer
+	
+	Method OnTextChanged()
+	
+		If _timer _timer.Cancel()
+		
+		_timer=New Timer( 1,Lambda()
+		
+			Local tmp:=MainWindow.AllocTmpPath( "_mx2cc_parse_",".monkey2" )
+			
+			Print "parsing:"+tmp
+			
+			SaveString( _doc.Text,tmp )
+		
+			UpdateTree( tmp )
+			
+			Print "finished:"+tmp
+			
+			DeleteFile( tmp )
+			
+			_timer.Cancel()
+			
+			_timer=Null
+		
+		End )
+	End
+	
+	Method UpdateTree( path:String )
+	
+		Local cmd:="~q"+MainWindow.Mx2ccPath+"~q makeapp -parse -geninfo ~q"+path+"~q"
+					
+		Local str:=LoadString( "process::"+cmd )
+		
+		Local jobj:JsonObject,i:=str.Find( "{" )
+		
+		If i<>-1 jobj=JsonObject.Parse( str.Slice( i ) )
+		
+		Super.Value=jobj
+		
+	End
+
+End

+ 4 - 0
src/ted2/ted2.monkey2

@@ -3,6 +3,8 @@
 #Import "bin/wget.exe"
 #Import "bin/wget.exe"
 #End
 #End
 
 
+#Import "<reflection>"
+
 #Import "<std>"
 #Import "<std>"
 #Import "<mojo>"
 #Import "<mojo>"
 #Import "<mojox>"
 #Import "<mojox>"
@@ -22,6 +24,8 @@
 #Import "modulemanager"
 #Import "modulemanager"
 #import "ted2textview"
 #import "ted2textview"
 #Import "jsontreeview"
 #Import "jsontreeview"
+#Import "xmltreeview"
+#Import "monkey2treeview"
 #Import "gutterview"
 #Import "gutterview"
 
 
 #import "plugin"
 #import "plugin"

+ 13 - 0
src/ted2/ted2document.monkey2

@@ -44,6 +44,13 @@ Class Ted2Document
 		Return _view
 		Return _view
 	End
 	End
 	
 	
+	Property BrowserView:View()
+	
+		If Not _browser _browser=OnCreateBrowser()
+		
+		Return _browser
+	End
+	
 	Property TextView:TextView()
 	Property TextView:TextView()
 	
 	
 		Return OnGetTextView( View )
 		Return OnGetTextView( View )
@@ -123,6 +130,11 @@ Class Ted2Document
 		Return Null
 		Return Null
 	End
 	End
 	
 	
+	Method OnCreateBrowser:View() Virtual
+	
+		Return Null
+	End
+	
 	Method OnGetTextView:TextView( view:View ) virtual
 	Method OnGetTextView:TextView( view:View ) virtual
 	
 	
 		Return Cast<TextView>( view )
 		Return Cast<TextView>( view )
@@ -138,6 +150,7 @@ Class Ted2Document
 	Field _modTime:Long
 	Field _modTime:Long
 	Field _state:String
 	Field _state:String
 	Field _view:View
 	Field _view:View
+	Field _browser:View
 	
 	
 End
 End
 
 

+ 15 - 98
src/ted2/xmldocument.monkey2

@@ -1,112 +1,27 @@
 
 
 Namespace ted2
 Namespace ted2
 
 
+Class XmlDocument Extends Ted2Document
 
 
-
-Class XmlDocumentView Extends DockingView
-
-	Method New( doc:TextDocument )
-	
-		_textView=New TextView( doc )
-		
-		doc.TextChanged+=Lambda()
+	Method New( path:String )
+		Super.New( path )
 		
 		
-			_treeView.RootNode.RemoveAllChildren()
-			
-			Local xml:=_textView.Text
-			
-			Local doc := New XMLDocument()
-			
-			If doc.Parse( xml ) <> XMLError.XML_SUCCESS
-				Return
-			Endif
- 
-			_treeView.RootNode.Text = "XML Document"
- 
-			AddXMLNodeToTree( doc,_treeView.RootNode )
+		_doc=New TextDocument
 		
 		
-		End
+		_view=New TextView( _doc )
 		
 		
-		_treeView=New TreeView
-
-		AddView( _treeView,"right",300,True )
+		_browser=New XmlTreeView
 		
 		
-		ContentView=_textView
-	End
-	
-	Property TextView:TextView()
-	
-		Return _textView
-	End
-	
-	Property TreeView:TreeView()
-	
-		Return _treeView
-	End
-	
-	Private
-	
-	Field _textView:TextView
-	
-	Field _treeView:TreeView
-	
-	Method AddXMLNodeToTree(xmlNode:XMLNode, parent:TreeView.Node)
-	
-		Local str := ""
-	
-		Local xmlElement := xmlNode.ToElement()
-		
-		If xmlElement
+		_doc.TextChanged+=Lambda()
 		
 		
-			str += "<" + xmlNode.Value()
-			
-			Local attrib := xmlElement.FirstAttribute()
-			While attrib 
-				str += " " + attrib.Name() + "=~q" + attrib.Value() + "~q "
-				attrib=attrib.NextAttribute()
-			wend
+			Local xml:=New XMLDocument
 			
 			
-			str += ">"
-		Else
-			str += xmlNode.Value()
-		Endif
- 
-		Local treeNode:TreeView.Node
-	
-		If str
-			treeNode = New TreeView.Node(str, parent)
-		Endif
-		
-		Local xmlChild := xmlNode.FirstChild()
-	
-		While xmlChild
-		
-			If Not xmlChild.NoChildren()
-				If treeNode Then parent = treeNode
-			Endif
-		
-			AddXMLNodeToTree(xmlChild, parent)
+			If xml.Parse( _doc.Text )<>XMLError.XML_SUCCESS xml=Null
 			
 			
-			xmlChild = xmlChild.NextSibling()
-	
-		Wend
-	
-	End
-
-End
-
-Class XmlDocument Extends Ted2Document
-
-	Method New( path:String )
-		Super.New( path )
-		
-		_doc=New TextDocument
+			_browser.Data=xml
 		
 		
-		_doc.TextChanged+=Lambda()
 			Dirty=True
 			Dirty=True
 		End
 		End
-		
-		_view=New XmlDocumentView( _doc )
 	End
 	End
 
 
 	Protected
 	Protected
@@ -132,16 +47,18 @@ Class XmlDocument Extends Ted2Document
 		Return _view
 		Return _view
 	End
 	End
 	
 	
-	Method OnGetTextView:TextView( view:View ) Override
+	Method OnCreateBrowser:View() Override
 	
 	
-		Return Cast<XmlDocumentView>( view ).TextView
+		Return _browser
 	End
 	End
 	
 	
 	Private
 	Private
 	
 	
 	Field _doc:TextDocument
 	Field _doc:TextDocument
 	
 	
-	Field _view:XmlDocumentView
+	Field _view:TextView
+	
+	Field _browser:XmlTreeView
 End
 End
 
 
 Class XmlDocumentType Extends Ted2DocumentType
 Class XmlDocumentType Extends Ted2DocumentType

+ 78 - 0
src/ted2/xmltreeview.monkey2

@@ -0,0 +1,78 @@
+
+Namespace ted2
+
+'Based on code by Shane Raffa!
+'
+Class XmlTreeView Extends TreeView
+
+	Method New()
+		RootNode.Text="[No Data]"
+	End
+
+	Property Data:XMLDocument()
+	
+		Return _data
+	
+	Setter( data:XMLDocument )
+	
+		_data=data
+		
+		RootNode.RemoveAllChildren()
+		
+		If Not _data
+			RootNode.Text="[No Data]"
+			Return
+		Endif
+
+		RootNode.Text = "XML Document"
+ 
+		AddXMLNodeToTree( _data,RootNode )
+	End
+	
+	Private
+	
+	Field _data:XMLDocument
+	
+	Method AddXMLNodeToTree( xmlNode:XMLNode,parent:Node )
+	
+		Local str := ""
+	
+		Local xmlElement := xmlNode.ToElement()
+		
+		If xmlElement
+		
+			str += "<" + xmlNode.Value()
+			
+			Local attrib := xmlElement.FirstAttribute()
+			While attrib 
+				str += " " + attrib.Name() + "=~q" + attrib.Value() + "~q "
+				attrib=attrib.NextAttribute()
+			wend
+			
+			str += ">"
+		Else
+			str += xmlNode.Value()
+		Endif
+ 
+		Local treeNode:Node
+	
+		If str
+			treeNode = New Node(str, parent)
+		Endif
+		
+		Local xmlChild := xmlNode.FirstChild()
+	
+		While xmlChild
+		
+			If Not xmlChild.NoChildren()
+				If treeNode Then parent = treeNode
+			Endif
+		
+			AddXMLNodeToTree(xmlChild, parent)
+			
+			xmlChild = xmlChild.NextSibling()
+	
+		Wend
+	
+	End
+End