2
0
Эх сурвалжийг харах

Added support for theme changes to ted2.

Mark Sibly 9 жил өмнө
parent
commit
725d8aaaae

+ 14 - 22
src/ted2/debugview.monkey2

@@ -1,14 +1,6 @@
 
 Namespace ted2
 
-#Import "assets/debug_icons.png@/ted2"
-
-Private
-
-Global icons:Image[]
-
-Public
-
 Class DebugView Extends DockingView
 
 	Method New( docs:DocumentManager,console:Console )
@@ -16,22 +8,19 @@ Class DebugView Extends DockingView
 		_docs=docs
 		_console=console
 		
+		'FIXME: this will never get removed...
 		_console.Finished+=Lambda( exitCode:Int )
 			If Not _debugging Return
 			
 			If _stopped Resume()
 		End
-	
-		If Not icons icons=App.Theme.LoadIcons( "asset::ted2/debug_icons.png" )
-	
-		Local tools:=New ToolBar
-		
-		tools.Style=New Style( tools.Style )
-		tools.Style.Border=New Recti( -4,-4,4,4 )
-		tools.Style.BorderColor=App.Theme.GetColor( "content" )
+
+		_toolBar=New ToolBar
+		_toolBar.Style=GetStyle( "DebugToolBar" )
+		Local icons:=_toolBar.Style.Icons
 		
 		'run/pause
-		_run=tools.AddAction( "",icons[2] )
+		_run=_toolBar.AddAction( "",icons[2] )
 		_run.Triggered=Lambda()
 			If Not _debugging Return
 		
@@ -45,7 +34,7 @@ Class DebugView Extends DockingView
 		End
 
 		'step over		
-		_step=tools.AddAction( "",icons[3] )
+		_step=_toolBar.AddAction( "",icons[3] )
 		_step.Triggered=Lambda()
 			If Not _debugging Return
 			
@@ -57,7 +46,7 @@ Class DebugView Extends DockingView
 		End
 		
 		'step into
-		_enter=tools.AddAction( "",icons[4] )
+		_enter=_toolBar.AddAction( "",icons[4] )
 		_enter.Triggered=Lambda()
 			If Not _debugging Return
 		
@@ -69,7 +58,7 @@ Class DebugView Extends DockingView
 		End
 
 		'step out
-		_leave=tools.AddAction( "",icons[5] )
+		_leave=_toolBar.AddAction( "",icons[5] )
 		_leave.Triggered=Lambda()
 			If Not _debugging Return
 		
@@ -81,7 +70,7 @@ Class DebugView Extends DockingView
 		End
 		
 		'kill
-		_kill=tools.AddAction( "",icons[1] )
+		_kill=_toolBar.AddAction( "",icons[1] )
 		_kill.Triggered=Lambda()
 			If Not _debugging Return
 		
@@ -95,7 +84,7 @@ Class DebugView Extends DockingView
 		
 		End
 		
-		AddView( tools,"top" )
+		AddView( _toolBar,"top" )
 		
 		_tree=New TreeView
 		_tree.RootNodeVisible=False
@@ -265,6 +254,8 @@ Class DebugView Extends DockingView
 	End
 	
 	Field _tree:TreeView
+	
+	Field _toolBar:ToolBar
 
 	Field _docs:DocumentManager	
 	Field _console:Console
@@ -456,6 +447,7 @@ Class DebugView Extends DockingView
 	End
 	
 	Method UpdateActions()
+		Local icons:=_toolBar.Style.Icons
 		_run.Icon=_stopped ? icons[0] Else icons[2]
 		_run.Enabled=_debugging
 		_step.Enabled=_stopped And _debugging

+ 1 - 1
src/ted2/editproductdialog.monkey2

@@ -80,7 +80,7 @@ Class EditProductDialog Extends Dialog
 		_table.AddColumn( "Setting" )
 		_table.AddColumn( "Value" )
 		
-		_table.AddRows( _vars.Length )
+		_table.Rows+=_vars.Length
 		
 		For Local i:=0 Until _vars.Length
 			Local pvar:=_vars[i]

+ 7 - 10
src/ted2/finddialog.monkey2

@@ -21,18 +21,15 @@ Class FindDialog Extends Dialog
 		_caseSensitive.Layout="float"
 		
 '		_escapedText=New CheckButton( "Escaped text" )
-		
-		Local find:=New DockingView
-		find.AddView( New Label( "Find" ),"left",80,False )
-		find.ContentView=_findField
-		
-		Local replace:=New DockingView
-		replace.AddView( New Label( "Replace" ),"left",80,False )
-		replace.ContentView=_replaceField
+
+		Local table:=New TableView( 2,2 )
+		table[0,0]=New Label( "Find" )
+		table[1,0]=_findField
+		table[0,1]=New Label( "Replace" )
+		table[1,1]=_replaceField 
 		
 		_docker=New DockingView
-		_docker.AddView( find,"top" )
-		_docker.AddView( replace,"top" )
+		_docker.AddView( table,"top" )
 		_docker.AddView( _caseSensitive,"top" )
 '		_docker.AddView( _escapedText,"top" )
 		_docker.AddView( New Label( " " ),"top" )

+ 20 - 7
src/ted2/gutterview.monkey2

@@ -4,30 +4,39 @@ Namespace ted2
 Class GutterView Extends View
 
 	Method New( textView:TextView )
+		Style=GetStyle( "GutterView" )
 	
 		_textView=textView
-		
-		Style.Margin=New Recti( 0,0,8,0 )
 	End
 	
 	Protected
 	
-	Method OnMeasure:Vec2i() Override
+	Method OnValidateStyle() Override
+	
+		Local font:=RenderStyle.Font
+	
+		_width=font.TextWidth( "1234567" )
 
-		Return New Vec2i( RenderStyle.Font.TextWidth( "XXXXXXX" ),0 )
+		_size=New Vec2i( font.TextWidth( "12345678" ),0 )
+	End
+	
+	Method OnMeasure:Vec2i() Override
+	
+		Return _size
 	End
 	
 	Method OnRender( canvas:Canvas ) Override
 	
-		canvas.Color=_textView.RenderStyle.BackgroundColor
+		canvas.Color=RenderStyle.BackgroundColor
 		
 		canvas.DrawRect( Rect.X,Rect.Y,Rect.Width,Rect.Height )
 		
-		canvas.Color=Color.Grey
+		canvas.Color=RenderStyle.TextColor
 		
 		Local vrect:=_textView.VisibleRect
 		
 		Local firstLine:=_textView.LineAtPoint( vrect.TopLeft )
+
 		Local lastLine:=_textView.LineAtPoint( vrect.BottomLeft )+1
 		
 		canvas.Translate( 0,-vrect.Top )
@@ -36,11 +45,15 @@ Class GutterView Extends View
 		
 			Local rect:=_textView.LineRect( i )
 		
-			canvas.DrawText( i+1,Width,rect.Top,1,0 )
+			canvas.DrawText( i+1,_width,rect.Top,1,0 )
 		Next
 		
 	End
 	
+	Private
+	
+	Field _width:Int
+	Field _size:Vec2i
 	Field _textView:TextView
 	
 End

+ 3 - 6
src/ted2/helptree.monkey2

@@ -212,14 +212,11 @@ Class HelpTree Extends TreeView
 	End
 	
 	Method Init()
+
+		_highlight=GetStyle( "SelectedNodeStyle" )
 	
-		_highlight=New Style( Style )
-		_highlight.TextColor=App.Theme.GetColor( "text-highlight" )
-		
 		_textField=New TextField
-		_textField.Style=New Style( _textField.Style )
-		_textField.Style.SkinColor=App.Theme.GetColor( "panel" )
-'		_textField.MaxSize=New Vec2i( 320,0 )
+		_textField.Style=GetStyle( "HelpTextField" )
 		
 		_textField.Entered=Lambda()
 		

+ 118 - 9
src/ted2/mainwindow.monkey2

@@ -2,11 +2,10 @@
 Namespace ted2
 
 #Import "assets/about.html@/ted2"
-#Import "assets/scripts.json@/ted2"
 
-#Import "assets/newfiles/Simple_Console_App.monkey2@/ted2/newfiles"
-#Import "assets/newfiles/Simple_Mojo_App.monkey2@/ted2/newfiles"
-#Import "assets/newfiles/Letterboxed_Mojo_App.monkey2@/ted2/newfiles"
+#Import "assets/themes/@/themes"
+
+#Import "assets/newfiles/@/ted2/newfiles"
 
 Global MainWindow:MainWindowInstance
 
@@ -89,6 +88,8 @@ Class MainWindowInstance Extends Window
 
 		_tmp=RealPath( "tmp/" )
 		
+		'File menu
+		'
 		_newFiles=New Menu( "New..." )
 		Local p:=AssetsDir()+"ted2/newfiles/"
 		For Local f:=Eachin LoadDir( p )
@@ -124,6 +125,8 @@ Class MainWindowInstance Extends Window
 		_fileMenu.AddSeparator()
 		_fileMenu.AddAction( _fileActions.quit )
 		
+		'Edit menu
+		'
 		_editMenu=New Menu( "Edit" )
 		_editMenu.AddAction( _editActions.undo )
 		_editMenu.AddAction( _editActions.redo )
@@ -141,6 +144,8 @@ Class MainWindowInstance Extends Window
 		_editMenu.AddAction( _findActions.replace )
 		_editMenu.AddAction( _findActions.replaceAll )
 		
+		'Build menu
+		'
 		_forceStop=New Action( "Force Stop" )
 		_forceStop.Triggered=Lambda()
 			If _buildConsole.Running
@@ -169,6 +174,17 @@ Class MainWindowInstance Extends Window
 		_buildMenu.AddSeparator()
 		_buildMenu.AddAction( _buildActions.moduleManager )
 		
+		'View menu
+		'
+		_themesMenu=CreateThemesMenu( "Themes..." )
+		
+		_viewMenu=New Menu( "View" )
+		AddZoomActions( _viewMenu )
+		_viewMenu.AddSeparator()
+		_viewMenu.AddSubMenu( _themesMenu )
+		
+		'Help menu
+		'
 		_helpMenu=New Menu( "Help" )
 		_helpMenu.AddAction( _helpActions.onlineHelp )
 		_helpMenu.AddAction( _helpActions.viewManuals )
@@ -177,10 +193,13 @@ Class MainWindowInstance Extends Window
 		_helpMenu.AddSeparator()
 		_helpMenu.AddAction( _helpActions.about )
 		
+		'Menu bar
+		'
 		_menuBar=New MenuBar
 		_menuBar.AddMenu( _fileMenu )
 		_menuBar.AddMenu( _editMenu )
 		_menuBar.AddMenu( _buildMenu )
+		_menuBar.AddMenu( _viewMenu )
 		_menuBar.AddMenu( _helpMenu )
 		
 		_browsersTabView.AddTab( "Files",_projectView,True )
@@ -201,12 +220,13 @@ Class MainWindowInstance Extends Window
 
 		LoadState( jobj )
 		
+		App.MouseEventFilter+=ThemeScaleMouseFilter
+		
 		Plugin.CreatePlugins()
-
+		
 		App.Idle+=OnAppIdle
 		
 		If GetFileType( "bin/ted2.state.json" )=FileType.None _helpActions.about.Trigger()
-		
 	End
 	
 	Method Terminate()
@@ -340,6 +360,10 @@ Class MainWindowInstance Extends Window
 		End
 		jobj["recentFiles"]=recent
 		
+		jobj["theme"]=New JsonString( _theme )
+		
+		jobj["themeScale"]=New JsonNumber( App.Theme.Scale.y )
+		
 		_docsManager.SaveState( jobj )
 		_buildActions.SaveState( jobj )
 		_projectView.SaveState( jobj )
@@ -351,10 +375,8 @@ Class MainWindowInstance Extends Window
 	
 	Method LoadState( jobj:JsonObject )
 	
-		'for 'reload' later...
-		_projectView.ProjectOpened-=UpdateCloseProjectMenu
-		
 		If jobj.Contains( "browserSize" ) _contentView.SetViewSize( _browsersTabView,jobj.GetNumber( "browserSize" ) )
+
 		If jobj.Contains( "consoleSize" ) _contentView.SetViewSize( _consolesTabView,jobj.GetNumber( "consoleSize" ) )
 			
 		If jobj.Contains( "recentFiles" )
@@ -365,6 +387,13 @@ Class MainWindowInstance Extends Window
 			Next
 		End
 		
+		If jobj.Contains( "theme" ) _theme=jobj.GetString( "theme" )
+		
+		If jobj.Contains( "themeScale" )
+			_themeScale=jobj.GetNumber( "themeScale" )
+			App.Theme.Scale=New Vec2f( _themeScale,_themeScale )
+		Endif
+		
 		_docsManager.LoadState( jobj )
 		_buildActions.LoadState( jobj )
 		_projectView.LoadState( jobj )
@@ -393,6 +422,7 @@ Class MainWindowInstance Extends Window
 				Else
 					_consolesTabView.Visible=Not _consolesTabView.Visible
 				Endif
+			Case Key.Keypad1
 			End
 		End
 	End
@@ -437,10 +467,16 @@ Class MainWindowInstance Extends Window
 	Field _newFiles:Menu
 	Field _fileMenu:Menu
 	Field _editMenu:Menu
+	Field _viewMenu:Menu
 	Field _buildMenu:Menu
 	Field _helpMenu:Menu
 	Field _menuBar:MenuBar
 	
+	Field _themesMenu:Menu
+	
+	Field _theme:String="default"
+	Field _themeScale:Float=1
+	
 	Field _contentView:DockingView
 
 	Field _recentFiles:=New StringStack
@@ -500,6 +536,79 @@ Class MainWindowInstance Extends Window
 		Next
 	End
 	
+	Method AddZoomActions( menu:Menu )
+		
+		menu.AddAction( "Zoom in" ).Triggered=Lambda()
+			If _themeScale>=4 Return
+			
+			_themeScale+=.125
+
+			App.Theme.Scale=New Vec2f( _themeScale,_themeScale )
+		End
+		
+		menu.AddAction( "Zoom out" ).Triggered=Lambda()
+			If _themeScale<=.5 Return
+			
+			_themeScale-=.125
+
+			App.Theme.Scale=New Vec2f( _themeScale,_themeScale )
+		End
+		
+		menu.AddAction( "Reset zoom" ).Triggered=Lambda()
+		
+			_themeScale=1
+			
+			App.Theme.Scale=New Vec2f( _themeScale,_themeScale )
+		End
+	End
+
+	Method ThemeScaleMouseFilter( event:MouseEvent )
+	
+		If event.Eaten Return
+			
+		If event.Type=EventType.MouseWheel And event.Modifiers & Modifier.Menu
+			
+			If event.Wheel.y>0
+				If _themeScale<4 _themeScale+=0.125
+			Else
+				If _themeScale>.5 _themeScale-=0.125
+			Endif
+				
+			App.Theme.Scale=New Vec2f( _themeScale,_themeScale )
+
+			event.Eat()
+				
+		Else If event.Type=EventType.MouseDown And event.Button=MouseButton.Middle And event.Modifiers & Modifier.Menu
+			
+			_themeScale=1
+
+			App.Theme.Scale=New Vec2f( _themeScale,_themeScale )
+			
+			event.Eat()
+		Endif
+		
+	End
+	
+	Method CreateThemesMenu:Menu( text:String )
+	
+		Local menu:=New Menu( text )
+		
+		Local themes:=JsonObject.Load( "theme::themes.json" )
+		If Not themes Return menu
+		
+		For Local it:=Eachin themes
+			Local name:=it.Key
+			Local value:=it.Value.ToString()
+			menu.AddAction( name ).Triggered=Lambda()
+				_theme=value
+				App.Theme.Load( _theme,New Vec2f( _themeScale ) )
+				SaveState()
+			End
+		Next
+		
+		Return menu
+	End
+		
 	Method OnAppIdle()
 	
 		_docsManager.Update()

+ 1 - 1
src/ted2/modulemanager.monkey2

@@ -554,7 +554,7 @@ Class ModuleManager Extends Dialog
 			Local module:=it.Value
 			If Not _filters[module.status].Checked Continue
 			
-			_table.AddRows( 1 )
+			_table.Rows+=1
 			
 			Local about:=module.about
 			

+ 84 - 23
src/ted2/monkey2document.monkey2

@@ -204,17 +204,11 @@ Public
 Class Monkey2DocumentView Extends Ted2TextView
 
 	Method New( doc:Monkey2Document )
-	
 		_doc=doc
 		
 		Document=_doc.TextDocument
 		
-		ContentView.Style.Border=New Recti( -4,-4,4,4 )
-		
 		AddView( New GutterView( Self ),"left" )
-
-		CursorColor=New Color( 0,.5,1 )
-		SelectionColor=New Color( .4,.4,.4 )
 	End
 	
 	Protected
@@ -257,46 +251,87 @@ Class Monkey2DocumentView Extends Ted2TextView
 	
 	Field _doc:Monkey2Document
 	
-	Method Capitalize()
+	Field _typing:Bool
+	
+	Method Capitalize( all:Bool )
+	
+		_typing=False
 	
 		Local cursor:=Cursor
 		
+		'ignore comments...
+		'
 		Local state:=Document.LineState( Document.FindLine( cursor ) )
 		If state & 255 <> 255 Return
 		
 		Local text:=Text
 		Local start:=cursor
+		Local term:=all ? text.Length Else start
+
+		'find start of ident
+		'		
 		While start And IsIdent( text[start-1] )
 			start-=1
 		Wend
-		While start<text.Length And IsDigit( text[start] )
+		While start<cursor And IsDigit( text[start] )
 			start+=1
 		Wend
-		
-		If start<text.Length 
-			Local color:=Document.Colors[start]
-			If color<>COLOR_KEYWORD And color<>COLOR_IDENT Return
+		If start>=term Or Not IsIdent( text[start] ) Return
+		
+		'only capitalize keywords and idents
+		'
+		Local color:=Document.Colors[start]
+		If color<>COLOR_KEYWORD And color<>COLOR_IDENT
+			'
+			If color<>COLOR_PREPROC Return
+			'
+			'only do first ident on preproc line
+			'
+			Local i:=start
+			While i And text[i-1]<=32
+				i-=1
+			Wend
+			If Not i Or text[i-1]<>35 Return
+			i-=1
+			While i And text[i-1]<>10
+				i-=1
+				If text[i]>32 Return
+			Wend
+			'
 		Endif
-		
-		Local ident:=text.Slice( start,cursor )
-		If Not ident Return
-		
+
+		'find end of ident
+		Local ends:=start
+		'
+		While ends<term And IsIdent( text[ends] ) And text[ends]<>10
+			ends+=1
+		Wend
+		If ends=start return
+
+		Local ident:=text.Slice( start,ends )
+
 		Local kw:=Keywords[ident.ToLower()]
-		If kw And kw<>ident Document.ReplaceText( Cursor-ident.Length,Cursor,kw )
+		If Not kw Or kw=ident Return
+		
+		Document.ReplaceText( start,ends,kw )
 		
 	End
 	
-	Method IdentAtCursor:String()
+	Method IdentNearestCursor:String()
 	
 		Local text:=Text
 		Local start:=Cursor
 		
+		If start And start=text.Length start-=1
+		
 		While start And Not IsIdent( text[start] ) And text[start-1]<>10
 			start-=1
 		Wend
+		
 		While start And IsIdent( text[start-1] ) And text[start-1]<>10
 			start-=1
 		Wend
+		
 		While start<text.Length And IsDigit( text[start] ) And text[start]<>10
 			start+=1
 		Wend
@@ -310,6 +345,7 @@ Class Monkey2DocumentView Extends Ted2TextView
 		Return text.Slice( start,ends )
 	End
 	
+	
 	Method OnKeyEvent( event:KeyEvent ) Override
 	
 		Select event.Type
@@ -318,20 +354,45 @@ Class Monkey2DocumentView Extends Ted2TextView
 			Select event.Key
 			Case Key.F1
 			
-				Local ident:=IdentAtCursor()
+				Local ident:=IdentNearestCursor()
 				
 				If ident MainWindow.ShowQuickHelp( ident )
 				
 			Case Key.Tab,Key.Enter
-				Capitalize()
+			
+				If _typing Capitalize( False )
+				
+			Case Key.Left
+			
+				If _typing
+					Local text:=Text
+					Local cursor:=Cursor
+					If cursor And Not IsIdent( text[cursor-1] )
+						Capitalize( True )
+					Endif
+				Endif
+				
+			Case Key.Right
+			
+				If _typing
+					Local text:=Text
+					Local cursor:=Cursor
+					If cursor<text.Length And Not IsIdent( text[cursor] )
+						Capitalize( True )
+					Endif
+				Endif
+				
 			Case Key.Up,Key.Down
-				Capitalize()
+			
+				Capitalize( True )	'in cased we missed anything...
 			End
 		
 		Case EventType.KeyChar
 		
-			If Not IsIdent( event.Text[0] )
-				Capitalize()
+			If IsIdent( event.Text[0] )
+				_typing=True
+			Else
+				If _typing Capitalize( False )
 			Endif
 		End
 

+ 18 - 2
src/ted2/ted2.monkey2

@@ -64,9 +64,23 @@ Function Main()
 	
 #Endif
 	
+	'load ted2 state
+	'
 	Local jobj:=JsonObject.Load( "bin/ted2.state.json" )
 	If Not jobj jobj=New JsonObject
+
+	'initial theme
+	'	
+	If Not jobj.Contains( "theme" ) jobj["theme"]=New JsonString( "theme-classic-dark" )
+	If Not jobj.Contains( "themeScale" ) jobj["themeScale"]=New JsonNumber( 1 )
+	
+	Local config:=New StringMap<String>
+	
+	config["initialTheme"]=jobj.GetString( "theme" )
+	config["initialThemeScale"]=jobj.GetNumber( "themeScale" )
 	
+	'initial window state
+	'
 	Local flags:=WindowFlags.Resizable
 	
 	Local rect:Recti
@@ -77,8 +91,10 @@ Function Main()
 		rect=New Recti( 0,0,1024,768 )
 		flags|=WindowFlags.Center
 	Endif
-	
-	New AppInstance
+
+	'start the app!
+	'	
+	New AppInstance( config )
 	
 	New MainWindowInstance( "Ted2",rect,flags,jobj )
 	

+ 2 - 1
src/ted2/ted2textview.monkey2

@@ -4,7 +4,8 @@ Namespace ted2
 Class Ted2TextView Extends TextView
 
 	Method New()
-		CursorBlinkRate=2.75	'ha! faster than nerobot's!
+
+		CursorBlinkRate=2.5
 	End
 
 	Protected