Пример #1
0
 public CustomLexter(TextEditor textEditor, AbstractFoldingStrategy foldingStrategy, IIndentationStrategy indentationStrategy, CodeCompletionList codeCompletionList)
     : base(textEditor)
 {
     FoldingStrategy     = foldingStrategy;
     IndentationStrategy = indentationStrategy;
     CodeCompletionList  = codeCompletionList;
 }
Пример #2
0
 void SetStrategyFromExtension(string extension, IIndentationStrategy indentation /*, AbstractFoldingStrategy folding*/, Brush background, Brush foreground)
 {
     SetStrategy(
         HighlightingManager.Instance.GetDefinitionByExtension(extension),
         indentation, /*folding,*/ background, foreground
         );
 }
Пример #3
0
		/// <summary>
		/// Initializes a new instance of the <see cref="AvalonEditor"/> class.
		/// </summary>
		/// <exception cref="System.InvalidOperationException">Failed to load syntax definition</exception>
		public AvalonEditor()
		{
			_foldingManager = FoldingManager.Install(TextArea);
			_folding = new XmlFoldingStrategy();

			_htmlIndent = new HtmlIndentationStrategy();
			_defaultIndent = new DefaultIndentationStrategy();

			AutoIndent = true;
			AutoIndentAmount = 1;

			ShowLineNumbers = true;

			// Load our HTML highlighting
			using (var s = typeof(AvalonEditor).Assembly.GetManifestResourceStream(typeof(AvalonEditor), "HtmlHighlighting.xml"))
			{
				if (s == null)
					throw new InvalidOperationException("Failed to load syntax definition");
				using (var r = XmlReader.Create(s))
				{
					var highlightingDefinition = HighlightingLoader.Load(r, HighlightingManager.Instance);

					SyntaxHighlighting = highlightingDefinition;
				}
			}

            IsDirty = false;

            Task.Factory.StartNew(FoldingUpdateLoop);
		}
Пример #4
0
        void SetStrategy(IHighlightingDefinition highlighter, IIndentationStrategy indentation /*, AbstractFoldingStrategy folding*/, Brush background, Brush foreground)
        {
            SyntaxHighlighting           = highlighter;
            TextArea.IndentationStrategy = indentation;
//			FoldingStrategy = folding;
            Background = background;
            Foreground = foreground;
        }
Пример #5
0
        public void RegisterSourceFile(AvaloniaEdit.TextEditor editor, ISourceFile file, TextDocument doc)
        {
            CPlusPlusDataAssociation association = null;

            if (dataAssociations.TryGetValue(file, out association))
            {
                throw new Exception("Source file already registered with language service.");
            }

            IndentationStrategy = new CSharpIndentationStrategy(editor.Options);

            association = new CPlusPlusDataAssociation(doc);
            dataAssociations.Add(file, association);

            association.TextInputHandler = (sender, e) =>
            {
                if (editor.Document == doc)
                {
                    editor.BeginChange();
                    OpenBracket(editor, editor.Document, e.Text);
                    CloseBracket(editor, editor.Document, e.Text);

                    switch (e.Text)
                    {
                    case "}":
                    case ";":
                        editor.CaretOffset = Format(editor.Document, 0, (uint)editor.Document.TextLength, editor.CaretOffset);
                        break;

                    case "{":
                        var lineCount = editor.Document.LineCount;
                        var offset    = Format(editor.Document, 0, (uint)editor.Document.TextLength, editor.CaretOffset);

                        // suggests clang format didnt do anything, so we can assume not moving to new line.
                        if (lineCount != editor.Document.LineCount)
                        {
                            if (offset <= editor.Document.TextLength)
                            {
                                var newLine = editor.Document.GetLineByOffset(offset);
                                editor.CaretOffset = newLine.PreviousLine.EndOffset;
                            }
                        }
                        else
                        {
                            editor.CaretOffset = offset;
                        }
                        break;
                    }

                    editor.EndChange();
                }
            };

            editor.TextArea.TextEntered += association.TextInputHandler;
        }
Пример #6
0
 public static CommandIndentationStrategy AsCommandIndentationStrategy(this IIndentationStrategy strategy)
 {
     if (strategy is CommandIndentationStrategy)
     {
         return((CommandIndentationStrategy)strategy);
     }
     else
     {
         throw new ArgumentException("strategy");
     }
 }
Пример #7
0
        static public void GetStrategyFromName2(this TextEditor editor, IEditorContext control)
        {
            FoldingManager.Uninstall(control.FoldingManager);
            AbstractFoldingStrategy NewFoldingStrategy     = null;
            IIndentationStrategy    NewIndentationStrategy = null;

            if (editor.SyntaxHighlighting == null)
            {
            }                                                    //control.FoldingStrategy = null;
            else
            {
                switch (editor.SyntaxHighlighting.Name)
                {
                case "XML":
                    NewFoldingStrategy     = new XmlFoldingStrategy();
                    NewIndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.DefaultIndentationStrategy();
                    break;

                case "C#":
                case "C++":
                case "PHP":
                case "Java":
                    NewFoldingStrategy     = new CSharpPragmaRegionFoldingStrategy();
                    NewIndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy();
                    break;

                default:
                    NewFoldingStrategy     = new CSharpPragmaRegionFoldingStrategy();
                    NewIndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.DefaultIndentationStrategy();
                    break;
                }
            }
            //control.FoldingStrategy is not assigned
            //control.FoldingStrategy,editor.TextArea.IndentationStrategy
            if (NewFoldingStrategy != null)
            {
                control.FoldingStrategy = NewFoldingStrategy;
                if (control.FoldingManager == null)
                {
                    control.FoldingManager = FoldingManager.Install(editor.TextArea);
                }

                control.FoldingStrategy.UpdateFoldings(control.FoldingManager, editor.Document);
            }
            else
            {
                if (control.FoldingManager != null)
                {
                    FoldingManager.Uninstall(control.FoldingManager);
                    control.FoldingManager = null;
                }
            }
        }
Пример #8
0
        public void Indent(IIndentationStrategy indentationStrategy)
        {
            if (CaretIndex >= 0 && CaretIndex < TextDocument.TextLength)
            {
                if (TextDocument.GetCharAt(CaretIndex) == '}')
                {
                    TextDocument.Insert(CaretIndex, Environment.NewLine);
                    CaretIndex--;

                    var currentLine = TextDocument.GetLineByOffset(CaretIndex);

                    CaretIndex = indentationStrategy.IndentLine(TextDocument, currentLine, CaretIndex);
                    CaretIndex = indentationStrategy.IndentLine(TextDocument, currentLine.NextLine.NextLine, CaretIndex);
                    CaretIndex = indentationStrategy.IndentLine(TextDocument, currentLine.NextLine, CaretIndex);
                }

                var newCaret = indentationStrategy.IndentLine(TextDocument,
                                                              TextDocument.GetLineByOffset(CaretIndex), CaretIndex);

                CaretIndex = newCaret;
            }
        }
Пример #9
0
        static public void SetStrategy(this Editor editor, IHighlightingDefinition highlighter, IIndentationStrategy indentation /*, AbstractFoldingStrategy folding*/, Brush background, Brush foreground)
        {
            editor.SyntaxHighlighting           = highlighter;
            editor.TextArea.IndentationStrategy = indentation;
//			editor.FoldingStrategy = folding;
            editor.Background = background;
            editor.Foreground = foreground;
        }
        public void RegisterSourceFile(IEditor editor)
        {
            if (clangAccessJobRunner == null)
            {
                clangAccessJobRunner = new JobRunner();

                Task.Factory.StartNew(() => { clangAccessJobRunner.RunLoop(new CancellationToken()); });
            }

            if (dataAssociations.TryGetValue(editor.SourceFile, out CPlusPlusDataAssociation association))
            {
                throw new Exception("Source file already registered with language service.");
            }

            IndentationStrategy = new CSharpIndentationStrategy(new AvaloniaEdit.TextEditorOptions {
                ConvertTabsToSpaces = true
            });

            association = new CPlusPlusDataAssociation();
            dataAssociations.Add(editor.SourceFile, association);

            association.TextInputHandler = (sender, e) =>
            {
                switch (e.Text)
                {
                case "}":
                case ";":
                    editor.IndentLine(editor.Line);
                    break;

                case "{":
                    if (IndentationStrategy != null)
                    {
                        editor.IndentLine(editor.Line);
                    }
                    break;
                }

                OpenBracket(editor, editor.Document, e.Text);
                CloseBracket(editor, editor.Document, e.Text);
            };

            association.BeforeTextInputHandler = (sender, e) =>
            {
                switch (e.Text)
                {
                case "\n":
                case "\r\n":
                    var nextChar = ' ';

                    if (editor.CaretOffset != editor.Document.TextLength)
                    {
                        nextChar = editor.Document.GetCharAt(editor.CaretOffset);
                    }

                    if (nextChar == '}')
                    {
                        var newline = "\r\n";     // TextUtilities.GetNewLineFromDocument(editor.Document, editor.TextArea.Caret.Line);
                        editor.Document.Insert(editor.CaretOffset, newline);

                        editor.Document.TrimTrailingWhiteSpace(editor.Line - 1);

                        editor.IndentLine(editor.Line);

                        editor.CaretOffset -= newline.Length;
                    }
                    break;
                }
            };

            editor.TextEntered  += association.TextInputHandler;
            editor.TextEntering += association.BeforeTextInputHandler;
        }