/// <summary>
        /// Exports the content of a SyntaxDocument to a HTML formatted string
        /// </summary>
        /// <param name="doc">SyntaxDocument object to export from</param>
        /// <param name="BGColor">HTML color string to use as background color</param>
        /// <param name="ImagePath">File path tho the images to use in the HTML string</param>
        /// <param name="Style">HTML style string that should be applied to the output</param>
        /// <returns></returns>
        public string Export(SyntaxDocument doc, Color BGColor, string ImagePath, string Style)
        {
            sb = new StringBuilder();
            doc.ParseAll(true);
            int i = 0;

            string guid = DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture);

            //style=\"font-family:courier new;font-size:13px;\"
            if (BGColor.A == 0) {
                Out("<table  ><tr><td nowrap><div style=\"" + Style + "\">");
            } else {
                Out("<table  style=\"background-color:" + GetHTMLColor(BGColor) + ";" + Style +
                    "\"><tr><td nowrap><div>");
            }
            foreach (Row r in doc) {
                i++;
                if (r.CanFold) {
                    RenderCollapsed(r.VirtualCollapsedRow, r, i, ImagePath, guid);
                    Out("<div style=\"display:block;\" id=\"open" + guid + "_" +
                        i.ToString(CultureInfo.InvariantCulture) + "\">");

                    string img = "minus.gif";
                    try {
                        if (r.expansion_StartSpan.Parent.Parent == null) {
                            img = "minusNoTopLine.gif";
                        }
                    } catch {}
                    Out("<img src=\"" + ImagePath + img + "\" align=top onclick=\"open" + guid + "_" +
                        i.ToString(CultureInfo.InvariantCulture) + ".style.display='none'; closed" + guid + "_" +
                        i.ToString(CultureInfo.InvariantCulture) + ".style.display='block'; \">");
                } else {
                    if (r.CanFoldEndPart) {
                        Out("<img src=\"" + ImagePath + "L.gif\"  align=top>");
                    } else {
                        if (r.HasExpansionLine) {
                            Out("<img src=\"" + ImagePath + "I.gif\"  align=top>");
                        } else {
                            Out("<img src=\"" + ImagePath + "clear.gif\"  align=top>");
                        }
                    }
                }
                foreach (Word w in r) {
                    write(w.Text, w.Style);
                }
                if (r.CanFoldEndPart) {
                    Out("</div>\n");
                } else {
                    Out("<br>\n");
                }
            }
            Out("</div></td></tr></table>");

            return sb.ToString();
        }
Ejemplo n.º 2
0
        public static string Export(SyntaxDocument doc, string CssClass)
        {
            sb = new StringBuilder();
            doc.ParseAll(true);

            Out("<div class=\"" + CssClass + "\">" + Environment.NewLine);
            foreach (Row r in doc) {
                foreach (Word w in r) {
                    write(w.Text, w.Style);
                }

                Out("<br>" + Environment.NewLine);
            }
            Out("</div>");

            return sb.ToString();
        }
 /// <summary>
 /// Exports the content of a SyntaxDocument to a HTML formatted string
 /// </summary>
 /// <param name="doc">SyntaxDocument object to export from</param>
 /// <param name="ImagePath">File path tho the images to use in the HTML string</param>
 /// <returns></returns>
 public string Export(SyntaxDocument doc, string ImagePath)
 {
     return Export(doc, Color.Transparent, ImagePath, "");
 }
Ejemplo n.º 4
0
		/// <summary>
		/// Exports the content of a SyntaxDocument to a HTML formatted string
		/// </summary>
		/// <param name="doc">SyntaxDocument object to export from</param>
		/// <param name="ImagePath">File path tho the images to use in the HTML string</param>
		/// <returns></returns>
		public string Export(SyntaxDocument doc,string ImagePath)
		{
			return this.Export (doc,System.Drawing.Color.Transparent, ImagePath,"");
		}
Ejemplo n.º 5
0
 /// <summary>
 /// Exports the content of a SyntaxDocument to a HTML formatted string
 /// </summary>
 /// <param name="doc">SyntaxDocument object to export from</param>
 /// <param name="ImagePath">File path tho the images to use in the HTML string</param>
 /// <returns></returns>
 public string Export(SyntaxDocument doc, string ImagePath)
 {
     return(Export(doc, Color.Transparent, ImagePath, ""));
 }
Ejemplo n.º 6
0
 public SourceCodePrintDocument(SyntaxDocument document) : base()
 {
     this.Document = document;
 }
Ejemplo n.º 7
0
        protected virtual void SetupDataProvider(string fileName, SyntaxDocument document, ExpressionResult expressionResult, int caretLineNumber, int caretColumn)
        {
            bool constructorInsight = false;

            if (expressionResult.Context.IsAttributeContext)
            {
                constructorInsight = true;
            }
            else if (expressionResult.Context.IsObjectCreation)
            {
                constructorInsight       = true;
                expressionResult.Context = ExpressionContext.Type;
            }

            ResolveResult      results  = Parser.ProjectParser.GetResolver().Resolve(expressionResult, caretLineNumber, caretColumn, fileName, document.Text);
            LanguageProperties language = Parser.ProjectParser.CurrentProjectContent.Language;


            IReturnType type = results.ResolvedType;

            if (type != null)
            {
                foreach (IProperty i in type.GetProperties())
                {
                    if (i.IsIndexer)
                    {
                        methods.Add(i);
                    }
                }
            }

            TypeResolveResult trr = results as TypeResolveResult;

            if (trr == null && language.AllowObjectConstructionOutsideContext)
            {
                if (results is MixedResolveResult)
                {
                    trr = (results as MixedResolveResult).TypeResult;
                }
            }
            if (trr != null && !constructorInsight)
            {
                if (language.AllowObjectConstructionOutsideContext)
                {
                    constructorInsight = true;
                }
            }
            if (constructorInsight)
            {
                if (trr == null)
                {
                    return;
                }
                foreach (IMethod method in trr.ResolvedType.GetMethods())
                {
                    if (method.IsConstructor && !method.IsStatic)
                    {
                        methods.Add(method);
                    }
                }

                if (methods.Count == 0 && trr.ResolvedClass != null && !trr.ResolvedClass.IsAbstract && !trr.ResolvedClass.IsStatic)
                {
                    // add default constructor
                    methods.Add(Constructor.CreateDefault(trr.ResolvedClass));
                }
            }
            else
            {
                MethodResolveResult result = results as MethodResolveResult;
                if (result == null)
                {
                    return;
                }
                bool classIsInInheritanceTree = false;
                if (result.CallingClass != null)
                {
                    classIsInInheritanceTree = result.CallingClass.IsTypeInInheritanceTree(result.ContainingType.GetUnderlyingClass());
                }
                foreach (IMethod method in result.ContainingType.GetMethods())
                {
                    if (language.NameComparer.Equals(method.Name, result.Name))
                    {
                        if (method.IsAccessible(result.CallingClass, classIsInInheritanceTree))
                        {
                            methods.Add(method);
                        }
                    }
                }
                if (methods.Count == 0 && result.CallingClass != null && language.SupportsExtensionMethods)
                {
                    ArrayList list = new ArrayList();
                    ResolveResult.AddExtensions(language, list, result.CallingClass, result.ContainingType);
                    foreach (IMethodOrProperty mp in list)
                    {
                        if (language.NameComparer.Equals(mp.Name, result.Name) && mp is IMethod)
                        {
                            IMethod m = (IMethod)mp.Clone();
                            m.Parameters.RemoveAt(0);
                            methods.Add(m);
                        }
                    }
                }
            }
        }
 public SourceCodePrintDocument(SyntaxDocument document)
 {
     Document = document;
 }
Ejemplo n.º 9
0
        private void InternalParseLine(int index, bool ParseKeywords)
        {
            if (this.mLanguage == null)
            {
                return;
            }

            //
            //			if (ParseKeywords)
            //				return;
            //			ParseKeywords=true;
            SyntaxDocument doc = Document;
            Row            Row = doc[index];

            Segment OldEndSegment   = Row.EndSegment;
            Segment OldStartSegment = Row.StartSegment;
            bool    Fold            = !Row.IsCollapsed;


            if (Row.IsCollapsedEndPart)
            {
                //Row.Expansion_EndSegment.Expanded = true;
                //Row.Expansion_EndSegment.EndRow = null;
                Row.Expansion_EndSegment.EndWord = null;
            }


            //set startsegment for this row
            if (index > 0)
            {
                Row.StartSegment = Document[index - 1].EndSegment;
            }
            else
            {
                if (Row.StartSegment == null)
                {
                    Row.StartSegment           = new Segment(Row);
                    Row.StartSegment.BlockType = this.mLanguage.MainBlock;
                }
            }

            int     CurrentPosition = 0;
            Segment CurrentSegment  = Row.StartSegment;

            if (CurrentSegment == null)
            {
                return; //%%__|JMP(12/29/2010) Probably a timing issue.
            }

            //kör tills vi kommit till slutet av raden..
            Row.EndSegments.Clear();
            Row.StartSegments.Clear();
            Row.Clear();
            //		bool HasEndSegment=false;

            while (true)
            {
                ScanResult_Segment ChildSegment = GetNextChildSegment(Row, CurrentSegment, CurrentPosition);
                ScanResult_Segment EndSegment   = GetEndSegment(Row, CurrentSegment, CurrentPosition);

                if ((EndSegment.HasContent && ChildSegment.HasContent && EndSegment.Position <= ChildSegment.Position) || (EndSegment.HasContent && ChildSegment.HasContent == false))
                {
                    //this is an end segment

                    if (ParseKeywords)
                    {
                        string Text = Row.Text.Substring(CurrentPosition, EndSegment.Position - CurrentPosition);
                        ParseText(Row, CurrentSegment, Text);
                    }

                    Segment oldseg = CurrentSegment;
                    while (CurrentSegment != EndSegment.Segment)
                    {
                        Row.EndSegments.Add(CurrentSegment);
                        CurrentSegment = CurrentSegment.Parent;
                        if (CurrentSegment == null)
                        {
                            System.Threading.Thread.Sleep(1);
                        }
                    }
                    Row.EndSegments.Add(CurrentSegment);

                    TextStyle st2 = CurrentSegment.Scope.Style;

                    ParseTools.AddPatternString(EndSegment.Token, Row, EndSegment.Pattern, st2, CurrentSegment, false);
                    while (oldseg != EndSegment.Segment)
                    {
                        oldseg.EndRow  = Row;
                        oldseg.EndWord = Row[Row.Count - 1];
                        oldseg         = oldseg.Parent;
                    }

                    CurrentSegment.EndRow  = Row;
                    CurrentSegment.EndWord = Row[Row.Count - 1];



                    if (CurrentSegment.Parent != null)
                    {
                        CurrentSegment = CurrentSegment.Parent;
                        if (CurrentSegment == null)
                        {
                            System.Threading.Thread.Sleep(1);
                        }
                    }

                    CurrentPosition = EndSegment.Position + EndSegment.Token.Length;
                }
                else if (ChildSegment.HasContent)
                {
                    //this is a child block

                    if (ParseKeywords)
                    {
                        string Text = Row.Text.Substring(CurrentPosition, ChildSegment.Position - CurrentPosition);
                        //TextStyle st=CurrentSegment.BlockType.Style;
                        ParseText(Row, CurrentSegment, Text);
                        //ParseTools.AddString (Text,Row,st,CurrentSegment);
                    }



                    Segment NewSeg = new Segment();
                    NewSeg.Parent    = CurrentSegment;
                    NewSeg.BlockType = ChildSegment.BlockType;
                    NewSeg.Scope     = ChildSegment.Scope;

                    Row.StartSegments.Add(NewSeg);

                    TextStyle st2 = NewSeg.Scope.Style;
                    ParseTools.AddPatternString(ChildSegment.Token, Row, ChildSegment.Pattern, st2, NewSeg, false);
                    NewSeg.StartRow  = Row;
                    NewSeg.StartWord = Row[Row.Count - 1];


                    CurrentSegment = NewSeg;
                    if (CurrentSegment == null)
                    {
                        System.Threading.Thread.Sleep(1);
                    }

                    CurrentPosition = ChildSegment.Position + ChildSegment.Token.Length;

                    if (ChildSegment.Scope.SpawnBlockOnStart != null)
                    {
                        Segment SpawnSeg = new Segment();
                        SpawnSeg.Parent    = NewSeg;
                        SpawnSeg.BlockType = ChildSegment.Scope.SpawnBlockOnStart;
                        SpawnSeg.Scope     = new Scope();
                        SpawnSeg.StartWord = NewSeg.StartWord;
                        Row.StartSegments.Add(SpawnSeg);
                        CurrentSegment = SpawnSeg;
                        if (CurrentSegment == null)
                        {
                            System.Threading.Thread.Sleep(1);
                        }
                    }
                }
                else
                {
                    if (CurrentPosition < Row.Text.Length)
                    {
                        if (ParseKeywords)
                        {
                            //we did not find a childblock nor an endblock , just output the last pice of text
                            string Text = Row.Text.Substring(CurrentPosition);
                            //TextStyle st=CurrentSegment.BlockType.Style;
                            ParseText(Row, CurrentSegment, Text);
                            //ParseTools.AddString (Text,Row,st,CurrentSegment);
                        }
                    }
                    break;
                }
            }

            while (!CurrentSegment.BlockType.MultiLine)
            {
                Row.EndSegments.Add(CurrentSegment);
                CurrentSegment = CurrentSegment.Parent;
            }

            Row.EndSegment = CurrentSegment;
            Row.SetExpansionSegment();

            if (ParseKeywords)
            {
                Row.RowState = RowState.AllParsed;
            }
            else
            {
                Row.RowState = RowState.SegmentParsed;
            }

            if (IsSameButDifferent(index, OldStartSegment))
            {
                MakeSame(index);
                //if (!IsSameButDifferent(index))
                //	System.Diagnostics.Debugger.Break();
            }

            if (Row.CanFold)
            {
                Row.Expansion_StartSegment.Expanded = Fold;
            }

            //dont flag next line as needs parsing if only parsing keywords
            if (!ParseKeywords)
            {
                if (OldEndSegment != null)
                {
                    if (Row.EndSegment != OldEndSegment && index <= Document.Count - 2)
                    {
                        //if (Row.CanFold)
                        //	Row.Expansion_StartSegment.Expanded = true;
                        Document[index + 1].AddToParseQueue();
                        Document.NeedResetRows = true;
                    }
                }
                else if (index <= Document.Count - 2)
                {
                    //if (Row.CanFold)
                    //	Row.Expansion_StartSegment.Expanded = true;
                    Document[index + 1].AddToParseQueue();
                    Document.NeedResetRows = true;
                }
            }

            if (OldEndSegment != null)
            {
                //expand segment if this line dont have an end word
                if (OldEndSegment.EndWord == null)
                {
                    OldEndSegment.Expanded = true;
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Exports the content of a SyntaxDocument to a HTML formatted string
        /// </summary>
        /// <param name="doc">SyntaxDocument object to export from</param>
        /// <param name="BGColor">HTML color string to use as background color</param>
        /// <param name="ImagePath">File path tho the images to use in the HTML string</param>
        /// <param name="Style">HTML style string that should be applied to the output</param>
        /// <returns></returns>
        public string Export(SyntaxDocument doc, Color BGColor, string ImagePath, string Style)
        {
            sb = new StringBuilder();
            doc.ParseAll(true);
            int i = 0;

            string guid = DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture);

            //style=\"font-family:courier new;font-size:13px;\"
            if (BGColor.A == 0)
            {
                Out("<table  ><tr><td nowrap><div style=\"" + Style + "\">");
            }
            else
            {
                Out("<table  style=\"background-color:" + GetHTMLColor(BGColor) + ";" + Style +
                    "\"><tr><td nowrap><div>");
            }
            foreach (Row r in doc)
            {
                i++;
                if (r.CanFold)
                {
                    RenderCollapsed(r.VirtualCollapsedRow, r, i, ImagePath, guid);
                    Out("<div style=\"display:block;\" id=\"open" + guid + "_" +
                        i.ToString(CultureInfo.InvariantCulture) + "\">");

                    string img = "minus.gif";
                    try
                    {
                        if (r.expansion_StartSpan.Parent.Parent == null)
                        {
                            img = "minusNoTopLine.gif";
                        }
                    }
                    catch {}
                    Out("<img src=\"" + ImagePath + img + "\" align=top onclick=\"open" + guid + "_" +
                        i.ToString(CultureInfo.InvariantCulture) + ".style.display='none'; closed" + guid + "_" +
                        i.ToString(CultureInfo.InvariantCulture) + ".style.display='block'; \">");
                }
                else
                {
                    if (r.CanFoldEndPart)
                    {
                        Out("<img src=\"" + ImagePath + "L.gif\"  align=top>");
                    }
                    else
                    {
                        if (r.HasExpansionLine)
                        {
                            Out("<img src=\"" + ImagePath + "I.gif\"  align=top>");
                        }
                        else
                        {
                            Out("<img src=\"" + ImagePath + "clear.gif\"  align=top>");
                        }
                    }
                }
                foreach (Word w in r)
                {
                    write(w.Text, w.Style);
                }
                if (r.CanFoldEndPart)
                {
                    Out("</div>\n");
                }
                else
                {
                    Out("<br>\n");
                }
            }
            Out("</div></td></tr></table>");

            return(sb.ToString());
        }
Ejemplo n.º 11
0
        private void InternalParseLine(int index, bool ParseKeywords)
        {
            if (mSyntaxDefinition == null)
            {
                return;
            }

            //
            //			if (ParseKeywords)
            //				return;
            //			ParseKeywords=true;
            SyntaxDocument doc          = Document;
            Row            Row          = doc[index];
            Span           oldEndSpan   = Row.endSpan;
            Span           oldStartSpan = Row.startSpan;
            bool           Fold         = !Row.IsCollapsed;


            if (Row.IsCollapsedEndPart)
            {
                //Row.expansion_EndSpan.Expanded = true;
                //Row.expansion_EndSpan.EndRow = null;
                Row.expansion_EndSpan.EndWord = null;
            }


            //set startsegment for this row
            if (index > 0)
            {
                Row.startSpan = Document[index - 1].endSpan;
            }
            else
            {
                if (Row.startSpan == null)
                {
                    Row.startSpan = new Span(Row)
                    {
                        spanDefinition = mSyntaxDefinition.mainSpanDefinition
                    };
                }
            }

            int  CurrentPosition = 0;
            Span currentSpan     = Row.startSpan;


            //kör tills vi kommit till slutet av raden..
            Row.endSpans.Clear();
            Row.startSpans.Clear();
            Row.Clear();
            //		bool HasEndSegment=false;

            while (true)
            {
                ScanResultSegment ChildSegment = GetNextChildSegment(Row,
                                                                     currentSpan, CurrentPosition);
                ScanResultSegment EndSegment = GetEndSegment(Row, currentSpan,
                                                             CurrentPosition);

                if ((EndSegment.HasContent && ChildSegment.HasContent &&
                     EndSegment.Position <= ChildSegment.Position) ||
                    (EndSegment.HasContent && ChildSegment.HasContent == false))
                {
                    //this is an end span

                    if (ParseKeywords)
                    {
                        string Text = Row.Text.Substring(CurrentPosition,
                                                         EndSegment.Position - CurrentPosition);
                        ParseText(Row, currentSpan, Text);
                    }

                    Span oldseg = currentSpan;
                    while (currentSpan != EndSegment.span)
                    {
                        Row.endSpans.Add(currentSpan);
                        currentSpan = currentSpan.Parent;
                    }
                    Row.endSpans.Add(currentSpan);

                    TextStyle st2 = currentSpan.Scope.Style;

                    ParseTools.AddPatternString(EndSegment.Token, Row, EndSegment.Pattern,
                                                st2, currentSpan, false);
                    while (oldseg != EndSegment.span)
                    {
                        oldseg.EndRow  = Row;
                        oldseg.EndWord = Row[Row.Count - 1];
                        oldseg         = oldseg.Parent;
                    }

                    currentSpan.EndRow  = Row;
                    currentSpan.EndWord = Row[Row.Count - 1];


                    if (currentSpan.Parent != null)
                    {
                        currentSpan = currentSpan.Parent;
                    }

                    CurrentPosition = EndSegment.Position + EndSegment.Token.Length;
                }
                else if (ChildSegment.HasContent)
                {
                    //this is a child block

                    if (ParseKeywords)
                    {
                        string Text = Row.Text.Substring(CurrentPosition,
                                                         ChildSegment.Position - CurrentPosition);
                        //TextStyle st=currentSpan.spanDefinition.Style;
                        ParseText(Row, currentSpan, Text);
                        //ParseTools.AddString (Text,Row,st,currentSpan);
                    }


                    var NewSeg = new Span
                    {
                        Parent         = currentSpan,
                        spanDefinition = ChildSegment.spanDefinition,
                        Scope          = ChildSegment.Scope
                    };

                    Row.startSpans.Add(NewSeg);

                    TextStyle st2 = NewSeg.Scope.Style;
                    ParseTools.AddPatternString(ChildSegment.Token, Row,
                                                ChildSegment.Pattern, st2, NewSeg, false);
                    NewSeg.StartRow  = Row;
                    NewSeg.StartWord = Row[Row.Count - 1];


                    currentSpan     = NewSeg;
                    CurrentPosition = ChildSegment.Position + ChildSegment.Token.Length;

                    if (ChildSegment.Scope.spawnSpanOnStart != null)
                    {
                        var SpawnSeg = new Span
                        {
                            Parent         = NewSeg,
                            spanDefinition = ChildSegment.Scope.spawnSpanOnStart,
                            Scope          = new Scope(),
                            StartWord      = NewSeg.StartWord
                        };
                        Row.startSpans.Add(SpawnSeg);
                        currentSpan = SpawnSeg;
                    }
                }
                else
                {
                    if (CurrentPosition < Row.Text.Length)
                    {
                        if (ParseKeywords)
                        {
                            //we did not find a childblock nor an endblock , just output the last pice of text
                            string Text = Row.Text.Substring(CurrentPosition);
                            //TextStyle st=currentSpan.spanDefinition.Style;
                            ParseText(Row, currentSpan, Text);
                            //ParseTools.AddString (Text,Row,st,currentSpan);
                        }
                    }
                    break;
                }
            }

            while (!currentSpan.spanDefinition.MultiLine)
            {
                Row.endSpans.Add(currentSpan);
                currentSpan = currentSpan.Parent;
            }

            Row.endSpan = currentSpan;
            Row.SetExpansionSegment();

            Row.RowState = ParseKeywords ? RowState.AllParsed : RowState.SpanParsed;

            if (IsSameButDifferent(index, oldStartSpan))
            {
                MakeSame(index);
                //if (!IsSameButDifferent(index))
                //	System.Diagnostics.Debugger.Break();
            }

            if (Row.CanFold)
            {
                Row.expansion_StartSpan.Expanded = Fold;
            }

            //dont flag next line as needs parsing if only parsing keywords
            if (!ParseKeywords)
            {
                if (oldEndSpan != null)
                {
                    if (Row.endSpan != oldEndSpan && index <= Document.Count - 2)
                    {
                        //if (Row.CanFold)
                        //	Row.expansion_StartSpan.Expanded = true;
                        Document[index + 1].AddToParseQueue();
                        Document.NeedResetRows = true;
                    }
                }
                else if (index <= Document.Count - 2)
                {
                    //if (Row.CanFold)
                    //	Row.expansion_StartSpan.Expanded = true;
                    Document[index + 1].AddToParseQueue();
                    Document.NeedResetRows = true;
                }
            }

            if (oldEndSpan != null)
            {
                //expand span if this line dont have an end word
                if (oldEndSpan.EndWord == null)
                {
                    oldEndSpan.Expanded = true;
                }
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Exports the content of a SyntaxDocument to a HTML formatted string
 /// </summary>
 /// <param name="doc">SyntaxDocument object to export from</param>
 /// <param name="ImagePath">File path tho the images to use in the HTML string</param>
 /// <returns></returns>
 public string Export(SyntaxDocument doc, string ImagePath)
 {
     return(this.Export(doc, System.Drawing.Color.Transparent, ImagePath, ""));
 }
Ejemplo n.º 13
0
        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);
            }
        }
        /// <summary>
        /// Sets the text async.
        /// </summary>
        private void SetAsyncEditorText()
        {
            Compona.SourceCode.SyntaxDocument doc = new SyntaxDocument();
            doc.Parser.Init(language);
            doc.Text = textValue;

            // be sure to set parse all, this allows the parsing to be done in this method.
            doc.ParseAll(true);

            this.Invoke(new SetEditorDocumentEventHandler(SetEditorDocument), new object[] {doc});
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.components = new System.ComponentModel.Container();
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(EditForm));
     this.statusBar1      = new System.Windows.Forms.StatusBar();
     this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
     this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
     this.statusBarPanel3 = new System.Windows.Forms.StatusBarPanel();
     this.sDoc            = new Alsing.SourceCode.SyntaxDocument(this.components);
     this.tbrSettings     = new System.Windows.Forms.ToolBar();
     this.btnWhitespace   = new System.Windows.Forms.ToolBarButton();
     this.btnTabGuides    = new System.Windows.Forms.ToolBarButton();
     this.btnFolding      = new System.Windows.Forms.ToolBarButton();
     this.btnSettings     = new System.Windows.Forms.ToolBarButton();
     this.imlIcons        = new System.Windows.Forms.ImageList(this.components);
     this.sBox            = new Alsing.Windows.Forms.SyntaxBoxControl();
     this.syntaxDocument1 = new Alsing.SourceCode.SyntaxDocument(this.components);
     ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
     ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
     ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).BeginInit();
     this.SuspendLayout();
     //
     // statusBar1
     //
     this.statusBar1.Location = new System.Drawing.Point(0, 471);
     this.statusBar1.Name     = "statusBar1";
     this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
         this.statusBarPanel1,
         this.statusBarPanel2,
         this.statusBarPanel3
     });
     this.statusBar1.ShowPanels = true;
     this.statusBar1.Size       = new System.Drawing.Size(504, 22);
     this.statusBar1.TabIndex   = 1;
     //
     // statusBarPanel1
     //
     this.statusBarPanel1.Name  = "statusBarPanel1";
     this.statusBarPanel1.Width = 200;
     //
     // statusBarPanel2
     //
     this.statusBarPanel2.Name  = "statusBarPanel2";
     this.statusBarPanel2.Width = 200;
     //
     // statusBarPanel3
     //
     this.statusBarPanel3.Name = "statusBarPanel3";
     //
     // sDoc
     //
     this.sDoc.Lines = new string[] {
         "abc"
     };
     this.sDoc.MaxUndoBufferSize = 1000;
     this.sDoc.Modified          = false;
     this.sDoc.UndoStep          = 0;
     this.sDoc.Change           += new System.EventHandler(this.sDoc_Change);
     this.sDoc.ModifiedChanged  += new System.EventHandler(this.sDoc_ModifiedChanged);
     //
     // tbrSettings
     //
     this.tbrSettings.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
     this.tbrSettings.AutoSize   = false;
     this.tbrSettings.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
         this.btnWhitespace,
         this.btnTabGuides,
         this.btnFolding,
         this.btnSettings
     });
     this.tbrSettings.Divider        = false;
     this.tbrSettings.Dock           = System.Windows.Forms.DockStyle.Left;
     this.tbrSettings.DropDownArrows = true;
     this.tbrSettings.ImageList      = this.imlIcons;
     this.tbrSettings.Location       = new System.Drawing.Point(0, 0);
     this.tbrSettings.Name           = "tbrSettings";
     this.tbrSettings.ShowToolTips   = true;
     this.tbrSettings.Size           = new System.Drawing.Size(25, 471);
     this.tbrSettings.TabIndex       = 2;
     this.tbrSettings.ButtonClick   += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tbrSettings_ButtonClick);
     //
     // btnWhitespace
     //
     this.btnWhitespace.ImageIndex  = 1;
     this.btnWhitespace.Name        = "btnWhitespace";
     this.btnWhitespace.Style       = System.Windows.Forms.ToolBarButtonStyle.ToggleButton;
     this.btnWhitespace.ToolTipText = "Toggle Whitespace On/Off";
     //
     // btnTabGuides
     //
     this.btnTabGuides.ImageIndex  = 0;
     this.btnTabGuides.Name        = "btnTabGuides";
     this.btnTabGuides.Style       = System.Windows.Forms.ToolBarButtonStyle.ToggleButton;
     this.btnTabGuides.ToolTipText = "Toggle Tab guides On/Off";
     //
     // btnFolding
     //
     this.btnFolding.ImageIndex  = 2;
     this.btnFolding.Name        = "btnFolding";
     this.btnFolding.Pushed      = true;
     this.btnFolding.Style       = System.Windows.Forms.ToolBarButtonStyle.ToggleButton;
     this.btnFolding.ToolTipText = "Toggle Folding On/Off";
     //
     // btnSettings
     //
     this.btnSettings.Name = "btnSettings";
     this.btnSettings.Text = "S";
     //
     // imlIcons
     //
     this.imlIcons.ImageStream      = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imlIcons.ImageStream")));
     this.imlIcons.TransparentColor = System.Drawing.Color.Transparent;
     this.imlIcons.Images.SetKeyName(0, "");
     this.imlIcons.Images.SetKeyName(1, "");
     this.imlIcons.Images.SetKeyName(2, "");
     //
     // sBox
     //
     this.sBox.ActiveView           = Alsing.Windows.Forms.ActiveView.BottomRight;
     this.sBox.AutoListPosition     = null;
     this.sBox.AutoListSelectedText = "a123";
     this.sBox.AutoListVisible      = false;
     this.sBox.BackColor            = System.Drawing.Color.White;
     this.sBox.BorderStyle          = Alsing.Windows.Forms.BorderStyle.None;
     this.sBox.ChildBorderColor     = System.Drawing.Color.White;
     this.sBox.ChildBorderStyle     = Alsing.Windows.Forms.BorderStyle.None;
     this.sBox.CopyAsRTF            = false;
     this.sBox.Dock                 = System.Windows.Forms.DockStyle.Fill;
     this.sBox.Document             = this.sDoc;
     this.sBox.FontName             = "Courier new";
     this.sBox.ImeMode              = System.Windows.Forms.ImeMode.NoControl;
     this.sBox.InfoTipCount         = 1;
     this.sBox.InfoTipPosition      = null;
     this.sBox.InfoTipSelectedIndex = 1;
     this.sBox.InfoTipVisible       = false;
     this.sBox.Location             = new System.Drawing.Point(25, 0);
     this.sBox.LockCursorUpdate     = false;
     this.sBox.Name                 = "sBox";
     this.sBox.ScopeIndicatorColor  = System.Drawing.Color.Black;
     this.sBox.ShowScopeIndicator   = false;
     this.sBox.Size                 = new System.Drawing.Size(479, 471);
     this.sBox.SmoothScroll         = false;
     this.sBox.SplitviewH           = -4;
     this.sBox.SplitviewV           = -4;
     this.sBox.TabGuideColor        = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(219)))), ((int)(((byte)(214)))));
     this.sBox.TabIndex             = 3;
     this.sBox.Text                 = "syntaxBoxControl1";
     this.sBox.WhitespaceColor      = System.Drawing.SystemColors.ControlDark;
     //
     // syntaxDocument1
     //
     this.syntaxDocument1.Lines = new string[] {
         ""
     };
     this.syntaxDocument1.MaxUndoBufferSize = 1000;
     this.syntaxDocument1.Modified          = false;
     this.syntaxDocument1.UndoStep          = 0;
     //
     // EditForm
     //
     this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
     this.ClientSize        = new System.Drawing.Size(504, 493);
     this.Controls.Add(this.sBox);
     this.Controls.Add(this.tbrSettings);
     this.Controls.Add(this.statusBar1);
     this.Icon     = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
     this.Name     = "EditForm";
     this.Text     = "EditForm";
     this.Closing += new System.ComponentModel.CancelEventHandler(this.EditForm_Closing);
     ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
     ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
     ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).EndInit();
     this.ResumeLayout(false);
 }
 /// <summary>
 /// Sets the editor document.
 /// </summary>
 /// <param name="document"> The SyntaxDocument to use.</param>
 private void SetEditorDocument(SyntaxDocument document)
 {
     this.txtEditor.Document = document;
 }
Ejemplo n.º 17
0
 public EditableDocumentBaseUI(EditableDocumentBase parentDoc, SyntaxDocument doc) :
     base()
 {
     _parentDoc = parentDoc;
     Initialize(doc);
 }