Skip to content

Commit

Permalink
Merge pull request #6 from mcneel/warning-indicators
Browse files Browse the repository at this point in the history
Warning indicators
  • Loading branch information
sbaer authored Mar 25, 2018
2 parents a43e230 + b447739 commit 38d5700
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 20 deletions.
65 changes: 59 additions & 6 deletions src/Eto.CodeEditor.Wpf/CodeEditorHandler.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Eto;
using Eto.Forms;
using Eto.CodeEditor;
using Eto.CodeEditor.Wpf;
using ScintillaNET;

[assembly: ExportHandler(typeof(CodeEditor), typeof(CodeEditorHandler))]

Expand Down Expand Up @@ -127,6 +129,55 @@ public void SetColor(Section section, Eto.Drawing.Color forecolor, Eto.Drawing.C
}
}

private const int ErrorIndex = 20;
private const int WarningIndex = 21;
private const int TypeNameIndex = 22;

public void SetupIndicatorStyles()
{
WinFormsControl.Indicators[ErrorIndex].Style = IndicatorStyle.CompositionThick;
WinFormsControl.Indicators[ErrorIndex].ForeColor = Color.Crimson;
//WinFormsControl.Indicators[ErrorIndex].Alpha = 255;

WinFormsControl.Indicators[WarningIndex].Style = IndicatorStyle.CompositionThick;
WinFormsControl.Indicators[WarningIndex].ForeColor = Color.DarkOrange;
//WinFormsControl.Indicators[WarningIndex].Alpha = 255;

WinFormsControl.Indicators[TypeNameIndex].Style = IndicatorStyle.TextFore;
WinFormsControl.Indicators[TypeNameIndex].ForeColor = Color.FromArgb(43, 145, 175);
}
public void ClearAllErrorIndicators()
{
WinFormsControl.IndicatorCurrent = ErrorIndex;
WinFormsControl.IndicatorClearRange(0, WinFormsControl.TextLength);
}
public void ClearAllWarningIndicators()
{
WinFormsControl.IndicatorCurrent = WarningIndex;
WinFormsControl.IndicatorClearRange(0, WinFormsControl.TextLength);
}
public void ClearAllTypeNameIndicators()
{
WinFormsControl.IndicatorCurrent = TypeNameIndex;
WinFormsControl.IndicatorClearRange(0, WinFormsControl.TextLength);
}

public void AddErrorIndicator(int position, int length)
{
WinFormsControl.IndicatorCurrent = ErrorIndex;
WinFormsControl.IndicatorFillRange(position, length);
}
public void AddWarningIndicator(int position, int length)
{
WinFormsControl.IndicatorCurrent = WarningIndex;
WinFormsControl.IndicatorFillRange(position, length);
}
public void AddTypeNameIndicator(int position, int length)
{
WinFormsControl.IndicatorCurrent = TypeNameIndex;
WinFormsControl.IndicatorFillRange(position, length);
}

public int LineNumberColumnWidth
{
get
Expand Down Expand Up @@ -158,15 +209,15 @@ void SetupTheme()
//WinFormsControl.Lexer = ScintillaNET.Lexer.Cpp;
//WinFormsControl.SetKeywords(0, "abstract as base break case catch checked continue default delegate do else event explicit extern false finally fixed for foreach goto if implicit in interface internal is lock namespace new null object operator out override params private protected public readonly ref return sealed sizeof stackalloc switch this throw true try typeof unchecked unsafe using virtual while");
//WinFormsControl.SetKeywords(1, "bool byte char class const decimal double enum float int long sbyte short static string struct uint ulong ushort void");
//WinFormsControl.Styles[ScintillaNET.Style.Cpp.Comment].ForeColor = System.Drawing.Color.Gray;
//WinFormsControl.Styles[ScintillaNET.Style.Cpp.CommentLine].ForeColor = System.Drawing.Color.Gray;
//WinFormsControl.Styles[ScintillaNET.Style.Cpp.CommentDoc].ForeColor = System.Drawing.Color.Gray;
//WinFormsControl.Styles[ScintillaNET.Style.Cpp.Comment].ForeColor = System.Drawing.Color.Black;
//WinFormsControl.Styles[ScintillaNET.Style.Cpp.CommentLine].ForeColor = System.Drawing.Color.Black;
//WinFormsControl.Styles[ScintillaNET.Style.Cpp.CommentDoc].ForeColor = System.Drawing.Color.Black;
WinFormsControl.Styles[ScintillaNET.Style.Cpp.Number].ForeColor = System.Drawing.Color.Black;
WinFormsControl.Styles[ScintillaNET.Style.Cpp.String].ForeColor = System.Drawing.Color.Red;
WinFormsControl.Styles[ScintillaNET.Style.Cpp.Character].ForeColor = System.Drawing.Color.Black;
WinFormsControl.Styles[ScintillaNET.Style.Cpp.String].ForeColor = System.Drawing.Color.Brown;
WinFormsControl.Styles[ScintillaNET.Style.Cpp.Character].ForeColor = System.Drawing.Color.Brown;
WinFormsControl.Styles[ScintillaNET.Style.Cpp.Preprocessor].ForeColor = System.Drawing.Color.Black;
WinFormsControl.Styles[ScintillaNET.Style.Cpp.Operator].ForeColor = System.Drawing.Color.Black;
WinFormsControl.Styles[ScintillaNET.Style.Cpp.Regex].ForeColor = System.Drawing.Color.Black;
WinFormsControl.Styles[ScintillaNET.Style.Cpp.Regex].ForeColor = System.Drawing.Color.Crimson;
WinFormsControl.Styles[ScintillaNET.Style.Cpp.CommentLineDoc].ForeColor = System.Drawing.Color.Black;
//WinFormsControl.Styles[ScintillaNET.Style.Cpp.Word].ForeColor = System.Drawing.Color.Blue;
//WinFormsControl.Styles[ScintillaNET.Style.Cpp.Word2].ForeColor = System.Drawing.Color.CadetBlue;
Expand All @@ -179,6 +230,8 @@ void SetupTheme()
//WinFormsControl.Styles[ScintillaNET.Style.LineNumber].BackColor = System.Drawing.Color.White;
//WinFormsControl.Styles[ScintillaNET.Style.LineNumber].ForeColor = System.Drawing.Color.CadetBlue;

WinFormsControl.AutomaticFold = AutomaticFold.Click;

FontName = "Consolas";
FontSize = 10;
LineNumberColumnWidth = 40;
Expand Down
46 changes: 46 additions & 0 deletions src/Eto.CodeEditor.XamMac/CodeEditorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,52 @@ public void SetColor(Section section, Eto.Drawing.Color foreground, Eto.Drawing.
}
}
}
private const int ErrorIndex = 20;
private const int WarningIndex = 21;
public void SetupIndicatorStyles()
{
SetupIndicator(ErrorIndex, NativeMethods.INDIC_SQUIGGLE, Eto.Drawing.Colors.Red);
SetupIndicator(WarningIndex, NativeMethods.INDIC_SQUIGGLE, Eto.Drawing.Colors.Gold);
}

void SetupIndicator(uint index, int style, Eto.Drawing.Color forecolor)
{
Control.Message(NativeMethods.SCI_INDICSETSTYLE, new IntPtr(index), new IntPtr(style));
int abgr = forecolor.Rb | forecolor.Gb << 8 | forecolor.Bb << 16;
Control.Message(NativeMethods.SCI_INDICSETFORE, new IntPtr(index), new IntPtr(abgr));
Control.Message(NativeMethods.SCI_INDICSETALPHA, new IntPtr(index), new IntPtr(0));
Control.Message(NativeMethods.SCI_INDICSETUNDER, new IntPtr(index), new IntPtr(1));
}

public void ClearAllErrorIndicators()
{
Control.Message(NativeMethods.SCI_SETINDICATORCURRENT, new IntPtr(ErrorIndex), IntPtr.Zero);
int length = Text.Length;
Control.Message(NativeMethods.SCI_INDICATORCLEARRANGE, IntPtr.Zero, new IntPtr(length));
}

public void ClearAllWarningIndicators()
{
Control.Message(NativeMethods.SCI_SETINDICATORCURRENT, new IntPtr(WarningIndex), IntPtr.Zero);
int length = Text.Length;
Control.Message(NativeMethods.SCI_INDICATORCLEARRANGE, IntPtr.Zero, new IntPtr(length));
}

public void AddErrorIndicator(int position, int length)
{
Control.Message(NativeMethods.SCI_SETINDICATORCURRENT, new IntPtr(ErrorIndex), IntPtr.Zero);
Control.Message(NativeMethods.SCI_INDICATORFILLRANGE, new IntPtr(position), new IntPtr(length));
}

public void AddWarningIndicator(int position, int length)
{
Control.Message(NativeMethods.SCI_SETINDICATORCURRENT, new IntPtr(WarningIndex), IntPtr.Zero);
Control.Message(NativeMethods.SCI_INDICATORFILLRANGE, new IntPtr(position), new IntPtr(length));
}

public void ClearAllTypeNameIndicators() { }
public void AddTypeNameIndicator(int position, int length) { }


public event EventHandler TextChanged
{
Expand Down
41 changes: 39 additions & 2 deletions src/Eto.CodeEditor/CodeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public CodeEditor(ProgrammingLanguage language)
_language = language;
Handler.SetProgrammingLanguage( language, GetKeywords(language) );

SetColor(Section.Comment, Drawing.Colors.Gray, Drawing.Colors.White);
SetColor(Section.Keyword, Drawing.Colors.SeaGreen, Drawing.Colors.White);
SetColor(Section.Comment, Drawing.Colors.DarkGray, Drawing.Colors.White);
SetColor(Section.Keyword, Drawing.Colors.Blue, Drawing.Colors.White);
SetColor(Section.LineNumber, Drawing.Colors.Gray, Drawing.Colors.White);
}

Expand Down Expand Up @@ -75,6 +75,35 @@ public void SetColor(Section section, Eto.Drawing.Color foreground, Eto.Drawing.
Handler.SetColor(section, foreground, background);
}

public void SetupIndicatorStyles()
{
Handler.SetupIndicatorStyles();
}
public void ClearAllErrorIndicators()
{
Handler.ClearAllErrorIndicators();
}
public void ClearAllWarningIndicators()
{
Handler.ClearAllWarningIndicators();
}
public void ClearAllTypeNameIndicators()
{
Handler.ClearAllTypeNameIndicators();
}
public void AddErrorIndicator(int position, int length)
{
Handler.AddErrorIndicator(position, length);
}
public void AddWarningIndicator(int position, int length)
{
Handler.AddWarningIndicator(position, length);
}
public void AddTypeNameIndicator(int position, int length)
{
Handler.AddTypeNameIndicator(position, length);
}

public event EventHandler TextChanged
{
add
Expand All @@ -96,6 +125,14 @@ public event EventHandler TextChanged
int LineNumberColumnWidth { get; set; }
void SetColor(Section section, Eto.Drawing.Color foreground, Eto.Drawing.Color background);

void SetupIndicatorStyles();
void ClearAllErrorIndicators();
void ClearAllWarningIndicators();
void ClearAllTypeNameIndicators();
void AddErrorIndicator(int position, int length);
void AddWarningIndicator(int position, int length);
void AddTypeNameIndicator(int position, int length);

event EventHandler TextChanged;
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/Scintilla.XamMac2/ApiDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//using Scintilla;

// @protocol ScintillaNotificationProtocol
[Protocol, Model]
[Protocol]
interface ScintillaNotificationProtocol
{
// @required -(void)notification:(SCNotification *)notification;
Expand Down Expand Up @@ -76,5 +76,10 @@ interface ScintillaView
// -(NSString *)getStringProperty:(int)property parameter:(long)parameter;
[Export("getStringProperty:parameter:")]
string GetStringProperty(int property, nint parameter);

// -(sptr_t)message:(unsigned int)message wParam:(uptr_t)wParam lParam:(sptr_t)lParam;
[Export("message:wParam:lParam:")]
IntPtr Message(uint message, IntPtr wParam, IntPtr lParam);

}

3 changes: 0 additions & 3 deletions src/Scintilla.XamMac2/StructsAndEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using ObjCRuntime;
//using Scintilla;

namespace ScintillaNET
{

static class CFunctions
{
Expand Down Expand Up @@ -124,4 +122,3 @@ public struct SCNotification
public int listCompletionMethod;
}

}
11 changes: 3 additions & 8 deletions test/Eto.CodeEditor.TestApp/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@ public MainForm()
var editor = new CodeEditor(ProgrammingLanguage.CSharp)
{
Text =
@"// Just some sample code
@"// Just some sample code
for( int i=0; i<10; i++ )
{
print(i);
}"
};
editor.TextInput += Editor_TextInput;

editor.SetupIndicatorStyles();
editor.AddErrorIndicator(13, 6);
Content = editor;
}

private void Editor_TextInput(object sender, TextInputEventArgs e)
{
int i = 0;
}
}
}

0 comments on commit 38d5700

Please sign in to comment.