protected SyntaxDefinition LoadSyntax() { if (string.IsNullOrWhiteSpace(_SyntaxName)) { return(null); } using Stream streamSyntax = Utils.GetEmbeddedResource(Assembly.GetAssembly(typeof(SpreadCommanderCommon)), $"SyntaxFiles.{_SyntaxName}.syn"); streamSyntax.Seek(0, SeekOrigin.Begin); using StreamReader reader = new StreamReader(streamSyntax); var syntax = SyntaxDefinition.FromSyntaxXml(reader.ReadToEnd()); return(syntax); }
public SettingsForm(Plugin plugin) { InitializeComponent(); this.plugin = plugin; variableTypeNames[typeof(CurrentTimeChannel).FullName] = "Current time"; variableTypeNames[typeof(RandomIntegerChannel).FullName] = "Random integer"; variableTypeNames[typeof(SawIntegerChannel).FullName] = "Saw (integer -100 .. 100)"; variableTypeNames[typeof(RampIntegerChannel).FullName] = "Ramp (integer 0 .. 100)"; variableTypeNames[typeof(SinusDoubleChannel).FullName] = "Sinus (double -1 .. 1)"; variableTypeNames[typeof(GenericChannel <int>).FullName] = "Simple integer"; variableTypeNames[typeof(GenericChannel <string>).FullName] = "Simple string"; variableTypeNames[typeof(GenericChannel <float>).FullName] = "Simple float"; variableTypeNames[typeof(ComputableChannel).FullName] = "Computable"; foreach (KeyValuePair <string, string> pair in variableTypeNames) { channelNames.Add(pair.Value); } grid.SelectionMode = SourceGrid.GridSelectionMode.Row; grid.Selection.EnableMultiSelection = false; DevAge.Drawing.RectangleBorder b = grid.Selection.Border; b.SetWidth(0); grid.Selection.Border = b; grid.Selection.FocusBackColor = grid.Selection.BackColor; grid.ColumnsCount = 3; grid.RowsCount = 1; grid[0, 0] = new SourceGrid.Cells.ColumnHeader("Channel name"); grid[0, 1] = new SourceGrid.Cells.ColumnHeader("Type"); grid[0, 2] = new SourceGrid.Cells.ColumnHeader("Read only"); string iPyFormatXML = (new StreamReader(new MemoryStream(global::FreeSCADA.Communication.SimulatorPlug.Resources.IronPython))).ReadToEnd(); SyntaxDefinition syntax = SyntaxDefinition.FromSyntaxXml(iPyFormatXML); expressionEditBox.Document.Parser.Init(syntax); grid.Selection.SelectionChanged += new SourceGrid.RangeRegionChangedEventHandler(OnSelectionChanged); LoadChannels(); grid.AutoStretchColumnsToFitWidth = true; grid.AutoSizeCells(); InitializeTooltips(); UpdateExpressionField(); }
public ScriptView(string scriptName) : base(new DummyDocument(scriptName)) { this.script = Env.Current.ScriptManager.GetScript(scriptName); InitializeComponent(); DocumentName = script.Name; string iPyFormatXML = (new StreamReader(new MemoryStream(global::FreeSCADA.Designer.Resources.IronPython))).ReadToEnd(); SyntaxDefinition syntax = SyntaxDefinition.FromSyntaxXml(iPyFormatXML); syntaxBoxControl.Document.Parser.Init(syntax); syntaxBoxControl.Document.Text = script.Text; IsModified = false; script.TextUpdated += new EventHandler(OnScriptTextUpdated); syntaxBoxControl.TextChanged += new System.EventHandler(this.syntaxBoxControl_TextChanged); InitializeEditor(); InitializeCommands(); }
protected void DoWriteSyntaxText(string text, SyntaxName syntaxName, SyntaxTextOptions options) { options ??= new SyntaxTextOptions(); var book = options.Book?.Document ?? Document; string strSyntax = null; switch (syntaxName) { case SyntaxName.CSharp: strSyntax = "C#"; break; case SyntaxName.CPlusPlus: strSyntax = "C++"; break; case SyntaxName.Delphi: strSyntax = "Delphi"; break; case SyntaxName.DOSBatch: strSyntax = "DOSBatch"; break; case SyntaxName.FSharp: strSyntax = "F#"; break; case SyntaxName.Fortran90: strSyntax = "Fortran90"; break; case SyntaxName.Java: strSyntax = "Java"; break; case SyntaxName.JavaScript: strSyntax = "JavaScript"; break; case SyntaxName.LotusScript: strSyntax = "LotusScript"; break; case SyntaxName.MSIL: strSyntax = "MSIL"; break; case SyntaxName.Perl: strSyntax = "Perl"; break; case SyntaxName.PHP: strSyntax = "PHP"; break; case SyntaxName.PowerShell: strSyntax = "PowerShell"; break; case SyntaxName.Python: strSyntax = "Python"; break; case SyntaxName.R: strSyntax = "R"; break; case SyntaxName.SQL: strSyntax = "SqlScript"; break; case SyntaxName.VBNet: strSyntax = "VB.Net"; break; case SyntaxName.XML: strSyntax = "XML"; break; } book.BeginUpdate(); try { string rtfText; DocumentRange range; if (!string.IsNullOrWhiteSpace(strSyntax)) { using (var syntaxDocument = new SyntaxDocument()) { SyntaxDefinition syntaxDefinition = LoadSyntax(strSyntax); syntaxDocument.Parser.Init(syntaxDefinition); syntaxDocument.ReParse(); syntaxDocument.Text = text; rtfText = syntaxDocument.ExportToRTF(null, "Lucida Console"); } range = book.AppendRtfText(rtfText, InsertOptions.KeepSourceFormatting); } else { range = book.AppendText(text); } if (!string.IsNullOrWhiteSpace(options.ParagraphStyle)) { var style = book.ParagraphStyles[options.ParagraphStyle] ?? throw new Exception($"Paragraph style '{options.ParagraphStyle}' does not exist."); var pp = book.BeginUpdateParagraphs(range); try { pp.Style = style; } finally { book.EndUpdateParagraphs(pp); } } Script.Book.SCBook.AddComments(book, range, options); WriteRangeToConsole(book, range); if (range?.End != null) { book.CaretPosition = range.End; Script.Book.SCBook.ResetBookFormatting(book, range.End); ScrollToCaret(); } } finally { book.EndUpdate(); } SyntaxDefinition LoadSyntax(string syntaxFileName) { if (string.IsNullOrWhiteSpace(syntaxFileName)) { return(null); } using var streamSyntax = Utils.GetEmbeddedResource(System.Reflection.Assembly.GetAssembly(this.GetType()), $"SyntaxFiles.{syntaxFileName}.syn"); streamSyntax.Seek(0, SeekOrigin.Begin); using var reader = new StreamReader(streamSyntax); var syntax = SyntaxDefinition.FromSyntaxXml(reader.ReadToEnd()); return(syntax); } }