فهرست منبع

Merge commit '6d28c08b73537e5edaf6f3b2c15f1fd55bac8c79' into develop

Mark Sibly 7 سال پیش
والد
کامیت
62cd262f05

+ 7 - 8
src/ted2go/MainWindow.monkey2

@@ -205,9 +205,9 @@ Class MainWindowInstance Extends Window
 		Local explorerAct:=New Action( " [*] " )
 		explorerAct.Triggered+=Lambda()
 			Local url:=_helpView.Url
-			requesters.OpenUrl( url )
+			OpenInExplorer( url )
 		End
-		Local explorerBtn:=New ToolButtonExt( explorerAct,"Show in Explorer" )
+		Local explorerBtn:=New ToolButtonExt( explorerAct,GetShowInExplorerTitle() )
 		bar.AddView( explorerBtn )
 		
 		bar.AddSeparator()
@@ -385,7 +385,7 @@ Class MainWindowInstance Extends Window
 		_editMenu.AddAction( _editActions.paste )
 		_editMenu.AddSeparator()
 		_editMenu.AddAction( _editActions.selectAll )
-		_editMenu.AddAction( _editActions.selectWord )
+		_editMenu.AddAction( _editActions.expandSelection )
 		_editMenu.AddSeparator()
 		' Edit -- Text
 		Local subText:=New MenuExt( "Text" )
@@ -1144,10 +1144,9 @@ Class MainWindowInstance Extends Window
 			Return
 		Endif
 		
-		Local ident:=view.IdentBeforeCursor()
+		Local ident:=view.IdentBeforeCursor( True,True )
 		
 		If Not ident Return
-		
 		Local parser:=ParsersManager.Get( view.FileType )
 		Local item:=parser.ItemAtScope( ident,view.FilePath,GetCursorPos( view ) )
 		
@@ -1161,9 +1160,9 @@ Class MainWindowInstance Extends Window
 			Local pathToIdent:=(item.Namespac+"."+item.Scope).Replace( ".","-" )
 			Local path:=pathTemplate.Replace( "{mod-name}",modName ).Replace( "{path-to-ident}",pathToIdent )
 			
-			Global __prevPath:=""
+			Global _prevPath:=""
 			
-			If path=__prevPath
+			If path=_prevPath
 				
 				If modName ' show docs for modules members
 					
@@ -1197,7 +1196,7 @@ Class MainWindowInstance Extends Window
 			
 			Endif
 			
-			__prevPath=path
+			_prevPath=path
 			
 		Elseif KeywordsManager.Get( view.FileType ).Contains( ident )
 			

+ 13 - 14
src/ted2go/PathsProvider.monkey2

@@ -56,32 +56,31 @@ Class PathsProvider
 				Local modName:=path.Slice( i1,i2 )
 				' main file of a module
 				'
-				path=modsDir+modName+"/"+modName+".monkey2"
+				Return modsDir+modName+"/"+modName+".monkey2"
 			Endif
 		Else
-			' is it a project file?
+			' priority for locked file
+			'
+			Local lockedPath:=docsManager().LockedDocument?.Path
+			If lockedPath
+				If ExtractDir( path ).Contains( ExtractDir( lockedPath ) )
+					' will parse locked file coz 'path' is under 'locked' folder
+					Return lockedPath
+				Endif
+			Endif
+			' check as a part of project
 			'
 			Local proj:=ProjectView.FindProject( path )
 			If proj
 				Local showNote:=True
 				If proj.MainFilePath
-					path=proj.MainFilePath
-				Else
-					Local lockedProj:Monkey2Project
-					Local lockedPath:=docsManager().LockedDocument?.Path
-					If lockedPath And lockedPath<>path
-						lockedProj=ProjectView.FindProject( lockedPath )
-						If lockedProj And lockedProj=proj
-							' will parse locked file coz it's the same project as current file
-							path=lockedPath
-							showNote=False
-						Endif
-					Endif
+					Return proj.MainFilePath
 				Endif
 				If showNote Then ProjectView.CheckMainFilePath( proj,False )
 			Endif
 		Endif
 		
+		' as is
 		Return path
 	End
 	

+ 3 - 1
src/ted2go/Ted2.monkey2

@@ -149,7 +149,7 @@ Using sdl2..
 
 Const MONKEY2_DOMAIN:="http://monkeycoder.co.nz"
 
-Global AppTitle:="Ted2Go v2.12"
+Global AppTitle:="Ted2Go v2.13"
 
 
 Function Main()
@@ -228,6 +228,8 @@ Function Main()
 		Next
 	End
 	
+	SDL_EnableScreenSaver()
+	
 	App.Run()
 	
 End

+ 17 - 8
src/ted2go/action/EditActions.monkey2

@@ -10,7 +10,8 @@ Class EditActions
 	Field copy:Action
 	Field paste:Action
 	Field selectAll:Action
-	Field selectWord:Action
+	Field expandSelection:Action
+	Field shrinkSelection:Action
 	Field wordWrap:Action
 	' Edit -- Text
 	Field textDeleteWordForward:Action
@@ -64,10 +65,15 @@ Class EditActions
 		selectAll.HotKey=Key.A
 		selectAll.HotKeyModifiers=Modifier.Menu|Modifier.Ignore
 		
-		selectWord=New Action( "Select word" )
-		selectWord.Triggered=OnSelectWord
-		selectWord.HotKey=Key.W
-		selectWord.HotKeyModifiers=Modifier.Control
+		expandSelection=New Action( "Expand selection" )
+		expandSelection.Triggered=OnExpandSelection
+		expandSelection.HotKey=Key.Up
+		expandSelection.HotKeyModifiers=Modifier.Alt
+		
+		shrinkSelection=New Action( "Shrink selection" )
+		shrinkSelection.Triggered=OnShrinkSelection
+		shrinkSelection.HotKey=Key.Down
+		shrinkSelection.HotKeyModifiers=Modifier.Alt
 		
 		wordWrap=New Action( "Toggle word wrap" )
 		wordWrap.Triggered=OnWordWrap
@@ -248,11 +254,14 @@ Class EditActions
 		If tv tv.SelectAll()
 	End
 	
-	Method OnSelectWord()
+	Method OnExpandSelection()
 		
-		Local tv:=Cast<TextView>( App.KeyView )
+		Cast<CodeTextView>( App.KeyView )?.ExpandSelection()
+	End
+	
+	Method OnShrinkSelection()
 		
-		If tv tv.SelectWord()
+		Cast<CodeTextView>( App.KeyView )?.ShrinkSelection()
 	End
 	
 	Method OnWordWrap()

+ 3 - 2
src/ted2go/action/FileActions.monkey2

@@ -37,7 +37,8 @@ Class FileActions
 		
 		close=New Action( "Close tab" )
 		close.HotKey=Key.W
-		close.HotKeyModifiers=Modifier.Alt
+		close.HotKeyModifiers=Modifier.Menu
+		
 		close.Triggered=OnClose
 		
 		closeOthers=New Action( "Close other tabs" )
@@ -76,7 +77,7 @@ Class FileActions
 #Elseif __TARGET__="linux"
 		quit.HotKey=Key.F4
 		quit.HotKeyModifiers=Modifier.Alt|Modifier.Ignore
-#endif		
+#endif
 
 		prefs=New Action( "Preferences..." )
 		prefs.Triggered=OnPrefs

+ 5 - 0
src/ted2go/action/GotoActions.monkey2

@@ -32,7 +32,12 @@ Class GotoActions
 		
 		gotoDeclaration=New Action( "Goto definition" )
 		gotoDeclaration.Triggered=OnGotoDeclaration
+		#If __TARGET__="macos"
+		gotoDeclaration.HotKey=Key.B
+		gotoDeclaration.HotKeyModifiers=Modifier.Control
+		#Else
 		gotoDeclaration.HotKey=Key.F12
+		#Endif
 		
 		prevScope=New Action( "Previous scope" )
 		prevScope.Triggered=OnPrevScope

+ 1 - 1
src/ted2go/assets/aboutTed2Go.html

@@ -128,7 +128,7 @@ ToolBar icons were taken from <a href="https://icons8.com/icon/new-icons/win8">i
 
 <h3>Special thanks</h3>
 
-<p>Jimmy Söderman, Second Gear Games, Dominique MIS, Rajasekaran Senthil Kumaran, abakobo, Peter Rigby, Dmitry Fadeev, James Boyd, Sam Fisher, Matthew Bowen, Mark Mcvittie, Simon Armstrong, Rudy van Etten, Hezkore, Sal Gunduz, Peter Scheutz, Matthieu Chemin, David Maziarka, Leonardo Teixeira, Jesus Perez, Mark Sibly, Philipp Moeller, Lee Wade.</p>
+<p>Jean-Marc Quere, Jimmy Söderman, Second Gear Games, Dominique MIS, Rajasekaran Senthil Kumaran, abakobo, Peter Rigby, Dmitry Fadeev, James Boyd, Sam Fisher, Matthew Bowen, Mark Mcvittie, Simon Armstrong, Rudy van Etten, Hezkore, Sal Gunduz, Peter Scheutz, Matthieu Chemin, David Maziarka, Leonardo Teixeira, Jesus Perez, Mark Sibly, Philipp Moeller, Lee Wade.</p>
 
 </body>
 

+ 9 - 1
src/ted2go/document/CodeDocument.monkey2

@@ -1053,6 +1053,8 @@ Class CodeDocument Extends Ted2Document
 		Local clickFunc:=Lambda( node:TreeView.Node )
 		
 			Local codeNode:=Cast<CodeTreeNode>( node )
+			If Not codeNode Return
+			
 			Local item:=codeNode.CodeItem
 			JumpToPosition( item.FilePath,item.ScopeStartPos )
 		End
@@ -1311,7 +1313,7 @@ Class CodeDocument Extends Ted2Document
 		
 		If Not _parsingEnabled Return
 		
-		Local ident:=_codeView.IdentBeforeCursor()
+		Local ident:=_codeView.IdentBeforeCursor( True,True )
 		Local item:=_parser.ItemAtScope( ident,Path,CursorPos )
 		
 		If item
@@ -1723,6 +1725,7 @@ Class CodeDocument Extends Ted2Document
 	Method OnUpdateCurrentScope()
 		
 		_treeViewInnerList.RootNode.RemoveAllChildren()
+		_treeViewInnerList.RootNodeVisible=False
 		
 		Local scope:=_parser.GetNearestScope( Path,CursorPos )
 		'Print ""+CursorPos+", "+scope?.KindStr+", "+scope?.Text
@@ -1752,6 +1755,11 @@ Class CodeDocument Extends Ted2Document
 					_treeViewInnerList.Selected=_treeViewInnerList.FindNode( _treeViewInnerList.RootNode,storedScope )
 				Endif
 			Endif
+			
+			_treeViewInnerList.RootNodeVisible=True
+			_treeViewInnerList.RootNode.Text=scope.Text
+			_treeViewInnerList.RootNode.Icon=CodeItemIcons.GetIcon( scope )
+			_treeViewInnerList.RootNode.Expanded=True
 		Endif
 	End
 	

+ 5 - 1
src/ted2go/utils/TextUtils.monkey2

@@ -87,6 +87,7 @@ Struct Chars
 	Const DOUBLE_QUOTE:="~q"[0] '34
 	Const COMMA:=","[0] '44
 	Const SEMICOLON:=";"[0]
+	Const COLON:=":"[0]
 	Const DOT:="."[0] '46
 	Const EQUALS:="="[0] '61
 	Const LESS_BRACKET:="<"[0] '60
@@ -102,5 +103,8 @@ Struct Chars
 	Const TAB:="~t"[0] '9
 	Const SPACE:=" "[0] '32
 	Const NEW_LINE:="~n"[0] '10
-	
+	Const QUESTION:="?"[0]
+	Const PLUS:="+"[0]
+	Const MINUS:="-"[0]
+	Const UNDERLINE:="_"[0]
 End

+ 31 - 5
src/ted2go/utils/Utils.monkey2

@@ -2,6 +2,20 @@
 Namespace ted2go
 
 
+Function OpenInExplorer( path:String )
+	
+#If __HOSTOS__="macos"
+
+	libc.system( "open ~q"+path+"~q" )
+	
+#Else
+
+	OpenUrl( path )
+
+#Endif
+
+End
+
 Function SwapCase:String( s:String )
 	
 	Local result:="",ss:String,lower:String
@@ -37,6 +51,16 @@ Function GetCaseSensitivePath:String( path:String )
 #Endif
 End
 
+Function GetShowInExplorerTitle:String()
+	
+#If __TARGET__="macos"
+	Return "Show in Finder"
+#Else
+	Return "Show in Explorer"
+#Endif
+End
+
+
 Class Utils Final
 	
 	Function ArrayContains<T>:Bool( arr:T[],value:T )
@@ -372,14 +396,16 @@ End
 
 #Rem monkeydocs Return ident and position in line where ident starts
 #End
-Function GetIndentBeforePos_Mx2:IdentInfo( line:String,posInLine:Int,withDots:Bool )
+Function GetIndentBeforePos_Mx2:IdentInfo( line:String,posInLine:Int,withDots:Bool,wholeWord:Bool=False )
 	
 	' grab whole word under cursor
 	'
-'	Local len:=line.Length
-'	While pos <= posInLine And IsIdent( line[pos] )
-'		pos+=1
-'	Wend
+	If wholeWord
+		Local len:=line.Length
+		While posInLine < len And IsIdent( line[posInLine] )
+			posInLine+=1
+		Wend
+	Endif
 	
 	Local n:=posInLine-1
 	

+ 142 - 4
src/ted2go/view/CodeTextView.monkey2

@@ -234,6 +234,143 @@ Class CodeTextView Extends TextView
 		Endif
 	End
 	
+	Method ExpandSelection()
+		
+		' this method tries to intelligent expand
+		' selection under cursor
+		'
+		Local min:=Min( Cursor,Anchor )
+		Local max:=Max( Cursor,Anchor )
+		Local lineStart:=Document.StartOfLine( Document.FindLine( min ) )
+		Local lineEnd:=Document.EndOfLine( Document.FindLine( max ) )
+		
+		Local ch1:=min>lineStart ? Text[min-1] Else -1
+		Local ch2:=max<lineEnd ? Text[max] Else -1
+		
+		Local found:=False
+		
+		If IsIdent( ch1 )
+			min-=1
+			While min>lineStart And IsIdent( Text[min] )
+				min-=1
+			Wend
+			min+=1
+			found=True
+		Endif
+		
+		If IsIdent( ch2 )
+			While max<lineEnd And IsIdent( Text[max] )
+				max+=1
+			Wend
+			found=True
+		Endif
+		
+		If Not found
+			' valid ident parts: .?->[]
+			Local arr:=New Int[]( 
+						Chars.DOT,
+						Chars.QUESTION,
+						Chars.MINUS,
+						Chars.MORE_BRACKET,
+						Chars.OPENED_SQUARE_BRACKET,
+						Chars.CLOSED_SQUARE_BRACKET)
+						
+			If Utils.ArrayContains( arr,ch1 )
+				min-=1
+				Local letters:=False
+				While min>lineStart
+					Local ch:=Text[min]
+					If Utils.ArrayContains( arr,ch ) Or
+							IsIdent( ch )
+						Local let:=IsAlpha( ch ) Or ch=Chars.UNDERLINE
+						If letters And Not let Exit
+						letters=let
+						min-=1
+					Else
+						Exit
+					Endif
+				Wend
+				min+=1
+				found=True
+			Endif
+			
+			If Not found And Utils.ArrayContains( arr,ch2 )
+				Local letters:=False
+				While max<lineEnd
+					Local ch:=Text[max]
+					If Utils.ArrayContains( arr,ch ) Or
+							IsIdent( ch )
+						Local let:=IsAlpha( ch ) Or ch=Chars.UNDERLINE
+						If letters And Not let Exit
+						max+=1
+					Else
+						Exit
+					Endif
+				Wend
+				found=True
+			Endif
+			
+			If Not found And ch1=Chars.COLON
+				min-=2
+				While min>lineStart And IsIdent( Text[min] )
+					min-=1
+				Wend
+				min+=1
+				found=True
+			Endif
+			
+			If Not found And ch2=Chars.COLON
+				max+=1
+				While max<lineEnd And IsIdent( Text[max] )
+					max+=1
+				Wend
+				found=True
+			Endif
+			
+			' scope of (...)
+			If Not found
+				Local pos:=Text.Find( "(",lineStart )
+				If pos>=lineStart And pos<min
+					Local pos2:=Text.Find( ")",max )
+					If pos2>0 And pos2<=lineEnd
+						
+						If min-pos>1 Or pos2-max>1
+							min=pos+1
+							max=pos2
+							found=True
+						Endif
+					Endif
+				Endif
+			Endif
+			
+			' whole line
+			If Not found
+				min=lineStart
+				While min<lineEnd And Text[min]<=Chars.SPACE
+					min+=1
+				Wend
+				max=lineEnd
+				While max>lineStart And Text[max]<=Chars.SPACE
+					max-=1
+				Wend
+				max+=1
+				If min=max 'have no printable chars
+					min=lineStart
+					max=lineEnd
+				Endif
+				found=True
+			Endif
+			
+		Endif
+		
+		SelectText( min,max )
+		
+	End
+	
+	Method ShrinkSelection()
+		' todo
+	End
+	
 	Property SelectedText:String()
 		
 		If Not CanCopy Return ""
@@ -275,9 +412,9 @@ Class CodeTextView Extends TextView
 		Return text.Slice( start,ends )
 	End
 	
-	Method IdentBeforeCursor:String( withDots:Bool=True )
+	Method IdentBeforeCursor:String( withDots:Bool=True,wholeWord:Bool=False )
 		
-		Local info:=GetIndentBeforePos_Mx2( LineTextAtCursor,PosInLineAtCursor,withDots )
+		Local info:=GetIndentBeforePos_Mx2( LineTextAtCursor,PosInLineAtCursor,withDots,wholeWord )
 		Return info.ident
 	End
 	
@@ -709,8 +846,9 @@ Class CodeTextView Extends TextView
 		Select event.Type
 			
 			Case EventType.MouseWheel 'little faster scroll
-		
-				Scroll-=New Vec2i( 0,RenderStyle.Font.Height*event.Wheel.Y*3 )
+				
+				Local delta:=New Vec2i( RenderStyle.Font.Height,-RenderStyle.Font.Height*2 )
+				Scroll+=delta*event.Wheel
 				Return
 			
 			Case EventType.MouseDown 'prevent selection by dragging with right-button

+ 6 - 4
src/ted2go/view/ExamplesView.monkey2

@@ -54,7 +54,7 @@ Class ExamplesView Extends DockingView
 	
 	Private
 	
-	Const VALID_FOLDERS:=New String[]( "bananas","examples","tests" )
+	Const VALID_FOLDERS:=New String[]( "bananas","examples","samples","tests" )
 	
 	Field _tree:TreeViewExt
 	Field _dirIcon:Image
@@ -73,7 +73,7 @@ Class ExamplesView Extends DockingView
 			
 			' bananas
 			For Local file:=Eachin LoadDir( path )
-				If GetFileType( path+file )=FileType.Directory
+				If file<>"ted2go-showcase" And GetFileType( path+file )=FileType.Directory
 					folders.Add( path+file )
 				Endif
 			Next
@@ -98,6 +98,7 @@ Class ExamplesView Extends DockingView
 				Next
 			Next
 			
+			_tree.Sort()
 			_tree.RootNode.Expanded=True
 			_tree.RootNodeVisible=False
 			
@@ -202,10 +203,11 @@ Class ExamplesView Extends DockingView
 				target.Add( folder+name )
 				Continue
 			Endif
-			'If lowercasedName="src"
+			
 			If lowercasedName="src" Or lowercasedName="include" Or lowercasedName="native" Or
 				lowercasedName="bin" Or lowercasedName="docs" Or lowercasedName=PathsProvider.MX2_TMP Or
-				lowercasedName.Contains( ".product" ) Or lowercasedName.Contains( ".buildv" )
+				lowercasedName.Contains( ".product" ) Or lowercasedName.Contains( ".buildv" ) Or
+				lowercasedName="module-manager" Or lowercasedName="contrib"
 				Continue
 			Endif
 			Local path:=folder+name

+ 2 - 2
src/ted2go/view/ProjectView.monkey2

@@ -547,10 +547,10 @@ Class ProjectView Extends DockingView
 			Local isFolder:=False
 			Local fileType:=GetFileType( path )
 			
-			menu.AddAction( "Show in Explorer" ).Triggered=Lambda()
+			menu.AddAction( GetShowInExplorerTitle() ).Triggered=Lambda()
 				
 				Local p:=(fileType=FileType.File) ? ExtractDir( path ) Else path
-				requesters.OpenUrl( p )
+				OpenInExplorer( p )
 			End
 			menu.AddAction( "Copy path" ).Triggered=Lambda()
 				

+ 10 - 5
src/ted2go/view/TabViewExt.monkey2

@@ -13,14 +13,19 @@ Class ScrollViewTabs Extends ScrollView
 		' catch horizontal scrolling
 		Select event.Type
 		Case EventType.MouseWheel
-		
-			Local scroll:=Scroll
-		
-			Local delta:=New Vec2i( 4*ContentView.RenderStyle.Font.Height*event.Wheel.Y,0 )
+			
+			Local wx:=event.Wheel.x
+			Local wy:=event.Wheel.y
+			Local wheelDelta:=0
+			If Abs( wx )>Abs( wy )
+				wheelDelta=-wx
+			Else
+				wheelDelta=wy
+			Endif
+			Local delta:=New Vec2i( 4*ContentView.RenderStyle.Font.Height*wheelDelta,0 )
 		
 			Scroll-=delta
 		
-			'If scroll<>Scroll event.Eat()
 			event.Eat()
 			Return
 		End

+ 0 - 39
src/ted2go/view/TextViewExt.monkey2

@@ -804,45 +804,6 @@ Class TextView Extends ScrollableView
 		SelectText( 0,_doc.TextLength )
 	End
 	
-	Method SelectWord()
-		
-		' this method tries to intelligent expand
-		' selection under cursor
-		'
-		Local line:=Document.FindLine( _cursor )
-		Local i1:=Document.StartOfLine( line )
-		Local i2:=Document.EndOfLine( line )
-		Local cur:=_cursor
-		Local anc:=Max( _anchor-1,i1 )
-		Local chr:=(anc>i1) ? Text[anc] Else Text[cur]
-		If Text[cur]=Chars.SPACE And chr<>Chars.SPACE
-			i2=cur
-		Endif
-		If Text[anc]=Chars.SPACE And (IsIdent( Text[cur] ) Or Text[cur]=Chars.DOT)
-			i1=anc+1
-			chr=Text[cur]
-		Endif
-		Local isIdent:=IsIdent( chr )
-		If isIdent
-			While anc>=i1 And IsIdent( Text[anc] )
-				anc-=1
-			Wend
-			While cur<i2 And IsIdent( Text[cur] )
-				cur+=1
-			Wend
-		Else
-			While anc>=i1 And Not IsIdent( Text[anc] )
-				anc-=1
-			Wend
-			While cur<i2 And Not IsIdent( Text[cur] )
-				cur+=1
-			Wend
-		Endif
-		If anc<>_anchor Then anc+=1
-		
-		SelectText( anc,cur )
-	End
-	
 	#rem monkeydoc Performs a cut.
 	#end
 	Method Cut()