Inheritance: System.Windows.Forms.Control
		/// <summary>
		/// This function sets the indentlevel in a range of lines.
		/// </summary>
		public override void IndentLines(TextArea textArea, int begin, int end)
		{
			if (textArea.Document.TextEditorProperties.IndentStyle != IndentStyle.Smart) {
				base.IndentLines(textArea, begin, end);
				return;
			}
			int cursorPos = textArea.Caret.Position.Y;
			int oldIndentLength = 0;
			
			if (cursorPos >= begin && cursorPos <= end)
				oldIndentLength = GetIndentation(textArea, cursorPos).Length;
			
			IndentationSettings set = new IndentationSettings();
			set.IndentString = Tab.GetIndentationString(textArea.Document);
			IndentationReformatter r = new IndentationReformatter();
			DocumentAccessor acc = new DocumentAccessor(textArea.Document, begin, end);
			r.Reformat(acc, set);
			
			if (cursorPos >= begin && cursorPos <= end) {
				int newIndentLength = GetIndentation(textArea, cursorPos).Length;
				if (oldIndentLength != newIndentLength) {
					// fix cursor position if indentation was changed
					int newX = textArea.Caret.Position.X - oldIndentLength + newIndentLength;
					textArea.Caret.Position = new TextLocation(Math.Max(newX, 0), cursorPos);
				}
			}
		}
		/// <summary>
		/// Indents the specified line based on the current depth of the XML hierarchy.
		/// </summary>
		/// <param name="p_txaTextArea">The text area containing the line to indent.</param>
		/// <param name="p_intLineNumber">The line number of the line to indent.</param>
		/// <returns>The indent depth of the specified line.</returns>
		protected override int AutoIndentLine(TextArea p_txaTextArea, int p_intLineNumber)
		{
			XmlParser.TagStack stkTags = XmlParser.ParseTags(p_txaTextArea.Document, p_intLineNumber, null, null);
			Int32 intDepth = 0;
			Int32 intLastLineNum = -1;
			while (stkTags.Count > 0)
			{
				if (stkTags.Peek().LineNumber != intLastLineNum)
				{
					intLastLineNum = stkTags.Peek().LineNumber;
					intDepth++;
				}
				stkTags.Pop();
			}

			StringBuilder stbLineWithIndent = new StringBuilder();
			for (Int32 i = 0; i < intDepth; i++)
				stbLineWithIndent.Append("\t");
			stbLineWithIndent.Append(TextUtilities.GetLineAsString(p_txaTextArea.Document, p_intLineNumber).Trim());
			LineSegment oldLine = p_txaTextArea.Document.GetLineSegment(p_intLineNumber);
			Int32 intCaretOffset = stbLineWithIndent.Length - oldLine.Length;
			SmartReplaceLine(p_txaTextArea.Document, oldLine, stbLineWithIndent.ToString());
			p_txaTextArea.Caret.Column += intCaretOffset;

			return intDepth;
		}
 /// <summary>
 /// Called when entry should be inserted. Forward to the insertion action of the completion data.
 /// </summary>
 public bool InsertAction(ICompletionData data, TextArea textArea, int insertionOffset, char key)
 {
     textArea.SelectionManager.SetSelection(textArea.Document.OffsetToPosition(
         Math.Min(insertionOffset - ((AEGISCompletionData)data).Expression.Length, textArea.Document.TextLength)
         ), textArea.Caret.Position);
     return data.InsertAction(textArea, key);
 }
示例#4
0
        public override void Execute(TextArea textArea)
        {
            try
            {
                int num_line = 0;

                string var = null;
                if (!textArea.SelectionManager.HasSomethingSelected)
                    var = WorkbenchServiceFactory.DebuggerManager.GetVariable(textArea, out num_line);
                else
                {
                    var = textArea.SelectionManager.SelectedText;
                    //num_line = textArea.SelectionManager.SelectionStart.Line;
                }
                if (var == null || var == "")
                {
                    WorkbenchServiceFactory.DebuggerOperationsService.GotoWatch();
                    return;
                    //VisualPABCSingleton.MainForm.SetCursorInWatch();
                }
                ValueItem vi = WorkbenchServiceFactory.DebuggerManager.FindVarByName(var, num_line) as ValueItem;
                if (vi != null)
                {
                    VisualPABCSingleton.MainForm.AddVariable(vi);
                }
                else
                {
                    WorkbenchServiceFactory.DebuggerOperationsService.AddVariable(var, true);
                }
            }
            catch (System.Exception e)
            {
                WorkbenchServiceFactory.DebuggerOperationsService.GotoWatch();
            }
        }
		void AddTemplates(TextArea textArea, char charTyped)
		{
			if (!ShowTemplates)
				return;
			ICompletionData suggestedData = DefaultIndex >= 0 ? completionData[DefaultIndex] : null;
			ICompletionData[] templateCompletionData = new TemplateCompletionDataProvider().GenerateCompletionData(fileName, textArea, charTyped);
			if (templateCompletionData == null || templateCompletionData.Length == 0)
				return;
			for (int i = 0; i < completionData.Count; i++) {
				if (completionData[i].ImageIndex == ClassBrowserIconService.KeywordIndex) {
					string text = completionData[i].Text;
					for (int j = 0; j < templateCompletionData.Length; j++) {
						if (templateCompletionData[j] != null && templateCompletionData[j].Text == text) {
							// replace keyword with template
							completionData[i] = templateCompletionData[j];
							templateCompletionData[j] = null;
						}
					}
				}
			}
			// add non-keyword code templates
			for (int j = 0; j < templateCompletionData.Length; j++) {
				if (templateCompletionData[j] != null)
					completionData.Add(templateCompletionData[j]);
			}
			if (suggestedData != null) {
				completionData.Sort(DefaultCompletionData.Compare);
				DefaultIndex = completionData.IndexOf(suggestedData);
			}
		}
        public ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
        {
            // We can return code-completion items like this:

            //			return new ICompletionData[] {
            //				new DefaultCompletionData("Text", "Description", 1)
            //			};

            NRefactoryResolver resolver = new NRefactoryResolver(mainForm.myProjectContent);
            Dom.ResolveResult rr = resolver.Resolve(FindExpression(textArea),
                                                    textArea.Caret.Line,
                                                    textArea.Caret.Column,
                                                    fileName,
                                                    textArea.MotherTextEditorControl.Text);
            List<ICompletionData> resultList = new List<ICompletionData>();
            if (rr != null) {
                ArrayList completionData = rr.GetCompletionData(mainForm.myProjectContent);
                if (completionData != null) {
                    AddCompletionData(resultList, completionData);
                }
            }

            //textArea.MotherTextEditorControl.Text = backup;

            return resultList.ToArray();
        }
		/// <summary>
		/// Inserts the PInvoke signature at the current cursor position.
		/// </summary>
		/// <param name="textArea">The text editor.</param>
		/// <param name="signature">A PInvoke signature string.</param>
		public void Generate(TextArea textArea, string signature)
		{
			IndentStyle oldIndentStyle = textArea.TextEditorProperties.IndentStyle;
			bool oldEnableEndConstructs = PropertyService.Get("VBBinding.TextEditor.EnableEndConstructs", true);

			try {

				textArea.BeginUpdate();
				textArea.Document.UndoStack.StartUndoGroup();
				textArea.TextEditorProperties.IndentStyle = IndentStyle.Smart;
				PropertyService.Set("VBBinding.TextEditor.EnableEndConstructs", false);

				string[] lines = signature.Replace("\r\n", "\n").Split('\n');
				
				for (int i = 0; i < lines.Length; ++i) {
					
					textArea.InsertString(lines[i]);
					
					// Insert new line if not the last line.
					if ( i < (lines.Length - 1))
					{
						Return(textArea);
					}
				}
				
			} finally {
				textArea.Document.UndoStack.EndUndoGroup();
				textArea.TextEditorProperties.IndentStyle = oldIndentStyle;
				PropertyService.Set("VBBinding.TextEditor.EnableEndConstructs", oldEnableEndConstructs);
				textArea.EndUpdate();
				textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
				textArea.Document.CommitUpdate();	
			}
		}
		/// <summary>
		/// Define CSharp specific smart indenting for a line :)
		/// </summary>
		protected override int SmartIndentLine(TextArea textArea, int lineNr)
		{
			if (lineNr <= 0) {
				return AutoIndentLine(textArea, lineNr);
			}
			
			string oldText = textArea.Document.GetText(textArea.Document.GetLineSegment(lineNr));
			
			DocumentAccessor acc = new DocumentAccessor(textArea.Document, lineNr, lineNr);
			
			IndentationSettings set = new IndentationSettings();
			set.IndentString = Tab.GetIndentationString(textArea.Document);
			set.LeaveEmptyLines = false;
			IndentationReformatter r = new IndentationReformatter();
			
			r.Reformat(acc, set);
			
			string t = acc.Text;
			if (t.Length == 0) {
				// use AutoIndentation for new lines in comments / verbatim strings.
				return AutoIndentLine(textArea, lineNr);
			} else {
				int newIndentLength = t.Length - t.TrimStart().Length;
				int oldIndentLength = oldText.Length - oldText.TrimStart().Length;
				if (oldIndentLength != newIndentLength && lineNr == textArea.Caret.Position.Y) {
					// fix cursor position if indentation was changed
					int newX = textArea.Caret.Position.X - oldIndentLength + newIndentLength;
					textArea.Caret.Position = new TextLocation(Math.Max(newX, 0), lineNr);
				}
				return newIndentLength;
			}
		}
        public TextAreaControl(TextEditorControl motherTextEditorControl)
        {
            this.motherTextEditorControl = motherTextEditorControl;

            this.textArea                = new TextArea(motherTextEditorControl, this);
            Controls.Add(textArea);

            vScrollBar.ValueChanged += new EventHandler(VScrollBarValueChanged);
            Controls.Add(this.vScrollBar);

            hScrollBar.ValueChanged += new EventHandler(HScrollBarValueChanged);
            Controls.Add(this.hScrollBar);
            ResizeRedraw = true;

            Document.TextContentChanged += DocumentTextContentChanged;
            Document.DocumentChanged += AdjustScrollBarsOnDocumentChange;
            Document.UpdateCommited  += DocumentUpdateCommitted;

            vScrollBar.VisibleChanged += (sender, e) =>
            {
                if (!vScrollBar.Visible)
                    vScrollBar.Value = 0;
            };

            hScrollBar.VisibleChanged += (sender, e) =>
            {
                if (!hScrollBar.Visible)
                    hScrollBar.Value = 0;
            };
        }
示例#10
0
 public GutterMargin(TextArea textArea)
     : base(textArea)
 {
     numberStringFormat.LineAlignment = StringAlignment.Far;
     numberStringFormat.FormatFlags   = StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.FitBlackBox |
         StringFormatFlags.NoWrap | StringFormatFlags.NoClip;
 }
        public void Validate(String doc,TextArea textArea)
        {
            this.textArea = textArea;
            textArea.Document.MarkerStrategy.RemoveAll(p => true);
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.CloseInput = true;
            settings.ValidationEventHandler += new ValidationEventHandler(settings_ValidationEventHandler);  // Your callback...
            settings.ValidationType = ValidationType.Schema;
            settings.Schemas.Add(schemaset);
            settings.ValidationFlags =
              XmlSchemaValidationFlags.ReportValidationWarnings |
              XmlSchemaValidationFlags.ProcessIdentityConstraints |
              XmlSchemaValidationFlags.ProcessInlineSchema |
              XmlSchemaValidationFlags.ProcessSchemaLocation;

            // Wrap document in an XmlNodeReader and run validation on top of that
            try
            {
                using (XmlReader validatingReader = XmlReader.Create(new StringReader(doc), settings))
                {
                    while (validatingReader.Read()) { /* just loop through document */ }
                }
            }
            catch (XmlException e)
            {
                var offset = textArea.Document.PositionToOffset(new TextLocation(e.LinePosition, e.LineNumber));

                var mk = new TextMarker(offset, 5, TextMarkerType.WaveLine,  Color.DarkBlue );
                mk.ToolTip = e.Message;
                textArea.Document.MarkerStrategy.AddMarker(mk);
            }
        }
		public override void Execute(TextArea services)
		{
			XmlEditorControl editor = services.MotherTextEditorControl as XmlEditorControl;
			if (editor != null) {
				editor.ShowCompletionWindow();			
			}
		}
		public void SetupDataProvider(string fileName, TextArea textArea)
		{
			if (setupOnlyOnce && this.textArea != null) return;
			IDocument document = textArea.Document;
			this.fileName = fileName;
			this.document = document;
			this.textArea = textArea;
			int useOffset = (lookupOffset < 0) ? textArea.Caret.Offset : lookupOffset;
			initialOffset = useOffset;
			
			
			IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(fileName);
			ExpressionResult expressionResult;
			if (expressionFinder == null)
				expressionResult = new ExpressionResult(TextUtilities.GetExpressionBeforeOffset(textArea, useOffset));
			else
				expressionResult = expressionFinder.FindExpression(textArea.Document.TextContent, useOffset);
			
			if (expressionResult.Expression == null) // expression is null when cursor is in string/comment
				return;
			expressionResult.Expression = expressionResult.Expression.Trim();
			
			if (LoggingService.IsDebugEnabled) {
				if (expressionResult.Context == ExpressionContext.Default)
					LoggingService.DebugFormatted("ShowInsight for >>{0}<<", expressionResult.Expression);
				else
					LoggingService.DebugFormatted("ShowInsight for >>{0}<<, context={1}", expressionResult.Expression, expressionResult.Context);
			}
			
			int caretLineNumber = document.GetLineNumberForOffset(useOffset);
			int caretColumn     = useOffset - document.GetLineSegment(caretLineNumber).Offset;
			// the parser works with 1 based coordinates
			SetupDataProvider(fileName, document, expressionResult, caretLineNumber + 1, caretColumn + 1);
		}
        public bool InsertAction(ICompletionData data, TextArea textArea, int insertionOffset, char key)
        {
            textArea.Caret.Position = textArea.Document.OffsetToPosition(
                Math.Min(insertionOffset, textArea.Document.TextLength));

            return data.InsertAction(textArea, key);
        }
		public virtual void GenerateCode(TextArea textArea, IList items)
		{
			List<AbstractNode> nodes = new List<AbstractNode>();
			GenerateCode(nodes, items);
			codeGen.InsertCodeInClass(currentClass, new TextEditorDocument(textArea.Document), textArea.Caret.Line, nodes.ToArray());
			ParserService.ParseCurrentViewContent();
		}
示例#16
0
 /// <summary>
 /// Execute the Goto Line action
 /// </summary>
 /// <param name="textArea">The text area in which to perform the
 /// action</param>
 public override void Execute(TextArea textArea)
 {
     using(GotoLineDlg dlg = new GotoLineDlg())
     {
         if(dlg.ShowDialog() == DialogResult.OK)
             textArea.Caret.Line = dlg.LineNumber - 1;
     }
 }
		void IndentLine(TextArea textArea)
		{
			int delta = textArea.Document.FormattingStrategy.IndentLine(textArea, textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset));
			if (delta != 0) {
				LineSegment caretLine = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);
				textArea.Caret.Position = textArea.Document.OffsetToPosition(Math.Min(textArea.Caret.Offset + delta, caretLine.Offset + caretLine.Length));
			}
		}		
		public override ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
		{
			ICompletionData[] data = new ICompletionData[texts.Length];
			for (int i = 0; i < data.Length; i++) {
				data[i] = new DefaultCompletionData(texts[i], null, ClassBrowserIconService.GotoArrowIndex);
			}
			return data;
		}
		public override ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
		{
			this.textArea = textArea;
			this.startOffset = textArea.Caret.Offset;
			this.nonMatchingCharTyped = false;
			this.DefaultIndex = 0;
			return new ICompletionData[] { new DefaultCompletionData("{res", null, ClassBrowserIconService.GotoArrowIndex) };
		}
		protected override void GenerateCompletionData(TextArea textArea, char charTyped)
		{
			preSelection = null;
			if (fixedExpression.Expression == null)
				GenerateCompletionData(textArea, GetExpression(textArea));
			else
				GenerateCompletionData(textArea, fixedExpression);
		}
 public override int FormatLine(TextArea textArea, int lineNr, int caretOffset, char charTyped) // used for comment tag formater/inserter
 {
     try
     {
         if (charTyped == '>')
         {
             StringBuilder stringBuilder = new StringBuilder();
             int offset = Math.Min(caretOffset - 2, textArea.Document.TextLength - 1);
             while (true)
             {
                 if (offset < 0)
                 {
                     break;
                 }
                 char ch = textArea.Document.GetCharAt(offset);
                 if (ch == '<')
                 {
                     string reversedTag = stringBuilder.ToString().Trim();
                     if (!reversedTag.StartsWith("/") && !reversedTag.EndsWith("/"))
                     {
                         bool validXml = true;
                         try
                         {
                             XmlDocument doc = new XmlDocument();
                             doc.LoadXml(textArea.Document.TextContent);
                         }
                         catch (Exception)
                         {
                             validXml = false;
                         }
                         // only insert the tag, if something is missing
                         if (!validXml)
                         {
                             StringBuilder tag = new StringBuilder();
                             for (int i = reversedTag.Length - 1; i >= 0 && !Char.IsWhiteSpace(reversedTag[i]); --i)
                             {
                                 tag.Append(reversedTag[i]);
                             }
                             string tagString = tag.ToString();
                             if (tagString.Length > 0 && !tagString.StartsWith("!") && !tagString.StartsWith("?"))
                             {
                                 textArea.Document.Insert(caretOffset, "</" + tagString + ">");
                             }
                         }
                     }
                     break;
                 }
                 stringBuilder.Append(ch);
                 --offset;
             }
         }
     }
     catch (Exception e)
     { // Insanity check
         Debug.Assert(false, e.ToString());
     }
     return charTyped == '\n' ? IndentLine(textArea, lineNr) : 0;
 }
		public virtual bool InsertAction(ICompletionData data, TextArea textArea, int insertionOffset, char key)
		{
			if (InsertSpace) {
				textArea.Document.Insert(insertionOffset++, " ");
			}
			textArea.Caret.Position = textArea.Document.OffsetToPosition(insertionOffset);
			
			return data.InsertAction(textArea, key);
		}
		public void Attach(TextArea textArea)
		{
			this.textArea = textArea;
			textArea.AllowDrop = true;
			
			textArea.DragEnter += MakeDragEventHandler(OnDragEnter);
			textArea.DragDrop  += MakeDragEventHandler(OnDragDrop);
			textArea.DragOver  += MakeDragEventHandler(OnDragOver);
		}
			public override bool InsertAction(TextArea textArea, char ch)
			{
				if (ch == '\t' || automaticInsert) {
					((SharpDevelopTextAreaControl)textArea.MotherTextEditorControl).InsertTemplate(template);
					return false;
				} else {
					return base.InsertAction(textArea, ch);
				}
			}
		public override ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
		{
			if (completionData == null) {
				completionData = baseProvider.GenerateCompletionData(fileName, textArea, charTyped);
				preSelection = baseProvider.PreSelection;
				this.DefaultIndex = baseProvider.DefaultIndex;
			}
			return completionData;
		}
示例#26
0
        void Init()
        {
            propertyGridComboBox.SelectedIndex = 1;
            textArea = textEditorControl.ActiveTextAreaControl.TextArea;
            textArea.KeyEventHandler += ProcessKey;

            PopulateHighlightingComboBox();

            highlightingToolStripComboBox.Text = "C#";
        }
示例#27
0
文件: Caret.cs 项目: umabiel/WsdlUI
 public Caret(TextArea textArea)
 {
     this.textArea = textArea;
     textArea.GotFocus  += new EventHandler(GotFocus);
     textArea.LostFocus += new EventHandler(LostFocus);
     if (Environment.OSVersion.Platform == PlatformID.Unix)
         caretImplementation = new ManagedCaret(this);
     else
         caretImplementation = new Win32Caret(this);
 }
		/// <summary>
		/// Define XML specific smart indenting for a line :)
		/// </summary>
		protected override int SmartIndentLine(TextArea textArea, int lineNr)
		{
			if (lineNr <= 0) return AutoIndentLine(textArea, lineNr);
			try {
				TryIndent(textArea, lineNr, lineNr);
				return GetIndentation(textArea, lineNr).Length;
			} catch (XmlException) {
				return AutoIndentLine(textArea, lineNr);
			}
		}
        public override void Execute(TextArea textArea)
        {
            TextLocation position = textArea.Caret.Position;
            position.Line = _line;

            textArea.Caret.Position = position;
            textArea.SelectionManager.ClearSelection();
            textArea.SetDesiredColumn();
            
        }
示例#30
0
        public ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
        {
            string text = String.Concat(textArea.Document.GetText(0, textArea.Caret.Offset), charTyped);

            switch (charTyped)
            {
                case '<':
                    // Child element intellisense.
                    XmlElementPath parentPath = XmlParser.GetParentElementPath(text);
                    if (parentPath.Elements.Count > 0)
                    {
                        ICompletionData[] data = GetChildElementCompletionData(parentPath);
                        //returnval = data;
                        return data;
                    }
                    else if (defaultSchemaCompletionData != null)
                    {
                        return defaultSchemaCompletionData.GetElementCompletionData(defaultNamespacePrefix);
                    }
                    break;

                case ' ':
                    // Attribute intellisense.
                    if (!XmlParser.IsInsideAttributeValue(text, text.Length))
                    {
                        XmlElementPath path = XmlParser.GetActiveElementStartPath(text, text.Length);
                        if (path.Elements.Count > 0)
                        {
                            return GetAttributeCompletionData(path);
                        }
                    }
                    break;

                case '\'':
                case '\"':

                    // Attribute value intellisense.
                    //if (XmlParser.IsAttributeValueChar(charTyped)) {
                    text = text.Substring(0, text.Length - 1);
                    string attributeName = XmlParser.GetAttributeName(text, text.Length);
                    if (attributeName.Length > 0)
                    {
                        XmlElementPath elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
                        if (elementPath.Elements.Count > 0)
                        {
                            preSelection = charTyped.ToString();
                            return GetAttributeValueCompletionData(elementPath, attributeName);
                            //		}
                        }
                    }
                    break;
            }

            return null;
        }