using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Telerik.Windows.Controls;
using Telerik.WinForms.Controls.SyntaxEditor.Taggers;
using Telerik.WinForms.SyntaxEditor.Core.Tagging;
using Telerik.WinControls.UI;
using Telerik.WinForms.Controls.SyntaxEditor.UI;
using System.IO;
namespace WindowsFormsApp12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class PythonTagger : WordTaggerBase
{
private static readonly string[] Keywords = new string[]
{
"False", "None", "True", "and", "as", "assert","break", "class",
"continue", "def", "del", "elif", "else", "except", "for", "from",
"global", "if", "import", "in", "is", "lambda", "nonlocal", "not",
"or", "pass", "raise", "finally", "return", "try", "while", "with", "yield"
};
private static readonly string[] Comments = new string[]
{
"#"
};
private static readonly string[] Operators = new string[]
{
"+", "-", "*", "/"
};
public static readonly ClassificationType FruitsClassificationType = new ClassificationType("Fruits");
private static readonly string[] Fruits = new string[]
{
"apple", "banana", "cherry"
};
private static readonly Dictionary<string, ClassificationType> WordsToClassificationType = new Dictionary<string, ClassificationType>();
static PythonTagger()
{
WordsToClassificationType = new Dictionary<string, ClassificationType>();
foreach (var keyword in Keywords)
{
WordsToClassificationType.Add(keyword, ClassificationTypes.Keyword);
}
foreach (var preprocessor in Operators)
{
WordsToClassificationType.Add(preprocessor, ClassificationTypes.Operator);
}
foreach (var comment in Comments)
{
WordsToClassificationType.Add(comment, ClassificationTypes.Comment);
}
foreach (var comment in Fruits)
{
WordsToClassificationType.Add(comment, FruitsClassificationType);
}
}
public PythonTagger(RadSyntaxEditorElement editor)
: base(editor)
{
}
protected override Dictionary<string, ClassificationType> GetWordsToClassificationTypes()
{
return PythonTagger.WordsToClassificationType;
}
protected override bool TryGetClassificationType(string word, out ClassificationType classificationType)
{
int number;
if (int.TryParse(word, out number))
{
classificationType = ClassificationTypes.NumberLiteral;
return true;
}
return base.TryGetClassificationType(word, out classificationType);
}
}
private void Form1_Load(object sender, EventArgs e)
{
PythonTagger pythonTagger = new PythonTagger(this.radSyntaxEditor1.SyntaxEditorElement);
if (!this.radSyntaxEditor1.TaggersRegistry.IsTaggerRegistered(pythonTagger))
{
this.radSyntaxEditor1.TaggersRegistry.RegisterTagger(pythonTagger);
}
this.radSyntaxEditor1.TextFormatDefinitions.AddLast(ClassificationTypes.NumberLiteral, new TextFormatDefinition(new SolidBrush(Color.Red)));
this.radSyntaxEditor1.TextFormatDefinitions.AddLast(ClassificationTypes.Operator, new TextFormatDefinition(new SolidBrush(Color.YellowGreen)));
this.radSyntaxEditor1.TextFormatDefinitions.AddLast(PythonTagger.FruitsClassificationType, new TextFormatDefinition(new SolidBrush(Color.LightCoral)));
StreamReader reader = new StreamReader(@"C:\Python27amd64\Lib\msilib\text.py");
{
radSyntaxEditor1.Document = new Telerik.WinForms.SyntaxEditor.Core.Text.TextDocument(reader);
}
}
private void radMenuItem2_Click(object sender, EventArgs e)
{
StreamReader reader = new StreamReader(@"C:\Python27amd64\Lib\ctypes\util.py");
{
radSyntaxEditor1.Document = new Telerik.WinForms.SyntaxEditor.Core.Text.TextDocument(reader);
}
}
private void radSyntaxEditor1_Click(object sender, EventArgs e)
{
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Telerik.Windows.Controls;
using Telerik.WinForms.Controls.SyntaxEditor.Taggers;
using Telerik.WinForms.SyntaxEditor.Core.Tagging;
using Telerik.WinControls.UI;
using Telerik.WinForms.Controls.SyntaxEditor.UI;
using System.IO;
namespace WindowsFormsApp12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class PythonTagger : WordTaggerBase
{
private static readonly string[] Keywords = new string[]
{
"False", "None", "True", "and", "as", "assert","break", "class",
"continue", "def", "del", "elif", "else", "except", "for", "from",
"global", "if", "import", "in", "is", "lambda", "nonlocal", "not",
"or", "pass", "raise", "finally", "return", "try", "while", "with", "yield"
};
private static readonly string[] Comments = new string[]
{
"#"
};
private static readonly string[] Operators = new string[]
{
"+", "-", "*", "/"
};
public static readonly ClassificationType FruitsClassificationType = new ClassificationType("Fruits");
private static readonly string[] Fruits = new string[]
{
"apple", "banana", "cherry"
};
private static readonly Dictionary<string, ClassificationType> WordsToClassificationType = new Dictionary<string, ClassificationType>();
static PythonTagger()
{
WordsToClassificationType = new Dictionary<string, ClassificationType>();
foreach (var keyword in Keywords)
{
WordsToClassificationType.Add(keyword, ClassificationTypes.Keyword);
}
foreach (var preprocessor in Operators)
{
WordsToClassificationType.Add(preprocessor, ClassificationTypes.Operator);
}
foreach (var comment in Comments)
{
WordsToClassificationType.Add(comment, ClassificationTypes.Comment);
}
foreach (var comment in Fruits)
{
WordsToClassificationType.Add(comment, FruitsClassificationType);
}
}
public PythonTagger(RadSyntaxEditorElement editor)
: base(editor)
{
}
protected override Dictionary<string, ClassificationType> GetWordsToClassificationTypes()
{
return PythonTagger.WordsToClassificationType;
}
protected override bool TryGetClassificationType(string word, out ClassificationType classificationType)
{
int number;
if (int.TryParse(word, out number))
{
classificationType = ClassificationTypes.NumberLiteral;
return true;
}
return base.TryGetClassificationType(word, out classificationType);
}
}
private void Form1_Load(object sender, EventArgs e)
{
PythonTagger pythonTagger = new PythonTagger(this.radSyntaxEditor1.SyntaxEditorElement);
if (!this.radSyntaxEditor1.TaggersRegistry.IsTaggerRegistered(pythonTagger))
{
this.radSyntaxEditor1.TaggersRegistry.RegisterTagger(pythonTagger);
}
this.radSyntaxEditor1.TextFormatDefinitions.AddLast(ClassificationTypes.NumberLiteral, new TextFormatDefinition(new SolidBrush(Color.Red)));
this.radSyntaxEditor1.TextFormatDefinitions.AddLast(ClassificationTypes.Operator, new TextFormatDefinition(new SolidBrush(Color.YellowGreen)));
this.radSyntaxEditor1.TextFormatDefinitions.AddLast(PythonTagger.FruitsClassificationType, new TextFormatDefinition(new SolidBrush(Color.LightCoral)));
StreamReader reader = new StreamReader(@"C:\Python27amd64\Lib\msilib\text.py");
{
radSyntaxEditor1.Document = new Telerik.WinForms.SyntaxEditor.Core.Text.TextDocument(reader);
}
}
private void radMenuItem2_Click(object sender, EventArgs e)
{
StreamReader reader = new StreamReader(@"C:\Python27amd64\Lib\ctypes\util.py");
{
radSyntaxEditor1.Document = new Telerik.WinForms.SyntaxEditor.Core.Text.TextDocument(reader);
}
}
private void radSyntaxEditor1_Click(object sender, EventArgs e)
{
}
}
}