Skip to content

Commit

Permalink
Set Basic Syntax Hightlightning system
Browse files Browse the repository at this point in the history
  • Loading branch information
andresruizdev committed Sep 28, 2019
1 parent 84f740b commit 4e6e92b
Show file tree
Hide file tree
Showing 2 changed files with 217 additions and 38 deletions.
76 changes: 38 additions & 38 deletions DenebStudio/DenebStudio/DenebStudio.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

179 changes: 179 additions & 0 deletions DenebStudio/DenebStudio/DenebStudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,29 @@
using System.Threading.Tasks;
using System.Windows.Forms;
using EasyTabs;
using FastColoredTextBoxNS;
using System.Text.RegularExpressions;

namespace DenebStudio
{
public partial class DenebStudio : MaterialForm
{
static SolidBrush keywordBrush = new SolidBrush(Color.FromArgb(92, 204, 226));

readonly Style BlueBoldStyle = new TextStyle(Brushes.Blue, null, FontStyle.Bold);
readonly Style KeywordStyle = new TextStyle(keywordBrush, null, FontStyle.Regular);
readonly Style ClassNameStyle = new TextStyle(null, null, FontStyle.Bold | FontStyle.Underline);
readonly Style StringStyle = new TextStyle(Brushes.Brown, null, FontStyle.Italic);
readonly Style CommentTagStyle = new TextStyle(Brushes.Gray, null, FontStyle.Regular);
readonly Style CommentStyle = new TextStyle(Brushes.Green, null, FontStyle.Italic);
readonly Style AttributeStyle = new TextStyle(Brushes.Green, null, FontStyle.Italic);
readonly Style NumberStyle = new TextStyle(Brushes.Magenta, null, FontStyle.Regular);
readonly Style MaroonStyle = new TextStyle(Brushes.Maroon, null, FontStyle.Regular);
readonly Style RedStyle = new TextStyle(Brushes.Red, null, FontStyle.Regular);
readonly Style BlackStyle = new TextStyle(Brushes.Black, null, FontStyle.Regular);



protected TitleBarTabs ParentTabs
{
get
Expand Down Expand Up @@ -59,8 +77,10 @@ private static TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo)
foreach (var file in directoryInfo.GetFiles())
directoryNode.Nodes.Add(new TreeNode(file.Name) { Tag = file.FullName });
return directoryNode;

}


private string GetFileName(string fullPath)
{
string name = string.Empty;
Expand Down Expand Up @@ -123,6 +143,165 @@ private void tabOpenedFiles_SelectedIndexChanged(object sender, EventArgs e)
{
//MessageBox.Show(e.ToString());

}

static SolidBrush commentsBrush = new SolidBrush(Color.FromArgb(159, 205, 50));
Style commentsStyle = new TextStyle(commentsBrush, null, FontStyle.Italic);

static SolidBrush typesBrush = new SolidBrush(Color.FromArgb(106, 201, 216));
Style typesStyle = new TextStyle(typesBrush, null, FontStyle.Bold);

Regex DartStringRegex;
Regex DartCommentRegex1;
Regex DartCommentRegex2;
Regex DartCommentRegex3;
Regex DartNumberRegex;
Regex DartAttributeRegex;
Regex DartClassNameRegex;
Regex DartKeywordRegex;

protected void InitDartRegex()
{
//CSharpStringRegex = new Regex( @"""""|@""""|''|@"".*?""|(?<!@)(?<range>"".*?[^\\]"")|'.*?[^\\]'", RegexCompiledOption);

DartStringRegex =
new Regex(
@"
# Character definitions:
'
(?> # disable backtracking
(?:
\\[^\r\n]| # escaped meta char
[^'\r\n] # any character except '
)*
)
'?
|
# Normal string & verbatim strings definitions:
(?<verbatimIdentifier>@)? # this group matches if it is an verbatim string
""
(?> # disable backtracking
(?:
# match and consume an escaped character including escaped double quote ("") char
(?(verbatimIdentifier) # if it is a verbatim string ...
""""| # then: only match an escaped double quote ("") char
\\. # else: match an escaped sequence
)
| # OR
# match any char except double quote char ("")
[^""]
)*
)
""
",
RegexOptions.ExplicitCapture | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace |
RegexCompiledOption
); //thanks to rittergig for this regex

DartCommentRegex1 = new Regex(@"//.*$", RegexOptions.Multiline | RegexCompiledOption);
DartCommentRegex2 = new Regex(@"(/\*.*?\*/)|(/\*.*)", RegexOptions.Singleline | RegexCompiledOption);
DartCommentRegex3 = new Regex(@"(/\*.*?\*/)|(.*\*/)",
RegexOptions.Singleline | RegexOptions.RightToLeft | RegexCompiledOption);
DartNumberRegex = new Regex(@"\b\d+[\.]?\d*([eE]\-?\d+)?[lLdDfF]?\b|\b0x[a-fA-F\d]+\b",
RegexCompiledOption);
DartAttributeRegex = new Regex(@"^\s*(?<range>\[.+?\])\s*$", RegexOptions.Multiline | RegexCompiledOption);
DartClassNameRegex = new Regex(@"\b(class|struct|enum|interface)\s+(?<range>\w+?)\b", RegexCompiledOption);
DartKeywordRegex =
new Regex(
@"\b(abstract|add|alias|as|ascending|async|await|base|bool|break|by|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|descending|do|double|dynamic|else|enum|equals|event|explicit|extern|false|finally|fixed|float|for|foreach|from|get|global|goto|group|if|implicit|in|int|interface|internal|into|is|join|let|lock|long|nameof|namespace|new|null|object|on|operator|orderby|out|override|params|partial|private|protected|public|readonly|ref|remove|return|sbyte|sealed|select|set|short|sizeof|stackalloc|static|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|using|value|var|virtual|void|volatile|when|where|while|yield)\b|#region\b|#endregion\b",
RegexCompiledOption);
}

protected static readonly Platform platformType = PlatformType.GetOperationSystemPlatform();
public static RegexOptions RegexCompiledOption
{
get
{
if (platformType == Platform.X86)
return RegexOptions.Compiled;
else
return RegexOptions.None;
}
}

private bool firstTime = true;
private void txtCode_TextChanged(object sender, FastColoredTextBoxNS.TextChangedEventArgs e)
{
if (firstTime)
{
InitDartRegex();
firstTime = false;
}
Range range = (sender as FastColoredTextBox).Range;

range.ClearStyle(commentsStyle);
range.SetStyle(commentsStyle, @"//.*$", RegexOptions.Multiline);
range.SetStyle(typesStyle, @"\b(class|struct|enum)\s+(?<range>[\w_]+?)\b");

range.ClearStyle(commentsStyle);
//comment highlighting
range.SetStyle(commentsStyle, @"//.*$", RegexOptions.Multiline);
range.SetStyle(commentsStyle, @"(/\*.*?\*/)|(/\*.*)", RegexOptions.Singleline);
range.SetStyle(commentsStyle, @"(/\*.*?\*/)|(.*\*/)", RegexOptions.Singleline |
RegexOptions.RightToLeft);

range.tb.CommentPrefix = "//";
range.tb.LeftBracket = '(';
range.tb.RightBracket = ')';
range.tb.LeftBracket2 = '{';
range.tb.RightBracket2 = '}';
range.tb.BracketsHighlightStrategy = BracketsHighlightStrategy.Strategy2;

range.tb.AutoIndentCharsPatterns
= @"
^\s*[\w\.]+(\s\w+)?\s*(?<range>=)\s*(?<range>[^;=]+);
^\s*(case|default)\s*[^:]*(?<range>:)\s*(?<range>[^;]+);
";
//clear style of changed range
range.ClearStyle(StringStyle, CommentStyle, NumberStyle, AttributeStyle, ClassNameStyle, KeywordStyle);
//
//string highlighting
range.SetStyle(StringStyle, DartStringRegex);
//comment highlighting
range.SetStyle(CommentStyle, DartCommentRegex1);
range.SetStyle(CommentStyle, DartCommentRegex2);
range.SetStyle(CommentStyle, DartCommentRegex3);
//number highlighting
range.SetStyle(NumberStyle, DartNumberRegex);
//attribute highlighting
range.SetStyle(AttributeStyle, DartAttributeRegex);
//class name highlighting
range.SetStyle(ClassNameStyle, DartClassNameRegex);
//keyword highlighting
range.SetStyle(KeywordStyle, DartKeywordRegex);

//find document comments
foreach (Range r in range.GetRanges(@"^\s*///.*$", RegexOptions.Multiline))
{
//remove C# highlighting from this fragment
r.ClearStyle(StyleIndex.All);
//do XML highlighting;
//
r.SetStyle(CommentStyle);

//prefix '///'
foreach (Range rr in r.GetRanges(@"^\s*///", RegexOptions.Multiline))
{
rr.ClearStyle(StyleIndex.All);
rr.SetStyle(CommentTagStyle);
}
}

//clear folding markers
range.ClearFoldingMarkers();
//set folding markers
range.SetFoldingMarkers("{", "}"); //allow to collapse brackets block
range.SetFoldingMarkers(@"#region\b", @"#endregion\b"); //allow to collapse #region blocks
range.SetFoldingMarkers(@"/\*", @"\*/"); //allow to collapse comment block



}
}
}

0 comments on commit 4e6e92b

Please sign in to comment.