Beispiel #1
0
        public override void Attach(ITextEditor editor)
        {
            base.Attach(editor);

            // try to access the ICSharpCode.AvalonEdit.Rendering.TextView
            // of this ITextEditor
            this.textView = editor.GetService(typeof(TextView)) as TextView;

            // if editor is not an AvalonEdit.TextEditor
            // GetService returns null
            if (textView != null)
            {
                if (SD.Workbench != null)
                {
//					if (XamlBindingOptions.UseAdvancedHighlighting) {
//						colorizer = new XamlColorizer(editor, textView);
//						// attach the colorizer
//						textView.LineTransformers.Add(colorizer);
//					}
                    // add the XamlOutlineContentHost, which manages the tree view
                    contentHost = new XamlOutlineContentHost(editor);
                    textView.Services.AddService(typeof(IOutlineContentHost), contentHost);
                }
                // add ILanguageBinding
                textView.Services.AddService(typeof(XamlTextEditorExtension), this);
            }

            SD.ParserService.ParseInformationUpdated += ParseInformationUpdated;
        }
Beispiel #2
0
        public void Attach(ITextEditor editor)
        {
            this.editor       = editor;
            inspectionManager = new IssueManager(editor);
            codeManipulation  = new CodeManipulation(editor);
            renderer          = new CaretReferenceHighlightRenderer(editor);

            // Patch editor options (indentation) to project-specific settings
            if (!editor.ContextActionProviders.IsReadOnly)
            {
                contextActionProviders = AddInTree.BuildItems <IContextActionProvider>("/SharpDevelop/ViewContent/TextEditor/C#/ContextActions", null);
                editor.ContextActionProviders.AddRange(contextActionProviders);
            }

            // Create instance of options adapter and register it as service
            var formattingPolicy = CSharpFormattingPolicies.Instance.GetProjectOptions(
                SD.ProjectService.FindProjectContainingFile(editor.FileName));

            options = new CodeEditorFormattingOptionsAdapter(editor.Options, formattingPolicy.OptionsContainer);
            var textEditor = editor.GetService <TextEditor>();

            if (textEditor != null)
            {
                var textViewServices = textEditor.TextArea.TextView.Services;

                // Unregister any previous ITextEditorOptions instance from editor, if existing, register our impl.
                textViewServices.RemoveService(typeof(ITextEditorOptions));
                textViewServices.AddService(typeof(ITextEditorOptions), options);

                // Set TextEditor's options to same object
                originalEditorOptions = textEditor.Options;
                textEditor.Options    = options;
            }
        }
		public void Attach(ITextEditor editor)
		{
			this.editor = editor;
			inspectionManager = new IssueManager(editor);
			codeManipulation = new CodeManipulation(editor);
			renderer = new CaretReferenceHighlightRenderer(editor);
			
			// Patch editor options (indentation) to project-specific settings
			if (!editor.ContextActionProviders.IsReadOnly) {
				contextActionProviders = AddInTree.BuildItems<IContextActionProvider>("/SharpDevelop/ViewContent/TextEditor/C#/ContextActions", null);
				editor.ContextActionProviders.AddRange(contextActionProviders);
			}
			
			// Create instance of options adapter and register it as service
			var formattingPolicy = CSharpFormattingPolicies.Instance.GetProjectOptions(SD.ProjectService.FindProjectContainingFile(editor.FileName));
			var textEditor = editor.GetService<TextEditor>();
			
			if (textEditor != null) {
				options = new CodeEditorFormattingOptionsAdapter(textEditor.Options, editor.Options, formattingPolicy.OptionsContainer);
				var textViewServices = textEditor.TextArea.TextView.Services;
				
				// Unregister any previous ITextEditorOptions instance from editor, if existing, register our impl.
				textViewServices.RemoveService(typeof(ITextEditorOptions));
				textViewServices.AddService(typeof(ITextEditorOptions), options);
				
				// Set TextEditor's options to same object
				originalEditorOptions = textEditor.Options;
				textEditor.Options = options.TextEditorOptions;
			}
		}
		protected void OpenAtPosition(ITextEditor editor, int line, int column, bool openAtWordStart)
		{
			var editorUIService = editor == null ? null : editor.GetService(typeof(IEditorUIService)) as IEditorUIService;
			if (editorUIService != null) {
				var document = editor.Document;
				int offset = document.PositionToOffset(line, column);
				if (openAtWordStart) {
					int wordStart = document.FindPrevWordStart(offset);
					if (wordStart != -1) {
						var wordStartLocation = document.OffsetToPosition(wordStart);
						line = wordStartLocation.Line;
						column = wordStartLocation.Column;
					}
				}
				this.Placement = PlacementMode.Absolute;
				try
				{
					var caretScreenPos = editorUIService.GetScreenPosition(line, column);
					this.HorizontalOffset = caretScreenPos.X;
					this.VerticalOffset = caretScreenPos.Y;
				}
				catch
				{
					this.Placement = PlacementMode.MousePoint;
				}
				
			} else {
				// if no editor information, open at mouse positions
				this.Placement = PlacementMode.MousePoint;
			}
			this.Open();
		}
        InsertCtorDialog CreateDialog(InsertionContext context)
        {
            ITextEditor textEditor = context.TextArea.GetService(typeof(ITextEditor)) as ITextEditor;

            if (textEditor == null)
            {
                return(null);
            }

            IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService;

            if (uiService == null)
            {
                return(null);
            }

            ITextAnchor anchor = textEditor.Document.CreateAnchor(context.InsertionPosition);

            anchor.MovementType = AnchorMovementType.BeforeInsertion;

            InsertCtorDialog dialog = new InsertCtorDialog(context, textEditor, anchor);

            dialog.Element = uiService.CreateInlineUIElement(anchor, dialog);

            return(dialog);
        }
        void ITextEditorExtension.Attach(ITextEditor editor)
        {
            _outlineContent = new ModuleOutlineControl(editor);

            _textView = editor.GetService(typeof(TextView)) as TextView;
            _textView.Services.AddService(typeof(IOutlineContentHost), _outlineContent);
        }
		public override void Attach(ITextEditor editor)
		{
			base.Attach(editor);
			
			// try to access the ICSharpCode.AvalonEdit.Rendering.TextView
			// of this ITextEditor
			this.textView = editor.GetService(typeof(TextView)) as TextView;
			
			// if editor is not an AvalonEdit.TextEditor
			// GetService returns null
			if (textView != null) {
				if (SD.Workbench != null) {
//					if (XamlBindingOptions.UseAdvancedHighlighting) {
//						colorizer = new XamlColorizer(editor, textView);
//						// attach the colorizer
//						textView.LineTransformers.Add(colorizer);
//					}
					// add the XamlOutlineContentHost, which manages the tree view
					contentHost = new XamlOutlineContentHost(editor);
					textView.Services.AddService(typeof(IOutlineContentHost), contentHost);
				}
				// add ILanguageBinding
				textView.Services.AddService(typeof(XamlTextEditorExtension), this);
			}
			
			SD.ParserService.ParseInformationUpdated += ParseInformationUpdated;
		}
        public CodeSnippetCompletionWindow(ITextEditor editor, ICompletionItemList list)
            : base(editor, editor.GetService(typeof(TextArea)) as TextArea, list)
        {
            this.snippetInput = new TextBox();

            DockPanel panel = new DockPanel()
            {
                Children =
                {
                    snippetInput
                }
            };

            this.Content = panel;

            panel.Children.Add(CompletionList);

            snippetInput.SetValue(DockPanel.DockProperty, Dock.Top);

            this.Width  = 150;
            this.Height = 200;

            this.Loaded += delegate { Keyboard.Focus(snippetInput); };
            this.snippetInput.PreviewKeyDown += new KeyEventHandler(CodeSnippetCompletionWindowPreviewKeyDown);
            this.snippetInput.TextChanged    += new TextChangedEventHandler(CodeSnippetCompletionWindow_TextChanged);
        }
        public static void SetPosition(Popup popup, ITextEditor editor, int line, int column, bool openAtWordStart = false)
        {
            var editorUIService = editor == null ? null : editor.GetService(typeof(IEditorUIService)) as IEditorUIService;

            if (editorUIService != null)
            {
                var document = editor.Document;
                int offset   = document.GetOffset(line, column);
                if (openAtWordStart)
                {
                    int wordStart = document.FindPrevWordStart(offset);
                    if (wordStart != -1)
                    {
                        var wordStartLocation = document.GetLocation(wordStart);
                        line   = wordStartLocation.Line;
                        column = wordStartLocation.Column;
                    }
                }
                var caretScreenPos = editorUIService.GetScreenPosition(line, column);
                popup.HorizontalOffset = caretScreenPos.X;
                popup.VerticalOffset   = caretScreenPos.Y;
                popup.Placement        = PlacementMode.Absolute;
            }
            else
            {
                // if no editor information, open at mouse positions
                popup.Placement = PlacementMode.MousePoint;
            }
        }
        internal static CreatePropertiesDialog CreateDialog(InsertionContext context)
        {
            ITextEditor textEditor = context.TextArea.GetService(typeof(ITextEditor)) as ITextEditor;

            if (textEditor == null)
            {
                return(null);
            }

            using (textEditor.Document.OpenUndoGroup()) {
                IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService;

                if (uiService == null)
                {
                    return(null);
                }

                ITextAnchor anchor = textEditor.Document.CreateAnchor(context.InsertionPosition);
                anchor.MovementType = AnchorMovementType.BeforeInsertion;

                CreatePropertiesDialog dialog = new CreatePropertiesDialog(context, textEditor, anchor);

                dialog.Element = uiService.CreateInlineUIElement(anchor, dialog);

                // Add creation of this inline dialog as undoable operation
                TextDocument document = textEditor.Document as TextDocument;
                if (document != null)
                {
                    document.UndoStack.Push(dialog.UndoableCreationOperation);
                }

                return(dialog);
            }
        }
        void ITextEditorExtension.Attach(ITextEditor editor)
        {
            _outlineContent = new ModuleOutlineControl(editor);

            _textView = editor.GetService(typeof(TextView)) as TextView;
            _textView.Services.AddService(typeof(IOutlineContentHost), _outlineContent);
        }
Beispiel #12
0
 public IssueManager(ITextEditor editor)
 {
     this.editor        = editor;
     this.markerService = editor.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
     //SD.ParserService.ParserUpdateStepFinished += ParserService_ParserUpdateStepFinished;
     SD.ParserService.ParseInformationUpdated += new EventHandler <ParseInformationEventArgs>(SD_ParserService_ParseInformationUpdated);
     editor.ContextActionProviders.Add(this);
 }
		protected override void Run(ITextEditor textEditor, RefactoringProvider provider)
		{
			new Snippet {
				Elements = {
					new InlineRefactorSnippetElement(context => CreateProperties.CreateDialog(context), "")
				}
			}.Insert((TextArea)textEditor.GetService(typeof(TextArea)));
		}
 public void Attach(ITextEditor editor)
 {
     TextArea textArea = editor.GetService(typeof(TextArea)) as TextArea;
     if (textArea != null) {
         panel = SearchPanel.Install(textArea);
         panel.SearchOptionsChanged += SearchOptionsChanged;
     }
 }
 protected override void Run(ITextEditor textEditor, RefactoringProvider provider)
 {
     new Snippet {
         Elements =
         {
             new InlineRefactorSnippetElement(context => CreateProperties.CreateDialog(context), "")
         }
     }.Insert((TextArea)textEditor.GetService(typeof(TextArea)));
 }
Beispiel #16
0
 public override void Attach(ITextEditor editor)
 {
     base.Attach(editor);
                 te = editor.GetService(typeof(TextEditor)) as TextEditor;
                 if ( te !=null){
                         ta = te.TextArea;
                         vh = new VimHandler(ta, editor.FileName);
                         ta.ActiveInputHandler = vh;
                 }
 }
Beispiel #17
0
        public void Dispose()
        {
            this.editor.SelectionChanged -= CodeManipulationSelectionChanged;
            TextArea area = (TextArea)editor.GetService(typeof(TextArea));

            foreach (var b in bindings)
            {
                area.DefaultInputHandler.CommandBindings.Remove(b);
            }
        }
        public void Attach(ITextEditor editor)
        {
            TextArea textArea = editor.GetService(typeof(TextArea)) as TextArea;

            if (textArea != null)
            {
                panel = SearchPanel.Install(textArea);
                panel.SearchOptionsChanged += SearchOptionsChanged;
            }
        }
Beispiel #19
0
 public IssueManager(ITextEditor editor)
 {
     this.editor        = editor;
     this.markerService = editor.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
     //SD.ParserService.ParserUpdateStepFinished += ParserService_ParserUpdateStepFinished;
     SD.ParserService.ParseInformationUpdated             += SD_ParserService_ParseInformationUpdated;
     SD.ParserService.LoadSolutionProjectsThread.Finished += RerunAnalysis;
     IssueSeveritySettingsSaved += RerunAnalysis;             // re-run analysis when settings are changed
     editor.ContextActionProviders.Add(this);
 }
		public void Attach(ITextEditor editor)
		{
			// ITextEditor is SharpDevelop's abstraction of the text editor.
			// We use GetService() to get the underlying AvalonEdit instance.
			textView = editor.GetService(typeof(TextView)) as TextView;
			if (textView != null) {
				g = new ImageElementGenerator(Path.GetDirectoryName(editor.FileName));
				textView.ElementGenerators.Add(g);
			}
		}
 public void Attach(ITextEditor editor)
 {
     // ITextEditor is SharpDevelop's abstraction of the text editor.
     // We use GetService() to get the underlying AvalonEdit instance.
     textView = editor.GetService(typeof(TextView)) as TextView;
     if (textView != null)
     {
         g = new ImageElementGenerator(Path.GetDirectoryName(editor.FileName));
         textView.ElementGenerators.Add(g);
     }
 }
Beispiel #22
0
        public static PinLayer GetPinlayer(ITextEditor editor)
        {
            var textEditor = editor.GetService(typeof(TextEditor)) as TextEditor;

            if (textEditor != null)
            {
                return(textEditor.TextArea.TextView.Layers[3] as PinLayer);
            }

            return(null);
        }
        InsertCtorDialog CreateDialog(InsertionContext context)
        {
            ITextEditor textEditor = context.TextArea.GetService(typeof(ITextEditor)) as ITextEditor;

            if (textEditor == null)
            {
                return(null);
            }

            IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService;

            if (uiService == null)
            {
                return(null);
            }

            ParseInformation parseInfo = ParserService.GetParseInformation(textEditor.FileName);

            if (parseInfo == null)
            {
                return(null);
            }

            CodeGenerator generator = parseInfo.CompilationUnit.Language.CodeGenerator;

            // cannot use insertion position at this point, because it might not be
            // valid, because we are still generating the elements.
            // DOM is not updated
            ICSharpCode.AvalonEdit.Document.TextLocation loc = context.Document.GetLocation(context.StartPosition);

            IClass current = parseInfo.CompilationUnit.GetInnermostClass(loc.Line, loc.Column);

            if (current == null)
            {
                return(null);
            }

            List <PropertyOrFieldWrapper> parameters = CreateCtorParams(current).ToList();

            if (!parameters.Any())
            {
                return(null);
            }

            ITextAnchor anchor = textEditor.Document.CreateAnchor(context.InsertionPosition);

            anchor.MovementType = AnchorMovementType.BeforeInsertion;

            InsertCtorDialog dialog = new InsertCtorDialog(context, textEditor, anchor, current, parameters);

            dialog.Element = uiService.CreateInlineUIElement(anchor, dialog);

            return(dialog);
        }
Beispiel #24
0
 public override void Attach(ITextEditor editor)
 {
     base.Attach(editor);
     textArea = editor.GetService(typeof(TextArea)) as TextArea;
     if (textArea != null)
     {
         handler = new SearchInputHandler(textArea);
         textArea.DefaultInputHandler.NestedInputHandlers.Add(handler);
         handler.SearchOptionsChanged += SearchOptionsChanged;
     }
 }
Beispiel #25
0
 public override void Attach(ITextEditor editor)
 {
     base.Attach(editor);
     te = editor.GetService(typeof(TextEditor)) as TextEditor;
     if (te != null)
     {
         ta = te.TextArea;
         vh = new VimHandler(ta, editor.FileName);
         ta.ActiveInputHandler = vh;
     }
 }
		public override void Attach(ITextEditor editor)
		{
			// HACK: disable SharpDevelop's built-in folding
			codeEditorView = editor.GetService(typeof(AvalonEdit.TextEditor)) as AvalonEdit.AddIn.CodeEditorView;
			DisableParseInformationFolding();
				
			foldingManager = new XmlFoldingManager(editor);
			foldingManager.UpdateFolds();
			foldingManager.Start();
			
			base.Attach(editor);
		}
        public override void Attach(ITextEditor editor)
        {
            // HACK: disable SharpDevelop's built-in folding
            codeEditorView = editor.GetService(typeof(AvalonEdit.TextEditor)) as AvalonEdit.AddIn.CodeEditorView;
            DisableParseInformationFolding();

            foldingManager = new XmlFoldingManager(editor);
            foldingManager.UpdateFolds();
            foldingManager.Start();

            base.Attach(editor);
        }
Beispiel #28
0
        public override void Run()
        {
            ITextEditor editor = SD.GetActiveViewContentService <ITextEditor>();

            if (editor != null)
            {
                IBookmarkMargin margin = editor.GetService(typeof(IBookmarkMargin)) as IBookmarkMargin;
                if (editor != null && margin != null)
                {
                    Run(editor, margin);
                }
            }
        }
		public SnippetCompletionItem(ITextEditor textEditor, CodeSnippet codeSnippet)
		{
			if (textEditor == null)
				throw new ArgumentNullException("textEditor");
			if (codeSnippet == null)
				throw new ArgumentNullException("codeSnippet");
			this.textEditor = textEditor;
			this.textArea = textEditor.GetService(typeof(TextArea)) as TextArea;
			if (textArea == null)
				throw new ArgumentException("textEditor must be an AvalonEdit text editor");
			this.codeSnippet = codeSnippet;
			this.Priority = CodeCompletionDataUsageCache.GetPriority("snippet" + codeSnippet.Name, true);
		}
Beispiel #30
0
        public override void Run()
        {
            ITextEditorProvider provider       = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider;
            ITextEditor         editor         = provider.TextEditor;
            FoldingManager      foldingManager = editor.GetService(typeof(FoldingManager)) as FoldingManager;

            if (foldingManager != null)
            {
                foreach (FoldingSection fm in foldingManager.AllFoldings)
                {
                    fm.IsFolded = ParserFoldingStrategy.IsDefinition(fm);
                }
            }
        }
Beispiel #31
0
        public override void Run()
        {
            ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider;

            if (provider != null)
            {
                ITextEditor     editor = provider.TextEditor;
                IBookmarkMargin margin = editor.GetService(typeof(IBookmarkMargin)) as IBookmarkMargin;
                if (editor != null && margin != null)
                {
                    Run(editor, margin);
                }
            }
        }
		public CaretReferenceHighlightRenderer(ITextEditor editor)
		{
			if (editor == null)
				throw new ArgumentNullException("editor");
			this.editor = editor;
			this.textView = editor.GetService<TextView>();
			this.borderPen = new Pen(new SolidColorBrush(DefaultBorderColor), borderThickness);
			this.backgroundBrush = new SolidColorBrush(DefaultFillColor);
			this.borderPen.Freeze();
			this.backgroundBrush.Freeze();
			editor.Caret.LocationChanged += CaretLocationChanged;
			textView.VisualLinesChanged += VisualLinesChanged;
			SD.ParserService.ParseInformationUpdated += ParseInformationUpdated;
			SD.ParserService.LoadSolutionProjectsThread.Finished += LoadSolutionProjectsThreadFinished;
			this.textView.BackgroundRenderers.Add(this);
		}
		public CodeManipulation(ITextEditor editor)
		{
			this.editor = editor;
			this.editor.SelectionChanged += CodeManipulationSelectionChanged;
			
			TextArea area = (TextArea)editor.GetService(typeof(TextArea));
			
			bindings = new List<CommandBinding> {
				new CommandBinding(ExtendSelectionCommand, ExtendSelectionExecuted),
				new CommandBinding(ShrinkSelectionCommand, ShrinkSelectionExecuted),
				new CommandBinding(MoveStatementUpCommand, MoveStatementUpExecuted),
				new CommandBinding(MoveStatementDownCommand, MoveStatementDownExecuted)
			};
			
			area.DefaultInputHandler.CommandBindings.AddRange(bindings);
		}
Beispiel #34
0
        public CodeManipulation(ITextEditor editor)
        {
            this.editor = editor;
            this.editor.SelectionChanged += CodeManipulationSelectionChanged;

            TextArea area = (TextArea)editor.GetService(typeof(TextArea));

            bindings = new List <CommandBinding> {
                new CommandBinding(ExtendSelectionCommand, ExtendSelectionExecuted),
                new CommandBinding(ShrinkSelectionCommand, ShrinkSelectionExecuted),
                new CommandBinding(MoveStatementUpCommand, MoveStatementUpExecuted),
                new CommandBinding(MoveStatementDownCommand, MoveStatementDownExecuted)
            };

            area.DefaultInputHandler.CommandBindings.AddRange(bindings);
        }
        public override void Run()
        {
            ITextEditor    editor         = SD.GetActiveViewContentService <ITextEditor>();
            FoldingManager foldingManager = editor.GetService(typeof(FoldingManager)) as FoldingManager;

            if (foldingManager != null)
            {
                foreach (FoldingSection fm in foldingManager.AllFoldings)
                {
                    var newFolding = fm.Tag as NewFolding;
                    if (newFolding != null)
                    {
                        fm.IsFolded = newFolding.IsDefinition;
                    }
                }
            }
        }
        IEnumerable <DispatcherPriority> EraseText(RoutedUICommand deleteCommand)
        {
            IViewContent vc       = FileService.NewFile("stresstest.cs", "");
            ITextEditor  editor   = ((ITextEditorProvider)vc).TextEditor;
            TextArea     textArea = (TextArea)editor.GetService(typeof(TextArea));

            editor.Document.Text = File.ReadAllText(bigFile);
            editor.Caret.Offset  = editor.Document.TextLength / 2;
            yield return(DispatcherPriority.SystemIdle);

            for (int i = 0; i < Repetitions; i++)
            {
                deleteCommand.Execute(null, textArea);
                yield return(DispatcherPriority.SystemIdle);
            }
            vc.WorkbenchWindow.CloseWindow(true);
        }
        public static XamlCompletionContext ResolveCompletionContext(ITextEditor editor, char typedValue, int offset)
        {
            var binding = editor.GetService(typeof(XamlTextEditorExtension)) as XamlTextEditorExtension;

            if (binding == null)
            {
                throw new InvalidOperationException("Can only use ResolveCompletionContext with a XamlTextEditorExtension.");
            }

            var context = new XamlCompletionContext(ResolveContext(editor.FileName, editor.Document, offset))
            {
                PressedKey = typedValue,
                Editor     = editor
            };

            return(context);
        }
Beispiel #38
0
 public CaretReferenceHighlightRenderer(ITextEditor editor)
 {
     if (editor == null)
     {
         throw new ArgumentNullException("editor");
     }
     this.editor          = editor;
     this.textView        = editor.GetService <TextView>();
     this.borderPen       = new Pen(new SolidColorBrush(DefaultBorderColor), borderThickness);
     this.backgroundBrush = new SolidColorBrush(DefaultFillColor);
     this.borderPen.Freeze();
     this.backgroundBrush.Freeze();
     editor.Caret.LocationChanged                         += CaretLocationChanged;
     textView.VisualLinesChanged                          += VisualLinesChanged;
     SD.ParserService.ParseInformationUpdated             += ParseInformationUpdated;
     SD.ParserService.LoadSolutionProjectsThread.Finished += LoadSolutionProjectsThreadFinished;
     this.textView.BackgroundRenderers.Add(this);
 }
		public override void Attach(ITextEditor editor)
		{
			if (editor == null)
				return;
			
			var textEditor = editor.GetService(typeof(TextEditor)) as TextEditor;
			if (textEditor != null) {
				pinLayer = new PinLayer(textEditor.TextArea);
				textEditor.TextArea.TextView.InsertLayer(
					pinLayer,
					KnownLayer.Caret,
					LayerInsertionPosition.Above);
			}
			
			_editor = editor;
			CreatePins(_editor);
			
			base.Attach(editor);
		}
 public SnippetCompletionItem(ITextEditor textEditor, CodeSnippet codeSnippet)
 {
     if (textEditor == null)
     {
         throw new ArgumentNullException("textEditor");
     }
     if (codeSnippet == null)
     {
         throw new ArgumentNullException("codeSnippet");
     }
     this.textEditor = textEditor;
     this.textArea   = textEditor.GetService(typeof(TextArea)) as TextArea;
     if (textArea == null)
     {
         throw new ArgumentException("textEditor must be an AvalonEdit text editor");
     }
     this.codeSnippet = codeSnippet;
     this.Priority    = CodeCompletionDataUsageCache.GetPriority("snippet" + codeSnippet.Name, true);
 }
        public override void Run()
        {
            ITextEditor    editor         = SD.GetActiveViewContentService <ITextEditor>();
            FoldingManager foldingManager = editor.GetService(typeof(FoldingManager)) as FoldingManager;

            if (foldingManager != null)
            {
                // look for folding on this line:
                FoldingSection folding = foldingManager.GetNextFolding(editor.Document.PositionToOffset(editor.Caret.Line, 1));
                if (folding == null || editor.Document.GetLineForOffset(folding.StartOffset).LineNumber != editor.Caret.Line)
                {
                    // no folding found on current line: find innermost folding containing the caret
                    folding = foldingManager.GetFoldingsContaining(editor.Caret.Offset).LastOrDefault();
                }
                if (folding != null)
                {
                    folding.IsFolded = !folding.IsFolded;
                }
            }
        }
Beispiel #42
0
        public override void Run()
        {
            ITextEditorProvider   provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider;
            ITextEditor           editor   = provider.TextEditor;
            ParserFoldingStrategy strategy = editor.GetService(typeof(ParserFoldingStrategy)) as ParserFoldingStrategy;

            if (strategy != null)
            {
                // look for folding on this line:
                FoldingSection folding = strategy.FoldingManager.GetNextFolding(editor.Document.PositionToOffset(editor.Caret.Line, 1));
                if (folding == null || editor.Document.GetLineForOffset(folding.StartOffset).LineNumber != editor.Caret.Line)
                {
                    // no folding found on current line: find innermost folding containing the caret
                    folding = strategy.FoldingManager.GetFoldingsContaining(editor.Caret.Offset).LastOrDefault();
                }
                if (folding != null)
                {
                    folding.IsFolded = !folding.IsFolded;
                }
            }
        }
		public CaretReferenceHighlightRenderer(ITextEditor editor)
		{
			if (editor == null)
				throw new ArgumentNullException("editor");
			this.editor = editor;
			this.textView = editor.GetService<TextView>();
			this.borderPen = new Pen(new SolidColorBrush(DefaultBorderColor), borderThickness);
			this.backgroundBrush = new SolidColorBrush(DefaultFillColor);
			this.borderPen.Freeze();
			this.backgroundBrush.Freeze();
			this.timer = new DispatcherTimer {
				Interval = TimeSpan.FromMilliseconds(500)
			};
			timer.Tick += (sender, e) => ResolveAtCaret();
				
			editor.Caret.LocationChanged += CaretLocationChanged;
			editor.Document.ChangeCompleted += DocumentChanged;
			textView.VisualLinesChanged += VisualLinesChanged;
			SD.ParserService.ParseInformationUpdated += ParseInformationUpdated;
			SD.ParserService.LoadSolutionProjectsThread.Finished += LoadSolutionProjectsThreadFinished;
			this.textView.BackgroundRenderers.Add(this);
		}
        IEnumerable <DispatcherPriority> TypeCode()
        {
            IViewContent vc        = FileService.NewFile("stresstest.cs", "");
            ITextEditor  editor    = ((ITextEditorProvider)vc).TextEditor;
            TextArea     textArea  = (TextArea)editor.GetService(typeof(TextArea));
            string       inputText = string.Join("\n", File.ReadAllLines(bigFile).Where(l => !string.IsNullOrWhiteSpace(l) && !l.StartsWith("//", StringComparison.Ordinal)));

            yield return(DispatcherPriority.SystemIdle);

            for (int i = 0; i < Math.Min(inputText.Length, Repetitions); i++)
            {
                textArea.PerformTextInput(inputText[i].ToString());
                yield return(DispatcherPriority.SystemIdle);

                while (!textArea.StackedInputHandlers.IsEmpty)
                {
                    textArea.PopStackedInputHandler(textArea.StackedInputHandlers.Peek());
                }
                yield return(DispatcherPriority.SystemIdle);
            }
            vc.WorkbenchWindow.CloseWindow(true);
        }
		public static void SetPosition(Popup popup, ITextEditor editor, int line, int column, bool openAtWordStart = false)
		{
			var editorUIService = editor == null ? null : editor.GetService(typeof(IEditorUIService)) as IEditorUIService;
			if (editorUIService != null) {
				var document = editor.Document;
				int offset = document.GetOffset(line, column);
				if (openAtWordStart) {
					int wordStart = document.FindPrevWordStart(offset);
					if (wordStart != -1) {
						var wordStartLocation = document.GetLocation(wordStart);
						line = wordStartLocation.Line;
						column = wordStartLocation.Column;
					}
				}
				var caretScreenPos = editorUIService.GetScreenPosition(line, column);
				popup.HorizontalOffset = caretScreenPos.X;
				popup.VerticalOffset = caretScreenPos.Y;
				popup.Placement = PlacementMode.Absolute;
			} else {
				// if no editor information, open at mouse positions
				popup.Placement = PlacementMode.MousePoint;
			}
		}
		public CodeSnippetCompletionWindow(ITextEditor editor, ICompletionItemList list)
			: base(editor, editor.GetService(typeof(TextArea)) as TextArea, list)
		{
			this.snippetInput = new TextBox();
			
			DockPanel panel = new DockPanel() {
				Children = {
					snippetInput
				}
			};
			
			this.Content = panel;
			
			panel.Children.Add(CompletionList);
			
			snippetInput.SetValue(DockPanel.DockProperty, Dock.Top);
			
			this.Width = 150;
			this.Height = 200;
			
			this.Loaded += delegate { Keyboard.Focus(snippetInput); };
			this.snippetInput.PreviewKeyDown += new KeyEventHandler(CodeSnippetCompletionWindowPreviewKeyDown);
			this.snippetInput.TextChanged += new TextChangedEventHandler(CodeSnippetCompletionWindow_TextChanged);
		}
Beispiel #47
0
		public IssueManager(ITextEditor editor)
		{
			this.editor = editor;
			this.markerService = editor.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
			//SD.ParserService.ParserUpdateStepFinished += ParserService_ParserUpdateStepFinished;
			SD.ParserService.ParseInformationUpdated += SD_ParserService_ParseInformationUpdated;
			SD.ParserService.LoadSolutionProjectsThread.Finished += RerunAnalysis;
			IssueSeveritySettingsSaved += RerunAnalysis; // re-run analysis when settings are changed
			editor.ContextActionProviders.Add(this);
		}
        void FormatLineInternal(ITextEditor textArea, int lineNr, int cursorOffset, char ch)
        {
            IDocumentLine curLine = textArea.Document.GetLine(lineNr);
            IDocumentLine lineAbove = lineNr > 1 ? textArea.Document.GetLine(lineNr - 1) : null;
            string terminator = DocumentUtilitites.GetLineTerminator(textArea.Document, lineNr);

            string curLineText;
            //// local string for curLine segment
            if (ch == '-')
            {
                curLineText = curLine.Text;
                string lineAboveText = lineAbove == null ? "" : lineAbove.Text;
                if (curLineText != null && curLineText.EndsWith("---") && (lineAboveText == null || !lineAboveText.Trim().StartsWith("---")))
                {
                    string indentation = DocumentUtilitites.GetWhitespaceAfter(textArea.Document, curLine.Offset);
                    StringBuilder sb = new StringBuilder();
                    sb.Append(" <summary>");
                    sb.Append(terminator);
                    sb.Append(indentation);
                    sb.Append("--- ");
                    sb.Append(terminator);
                    sb.Append(indentation);
                    sb.Append("--- </summary>");

                    //sb.Append(terminator);
                    //sb.Append(indentation);
                    //sb.Append("--- <returns></returns>");
                    textArea.Document.Insert(cursorOffset, sb.ToString());

                    textArea.Caret.Offset = cursorOffset + indentation.Length + "--- ".Length + " <summary>".Length + terminator.Length;
                }
                else if (curLineText != null && curLineText.Trim() == "-" && (lineAboveText != null && lineAboveText.Trim().StartsWith("---")))
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("-- ");

                    //sb.Append(terminator);
                    //sb.Append(indentation);
                    //sb.Append("--- <returns></returns>");
                    textArea.Document.Insert(cursorOffset, sb.ToString());

                    textArea.Caret.Offset = cursorOffset + "-- ".Length;
                }
                return;
            }

            if (ch != '\n' && ch != '>')
            {
                if (IsInsideStringOrComment(textArea, curLine, cursorOffset))
                {
                    return;
                }
            }

            if (IsInsideStringOrComment(textArea, curLine, cursorOffset) == false
                && textArea.Caret.Offset == curLine.EndOffset // end of line, not editing something inside the line
                && (curLine.Text.TrimEnd().EndsWith("then")
                || curLine.Text.TrimEnd().EndsWith("do")))
            {
                string indentation = DocumentUtilitites.GetWhitespaceAfter(textArea.Document, curLine.Offset);
                StringBuilder sb = new StringBuilder();
                sb.Append(terminator);
                sb.Append(indentation + textArea.Options.IndentationString);
                sb.Append(terminator);
                sb.Append(indentation);
                sb.Append("end");
                textArea.Document.Insert(cursorOffset, sb.ToString());
                textArea.Caret.Offset =
                    cursorOffset
                    + terminator.Length // end of line
                    + indentation.Length // indentation
                    + textArea.Options.IndentationString.Length
                    ;
            }

            if (IsInsideStringOrComment(textArea, curLine, cursorOffset) == false
                && textArea.Caret.Offset == curLine.EndOffset // end of line, not editing something inside the line
                && curLine.Text.TrimStart().StartsWith("repeat"))
            {
                string indentation = DocumentUtilitites.GetWhitespaceAfter(textArea.Document, curLine.Offset);
                StringBuilder sb = new StringBuilder();
                sb.Append(terminator);
                sb.Append(indentation + textArea.Options.IndentationString);
                sb.Append(terminator);
                sb.Append(indentation);
                sb.Append("until ");
                textArea.Document.Insert(cursorOffset, sb.ToString());

                textArea.Caret.Offset =
                    cursorOffset
                    + indentation.Length
                    + terminator.Length // line 1
                    + indentation.Length
                    + textArea.Options.IndentationString.Length
                    + terminator.Length // line 2
                    + "until ".Length
                    ;

            }

            switch (ch)
            {
                case '>':
                    if (IsInsideDocumentationComment(textArea, curLine, cursorOffset))
                    {
                        curLineText = curLine.Text;
                        int column = cursorOffset - curLine.Offset;
                        int index = Math.Min(column - 1, curLineText.Length - 1);

                        while (index >= 0 && curLineText[index] != '<')
                        {
                            --index;
                            if (curLineText[index] == '/')
                                return; // the tag was an end tag or already
                        }

                        if (index > 0)
                        {
                            StringBuilder commentBuilder = new StringBuilder("");
                            for (int i = index; i < curLineText.Length && i < column && !Char.IsWhiteSpace(curLineText[i]); ++i)
                            {
                                commentBuilder.Append(curLineText[i]);
                            }
                            string tag = commentBuilder.ToString().Trim();
                            if (!tag.EndsWith(">"))
                            {
                                tag += ">";
                            }
                            if (!tag.StartsWith("/"))
                            {
                                textArea.Document.Insert(cursorOffset, "</" + tag.Substring(1), AnchorMovementType.BeforeInsertion);
                            }
                        }
                    }
                    break;
                case ')':
                    if (curLine.Text.TrimStart().StartsWith("function"))
                    {
                        string indentation = DocumentUtilitites.GetWhitespaceAfter(textArea.Document, curLine.Offset);
                        StringBuilder sb = new StringBuilder();
                        sb.Append(terminator);
                        sb.Append(indentation + textArea.Options.IndentationString);
                        sb.Append(terminator);
                        sb.Append(indentation);
                        sb.Append("end");
                        textArea.Document.Insert(cursorOffset, sb.ToString());
                        textArea.Caret.Offset =
                            cursorOffset
                            + terminator.Length // end of line
                            + indentation.Length // indentation
                            + textArea.Options.IndentationString.Length
                            ;
                    }
                    else
                        IndentLine(textArea, curLine);
                    break;
                case ':':
                case ']':
                case '}':
                case '{':
                    IndentLine(textArea, curLine);
                    break;
                case '\n':
                    string lineAboveText = lineAbove == null ? "" : lineAbove.Text;
                    //// curLine might have some text which should be added to indentation
                    curLineText = curLine.Text;


                    ISyntaxHighlighter highlighter = textArea.GetService(typeof(ISyntaxHighlighter)) as ISyntaxHighlighter;
                    bool isInMultilineComment = false;
                    bool isInMultilineString = false;
                    if (highlighter != null && lineAbove != null)
                    {
                        var spanStack = highlighter.GetSpanColorNamesFromLineStart(lineNr);
                        isInMultilineComment = spanStack.Contains(SyntaxHighligherKnownSpanNames.Comment);
                        isInMultilineString = spanStack.Contains(SyntaxHighligherKnownSpanNames.String);
                    }
                    bool isInNormalCode = !(isInMultilineComment || isInMultilineString);

                    if (lineAbove != null && isInMultilineComment)
                    {
                        string lineAboveTextTrimmed = lineAboveText.TrimStart();
                        if (lineAboveTextTrimmed.StartsWith("--[[", StringComparison.Ordinal))
                        {
                            textArea.Document.Insert(cursorOffset, " - ");
                            return;
                        }

                        if (lineAboveTextTrimmed.StartsWith("-", StringComparison.Ordinal))
                        {
                            textArea.Document.Insert(cursorOffset, "- ");
                            return;
                        }
                    }

                    if (lineAbove != null && isInNormalCode)
                    {
                        IDocumentLine nextLine = lineNr + 1 <= textArea.Document.TotalNumberOfLines ? textArea.Document.GetLine(lineNr + 1) : null;
                        string nextLineText = (nextLine != null) ? nextLine.Text : "";

                        int indexAbove = lineAboveText.IndexOf("---");
                        int indexNext = nextLineText.IndexOf("---");
                        if (indexAbove > 0 && (indexNext != -1 || indexAbove + 4 < lineAbove.Length))
                        {
                            textArea.Document.Insert(cursorOffset, "--- ");
                            return;
                        }

                        if (IsInNonVerbatimString(lineAboveText, curLineText))
                        {
                            textArea.Document.Insert(cursorOffset, "\"");
                            textArea.Document.Insert(lineAbove.Offset + lineAbove.Length,
                                                     "\" +");
                        }
                    }
                    return;
            }

        }
		public static XamlCompletionContext ResolveCompletionContext(ITextEditor editor, char typedValue, int offset)
		{
			var binding = editor.GetService(typeof(XamlTextEditorExtension)) as XamlTextEditorExtension;
			
			if (binding == null)
				throw new InvalidOperationException("Can only use ResolveCompletionContext with a XamlTextEditorExtension.");
			
			var context = new XamlCompletionContext(ResolveContext(editor.FileName, editor.Document, offset)) {
				PressedKey = typedValue,
				Editor = editor
			};
			
			return context;
		}
		void FormatLineInternal(ITextEditor textArea, int lineNr, int cursorOffset, char ch)
		{
			IDocumentLine curLine   = textArea.Document.GetLine(lineNr);
			IDocumentLine lineAbove = lineNr > 1 ? textArea.Document.GetLine(lineNr - 1) : null;
			string terminator = DocumentUtilitites.GetLineTerminator(textArea.Document, lineNr);
			
			string curLineText;
			//// local string for curLine segment
			if (ch == '/') {
				curLineText = curLine.Text;
				string lineAboveText = lineAbove == null ? "" : lineAbove.Text;
				if (curLineText != null && curLineText.EndsWith("///") && (lineAboveText == null || !lineAboveText.Trim().StartsWith("///"))) {
					string indentation = DocumentUtilitites.GetWhitespaceAfter(textArea.Document, curLine.Offset);
					object member = GetMemberAfter(textArea, lineNr);
					if (member != null) {
						StringBuilder sb = new StringBuilder();
						sb.Append(" <summary>");
						sb.Append(terminator);
						sb.Append(indentation);
						sb.Append("/// ");
						sb.Append(terminator);
						sb.Append(indentation);
						sb.Append("/// </summary>");
						
						if (member is IMethod) {
							IMethod method = (IMethod)member;
							if (method.Parameters != null && method.Parameters.Count > 0) {
								for (int i = 0; i < method.Parameters.Count; ++i) {
									sb.Append(terminator);
									sb.Append(indentation);
									sb.Append("/// <param name=\"");
									sb.Append(method.Parameters[i].Name);
									sb.Append("\"></param>");
								}
							}
							if (method.ReturnType != null && !method.IsConstructor && method.ReturnType.FullyQualifiedName != "System.Void") {
								sb.Append(terminator);
								sb.Append(indentation);
								sb.Append("/// <returns></returns>");
							}
						}
						textArea.Document.Insert(cursorOffset, sb.ToString());
						
						textArea.Caret.Offset = cursorOffset + indentation.Length + "/// ".Length + " <summary>".Length + terminator.Length;
					}
				}
				return;
			}
			
			if (ch != '\n' && ch != '>') {
				if (IsInsideStringOrComment(textArea, curLine, cursorOffset)) {
					return;
				}
			}
			switch (ch) {
				case '>':
					if (IsInsideDocumentationComment(textArea, curLine, cursorOffset)) {
						curLineText = curLine.Text;
						int column = cursorOffset - curLine.Offset;
						int index = Math.Min(column - 1, curLineText.Length - 1);
						
						while (index >= 0 && curLineText[index] != '<') {
							--index;
							if(curLineText[index] == '/')
								return; // the tag was an end tag or already
						}
						
						if (index > 0) {
							StringBuilder commentBuilder = new StringBuilder("");
							for (int i = index; i < curLineText.Length && i < column && !Char.IsWhiteSpace(curLineText[i]); ++i) {
								commentBuilder.Append(curLineText[ i]);
							}
							string tag = commentBuilder.ToString().Trim();
							if (!tag.EndsWith(">")) {
								tag += ">";
							}
							if (!tag.StartsWith("/")) {
								textArea.Document.Insert(cursorOffset, "</" + tag.Substring(1), AnchorMovementType.BeforeInsertion);
							}
						}
					}
					break;
				case ':':
				case ')':
				case ']':
				case '}':
				case '{':
					//if (textArea.Document.TextEditorProperties.IndentStyle == IndentStyle.Smart) {
					IndentLine(textArea, curLine);
					//}
					break;
				case '\n':
					string lineAboveText = lineAbove == null ? "" : lineAbove.Text;
					//// curLine might have some text which should be added to indentation
					curLineText = curLine.Text;
					
					if (lineAbove != null && lineAbove.Text.Trim().StartsWith("#region")
					    && NeedEndregion(textArea.Document))
					{
						textArea.Document.Insert(cursorOffset, "#endregion");
						return;
					}
					
					ISyntaxHighlighter highlighter = textArea.GetService(typeof(ISyntaxHighlighter)) as ISyntaxHighlighter;
					bool isInMultilineComment = false;
					bool isInMultilineString = false;
					if (highlighter != null && lineAbove != null) {
						var spanStack = highlighter.GetSpanColorNamesFromLineStart(lineNr);
						isInMultilineComment = spanStack.Contains(SyntaxHighligherKnownSpanNames.Comment);
						isInMultilineString = spanStack.Contains(SyntaxHighligherKnownSpanNames.String);
					}
					bool isInNormalCode = !(isInMultilineComment || isInMultilineString);
					
					if (lineAbove != null && isInMultilineComment) {
						string lineAboveTextTrimmed = lineAboveText.TrimStart();
						if (lineAboveTextTrimmed.StartsWith("/*", StringComparison.Ordinal)) {
							textArea.Document.Insert(cursorOffset, " * ");
							return;
						}
						
						if (lineAboveTextTrimmed.StartsWith("*", StringComparison.Ordinal)) {
							textArea.Document.Insert(cursorOffset, "* ");
							return;
						}
					}
					
					if (lineAbove != null && isInNormalCode) {
						IDocumentLine nextLine  = lineNr + 1 <= textArea.Document.TotalNumberOfLines ? textArea.Document.GetLine(lineNr + 1) : null;
						string nextLineText = (nextLine != null) ? nextLine.Text : "";
						
						int indexAbove = lineAboveText.IndexOf("///");
						int indexNext  = nextLineText.IndexOf("///");
						if (indexAbove > 0 && (indexNext != -1 || indexAbove + 4 < lineAbove.Length)) {
							textArea.Document.Insert(cursorOffset, "/// ");
							return;
						}
						
						if (IsInNonVerbatimString(lineAboveText, curLineText)) {
							textArea.Document.Insert(cursorOffset, "\"");
							textArea.Document.Insert(lineAbove.Offset + lineAbove.Length,
							                         "\" +");
						}
					}
					if (textArea.Options.AutoInsertBlockEnd && lineAbove != null && isInNormalCode) {
						string oldLineText = lineAbove.Text;
						if (oldLineText.EndsWith("{")) {
							if (NeedCurlyBracket(textArea.Document.Text)) {
								int insertionPoint = curLine.Offset + curLine.Length;
								textArea.Document.Insert(insertionPoint, terminator + "}");
								IndentLine(textArea, textArea.Document.GetLine(lineNr + 1));
								textArea.Caret.Offset = insertionPoint;
							}
						}
					}
					return;
			}
		}
		void FormatLineInternal(ITextEditor textArea, int lineNr, int cursorOffset, char ch)
		{
			IDocumentLine curLine   = textArea.Document.GetLineByNumber(lineNr);
			IDocumentLine lineAbove = lineNr > 1 ? textArea.Document.GetLineByNumber(lineNr - 1) : null;
			string terminator = DocumentUtilities.GetLineTerminator(textArea.Document, lineNr);
			
			string curLineText;
			// local string for curLine segment
			if (ch == '/') {
				curLineText = textArea.Document.GetText(curLine);
				string lineAboveText = lineAbove == null ? "" : textArea.Document.GetText(lineAbove);
				if (curLineText != null && curLineText.EndsWith("///", StringComparison.Ordinal) && (lineAboveText == null || !lineAboveText.Trim().StartsWith("///", StringComparison.Ordinal))) {
					string indentation = DocumentUtilities.GetWhitespaceAfter(textArea.Document, curLine.Offset);
					IUnresolvedEntity member = GetMemberAfter(textArea, lineNr);
					if (member != null) {
						StringBuilder sb = new StringBuilder();
						sb.Append(" <summary>");
						sb.Append(terminator);
						sb.Append(indentation);
						sb.Append("/// ");
						sb.Append(terminator);
						sb.Append(indentation);
						sb.Append("/// </summary>");
						
						if (member is IUnresolvedMethod) {
							IUnresolvedMethod method = (IUnresolvedMethod)member;
							for (int i = 0; i < method.Parameters.Count; ++i) {
								sb.Append(terminator);
								sb.Append(indentation);
								sb.Append("/// <param name=\"");
								sb.Append(method.Parameters[i].Name);
								sb.Append("\"></param>");
							}
							if (!method.IsConstructor) {
								KnownTypeReference returnType = method.ReturnType as KnownTypeReference;
								if (returnType == null || returnType.KnownTypeCode != KnownTypeCode.Void) {
									sb.Append(terminator);
									sb.Append(indentation);
									sb.Append("/// <returns></returns>");
								}
							}
						}
						textArea.Document.Insert(cursorOffset, sb.ToString());
						
						textArea.Caret.Offset = cursorOffset + indentation.Length + "/// ".Length + " <summary>".Length + terminator.Length;
					}
				}
				return;
			}
			
			if (ch != '\n' && ch != '>') {
				if (IsInsideStringOrComment(textArea, curLine, cursorOffset)) {
					return;
				}
			}
			switch (ch) {
				case '>':
					if (IsInsideDocumentationComment(textArea, curLine, cursorOffset)) {
						curLineText = textArea.Document.GetText(curLine);
						int column = cursorOffset - curLine.Offset;
						int index = Math.Min(column - 1, curLineText.Length - 1);
						
						while (index >= 0 && curLineText[index] != '<') {
							--index;
							if(curLineText[index] == '/')
								return; // the tag was an end tag or already
						}
						
						if (index > 0) {
							StringBuilder commentBuilder = new StringBuilder("");
							for (int i = index; i < curLineText.Length && i < column && !Char.IsWhiteSpace(curLineText[i]); ++i) {
								commentBuilder.Append(curLineText[ i]);
							}
							string tag = commentBuilder.ToString().Trim();
							if (!tag.EndsWith(">", StringComparison.Ordinal)) {
								tag += ">";
							}
							if (!tag.StartsWith("/", StringComparison.Ordinal)) {
								textArea.Document.Insert(cursorOffset, "</" + tag.Substring(1), AnchorMovementType.BeforeInsertion);
							}
						}
					}
					break;
				case ':':
				case ')':
				case ']':
				case '{':
					//if (textArea.Document.TextEditorProperties.IndentStyle == IndentStyle.Smart) {
					IndentLine(textArea, curLine);
					//}
					break;
				case '}':
					// Try to get corresponding block beginning brace
					var bracketSearchResult = textArea.Language.BracketSearcher.SearchBracket(textArea.Document, cursorOffset);
					if (bracketSearchResult != null) {
						// Format the block
						if (!FormatStatement(textArea, cursorOffset, bracketSearchResult.OpeningBracketOffset)) {
							// No auto-formatting seems to be active, at least indent the line
							IndentLine(textArea, curLine);
						}
					}
					break;
				case ';':
					// Format this line
					if (!FormatStatement(textArea, cursorOffset, cursorOffset)) {
						// No auto-formatting seems to be active, at least indent the line
						IndentLine(textArea, curLine);
					}
					break;
				case '\n':
					string lineAboveText = lineAbove == null ? "" : textArea.Document.GetText(lineAbove);
					// curLine might have some text which should be added to indentation
					curLineText = textArea.Document.GetText(curLine);
					
					if (lineAboveText != null && lineAboveText.Trim().StartsWith("#region", StringComparison.Ordinal)
						&& NeedEndregion(textArea.Document))
					{
						textArea.Document.Insert(cursorOffset, "#endregion");
						return;
					}
					
					IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter;
					bool isInMultilineComment = false;
					bool isInMultilineString = false;
					if (highlighter != null && lineAbove != null) {
						var spanStack = highlighter.GetColorStack(lineNr).Select(c => c.Name).ToArray();
						isInMultilineComment = spanStack.Contains(HighlighterKnownSpanNames.Comment);
						isInMultilineString = spanStack.Contains(HighlighterKnownSpanNames.String);
					}
					bool isInNormalCode = !(isInMultilineComment || isInMultilineString);
					
					if (lineAbove != null && isInMultilineComment) {
						string lineAboveTextTrimmed = lineAboveText.TrimStart();
						if (lineAboveTextTrimmed.StartsWith("/*", StringComparison.Ordinal)) {
							textArea.Document.Insert(cursorOffset, " * ");
							return;
						}
						
						if (lineAboveTextTrimmed.StartsWith("*", StringComparison.Ordinal)) {
							textArea.Document.Insert(cursorOffset, "* ");
							return;
						}
					}
					
					if (lineAbove != null && isInNormalCode) {
						IDocumentLine nextLine  = lineNr + 1 <= textArea.Document.LineCount ? textArea.Document.GetLineByNumber(lineNr + 1) : null;
						string nextLineText = (nextLine != null) ? textArea.Document.GetText(nextLine) : "";
						
						int indexAbove = lineAboveText.IndexOf("///", StringComparison.Ordinal);
						int indexNext = nextLineText.IndexOf("///", StringComparison.Ordinal);
						if (indexAbove > 0 && (indexNext != -1 || indexAbove + 4 < lineAbove.Length)) {
							textArea.Document.Insert(cursorOffset, "/// ");
							return;
						}
						
						if (IsInNonVerbatimString(lineAboveText, curLineText)) {
							textArea.Document.Insert(cursorOffset, "\"");
							textArea.Document.Insert(lineAbove.Offset + lineAbove.Length,
								"\" +");
						}
					}
					if (textArea.Options.AutoInsertBlockEnd && lineAbove != null && isInNormalCode) {
						string oldLineText = textArea.Document.GetText(lineAbove);
						if (oldLineText.EndsWith("{", StringComparison.Ordinal)) {
							if (NeedCurlyBracket(textArea.Document.Text)) {
								int insertionPoint = curLine.Offset + curLine.Length;
								textArea.Document.Insert(insertionPoint, terminator + "}");
								IndentLine(textArea, textArea.Document.GetLineByNumber(lineNr + 1));
								textArea.Caret.Offset = insertionPoint;
							}
						}
					}
					return;
		}
		}
Beispiel #52
0
		public override void Attach(ITextEditor editor)
		{
			TextArea textArea = editor.GetService(typeof(TextArea)) as TextArea;
			if (textArea == null) return;
			handler = new SearchInputHandler(textArea);
			textArea.DefaultInputHandler.NestedInputHandlers.Add(handler);
			handler.SearchOptionsChanged += SearchOptionsChanged;
		}
		public static PinLayer GetPinlayer(ITextEditor editor) {
			var textEditor = editor.GetService(typeof(TextEditor)) as TextEditor;
			if (textEditor != null) {
				return textEditor.TextArea.TextView.Layers[3] as PinLayer;
			}
			
			return null;
		}
 public CurveTemplateCompletionItem(ITextEditor editor)
 {
     templateText = StringParser.Parse("${res:Template.Text.Curve}");
     dialog = new CurveTemplateDialog(editor.GetService(typeof(TextArea)) as TextArea);
 }
		public static XamlCompletionContext ResolveCompletionContext(ITextEditor editor, char typedValue)
		{
			var binding = editor.GetService(typeof(XamlLanguageBinding)) as XamlLanguageBinding;
			
			if (binding == null)
				throw new InvalidOperationException("Can only use ResolveCompletionContext with a XamlLanguageBinding.");
			
			var context = new XamlCompletionContext(ResolveContext(editor.Document.CreateSnapshot(), editor.FileName, editor.Caret.Offset)) {
				PressedKey = typedValue,
				Editor = editor
			};
			
			return context;
		}
Beispiel #56
0
		public IssueManager(ITextEditor editor)
		{
			this.editor = editor;
			this.markerService = editor.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
			//SD.ParserService.ParserUpdateStepFinished += ParserService_ParserUpdateStepFinished;
			SD.ParserService.ParseInformationUpdated += new EventHandler<ParseInformationEventArgs>(SD_ParserService_ParseInformationUpdated);
			editor.ContextActionProviders.Add(this);
		}
 public GradientTemplateCompletionItem(ITextEditor editor)
 {
     TemplateText = StringParser.Parse("${res:Template.Text.Gradient}");
     dialog = new GradientTemplateDialog(editor.GetService(typeof(TextArea)) as TextArea);
 }