public DocumentManager(RunnableQuery q, Control hostControl)
 {
     this._query = q;
     this._hostControl = hostControl;
     this._document = new ActiproSoftware.SyntaxEditor.Document();
     this._document.get_SpanIndicatorLayers().Add(this._mainErrorLayer = new SpanIndicatorLayer("errors", 0x3e8));
     this._document.get_SpanIndicatorLayers().Add(this._warningsLayer = new SpanIndicatorLayer("warnings", 0x3e8));
     this._document.get_SpanIndicatorLayers().Add(this._executedSelectionLayer = new SpanIndicatorLayer("executedSelection", 0));
     this._document.get_SpanIndicatorLayers().Add(this._uriLayer = new SpanIndicatorLayer("uriLayer", 0));
     this._document.get_SpanIndicatorLayers().Add(this._stackTraceLayer = new SpanIndicatorLayer("stackTrace", 0));
     if (UserOptions.Instance.TabSize.HasValue)
     {
         this._document.set_TabSize(UserOptions.Instance.TabSizeActual);
     }
     if (UserOptions.Instance.ConvertTabsToSpaces)
     {
         this._document.set_AutoConvertTabsToSpaces(true);
     }
     this._typeResolver = new ActiproBridge.TypeResolver(delegate (string name) {
         if (Program.Splash != null)
         {
             Program.Splash.UpdateMessage("Performing one-time build of autocompletion cache: " + name);
         }
     }, MyExtensions.AdditionalRefs);
     this.ConfigureLanguage();
     this.ConfigureResolver();
 }
Esempio n. 2
0
        private void MarkError(ParserSyntaxError error)
        {
            //DocumentPosition pos = ;
            int                offset         = error.StartOffset == -1 ? editor.Document.PositionToOffset(new DocumentPosition(error.LineNumber, 0)) : error.StartOffset;
            DynamicToken       token          = (DynamicToken)editor.Document.Tokens.GetTokenAtOffset(offset);
            SpanIndicatorLayer indicatorLayer = editor.Document.SpanIndicatorLayers[ErrorLayerKey];
            SpanIndicator      indicator      = new WaveLineSpanIndicator("ErrorIndicator", Color.Red);

            if (indicatorLayer == null)
            {
                indicatorLayer = new SpanIndicatorLayer(ErrorLayerKey, 1);
                editor.Document.SpanIndicatorLayers.Add(indicatorLayer);
            }
            int startOffset = Math.Min(token.StartOffset, indicatorLayer.Document.Length - 1);
            int length      = Math.Max(token.Length, 1);

            if (startOffset < 0)
            {
                return;                 // don't add indicators for errors without an offset.
            }
            SpanIndicator[] indicators = indicatorLayer.GetIndicatorsForTextRange(new ActiproSoftware.SyntaxEditor.TextRange(startOffset, startOffset + length));
            foreach (SpanIndicator i in indicators)
            {
                // If there is already an error indicator on that word, don't add another one.
                if (i.TextRange.StartOffset == startOffset && i.TextRange.Length == length)
                {
                    continue;
                }
            }
            indicatorLayer.Add(indicator, startOffset, length);
        }
Esempio n. 3
0
		public void ClearErrors()
		{
			foreach (TabItem page in tabStrip1.Tabs)
			{
				foreach (Control ctl in page.AttachedControl.Controls)
				{
					if (ctl.GetType() == typeof(ucFunction))
					{
						SpanIndicatorLayer layer =
							((ucFunction)ctl).syntaxEditor1.Document.SpanIndicatorLayers[ErrorLayerKey];
						if (layer != null)
							layer.Clear();
						break;
					}
				}
			}
			if (listErrors.InvokeRequired)
			{
				CrossThreadHelper.CallCrossThreadMethod(listErrors.Items, "Clear", null);
			}
			else
			{
				listErrors.Items.Clear();
			}
		}
Esempio n. 4
0
 public DocumentManager(RunnableQuery q, Control hostControl)
 {
     this._query       = q;
     this._hostControl = hostControl;
     this._document    = new ActiproSoftware.SyntaxEditor.Document();
     this._document.get_SpanIndicatorLayers().Add(this._mainErrorLayer         = new SpanIndicatorLayer("errors", 0x3e8));
     this._document.get_SpanIndicatorLayers().Add(this._warningsLayer          = new SpanIndicatorLayer("warnings", 0x3e8));
     this._document.get_SpanIndicatorLayers().Add(this._executedSelectionLayer = new SpanIndicatorLayer("executedSelection", 0));
     this._document.get_SpanIndicatorLayers().Add(this._uriLayer        = new SpanIndicatorLayer("uriLayer", 0));
     this._document.get_SpanIndicatorLayers().Add(this._stackTraceLayer = new SpanIndicatorLayer("stackTrace", 0));
     if (UserOptions.Instance.TabSize.HasValue)
     {
         this._document.set_TabSize(UserOptions.Instance.TabSizeActual);
     }
     if (UserOptions.Instance.ConvertTabsToSpaces)
     {
         this._document.set_AutoConvertTabsToSpaces(true);
     }
     this._typeResolver = new ActiproBridge.TypeResolver(delegate(string name) {
         if (Program.Splash != null)
         {
             Program.Splash.UpdateMessage("Performing one-time build of autocompletion cache: " + name);
         }
     }, MyExtensions.AdditionalRefs);
     this.ConfigureLanguage();
     this.ConfigureResolver();
 }
Esempio n. 5
0
		private void MarkErrorWord(SyntaxEditor editor, int lineNumber, int characterPos, string message)
		{
			string text = editor.Document.Lines[lineNumber].Text;
			string compileText = CompileHelper.ReplaceUserOptionCalls(text);
			string preceedingText = characterPos <= compileText.Length ? compileText.Substring(0, characterPos) : "";

			#region Find all GetUserOption calls and discount them

			int index = preceedingText.LastIndexOf("GetUserOption");
			int offsetUO = "GetUserOptionValue('')".Length - "UserOptions.".Length;
			int castEndPos = 0;
			int castStartPos = 0;

			while (index >= 0)
			{
				characterPos -= offsetUO;

				while (preceedingText[index] != ')')
				{
					castEndPos = index;
					index -= 1;
				}
				while (preceedingText[index] != '(')
				{
					castStartPos = index;
					index -= 1;
				}
				characterPos -= castEndPos - castStartPos + 1;
				index = preceedingText.LastIndexOf("GetUserOption", index);
			}

			#endregion

			DocumentPosition position = new DocumentPosition(lineNumber, characterPos);
			int offset = editor.Document.PositionToOffset(position);
			DynamicToken token = (DynamicToken)editor.Document.Tokens.GetTokenAtOffset(offset);
			SpanIndicator indicator = new WaveLineSpanIndicator("ErrorIndicator", Color.Red);
			indicator.Tag = message;
			SpanIndicatorLayer indicatorLayer = editor.Document.SpanIndicatorLayers[ErrorLayerKey];

			if (indicatorLayer == null)
			{
				indicatorLayer = new SpanIndicatorLayer(ErrorLayerKey, 1);
				editor.Document.SpanIndicatorLayers.Add(indicatorLayer);
			}
			int startOffset = Math.Min(token.StartOffset, indicatorLayer.Document.Length - 1);
			int length = Math.Max(token.Length, 1);
			SpanIndicator[] indicators = indicatorLayer.GetIndicatorsForTextRange(new TextRange(startOffset, startOffset + length));

			foreach (SpanIndicator i in indicators)
			{
				// If there is already an error indicator on that word, don't add another one.
				if (i.TextRange.StartOffset == startOffset && i.TextRange.Length == length)
					return;
			}
			indicatorLayer.Add(indicator, startOffset, length);
		}
Esempio n. 6
0
        private void ClearErrors()
        {
            errors.Clear();
            errorTreeList.Nodes.Clear();
            SpanIndicatorLayer indicatorLayer = editor.Document.SpanIndicatorLayers[ErrorLayerKey];

            if (indicatorLayer != null)
            {
                indicatorLayer.Clear();
            }
        }
Esempio n. 7
0
        private void LoadErrors(IEnumerable <CompilationError> errors)
        {
            _syntaxEditor.Document.SpanIndicatorLayers.Clear();
            if (errors != null)
            {
                SpanIndicatorLayer spanIndicatorLayer = new SpanIndicatorLayer(null, 0);
                _syntaxEditor.Document.SpanIndicatorLayers.Add(spanIndicatorLayer);

                foreach (CompilationError error in errors)
                {
                    if (error.SourceRange != SourceRange.None)
                    {
                        TextRange       textRange          = GetTextRange(error.SourceRange);
                        SpanIndicator[] existingIndicators = spanIndicatorLayer.GetIndicatorsForTextRange(textRange);
                        if (existingIndicators.Length == 0)
                        {
                            SyntaxErrorSpanIndicator errorIndicator = new SyntaxErrorSpanIndicator();
                            errorIndicator.Tag = error;
                            spanIndicatorLayer.Add(errorIndicator, textRange);
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        private void DisplaySmartTag(Point?onlyIfAtThisLocation, bool activateDropDown)
        {
            SpanIndicatorLayer layer = base.get_Document().get_SpanIndicatorLayers().get_Item("Smart tags");

            if ((((layer != null) && (layer.get_Count() > 0)) && (layer.get_Visible() && !base.get_IntelliPrompt().get_SmartTag().get_Visible())) && (AutocompletionManager.CurrentSmartTag != null))
            {
                int num = layer.get_Item(0).get_TextRange().get_EndOffset() - 1;
                if (onlyIfAtThisLocation.HasValue)
                {
                    Rectangle characterBounds = base.get_SelectedView().GetCharacterBounds(base.get_SelectedView().OffsetToPosition(num));
                    characterBounds.Height += characterBounds.Height / 2;
                    characterBounds.Inflate(3, 0);
                    if (!characterBounds.Contains(onlyIfAtThisLocation.Value))
                    {
                        return;
                    }
                }
                base.get_IntelliPrompt().get_SmartTag().Show(num, AutocompletionManager.CurrentSmartTag);
                if (activateDropDown)
                {
                    this.OnIntelliPromptSmartTagClicked(EventArgs.Empty);
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Returns the quick info for the <see cref="SyntaxEditor"/> at the specified offset.
        /// </summary>
        /// <param name="syntaxEditor">The <see cref="SyntaxEditor"/> to examine.</param>
        /// <param name="offset">The offset to examine.  The offset is updated to the start of the context.</param>
        /// <returns>The quick info for the <see cref="SyntaxEditor"/> at the specified offset.</returns>
        private string GetQuickInfo(ActiproSoftware.SyntaxEditor.SyntaxEditor syntaxEditor, ref int offset)
        {
            Document document = syntaxEditor.Document;

            // Get the identifier at the offset, if any
            TextStream stream = syntaxEditor.Document.GetTextStream(offset);

            if (!stream.IsAtTokenStart)
            {
                stream.GoToCurrentTokenStart();
            }
            offset = stream.Offset;

            // Check to see if we're over a warning
            SpanIndicatorLayer warningLayer = document.SpanIndicatorLayers[WarningLayerId];

            if (warningLayer != null)
            {
                var sb = new StringBuilder();

                var             range = new TextRange(offset, offset + 1);
                SpanIndicator[] spans = warningLayer.GetIndicatorsForTextRange(range);
                foreach (LuatWarningSpanIndicator span in spans)
                {
                    LuatWarning[] warnings = span.Warnings.Filter(warning => warning.TextRange.OverlapsWith(range));

                    var groupedWarnings = warnings.GroupItems(a => a.Message, a => a.Script);

                    foreach (KeyValuePair <string, LuatScript[]> groupedWarning in groupedWarnings)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append("<br /><br />");
                        }

                        sb.Append("Context: ");
                        sb.Append("<b>");
                        sb.Append(groupedWarning.Value.ToCommaSeperatedList(a => a.Name));
                        sb.Append("</b>");
                        sb.Append("<br />");

                        sb.Append(groupedWarning.Key);
                    }
                }

                if (sb.Length > 0)
                {
                    return(sb.ToString());
                }
            }

            // Get the containing node
            var cu = syntaxEditor.Document.SemanticParseData as CompilationUnit;

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

            var qi = cu.FindNodeRecursive <IQuickInfoProvider>(stream.Offset);

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

            return(FormatText(qi.QuickInfo));
        }
Esempio n. 10
0
        private void MarkErrorWord(SyntaxEditor editor, int lineNumber, int characterPos, string message)
        {
            string text = editor.Document.Lines[lineNumber].Text;
            string compileText = CompileHelper.ReplaceUserOptionCalls(text);
            string preceedingText = characterPos <= compileText.Length ? compileText.Substring(0, characterPos) : "";

            #region Find all GetUserOption calls and discount them

            int index = preceedingText.LastIndexOf("GetUserOption");
            int offsetUO = "GetUserOptionValue('')".Length - "UserOptions.".Length;
            int castEndPos = 0;
            int castStartPos = 0;

            while (index >= 0)
            {
                characterPos -= offsetUO;

                while (preceedingText[index] != ')')
                {
                    castEndPos = index;
                    index -= 1;
                }
                while (preceedingText[index] != '(')
                {
                    castStartPos = index;
                    index -= 1;
                }
                characterPos -= castEndPos - castStartPos + 1;
                index = preceedingText.LastIndexOf("GetUserOption", index);
            }

            #endregion

            DocumentPosition position = new DocumentPosition(lineNumber, characterPos);
            int offset = editor.Document.PositionToOffset(position);
            DynamicToken token = (DynamicToken)editor.Document.Tokens.GetTokenAtOffset(offset);
            SpanIndicator indicator = new WaveLineSpanIndicator("ErrorIndicator", Color.Red);
            indicator.Tag = message;
            SpanIndicatorLayer indicatorLayer = editor.Document.SpanIndicatorLayers[ErrorLayerKey];

            if (indicatorLayer == null)
            {
                indicatorLayer = new SpanIndicatorLayer(ErrorLayerKey, 1);
                editor.Document.SpanIndicatorLayers.Add(indicatorLayer);
            }
            int startOffset = Math.Min(token.StartOffset, indicatorLayer.Document.Length - 1);
            int length = Math.Max(token.Length, 1);
            SpanIndicator[] indicators = indicatorLayer.GetIndicatorsForTextRange(new TextRange(startOffset, startOffset + length));

            foreach (SpanIndicator i in indicators)
            {
                // If there is already an error indicator on that word, don't add another one.
                if (i.TextRange.StartOffset == startOffset && i.TextRange.Length == length)
                    return;
            }
            indicatorLayer.Add(indicator, startOffset, length);
        }
        private void MarkError(ParserSyntaxError error)
        {
            //DocumentPosition pos = ;
            int offset = error.StartOffset == -1 ? editor.Document.PositionToOffset(new DocumentPosition(error.LineNumber, 0)) : error.StartOffset;
            DynamicToken token = (DynamicToken)editor.Document.Tokens.GetTokenAtOffset(offset);
            SpanIndicatorLayer indicatorLayer = editor.Document.SpanIndicatorLayers[ErrorLayerKey];
            SpanIndicator indicator = new WaveLineSpanIndicator("ErrorIndicator", Color.Red);
            if (indicatorLayer == null)
            {
                indicatorLayer = new SpanIndicatorLayer(ErrorLayerKey, 1);
                editor.Document.SpanIndicatorLayers.Add(indicatorLayer);
            }
            int startOffset = Math.Min(token.StartOffset, indicatorLayer.Document.Length - 1);
            int length = Math.Max(token.Length, 1);

            if (startOffset < 0)
                return; // don't add indicators for errors without an offset.

            SpanIndicator[] indicators = indicatorLayer.GetIndicatorsForTextRange(new ActiproSoftware.SyntaxEditor.TextRange(startOffset, startOffset + length));
            foreach (SpanIndicator i in indicators)
            {
                // If there is already an error indicator on that word, don't add another one.
                if (i.TextRange.StartOffset == startOffset && i.TextRange.Length == length)
                    continue;
            }
            indicatorLayer.Add(indicator, startOffset, length);
        }
Esempio n. 12
0
		private void LoadErrors(IEnumerable<CompilationError> errors)
		{
			_syntaxEditor.Document.SpanIndicatorLayers.Clear();
			if (errors != null)
			{
				SpanIndicatorLayer spanIndicatorLayer = new SpanIndicatorLayer(null, 0);
				_syntaxEditor.Document.SpanIndicatorLayers.Add(spanIndicatorLayer);

				foreach (CompilationError error in errors)
				{
					if (error.SourceRange != SourceRange.None)
					{
						TextRange textRange = GetTextRange(error.SourceRange);
						SpanIndicator[] existingIndicators = spanIndicatorLayer.GetIndicatorsForTextRange(textRange);
						if (existingIndicators.Length == 0)
						{
							SyntaxErrorSpanIndicator errorIndicator = new SyntaxErrorSpanIndicator();
							errorIndicator.Tag = error;
							spanIndicatorLayer.Add(errorIndicator, textRange);
						}
					}
				}
			}
		}
Esempio n. 13
0
        private static void DiffInSingleEditor(List <DiffMatchPatch.Diff> diffs, SyntaxEditor editor)
        {
            //editor.SuspendLayout();
            //editor.SuspendPainting();
            Document doc = new Document();

            Color backColorGreen = Color.FromArgb(230, 255, 230);
            Color backColorRed   = Color.FromArgb(255, 230, 230);

            #region Deleted style
            SpanIndicatorLayer deletedLayer             = new SpanIndicatorLayer("Deleted", 1000);
            HighlightingStyle  deletedHighlightingStyle = new HighlightingStyle("Deleted", null, Color.Empty, backColorRed)
            {
                StrikeOutStyle = HighlightingStyleLineStyle.Solid,
                StrikeOutColor = Color.Red
            };
            doc.SpanIndicatorLayers.Add(deletedLayer);
            #endregion

            #region New style
            SpanIndicatorLayer newLayer             = new SpanIndicatorLayer("New", 1000);
            HighlightingStyle  newHighlightingStyle = new HighlightingStyle("New", null, Color.Empty, backColorGreen);
            doc.SpanIndicatorLayers.Add(newLayer);
            #endregion

            System.Text.StringBuilder sb = new System.Text.StringBuilder(10000);

            foreach (DiffMatchPatch.Diff aDiff in diffs)
            {
                sb.Append(aDiff.text);
            }

            doc.Text = sb.ToString();

            int start     = 0;
            int endOffset = 0;
            int i         = 0;

            foreach (DiffMatchPatch.Diff aDiff in diffs)
            {
                int diffLength = aDiff.text.Length;

                switch (aDiff.operation)
                {
                case DiffMatchPatch.Operation.INSERT:                        //green
                    start     = i;
                    endOffset = i + diffLength;

                    if (endOffset > start)
                    {
                        newLayer.Add(new HighlightingStyleSpanIndicator("New", newHighlightingStyle), new TextRange(start, endOffset));
                    }

                    break;

                case DiffMatchPatch.Operation.DELETE:                        //red
                    start     = i;
                    endOffset = i + diffLength;

                    if (endOffset > start)
                    {
                        deletedLayer.Add(new HighlightingStyleSpanIndicator("Deleted", deletedHighlightingStyle), new TextRange(start, endOffset));
                    }

                    break;
                    //case Operation.EQUAL:
                    //    start = i;// editor.Document.GetText(LineTerminator.Newline).Length;
                    //    //editor.Document.InsertText(DocumentModificationType.Custom, start, aDiff.text);
                    //    //editor.Document.AppendText(aDiff.text);
                    //    break;
                }
                //if (aDiff.operation != Operation.DELETE)
                i += diffLength;
            }
            editor.Document = doc;
            //editor.SelectedView.EnsureVisible(1, false);
            //editor.ResumeLayout();
            //editor.ResumePainting();
        }
Esempio n. 14
0
        private static void DiffInSingleEditor(List<DiffMatchPatch.Diff> diffs, SyntaxEditor editor)
        {
            //editor.SuspendLayout();
            //editor.SuspendPainting();
            Document doc = new Document();

            Color backColorGreen = Color.FromArgb(230, 255, 230);
            Color backColorRed = Color.FromArgb(255, 230, 230);

            #region Deleted style
            SpanIndicatorLayer deletedLayer = new SpanIndicatorLayer("Deleted", 1000);
            HighlightingStyle deletedHighlightingStyle = new HighlightingStyle("Deleted", null, Color.Empty, backColorRed)
            {
                StrikeOutStyle = HighlightingStyleLineStyle.Solid,
                StrikeOutColor = Color.Red
            };
            doc.SpanIndicatorLayers.Add(deletedLayer);
            #endregion

            #region New style
            SpanIndicatorLayer newLayer = new SpanIndicatorLayer("New", 1000);
            HighlightingStyle newHighlightingStyle = new HighlightingStyle("New", null, Color.Empty, backColorGreen);
            doc.SpanIndicatorLayers.Add(newLayer);
            #endregion

            System.Text.StringBuilder sb = new System.Text.StringBuilder(10000);

            foreach (DiffMatchPatch.Diff aDiff in diffs)
                sb.Append(aDiff.text);

            doc.Text = sb.ToString();

            int start = 0;
            int endOffset = 0;
            int i = 0;

            foreach (DiffMatchPatch.Diff aDiff in diffs)
            {
                int diffLength = aDiff.text.Length;

                switch (aDiff.operation)
                {
                    case DiffMatchPatch.Operation.INSERT://green
                        start = i;
                        endOffset = i + diffLength;

                        if (endOffset > start)
                            newLayer.Add(new HighlightingStyleSpanIndicator("New", newHighlightingStyle), new TextRange(start, endOffset));

                        break;
                    case DiffMatchPatch.Operation.DELETE://red
                        start = i;
                        endOffset = i + diffLength;

                        if (endOffset > start)
                            deletedLayer.Add(new HighlightingStyleSpanIndicator("Deleted", deletedHighlightingStyle), new TextRange(start, endOffset));

                        break;
                    //case Operation.EQUAL:
                    //    start = i;// editor.Document.GetText(LineTerminator.Newline).Length;
                    //    //editor.Document.InsertText(DocumentModificationType.Custom, start, aDiff.text);
                    //    //editor.Document.AppendText(aDiff.text);
                    //    break;
                }
                //if (aDiff.operation != Operation.DELETE)
                i += diffLength;
            }
            editor.Document = doc;
            //editor.SelectedView.EnsureVisible(1, false);
            //editor.ResumeLayout();
            //editor.ResumePainting();
        }
Esempio n. 15
0
        /// <summary>
        /// Sets/unsets current-statement indicator for the specified line</summary>
        /// <param name="lineNumber">Line to set/unset statement indicator</param>
        /// <param name="set">True to set statement indicator, false to unset it</param>
        /// <remarks>
        /// Setting an already set current-statement indicator will not have any side effect.
        /// Unsetting an already unsetted current-statement indicator will not have any side effect.
        /// This method throws ArgumentOutOfRangeException if line number is out of range.</remarks>
        public void CurrentStatement(int lineNumber, bool set)
        {
            // check if the value is within the ranges.
            if (lineNumber < 1 || lineNumber > Document.Lines.Count)
                throw new ArgumentOutOfRangeException();

            var line = Document.Lines[lineNumber - 1];
            if (StringUtil.IsNullOrEmptyOrWhitespace(line.Text))
                return;

            // try to get indicators layer
            var layer = Document.SpanIndicatorLayers[SpanIndicatorLayer.CurrentStatementKey];
            if (set)
            {
                if (layer == null)
                {
                    layer = new SpanIndicatorLayer(SpanIndicatorLayer.CurrentStatementKey,
                                                   SpanIndicatorLayer.CurrentStatementDisplayPriority);
                    Document.SpanIndicatorLayers.Add(layer);
                }
                if (!layer.OverlapsWith(line.TextRange))
                    layer.Add(new CurrentStatementSpanIndicator(), line.TextRange);
            }
            else
            {
                if (layer != null && layer.OverlapsWith(line.TextRange))
                {
                    var spanIndicators = layer.GetIndicatorsForTextRange(line.TextRange);
                    foreach (var s in spanIndicators)
                    {
                        if (s is CurrentStatementSpanIndicator)
                            layer.Remove(s);
                    }
                }
            }
        }
Esempio n. 16
0
        protected override void OnSyntaxEditorSelectionChanged(ActiproSoftware.SyntaxEditor.SyntaxEditor syntaxEditor, SelectionEventArgs e)
        {
            Document document = syntaxEditor.Document;

            SpanIndicatorLayer referenceLayer = document.SpanIndicatorLayers[ReferenceLayerId];
            if (referenceLayer == null)
            {
                referenceLayer = new SpanIndicatorLayer(ReferenceLayerId, ReferenceLayerPriority);
                document.SpanIndicatorLayers.Add(referenceLayer);
            }

            SpanIndicatorLayer assignmentLayer = document.SpanIndicatorLayers[AssignmentLayerId];
            if (assignmentLayer == null)
            {
                assignmentLayer = new SpanIndicatorLayer(AssignmentLayerId, AssignmentLayerPriority);
                document.SpanIndicatorLayers.Add(assignmentLayer);
            }

            m_plugin.TaskQueue.AddTask(() =>
            {
                referenceLayer.Clear();
                assignmentLayer.Clear();

                var cu = document.SemanticParseData as CompilationUnit;
                if (cu == null)
                    return;

                var expression = cu.FindNodeRecursive<Expression>(e.Selection.StartOffset);
                if (expression == null)
                    return;

                string path = System.IO.Path.GetFullPath(document.Filename);

                foreach (LuatValue value in expression.ResolvedValues.Values)
                {
                    var variable = value as LuatVariable;
                    if (null != variable)
                    {
                        foreach (LuatValue.IReference reference in value.References)
                        {
                            if (path == System.IO.Path.GetFullPath(reference.Path))
                            {
                                referenceLayer.Add(new HighlightingStyleSpanIndicator(null, ReferenceStyle), ((SyntaxEditorTextRange)reference.TextRange).ToTextRange(), false);
                            }
                        }
                        foreach (LuatValue.IReference assignment in variable.Assignments)
                        {
                            if (path == System.IO.Path.GetFullPath(assignment.Path))
                            {
                                assignmentLayer.Add(new HighlightingStyleSpanIndicator(null, AssignmentStyle), ((SyntaxEditorTextRange)assignment.TextRange).ToTextRange(), false);
                            }
                        }
                    }
                }
            }, TaskQueue.Thread.Worker);

            base.OnSyntaxEditorSelectionChanged(syntaxEditor, e);
        }
Esempio n. 17
0
        /// <summary>
        /// Processes the syntax warnings for the document
        /// </summary>
        /// <param name="document"></param>
        private void DoProcessSyntaxWarnings(Document document)
        {
            // This function is expensive for the UI thread.
            // Only do this when the user is not bashing away at the keyboard
            TimeSpan time = DateTime.Now - m_timeLastKey;

            if (time.TotalSeconds < MinTimeAfterKeyBeforeRedraw)
            {
                // Too soon after the last key-press.
                // Queue up this task for later processing.
                ProcessSyntaxWarnings(document);
                return;
            }

            var cu = document.SemanticParseData as CompilationUnit;

            if (cu == null)
            {
                return;
            }

            // Ensure that a syntax error warningLayer is created...
            SpanIndicatorLayer warningLayer = document.SpanIndicatorLayers[WarningLayerId];

            if (warningLayer == null)
            {
                warningLayer = new SpanIndicatorLayer(WarningLayerId, WarningLayerPriority);
                document.SpanIndicatorLayers.Add(warningLayer);
            }

            warningLayer.Clear();

            var warnings = new List <LuatWarning>(cu.Warnings);

            warnings.Sort();

            // Merge overlapping warnings spans
            int count = warnings.Count;

            if (count > 0)
            {
                var spanWarnings = new List <LuatWarning>();
                int start = 0, end = 0;

                foreach (LuatWarning warning in warnings)
                {
                    if (warning.TextRange.StartOffset < end)
                    {
                        // Overlap.
                        end = Math.Max(end, warning.TextRange.StartOffset);
                    }
                    else
                    {
                        // No overlap.
                        // Flush existing spans
                        if (spanWarnings.Count > 0)
                        {
                            warningLayer.Add(new LuatWarningSpanIndicator(WarningStyle, spanWarnings.ToArray()), new TextRange(start, end), false);
                        }

                        // Create new span
                        spanWarnings.Clear();
                        start = warning.TextRange.StartOffset;
                        end   = warning.TextRange.EndOffset;
                    }

                    spanWarnings.Add(warning);
                }

                var textRange = new TextRange(start, end);
                warningLayer.Add(new LuatWarningSpanIndicator(WarningStyle, spanWarnings.ToArray()), textRange, false);
            }
        }
Esempio n. 18
0
        protected override void OnSyntaxEditorSelectionChanged(ActiproSoftware.SyntaxEditor.SyntaxEditor syntaxEditor, SelectionEventArgs e)
        {
            Document document = syntaxEditor.Document;

            SpanIndicatorLayer referenceLayer = document.SpanIndicatorLayers[ReferenceLayerId];

            if (referenceLayer == null)
            {
                referenceLayer = new SpanIndicatorLayer(ReferenceLayerId, ReferenceLayerPriority);
                document.SpanIndicatorLayers.Add(referenceLayer);
            }

            SpanIndicatorLayer assignmentLayer = document.SpanIndicatorLayers[AssignmentLayerId];

            if (assignmentLayer == null)
            {
                assignmentLayer = new SpanIndicatorLayer(AssignmentLayerId, AssignmentLayerPriority);
                document.SpanIndicatorLayers.Add(assignmentLayer);
            }

            m_plugin.TaskQueue.AddTask(() =>
            {
                referenceLayer.Clear();
                assignmentLayer.Clear();

                var cu = document.SemanticParseData as CompilationUnit;
                if (cu == null)
                {
                    return;
                }

                var expression = cu.FindNodeRecursive <Expression>(e.Selection.StartOffset);
                if (expression == null)
                {
                    return;
                }

                string path = System.IO.Path.GetFullPath(document.Filename);

                foreach (LuatValue value in expression.ResolvedValues.Values)
                {
                    var variable = value as LuatVariable;
                    if (null != variable)
                    {
                        foreach (LuatValue.IReference reference in value.References)
                        {
                            if (path == System.IO.Path.GetFullPath(reference.Path))
                            {
                                referenceLayer.Add(new HighlightingStyleSpanIndicator(null, ReferenceStyle), ((SyntaxEditorTextRange)reference.TextRange).ToTextRange(), false);
                            }
                        }
                        foreach (LuatValue.IReference assignment in variable.Assignments)
                        {
                            if (path == System.IO.Path.GetFullPath(assignment.Path))
                            {
                                assignmentLayer.Add(new HighlightingStyleSpanIndicator(null, AssignmentStyle), ((SyntaxEditorTextRange)assignment.TextRange).ToTextRange(), false);
                            }
                        }
                    }
                }
            }, TaskQueue.Thread.Worker);

            base.OnSyntaxEditorSelectionChanged(syntaxEditor, e);
        }
Esempio n. 19
0
        /// <summary>
        /// Populates a single Actipro SyntaxEditor with diff-highlighted text.
        /// </summary>
        /// <param name="editor">Actipro SyntaxEditor</param>
        /// <param name="text">Fully combined text.</param>
        /// <param name="newLines">Lines unique to the new file.</param>
        /// <param name="oldLines">Lines unique to the original file.</param>
        /// <param name="strikeoutLine2Lines"></param>
        public static void PopulateSyntaxEditor(ActiproSoftware.SyntaxEditor.SyntaxEditor editor, string text, SlyceMerge.LineSpan[] newLines, SlyceMerge.LineSpan[] oldLines, bool strikeoutLine2Lines)
        {
            editor.Text = text;
            SpanIndicatorLayer layer             = null;
            HighlightingStyle  highlightingStyle = null;
            List <int>         linesToNotCount   = new List <int>();

            if (strikeoutLine2Lines)
            {
                layer             = new SpanIndicatorLayer("Diff", 1000);
                highlightingStyle = new HighlightingStyle("Diff", null, Color.Empty, Color.Empty);
                highlightingStyle.StrikeOutStyle = HighlightingStyleLineStyle.Solid;
                highlightingStyle.StrikeOutColor = Color.Red;
                editor.Document.SpanIndicatorLayers.Add(layer);
            }
            for (int i = 0; i < oldLines.Length; i++)
            {
                if (strikeoutLine2Lines)
                {
                    for (int lineCounter = oldLines[i].StartLine; lineCounter <= oldLines[i].EndLine; lineCounter++)
                    {
                        editor.Document.Lines[lineCounter].BackColor = Color.MistyRose;                        // ColourUser;
                        editor.Document.Lines[lineCounter].SelectionMarginMarkColor = deletedMarkerColour;     // changedMarkerColour;
                        editor.Document.Lines[lineCounter].CustomLineNumber         = String.Empty;
                        layer.Add(new HighlightingStyleSpanIndicator("Diff", highlightingStyle), editor.Document.Lines[lineCounter].TextRange);
                        linesToNotCount.Add(lineCounter);
                    }
                }
                else
                {
                    for (int lineCounter = oldLines[i].StartLine; lineCounter <= oldLines[i].EndLine; lineCounter++)
                    {
                        editor.Document.Lines[lineCounter].BackColor = ColourNewGen;
                        editor.Document.Lines[lineCounter].SelectionMarginMarkColor = addedMarkerColour;
                    }
                }
            }
            for (int i = 0; i < newLines.Length; i++)
            {
                for (int lineCounter = newLines[i].StartLine; lineCounter <= newLines[i].EndLine; lineCounter++)
                {
                    editor.Document.Lines[lineCounter].BackColor = Color.Honeydew;                    // ColourUser;
                    editor.Document.Lines[lineCounter].SelectionMarginMarkColor = addedMarkerColour;  // changedMarkerColour;
                }
            }
            // Fix-up changed vs. new/deleted
            for (int i = 0; i < editor.Document.Lines.Count; i++)
            {
                if (editor.Document.Lines[i].SelectionMarginMarkColor == addedMarkerColour)
                {
                    int  startLine       = i;
                    int  endLine         = -1;
                    bool changeProcessed = false;

                    for (int checkCounter = i + 1; checkCounter < editor.Document.Lines.Count; checkCounter++)
                    {
                        if (changeProcessed)
                        {
                            break;
                        }
                        if (editor.Document.Lines[checkCounter].SelectionMarginMarkColor == addedMarkerColour)
                        {
                            continue;
                        }
                        else if (editor.Document.Lines[checkCounter].SelectionMarginMarkColor == deletedMarkerColour)
                        {
                            // We have found a change
                            for (int deleteCounter = checkCounter + 1; deleteCounter < editor.Document.Lines.Count; deleteCounter++)
                            {
                                if (editor.Document.Lines[deleteCounter].SelectionMarginMarkColor != deletedMarkerColour)
                                {
                                    endLine = deleteCounter - 1;

                                    // Apply the Change colouring
                                    for (int changeCounter = startLine; changeCounter <= endLine; changeCounter++)
                                    {
                                        editor.Document.Lines[changeCounter].SelectionMarginMarkColor = changedMarkerColour;
                                        editor.Document.Lines[changeCounter].BackColor = Color.LightYellow;
                                    }
                                    changeProcessed = true;
                                    // We are back to 'normal' lines - no change found
                                    i = checkCounter;
                                    break;
                                }
                                else
                                {
                                    editor.Document.Lines[deleteCounter].CustomLineNumber = string.Empty;
                                }
                            }
                        }
                        else
                        {
                            // We are back to 'normal' lines - no change found
                            i = checkCounter;
                            break;
                        }
                    }
                }
            }
            int lineNumber = 1;

            for (int i = 0; i < editor.Document.Lines.Count; i++)
            {
                if (linesToNotCount.Contains(i))
                {
                    editor.Document.Lines[i].CustomLineNumber = string.Empty;
                }
                else
                {
                    editor.Document.Lines[i].CustomLineNumber = lineNumber.ToString();
                    lineNumber++;
                }
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Populates two Actipro SyntaxEditors with diff-highlighted text.
        /// </summary>
        /// <param name="editor1">Actipro SyntaxEditor</param>
        /// <param name="editor2">Actipro SyntaxEditor</param>
        /// <param name="text">Fully combined text.</param>
        /// <param name="lines1">Lines unique to the left file.</param>
        /// <param name="lines2">Lines unique to the right file.</param>
        public static void PopulateSyntaxEditors(
            ActiproSoftware.SyntaxEditor.SyntaxEditor editor1,
            ActiproSoftware.SyntaxEditor.SyntaxEditor editor2,
            string text,
            SlyceMerge.LineSpan[] lines1,
            SlyceMerge.LineSpan[] lines2)
        {
            editor1.Text = text;
            editor2.Text = text;

            for (int i = 0; i < lines1.Length; i++)
            {
                for (int lineCounter = lines1[i].StartLine; lineCounter <= lines1[i].EndLine; lineCounter++)
                {
                    editor1.Document.Lines[lineCounter].BackColor = ColourNewGen;
                    editor2.Document.Lines[lineCounter].BackColor = Color.LightGray;
                    editor2.Document.DeleteText(ActiproSoftware.SyntaxEditor.DocumentModificationType.Delete, editor2.Document.Lines[lineCounter].StartOffset, editor2.Document.Lines[lineCounter].Length);
                }
            }
            for (int i = 0; i < lines2.Length; i++)
            {
                for (int lineCounter = lines2[i].StartLine; lineCounter <= lines2[i].EndLine; lineCounter++)
                {
                    editor2.Document.Lines[lineCounter].BackColor = ColourNewGen;
                    editor1.Document.Lines[lineCounter].BackColor = Color.LightGray;
                    editor1.Document.DeleteText(ActiproSoftware.SyntaxEditor.DocumentModificationType.Delete, editor1.Document.Lines[lineCounter].StartOffset, editor1.Document.Lines[lineCounter].Length);
                }
            }
            // Compact the displays
            int lineCount1 = 0;
            int lineCount2 = 0;

            for (int i = editor1.Document.Lines.Count - 1; i >= -1; i--)
            {
                Color lineColor = Color.Empty;

                if (i >= 0)
                {
                    lineColor = editor1.Document.Lines[i].BackColor;
                }
                if (lineColor == Color.Empty && (lineCount1 + lineCount2) > 0)
                {
                    // Process counted lines
                    int startIndex         = i + 1;
                    int condensedLineCount = Math.Max(lineCount1, lineCount2);
                    int numLinesToRemove   = lineCount1 + lineCount2 - condensedLineCount;
                    int lastLine           = startIndex + lineCount1 + lineCount2 - 1;

                    //if (numLinesToRemove > 0)
                    //{
                    //   // Walk backward when processing Left
                    //   for (int removeIndex = lastLine; removeIndex >= startIndex + condensedLineCount; removeIndex--)
                    //   {
                    //      editor1.Document.Lines[removeIndex].BackColor = editor1.Document.Lines[removeIndex + 1].BackColor;
                    //      editor1.Document.Lines.RemoveAt(removeIndex);

                    //      int newPos = lastLine - condensedLineCount - (lastLine - removeIndex);
                    //      string gg = editor2.Document.Lines[removeIndex].Text;
                    //      editor2.Document.Lines[newPos].Text = editor2.Document.Lines[removeIndex].Text;
                    //      editor2.Document.Lines[newPos].BackColor = editor2.Document.Lines[removeIndex].BackColor;
                    //      editor2.Document.Lines[removeIndex].BackColor = editor2.Document.Lines[removeIndex + 1].BackColor;
                    //      editor2.Document.Lines.RemoveAt(removeIndex);
                    //   }
                    //}
                    numLinesToRemove = Math.Min(lineCount1, lineCount2);
                    int linesRemoved1 = 0;
                    int linesRemoved2 = 0;

                    for (int x = startIndex + (lineCount1 + lineCount2); x >= startIndex; x--)
                    {
                        if (linesRemoved1 < numLinesToRemove &&
                            editor1.Document.Lines[x].BackColor == Color.LightGray)
                        {
                            editor1.Document.Lines[x].BackColor = editor1.Document.Lines[x + 1].BackColor;
                            editor1.Document.Lines.RemoveAt(x);
                            linesRemoved1++;
                        }
                        if (linesRemoved2 < numLinesToRemove &&
                            editor2.Document.Lines[x].BackColor == Color.LightGray)
                        {
                            editor2.Document.Lines[x].BackColor = editor2.Document.Lines[x + 1].BackColor;
                            editor2.Document.Lines.RemoveAt(x);
                            linesRemoved2++;
                        }
                    }
                    if (linesRemoved1 != linesRemoved2)
                    {
                        throw new Exception("Non-equal number of lines removed.");
                    }

                    //if (lineCount1 > lineCount2)
                    //{
                    //   // Remove trailing gray lines from editor2
                    //   for (int removeIndex = startIndex; removeIndex <= startIndex + numLinesToRemove; removeIndex++)
                    //   {
                    //      string q111 = editor1.Document.Lines[removeIndex].Text;
                    //      string gg = editor2.Document.Lines[removeIndex].Text;
                    //      editor2.Document.Lines.RemoveAt(removeIndex);
                    //   }
                    //}
                    //else if (lineCount2 > lineCount1)
                    //{
                    //   // Remove trailing gray lines from editor1
                    //   for (int removeIndex = lastLine; removeIndex >= startIndex + condensedLineCount; removeIndex--)
                    //   {
                    //      string q111 = editor1.Document.Lines[removeIndex].Text;
                    //      string gg = editor2.Document.Lines[removeIndex].Text;
                    //      editor1.Document.Lines.RemoveAt(removeIndex);
                    //   }
                    //}
                    lineCount1 = 0;
                    lineCount2 = 0;
                    continue;
                }
                else if (lineColor == ColourNewGen)
                {
                    lineCount1++;
                }
                else if (lineColor == Color.LightGray)
                {
                    lineCount2++;
                }
            }
            // Line Marker Colours, Strikethroughs
            string             layerKey          = "Diff";
            string             indicatorKey      = "Diff";
            SpanIndicatorLayer layer             = new SpanIndicatorLayer(layerKey, 1000);
            HighlightingStyle  highlightingStyle = new HighlightingStyle("Diff", null, Color.Empty, Color.Empty);

            highlightingStyle.StrikeOutStyle = HighlightingStyleLineStyle.Solid;
            highlightingStyle.StrikeOutColor = Color.Red;
            editor1.Document.SpanIndicatorLayers.Add(layer);

            int lineNumber1 = 1;
            int lineNumber2 = 1;

            for (int i = 0; i < editor1.Document.Lines.Count; i++)
            {
                // Set the line marker colours
                if (editor1.Document.Lines[i].BackColor == Color.LightGray &&
                    editor2.Document.Lines[i].BackColor == ColourNewGen)
                {
                    if (i > 0 && editor2.Document.Lines[i - 1].SelectionMarginMarkColor == changedMarkerColour)
                    {
                        editor2.Document.Lines[i].SelectionMarginMarkColor = changedMarkerColour;
                        editor2.Document.Lines[i].BackColor = Color.LightYellow;
                    }
                    else
                    {
                        editor2.Document.Lines[i].SelectionMarginMarkColor = addedMarkerColour;
                        editor2.Document.Lines[i].BackColor = Color.Honeydew;
                    }
                    editor1.Document.Lines[i].BackColor        = Color.WhiteSmoke;
                    editor1.Document.Lines[i].CustomLineNumber = string.Empty;
                    editor2.Document.Lines[i].CustomLineNumber = lineNumber2.ToString();
                    lineNumber2++;
                }
                else if (editor1.Document.Lines[i].BackColor == ColourNewGen &&
                         editor2.Document.Lines[i].BackColor == Color.LightGray)
                {
                    editor2.Document.Lines[i].SelectionMarginMarkColor = deletedMarkerColour;
                    editor1.Document.Lines[i].BackColor        = Color.MistyRose;
                    editor2.Document.Lines[i].BackColor        = Color.WhiteSmoke;
                    editor1.Document.Lines[i].CustomLineNumber = lineNumber1.ToString();
                    editor2.Document.Lines[i].CustomLineNumber = string.Empty;
                    lineNumber1++;
                }
                else if (editor1.Document.Lines[i].BackColor == ColourNewGen &&
                         editor2.Document.Lines[i].BackColor == ColourNewGen)
                {
                    editor2.Document.Lines[i].SelectionMarginMarkColor = changedMarkerColour;
                    editor1.Document.Lines[i].BackColor = Color.LightYellow;
                    editor2.Document.Lines[i].BackColor = Color.LightYellow;
                    layer.Add(new HighlightingStyleSpanIndicator(indicatorKey, highlightingStyle), editor1.Document.Lines[i].TextRange);
                    editor1.Document.Lines[i].CustomLineNumber = lineNumber1.ToString();
                    editor2.Document.Lines[i].CustomLineNumber = lineNumber2.ToString();
                    lineNumber1++;
                    lineNumber2++;
                }
                else
                {
                    editor1.Document.Lines[i].CustomLineNumber = lineNumber1.ToString();
                    editor2.Document.Lines[i].CustomLineNumber = lineNumber2.ToString();
                    lineNumber1++;
                    lineNumber2++;
                }
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Processes the syntax warnings for the document
        /// </summary>
        /// <param name="document"></param>
        private void DoProcessSyntaxWarnings(Document document)
        {
            // This function is expensive for the UI thread.
            // Only do this when the user is not bashing away at the keyboard
            TimeSpan time = DateTime.Now - m_timeLastKey;
            if (time.TotalSeconds < MinTimeAfterKeyBeforeRedraw)
            {
                // Too soon after the last key-press.
                // Queue up this task for later processing.
                ProcessSyntaxWarnings(document);
                return;
            }

            var cu = document.SemanticParseData as CompilationUnit;
            if (cu == null)
                return;

            // Ensure that a syntax error warningLayer is created...
            SpanIndicatorLayer warningLayer = document.SpanIndicatorLayers[WarningLayerId];
            if (warningLayer == null)
            {
                warningLayer = new SpanIndicatorLayer(WarningLayerId, WarningLayerPriority);
                document.SpanIndicatorLayers.Add(warningLayer);
            }

            warningLayer.Clear();

            var warnings = new List<LuatWarning>(cu.Warnings);
            warnings.Sort();

            // Merge overlapping warnings spans
            int count = warnings.Count;
            if (count > 0)
            {
                var spanWarnings = new List<LuatWarning>();
                int start = 0, end = 0;

                foreach (LuatWarning warning in warnings)
                {
                    if (warning.TextRange.StartOffset < end)
                    {
                        // Overlap.
                        end = Math.Max(end, warning.TextRange.StartOffset);
                    }
                    else
                    {
                        // No overlap.
                        // Flush existing spans
                        if (spanWarnings.Count > 0)
                        {
                            warningLayer.Add(new LuatWarningSpanIndicator(WarningStyle, spanWarnings.ToArray()), new TextRange(start, end), false);
                        }

                        // Create new span
                        spanWarnings.Clear();
                        start = warning.TextRange.StartOffset;
                        end = warning.TextRange.EndOffset;
                    }

                    spanWarnings.Add(warning);
                }

                var textRange = new TextRange(start, end);
                warningLayer.Add(new LuatWarningSpanIndicator(WarningStyle, spanWarnings.ToArray()), textRange, false);
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Populates a single Actipro SyntaxEditor with diff-highlighted text.
        /// </summary>
        /// <param name="editor">Actipro SyntaxEditor</param>
        /// <param name="text">Fully combined text.</param>
        /// <param name="newLines">Lines unique to the new file.</param>
        /// <param name="oldLines">Lines unique to the original file.</param>
        /// <param name="strikeoutLine2Lines"></param>
        public static void PopulateSyntaxEditor(ActiproSoftware.SyntaxEditor.SyntaxEditor editor, string text, SlyceMerge.LineSpan[] newLines, SlyceMerge.LineSpan[] oldLines, bool strikeoutLine2Lines)
        {
            editor.Text = text;
            SpanIndicatorLayer layer = null;
            HighlightingStyle highlightingStyle = null;
            List<int> linesToNotCount = new List<int>();

            if (strikeoutLine2Lines)
            {
                layer = new SpanIndicatorLayer("Diff", 1000);
                highlightingStyle = new HighlightingStyle("Diff", null, Color.Empty, Color.Empty);
                highlightingStyle.StrikeOutStyle = HighlightingStyleLineStyle.Solid;
                highlightingStyle.StrikeOutColor = Color.Red;
                editor.Document.SpanIndicatorLayers.Add(layer);
            }
            for (int i = 0; i < oldLines.Length; i++)
            {
                if (strikeoutLine2Lines)
                {
                    for (int lineCounter = oldLines[i].StartLine; lineCounter <= oldLines[i].EndLine; lineCounter++)
                    {
                        editor.Document.Lines[lineCounter].BackColor = Color.MistyRose;// ColourUser;
                        editor.Document.Lines[lineCounter].SelectionMarginMarkColor = deletedMarkerColour;// changedMarkerColour;
                        editor.Document.Lines[lineCounter].CustomLineNumber = String.Empty;
                        layer.Add(new HighlightingStyleSpanIndicator("Diff", highlightingStyle), editor.Document.Lines[lineCounter].TextRange);
                        linesToNotCount.Add(lineCounter);
                    }
                }
                else
                {
                    for (int lineCounter = oldLines[i].StartLine; lineCounter <= oldLines[i].EndLine; lineCounter++)
                    {
                        editor.Document.Lines[lineCounter].BackColor = ColourNewGen;
                        editor.Document.Lines[lineCounter].SelectionMarginMarkColor = addedMarkerColour;
                    }
                }
            }
            for (int i = 0; i < newLines.Length; i++)
            {
                for (int lineCounter = newLines[i].StartLine; lineCounter <= newLines[i].EndLine; lineCounter++)
                {
                    editor.Document.Lines[lineCounter].BackColor = Color.Honeydew;// ColourUser;
                    editor.Document.Lines[lineCounter].SelectionMarginMarkColor = addedMarkerColour;// changedMarkerColour;
                }
            }
            // Fix-up changed vs. new/deleted
            for (int i = 0; i < editor.Document.Lines.Count; i++)
            {
                if (editor.Document.Lines[i].SelectionMarginMarkColor == addedMarkerColour)
                {
                    int startLine = i;
                    int endLine = -1;
                    bool changeProcessed = false;

                    for (int checkCounter = i + 1; checkCounter < editor.Document.Lines.Count; checkCounter++)
                    {
                        if (changeProcessed)
                        {
                            break;
                        }
                        if (editor.Document.Lines[checkCounter].SelectionMarginMarkColor == addedMarkerColour)
                        {
                            continue;
                        }
                        else if (editor.Document.Lines[checkCounter].SelectionMarginMarkColor == deletedMarkerColour)
                        {
                            // We have found a change
                            for (int deleteCounter = checkCounter + 1; deleteCounter < editor.Document.Lines.Count; deleteCounter++)
                            {
                                if (editor.Document.Lines[deleteCounter].SelectionMarginMarkColor != deletedMarkerColour)
                                {
                                    endLine = deleteCounter - 1;

                                    // Apply the Change colouring
                                    for (int changeCounter = startLine; changeCounter <= endLine; changeCounter++)
                                    {
                                        editor.Document.Lines[changeCounter].SelectionMarginMarkColor = changedMarkerColour;
                                        editor.Document.Lines[changeCounter].BackColor = Color.LightYellow;
                                    }
                                    changeProcessed = true;
                                    // We are back to 'normal' lines - no change found
                                    i = checkCounter;
                                    break;
                                }
                                else
                                {
                                    editor.Document.Lines[deleteCounter].CustomLineNumber = string.Empty;
                                }
                            }
                        }
                        else
                        {
                            // We are back to 'normal' lines - no change found
                            i = checkCounter;
                            break;
                        }
                    }
                }
            }
            int lineNumber = 1;
            for (int i = 0; i < editor.Document.Lines.Count; i++)
            {
                if (linesToNotCount.Contains(i))
                {
                    editor.Document.Lines[i].CustomLineNumber = string.Empty;
                }
                else
                {
                    editor.Document.Lines[i].CustomLineNumber = lineNumber.ToString();
                    lineNumber++;
                }
            }
        }
Esempio n. 23
0
        private void ProcessBreakpointChange(DocumentLine line, BreakpointOperation ops)
        {
            // please notify ATF team before defining  FullISyntaxEditorControl
            if (line == null || StringUtil.IsNullOrEmptyOrWhitespace(line.Text))
                return;

            // get or create breakpoint layer.
            var layer = Document.SpanIndicatorLayers[SpanIndicatorLayer.BreakpointKey];
            if (layer == null)
            {
                layer = new SpanIndicatorLayer(SpanIndicatorLayer.BreakpointKey, SpanIndicatorLayer.BreakpointDisplayPriority);
                Document.SpanIndicatorLayers.Add(layer);
            }
            
            // find breakpoint indicator for the current line.
            BreakpointIndicator breakpointIndicator = null;
            foreach (SpanIndicator si in line.SpanIndicators)
            {
                breakpointIndicator = si as BreakpointIndicator;
                if (breakpointIndicator != null)
                    break;
            }

            var breakpointExist = breakpointIndicator != null;
            var addbreakpoint = ((ops == BreakpointOperation.Set || ops == BreakpointOperation.Toggle) && !breakpointExist);

            // do nothing 
            if (addbreakpoint == breakpointExist)
                return;
                       
            var e = new BreakpointEventArgs(addbreakpoint, line.Index + 1, line.Text);            
            if (BreakpointChanging != null)
                BreakpointChanging(this, e);

            // cancel the operation
            if (e.Cancel)
                return;

            if (addbreakpoint)
            {
                breakpointIndicator = new BreakpointIndicator();
                layer.Add(breakpointIndicator, line.TextRange);
            }
            else // remove breakpoint
            {
                layer.Remove(breakpointIndicator);                
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Populates two Actipro SyntaxEditors with diff-highlighted text.
        /// </summary>
        /// <param name="editor1">Actipro SyntaxEditor</param>
        /// <param name="editor2">Actipro SyntaxEditor</param>
        /// <param name="text">Fully combined text.</param>
        /// <param name="lines1">Lines unique to the left file.</param>
        /// <param name="lines2">Lines unique to the right file.</param>
        public static void PopulateSyntaxEditors(
  ActiproSoftware.SyntaxEditor.SyntaxEditor editor1,
  ActiproSoftware.SyntaxEditor.SyntaxEditor editor2,
  string text,
  SlyceMerge.LineSpan[] lines1,
  SlyceMerge.LineSpan[] lines2)
        {
            editor1.Text = text;
            editor2.Text = text;

            for (int i = 0; i < lines1.Length; i++)
            {
                for (int lineCounter = lines1[i].StartLine; lineCounter <= lines1[i].EndLine; lineCounter++)
                {
                    editor1.Document.Lines[lineCounter].BackColor = ColourNewGen;
                    editor2.Document.Lines[lineCounter].BackColor = Color.LightGray;
                    editor2.Document.DeleteText(ActiproSoftware.SyntaxEditor.DocumentModificationType.Delete, editor2.Document.Lines[lineCounter].StartOffset, editor2.Document.Lines[lineCounter].Length);
                }
            }
            for (int i = 0; i < lines2.Length; i++)
            {
                for (int lineCounter = lines2[i].StartLine; lineCounter <= lines2[i].EndLine; lineCounter++)
                {
                    editor2.Document.Lines[lineCounter].BackColor = ColourNewGen;
                    editor1.Document.Lines[lineCounter].BackColor = Color.LightGray;
                    editor1.Document.DeleteText(ActiproSoftware.SyntaxEditor.DocumentModificationType.Delete, editor1.Document.Lines[lineCounter].StartOffset, editor1.Document.Lines[lineCounter].Length);
                }
            }
            // Compact the displays
            int lineCount1 = 0;
            int lineCount2 = 0;

            for (int i = editor1.Document.Lines.Count - 1; i >= -1; i--)
            {
                Color lineColor = Color.Empty;

                if (i >= 0)
                {
                    lineColor = editor1.Document.Lines[i].BackColor;
                }
                if (lineColor == Color.Empty && (lineCount1 + lineCount2) > 0)
                {
                    // Process counted lines
                    int startIndex = i + 1;
                    int condensedLineCount = Math.Max(lineCount1, lineCount2);
                    int numLinesToRemove = lineCount1 + lineCount2 - condensedLineCount;
                    int lastLine = startIndex + lineCount1 + lineCount2 - 1;

                    //if (numLinesToRemove > 0)
                    //{
                    //   // Walk backward when processing Left
                    //   for (int removeIndex = lastLine; removeIndex >= startIndex + condensedLineCount; removeIndex--)
                    //   {
                    //      editor1.Document.Lines[removeIndex].BackColor = editor1.Document.Lines[removeIndex + 1].BackColor;
                    //      editor1.Document.Lines.RemoveAt(removeIndex);

                    //      int newPos = lastLine - condensedLineCount - (lastLine - removeIndex);
                    //      string gg = editor2.Document.Lines[removeIndex].Text;
                    //      editor2.Document.Lines[newPos].Text = editor2.Document.Lines[removeIndex].Text;
                    //      editor2.Document.Lines[newPos].BackColor = editor2.Document.Lines[removeIndex].BackColor;
                    //      editor2.Document.Lines[removeIndex].BackColor = editor2.Document.Lines[removeIndex + 1].BackColor;
                    //      editor2.Document.Lines.RemoveAt(removeIndex);
                    //   }
                    //}
                    numLinesToRemove = Math.Min(lineCount1, lineCount2);
                    int linesRemoved1 = 0;
                    int linesRemoved2 = 0;

                    for (int x = startIndex + (lineCount1 + lineCount2); x >= startIndex; x--)
                    {
                        if (linesRemoved1 < numLinesToRemove &&
                            editor1.Document.Lines[x].BackColor == Color.LightGray)
                        {
                            editor1.Document.Lines[x].BackColor = editor1.Document.Lines[x + 1].BackColor;
                            editor1.Document.Lines.RemoveAt(x);
                            linesRemoved1++;
                        }
                        if (linesRemoved2 < numLinesToRemove &&
                            editor2.Document.Lines[x].BackColor == Color.LightGray)
                        {
                            editor2.Document.Lines[x].BackColor = editor2.Document.Lines[x + 1].BackColor;
                            editor2.Document.Lines.RemoveAt(x);
                            linesRemoved2++;
                        }
                    }
                    if (linesRemoved1 != linesRemoved2)
                        throw new Exception("Non-equal number of lines removed.");

                    //if (lineCount1 > lineCount2)
                    //{
                    //   // Remove trailing gray lines from editor2
                    //   for (int removeIndex = startIndex; removeIndex <= startIndex + numLinesToRemove; removeIndex++)
                    //   {
                    //      string q111 = editor1.Document.Lines[removeIndex].Text;
                    //      string gg = editor2.Document.Lines[removeIndex].Text;
                    //      editor2.Document.Lines.RemoveAt(removeIndex);
                    //   }
                    //}
                    //else if (lineCount2 > lineCount1)
                    //{
                    //   // Remove trailing gray lines from editor1
                    //   for (int removeIndex = lastLine; removeIndex >= startIndex + condensedLineCount; removeIndex--)
                    //   {
                    //      string q111 = editor1.Document.Lines[removeIndex].Text;
                    //      string gg = editor2.Document.Lines[removeIndex].Text;
                    //      editor1.Document.Lines.RemoveAt(removeIndex);
                    //   }
                    //}
                    lineCount1 = 0;
                    lineCount2 = 0;
                    continue;
                }
                else if (lineColor == ColourNewGen)
                {
                    lineCount1++;
                }
                else if (lineColor == Color.LightGray)
                {
                    lineCount2++;
                }
            }
            // Line Marker Colours, Strikethroughs
            string layerKey = "Diff";
            string indicatorKey = "Diff";
            SpanIndicatorLayer layer = new SpanIndicatorLayer(layerKey, 1000);
            HighlightingStyle highlightingStyle = new HighlightingStyle("Diff", null, Color.Empty, Color.Empty);
            highlightingStyle.StrikeOutStyle = HighlightingStyleLineStyle.Solid;
            highlightingStyle.StrikeOutColor = Color.Red;
            editor1.Document.SpanIndicatorLayers.Add(layer);

            int lineNumber1 = 1;
            int lineNumber2 = 1;

            for (int i = 0; i < editor1.Document.Lines.Count; i++)
            {
                // Set the line marker colours
                if (editor1.Document.Lines[i].BackColor == Color.LightGray &&
                    editor2.Document.Lines[i].BackColor == ColourNewGen)
                {
                    if (i > 0 && editor2.Document.Lines[i - 1].SelectionMarginMarkColor == changedMarkerColour)
                    {
                        editor2.Document.Lines[i].SelectionMarginMarkColor = changedMarkerColour;
                        editor2.Document.Lines[i].BackColor = Color.LightYellow;
                    }
                    else
                    {
                        editor2.Document.Lines[i].SelectionMarginMarkColor = addedMarkerColour;
                        editor2.Document.Lines[i].BackColor = Color.Honeydew;
                    }
                    editor1.Document.Lines[i].BackColor = Color.WhiteSmoke;
                    editor1.Document.Lines[i].CustomLineNumber = string.Empty;
                    editor2.Document.Lines[i].CustomLineNumber = lineNumber2.ToString();
                    lineNumber2++;
                }
                else if (editor1.Document.Lines[i].BackColor == ColourNewGen &&
                    editor2.Document.Lines[i].BackColor == Color.LightGray)
                {
                    editor2.Document.Lines[i].SelectionMarginMarkColor = deletedMarkerColour;
                    editor1.Document.Lines[i].BackColor = Color.MistyRose;
                    editor2.Document.Lines[i].BackColor = Color.WhiteSmoke;
                    editor1.Document.Lines[i].CustomLineNumber = lineNumber1.ToString();
                    editor2.Document.Lines[i].CustomLineNumber = string.Empty;
                    lineNumber1++;
                }
                else if (editor1.Document.Lines[i].BackColor == ColourNewGen &&
                    editor2.Document.Lines[i].BackColor == ColourNewGen)
                {
                    editor2.Document.Lines[i].SelectionMarginMarkColor = changedMarkerColour;
                    editor1.Document.Lines[i].BackColor = Color.LightYellow;
                    editor2.Document.Lines[i].BackColor = Color.LightYellow;
                    layer.Add(new HighlightingStyleSpanIndicator(indicatorKey, highlightingStyle), editor1.Document.Lines[i].TextRange);
                    editor1.Document.Lines[i].CustomLineNumber = lineNumber1.ToString();
                    editor2.Document.Lines[i].CustomLineNumber = lineNumber2.ToString();
                    lineNumber1++;
                    lineNumber2++;
                }
                else
                {
                    editor1.Document.Lines[i].CustomLineNumber = lineNumber1.ToString();
                    editor2.Document.Lines[i].CustomLineNumber = lineNumber2.ToString();
                    lineNumber1++;
                    lineNumber2++;
                }
            }
        }