예제 #1
0
        /// <inheritdoc/>
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            if (!e.Handled && TextView != null && textArea != null)
            {
                e.Handled = true;
                textArea.Focus();

                SimpleSegment currentSeg = GetTextLineSegment(e);
                if (currentSeg == SimpleSegment.Invalid)
                {
                    return;
                }
                textArea.Caret.Offset = currentSeg.Offset + currentSeg.Length;
                if (CaptureMouse())
                {
                    selecting      = true;
                    selectionStart = new AnchorSegment(Document, currentSeg.Offset, currentSeg.Length);
                    if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                    {
                        SimpleSelection simpleSelection = textArea.Selection as SimpleSelection;
                        if (simpleSelection != null)
                        {
                            selectionStart = new AnchorSegment(Document, simpleSelection.SurroundingSegment);
                        }
                    }
                    textArea.Selection = Selection.Create(textArea, selectionStart);
                    if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                    {
                        ExtendSelection(currentSeg);
                    }
                }
            }
        }
예제 #2
0
        const string LineSelectedType = "MSDEVLineSelect";  // This is the type VS 2003 and 2005 use for flagging a whole line copy

        static void CopyWholeLine(TextArea textArea, DocumentLine line)
        {
            ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength);
            string   text      = textArea.Document.GetText(wholeLine);

            // Ensure we use the appropriate newline sequence for the OS
            text = TextUtilities.NormalizeNewLines(text, Environment.NewLine);
            DataObject data = new DataObject(text);

            // Also copy text in HTML format to clipboard - good for pasting text into Word
            // or to the SharpDevelop forums.
            IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter;

            HtmlClipboard.SetHtml(data, HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine, new HtmlOptions(textArea.Options)));

            MemoryStream lineSelected = new MemoryStream(1);

            lineSelected.WriteByte(1);
            data.SetData(LineSelectedType, lineSelected, false);

            try
            {
                Clipboard.SetDataObject(data, true);
            }
            catch (ExternalException)
            {
                // Apparently this exception sometimes happens randomly.
                // The MS controls just ignore it, so we'll do the same.
                return;
            }
            textArea.OnTextCopied(new TextEventArgs(text));
        }
예제 #3
0
        public void Process()
        {
            _currentWordSegment = _wordNav.Next(_text, _currentWordSegment.Offset);
            _currentSentSegment = _sentenceNav.Next(_text, _currentSentSegment.Offset);
            _currentSent        = _text.GetText(_currentSentSegment);
            while (!SimpleSegment.IsInvalid(_currentWordSegment))
            {
                _currentWord = _text.GetText(_currentWordSegment);
                if (_currentWordSegment.Offset > _currentSentSegment.EndOffset)
                {
                    _currentSentSegment = _sentenceNav.Next(_text, _currentSentSegment.Offset);
                    _currentSent        = _text.GetText(_currentSentSegment);
                }
                ProcessWord();
                _currentWordSegment = _wordNav.Next(_text, _currentWordSegment.Offset);
            }

            // Save stat
            File.WriteAllText("notFound.txt", NotFoundWords.Count + Environment.NewLine);
            File.AppendAllLines("notFound.txt", NotFoundWords);
            File.WriteAllText("SingleAccentWords.txt", SingleAccentWords.Count + Environment.NewLine);
            File.AppendAllLines("SingleAccentWords.txt", SingleAccentWords);
            File.WriteAllText("ManyAccentWords.txt", ManyAccentWords.Count + Environment.NewLine);
            File.AppendAllLines("ManyAccentWords.txt", ManyAccentWords);
        }
예제 #4
0
        /// <summary>
        /// Creates a HTML fragment from a part of a document.
        /// </summary>
        /// <param name="document">The document to create HTML from.</param>
        /// <param name="highlighter">The highlighter used to highlight the document. <c>null</c> is valid and will create HTML without any highlighting.</param>
        /// <param name="segment">The part of the document to create HTML for. You can pass <c>null</c> to create HTML for the whole document.</param>
        /// <param name="options">The options for the HTML creation.</param>
        /// <returns>HTML code for the document part.</returns>
        public static string CreateHtmlFragment(TextDocument document, IHighlighter highlighter, ISegment segment, HtmlOptions options)
        {
            if (document == null)
                throw new ArgumentNullException("document");
            if (options == null)
                throw new ArgumentNullException("options");
            if (highlighter != null && highlighter.Document != document)
                throw new ArgumentException("Highlighter does not belong to the specified document.");
            if (segment == null)
                segment = new SimpleSegment(0, document.TextLength);

            StringBuilder html = new StringBuilder();
            int segmentEndOffset = segment.EndOffset;
            DocumentLine line = document.GetLineByOffset(segment.Offset);
            while (line != null && line.Offset < segmentEndOffset) {
                HighlightedLine highlightedLine;
                if (highlighter != null)
                    highlightedLine = highlighter.HighlightLine(line.LineNumber);
                else
                    highlightedLine = new HighlightedLine(document, line);
                SimpleSegment s = segment.GetOverlap(line);
                if (html.Length > 0)
                    html.AppendLine("<br>");
                html.Append(highlightedLine.ToHtml(s.Offset, s.EndOffset, options));
                line = line.NextLine;
            }
            return html.ToString();
        }
예제 #5
0
        // [DIGITALRUNE] FIX: Check for read-only documents/sections.
        private static bool CanCutSelection(TextArea textArea)
        {
            Debug.Assert(textArea != null);

            var selection = textArea.Selection;

            if (selection.IsEmpty && !textArea.Options.CutCopyWholeLine)
            {
                return(false);
            }

            var readOnlySectionProvider = textArea.ReadOnlySectionProvider;

            if (readOnlySectionProvider is ReadOnlySectionDocument)
            {
                return(false);
            }

            if (readOnlySectionProvider is NoReadOnlySections)
            {
                return(true);
            }

            if (selection.IsEmpty)
            {
                Debug.Assert(textArea.Options.CutCopyWholeLine);
                var documentLine = textArea.Document.GetLineByNumber(textArea.Caret.Line);
                var segment      = new SimpleSegment(documentLine.Offset, documentLine.TotalLength);
                return(readOnlySectionProvider.GetDeletableSegments(segment).Any());
            }

            return(selection.Segments.SelectMany(segment => readOnlySectionProvider.GetDeletableSegments(segment)).Any());
        }
예제 #6
0
 public CodeSegment()
 {
     _codesegment = new SimpleSegment();
     _type = Token.Unknown;
     _line = -1;
     _next = null;
     _previous = null;
 }
예제 #7
0
        /// <summary>
        /// Produces HTML code for a section of the line, with &lt;span class="colorName"&gt; tags.
        /// </summary>
        public string ToHtml(int startOffset, int endOffset, HtmlOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            int documentLineStartOffset = this.DocumentLine.Offset;
            int documentLineEndOffset   = documentLineStartOffset + this.DocumentLine.Length;

            if (startOffset < documentLineStartOffset || startOffset > documentLineEndOffset)
            {
                throw new ArgumentOutOfRangeException("startOffset", startOffset, "Value must be between " + documentLineStartOffset + " and " + documentLineEndOffset);
            }
            if (endOffset < startOffset || endOffset > documentLineEndOffset)
            {
                throw new ArgumentOutOfRangeException("endOffset", endOffset, "Value must be between startOffset and " + documentLineEndOffset);
            }
            ISegment requestedSegment = new SimpleSegment(startOffset, endOffset - startOffset);

            List <HtmlElement> elements = new List <HtmlElement>();

            for (int i = 0; i < this.Sections.Count; i++)
            {
                HighlightedSection s = this.Sections[i];
                if (s.GetOverlap(requestedSegment).Length > 0)
                {
                    elements.Add(new HtmlElement(s.Offset, i, false, s.Color));
                    elements.Add(new HtmlElement(s.Offset + s.Length, i, true, s.Color));
                }
            }
            elements.Sort();

            TextDocument  document   = DocumentLine.Document;
            StringBuilder b          = new StringBuilder();
            int           textOffset = startOffset;

            foreach (HtmlElement e in elements)
            {
                int newOffset = Math.Min(e.Offset, endOffset);
                if (newOffset > startOffset)
                {
                    HtmlClipboard.EscapeHtml(b, document.GetText(textOffset, newOffset - textOffset), options);
                }
                textOffset = newOffset;
                if (e.IsEnd)
                {
                    b.Append("</span>");
                }
                else
                {
                    b.Append("<span style=\"");
                    b.Append(e.Color.ToCss());
                    b.Append("\">");
                }
            }
            HtmlClipboard.EscapeHtml(b, document.GetText(textOffset, endOffset - textOffset), options);
            return(b.ToString());
        }
예제 #8
0
        /// <summary>
        /// Produces HTML code for a section of the line, with &lt;span class="colorName"&gt; tags.
        /// </summary>
        public string ToHtml(int startOffset, int endOffset, HtmlOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            int documentLineStartOffset = this.DocumentLine.Offset;
            int documentLineEndOffset   = documentLineStartOffset + this.DocumentLine.Length;

            if (startOffset < documentLineStartOffset || startOffset > documentLineEndOffset)
            {
                throw new ArgumentOutOfRangeException("startOffset", startOffset, "Value must be between " + documentLineStartOffset + " and " + documentLineEndOffset);
            }
            if (endOffset < startOffset || endOffset > documentLineEndOffset)
            {
                throw new ArgumentOutOfRangeException("endOffset", endOffset, "Value must be between startOffset and " + documentLineEndOffset);
            }
            ISegment requestedSegment = new SimpleSegment(startOffset, endOffset - startOffset);

            List <HtmlElement> elements = new List <HtmlElement>();

            for (int i = 0; i < this.Sections.Count; i++)
            {
                HighlightedSection s = this.Sections[i];
                if (s.GetOverlap(requestedSegment).Length > 0)
                {
                    elements.Add(new HtmlElement(s.Offset, i, false, s.Color));
                    elements.Add(new HtmlElement(s.Offset + s.Length, i, true, s.Color));
                }
            }
            elements.Sort();

            TextDocument document   = this.Document;
            StringWriter w          = new StringWriter(CultureInfo.InvariantCulture);
            int          textOffset = startOffset;

            foreach (HtmlElement e in elements)
            {
                int newOffset = Math.Min(e.Offset, endOffset);
                if (newOffset > startOffset)
                {
                    HtmlClipboard.EscapeHtml(w, document.GetText(textOffset, newOffset - textOffset), options);
                }
                textOffset = Math.Max(textOffset, newOffset);
                if (e.IsEnd)
                {
                    w.Write("</span>");
                }
                else
                {
                    w.Write("<span");
                    options.WriteStyleAttributeForColor(w, e.Color);
                    w.Write('>');
                }
            }
            HtmlClipboard.EscapeHtml(w, document.GetText(textOffset, endOffset - textOffset), options);
            return(w.ToString());
        }
예제 #9
0
 public CodeSegment(ProjectItemCodeDocument codeDocument, Token token, string tokenstr, SimpleSegment anchorsegment, int line, int colstart, CodeSegment previous)
 {
     _type = token;
     _tokenstring = tokenstr;
     _codesegment = anchorsegment;
     _line = line;
     _column = colstart;
     _previous = previous;
     _codeDocument = codeDocument;
 }
    public static SimpleSegment Create(Point point0, Point point1, Point point2, Point point3)
    {
        var segment = new SimpleSegment
        {
            Type   = SegmentType.CubicBeizer,
            Points = new[] { point0, point1, point2, point3 }
        };

        return(segment);
    }
    public static SimpleSegment Create(Point point0, Point point1)
    {
        var segment = new SimpleSegment
        {
            Type   = SegmentType.Line,
            Points = new[] { point0, point1 }
        };

        return(segment);
    }
예제 #12
0
        ///// <summary>
        ///// Writes a part of the highlighted line to the RichTextWriter.
        ///// </summary>
        internal void WriteTo(RichTextWriter writer, int startOffset, int endOffset)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            int documentLineStartOffset = this.DocumentLine.Offset;
            int documentLineEndOffset   = documentLineStartOffset + this.DocumentLine.Length;

            if (startOffset < documentLineStartOffset || startOffset > documentLineEndOffset)
            {
                throw new ArgumentOutOfRangeException("startOffset", startOffset, "Value must be between " + documentLineStartOffset + " and " + documentLineEndOffset);
            }
            if (endOffset < startOffset || endOffset > documentLineEndOffset)
            {
                throw new ArgumentOutOfRangeException("endOffset", endOffset, "Value must be between startOffset and " + documentLineEndOffset);
            }
            ISegment requestedSegment = new SimpleSegment(startOffset, endOffset - startOffset);

            List <HtmlElement> elements = new List <HtmlElement>();

            for (int i = 0; i < this.Sections.Count; i++)
            {
                HighlightedSection s = this.Sections[i];
                if (SimpleSegment.GetOverlap(s, requestedSegment).Length > 0)
                {
                    elements.Add(new HtmlElement(s.Offset, i, false, s.Color));
                    elements.Add(new HtmlElement(s.Offset + s.Length, i, true, s.Color));
                }
            }
            elements.Sort();

            IDocument document   = this.Document;
            int       textOffset = startOffset;

            foreach (HtmlElement e in elements)
            {
                int newOffset = Math.Min(e.Offset, endOffset);
                if (newOffset > startOffset)
                {
                    document.WriteTextTo(writer, textOffset, newOffset - textOffset);
                }
                textOffset = Math.Max(textOffset, newOffset);
                if (e.IsEnd)
                {
                    writer.EndSpan();
                }
                else
                {
                    writer.BeginSpan(e.Color);
                }
            }
            document.WriteTextTo(writer, textOffset, endOffset - textOffset);
        }
    public static SimpleSegment Create(Point point0, Point point1, Point point2)
    {
        var point   = GeometryHelper.Lerp(point0, point1, 0.66666666666666663);
        var point3  = GeometryHelper.Lerp(point1, point2, 0.33333333333333331);
        var segment = new SimpleSegment
        {
            Type   = SegmentType.CubicBeizer,
            Points = new[] { point0, point, point3, point2 }
        };

        return(segment);
    }
예제 #14
0
 void ExtendSelection(SimpleSegment currentSeg)
 {
     if (currentSeg.Offset < selectionStart.Offset)
     {
         textArea.Caret.Offset = currentSeg.Offset;
         textArea.Selection    = Selection.Create(textArea, currentSeg.Offset, selectionStart.Offset + selectionStart.Length);
     }
     else
     {
         textArea.Caret.Offset = currentSeg.Offset + currentSeg.Length;
         textArea.Selection    = Selection.Create(textArea, selectionStart.Offset, currentSeg.Offset + currentSeg.Length);
     }
 }
예제 #15
0
 private void ExtendSelection(SimpleSegment currentSeg)
 {
     if (currentSeg.Offset < _selectionStart.Offset)
     {
         TextArea.Caret.Offset = currentSeg.Offset;
         TextArea.Selection    = Selection.Create(TextArea, currentSeg.Offset, _selectionStart.Offset + _selectionStart.Length);
     }
     else
     {
         TextArea.Caret.Offset = currentSeg.Offset + currentSeg.Length;
         TextArea.Selection    = Selection.Create(TextArea, _selectionStart.Offset, currentSeg.Offset + currentSeg.Length);
     }
 }
예제 #16
0
 void ExtendSelection(SimpleSegment currentSeg)
 {
     if (currentSeg.Offset < selectionStart.Offset)
     {
         TextArea.Caret.Offset = currentSeg.Offset;
         TextArea.Selection    = new SimpleSelection(currentSeg.Offset, selectionStart.Offset + selectionStart.Length);
     }
     else
     {
         TextArea.Caret.Offset = currentSeg.Offset + currentSeg.Length;
         TextArea.Selection    = new SimpleSelection(selectionStart.Offset, currentSeg.Offset + currentSeg.Length);
     }
 }
예제 #17
0
            public override IEnumerable <SimpleSegment> GetSimpleSegments()
            {
                var start = Start;
                // ReSharper disable once GenericEnumeratorNotDisposed
                var enumerator = _segment.Points.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    var current = enumerator.Current;
                    yield return(SimpleSegment.Create(start, current));

                    start = current;
                }
            }
예제 #18
0
 /// <inheritdoc/>
 protected override void OnMouseMove(MouseEventArgs e)
 {
     if (selecting && textArea != null && TextView != null)
     {
         e.Handled = true;
         SimpleSegment currentSeg = GetTextLineSegment(e);
         if (currentSeg == SimpleSegment.Invalid)
         {
             return;
         }
         ExtendSelection(currentSeg);
     }
     base.OnMouseMove(e);
 }
예제 #19
0
        private static bool CopyWholeLine(TextArea textArea, DocumentLine line)
        {
            ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength);
            var      text      = textArea.Document.GetText(wholeLine);

            // Ignore empty line copy
            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }
            // Ensure we use the appropriate newline sequence for the OS
            text = TextUtilities.NormalizeNewLines(text, Environment.NewLine);

            // TODO: formats
            //DataObject data = new DataObject();
            //if (ConfirmDataFormat(textArea, data, DataFormats.UnicodeText))
            //    data.SetText(text);

            //// Also copy text in HTML format to clipboard - good for pasting text into Word
            //// or to the SharpDevelop forums.
            //if (ConfirmDataFormat(textArea, data, DataFormats.Html))
            //{
            //    IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter;
            //    HtmlClipboard.SetHtml(data,
            //        HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine,
            //            new HtmlOptions(textArea.Options)));
            //}

            //if (ConfirmDataFormat(textArea, data, LineSelectedType))
            //{
            //    var lineSelected = new MemoryStream(1);
            //    lineSelected.WriteByte(1);
            //    data.SetData(LineSelectedType, lineSelected, false);
            //}

            //var copyingEventArgs = new DataObjectCopyingEventArgs(data, false);
            //textArea.RaiseEvent(copyingEventArgs);
            //if (copyingEventArgs.CommandCancelled)
            //    return false;

            SetClipboardText(text);

            textArea.OnTextCopied(new TextEventArgs(text));
            return(true);
        }
예제 #20
0
		const string LineSelectedType = "MSDEVLineSelect";  // This is the type VS 2003 and 2005 use for flagging a whole line copy
		
		static void CopyWholeLine(TextArea textArea, DocumentLine line)
		{
			ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength);
			string text = textArea.Document.GetText(wholeLine);
			// Ensure we use the appropriate newline sequence for the OS
			DataObject data = new DataObject(NewLineFinder.NormalizeNewLines(text, Environment.NewLine));
			
			// Also copy text in HTML format to clipboard - good for pasting text into Word
			// or to the SharpDevelop forums.
			DocumentHighlighter highlighter = textArea.GetService(typeof(DocumentHighlighter)) as DocumentHighlighter;
			HtmlClipboard.SetHtml(data, HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine, new HtmlOptions(textArea.Options)));
			
			MemoryStream lineSelected = new MemoryStream(1);
			lineSelected.WriteByte(1);
			data.SetData(LineSelectedType, lineSelected, false);
			
			Clipboard.SetDataObject(data, true);
		}
예제 #21
0
        /// <summary>
        /// Creates a HTML fragment from a part of a document.
        /// </summary>
        /// <param name="document">The document to create HTML from.</param>
        /// <param name="highlighter">The highlighter used to highlight the document. <c>null</c> is valid and will create HTML without any highlighting.</param>
        /// <param name="segment">The part of the document to create HTML for. You can pass <c>null</c> to create HTML for the whole document.</param>
        /// <param name="options">The options for the HTML creation.</param>
        /// <returns>HTML code for the document part.</returns>
        public static string CreateHtmlFragment(TextDocument document, IHighlighter highlighter, ISegment segment, HtmlOptions options)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (highlighter != null && highlighter.Document != document)
            {
                throw new ArgumentException("Highlighter does not belong to the specified document.");
            }
            if (segment == null)
            {
                segment = new SimpleSegment(0, document.TextLength);
            }

            StringBuilder html             = new StringBuilder();
            int           segmentEndOffset = segment.EndOffset;
            DocumentLine  line             = document.GetLineByOffset(segment.Offset);

            while (line != null && line.Offset < segmentEndOffset)
            {
                HighlightedLine highlightedLine;
                if (highlighter != null)
                {
                    highlightedLine = highlighter.HighlightLine(line.LineNumber);
                }
                else
                {
                    highlightedLine = new HighlightedLine(document, line);
                }
                SimpleSegment s = segment.GetOverlap(line);
                if (html.Length > 0)
                {
                    html.AppendLine("<br>");
                }
                html.Append(highlightedLine.ToHtml(s.Offset, s.EndOffset, options));
                line = line.NextLine;
            }
            return(html.ToString());
        }
예제 #22
0
        /// <inheritdoc/>
        protected void OnMouseLeftButtonDowns(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            if (!e.Handled && TextView != null && textArea != null)
            {
                e.Handled = true;
                textArea.Focus();

                SimpleSegment currentSeg = GetTextLineSegment(e);
                if (currentSeg == SimpleSegment.Invalid)
                {
                    return;
                }
                textArea.Caret.Offset = currentSeg.Offset + currentSeg.Length;

                int i = 0;
                while (Char.IsWhiteSpace(textArea.Document.Text[currentSeg.Offset + i]) && i < currentSeg.Length)
                {
                    i++;
                }

                if (CaptureMouse())
                {
                    selecting      = true;
                    selectionStart = new AnchorSegment(Document, currentSeg.Offset + i, currentSeg.Length - i);
                    if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                    {
                        SimpleSelection simpleSelection = textArea.Selection as SimpleSelection;
                        if (simpleSelection != null)
                        {
                            selectionStart = new AnchorSegment(Document, simpleSelection.SurroundingSegment);
                        }
                    }
                    textArea.Selection = Selection.Create(textArea, selectionStart);
                    if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                    {
                        ExtendSelection(currentSeg);
                    }
                    textArea.Caret.BringCaretToView(0.0);
                }
            }
        }
예제 #23
0
        private IEnumerable <SimpleSegment> GetEffectiveSegments(PathFigure pathFigure)
        {
            var startPoint = pathFigure.StartPoint;

            foreach (var iteratorVariable1 in pathFigure.AllSegments())
            {
                foreach (var iteratorVariable2 in iteratorVariable1.PathSegment.GetSimpleSegments(
                             iteratorVariable1.StartPoint))
                {
                    yield return(iteratorVariable2);

                    startPoint = iteratorVariable2.Points.Last();
                }
            }

            if (pathFigure.IsClosed)
            {
                yield return(SimpleSegment.Create(startPoint, pathFigure.StartPoint));
            }
        }
예제 #24
0
            public override IEnumerable <SimpleSegment> GetSimpleSegments()
            {
                var           start             = Start;
                IList <Point> points            = _segment.Points;
                var           iteratorVariable2 = _segment.Points.Count / 2;
                var           iteratorVariable3 = 0;

                while (true)
                {
                    if (iteratorVariable3 >= iteratorVariable2)
                    {
                        yield break;
                    }
                    var iteratorVariable4 = iteratorVariable3 * 2;
                    yield return(SimpleSegment.Create(start, points[iteratorVariable4],
                                                      points[iteratorVariable4 + 1]));

                    start = points[iteratorVariable4 + 1];
                    iteratorVariable3++;
                }
            }
예제 #25
0
        /// <summary>
        /// Sets the TextDataFormat.Html on the data object to the specified html fragment.
        /// This helper methods takes care of creating the necessary CF_HTML header.
        /// </summary>
        //public static void SetHtml(DataObject dataObject, string htmlFragment)
        //{
        //	if (dataObject == null)
        //		throw new ArgumentNullException("dataObject");
        //	if (htmlFragment == null)
        //		throw new ArgumentNullException("htmlFragment");

        //	string htmlStart = @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" + Environment.NewLine
        //		+ "<HTML>" + Environment.NewLine
        //		+ "<BODY>" + Environment.NewLine
        //		+ "<!--StartFragment-->" + Environment.NewLine;
        //	string htmlEnd = "<!--EndFragment-->" + Environment.NewLine + "</BODY>" + Environment.NewLine + "</HTML>" + Environment.NewLine;
        //	string dummyHeader = BuildHeader(0, 0, 0, 0);
        //	// the offsets are stored as UTF-8 bytes (see CF_HTML documentation)
        //	int startHTML = dummyHeader.Length;
        //	int startFragment = startHTML + htmlStart.Length;
        //	int endFragment = startFragment + Encoding.UTF8.GetByteCount(htmlFragment);
        //	int endHTML = endFragment + htmlEnd.Length;
        //	string cf_html = BuildHeader(startHTML, endHTML, startFragment, endFragment) + htmlStart + htmlFragment + htmlEnd;
        //	Debug.WriteLine(cf_html);
        //	dataObject.SetText(cf_html, TextDataFormat.Html);
        //}

        /// <summary>
        /// Creates a HTML fragment from a part of a document.
        /// </summary>
        /// <param name="document">The document to create HTML from.</param>
        /// <param name="highlighter">The highlighter used to highlight the document. <c>null</c> is valid and will create HTML without any highlighting.</param>
        /// <param name="segment">The part of the document to create HTML for. You can pass <c>null</c> to create HTML for the whole document.</param>
        /// <param name="options">The options for the HTML creation.</param>
        /// <returns>HTML code for the document part.</returns>
        public static string CreateHtmlFragment(IDocument document, IHighlighter highlighter, ISegment segment, HtmlOptions options)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (highlighter != null && highlighter.Document != document)
            {
                throw new ArgumentException("Highlighter does not belong to the specified document.");
            }
            if (segment == null)
            {
                segment = new SimpleSegment(0, document.TextLength);
            }

            var html             = new StringBuilder();
            var segmentEndOffset = segment.EndOffset;
            var line             = document.GetLineByOffset(segment.Offset);

            while (line != null && line.Offset < segmentEndOffset)
            {
                // ReSharper disable once UnusedVariable
                var highlightedLine = highlighter != null?highlighter.HighlightLine(line.LineNumber) : new HighlightedLine(document, line);

                if (html.Length > 0)
                {
                    html.AppendLine("<br>");
                }
                // TODO: html
                var s = SimpleSegment.GetOverlap(segment, line);
                html.Append(highlightedLine.ToHtml(s.Offset, s.EndOffset, options));
                line = line.NextLine;
            }
            return(html.ToString());
        }
예제 #26
0
 void targetElement_TextChanged(object sender, EventArgs e)
 {
     // Don't copy text if the segments overlap (we would get an endless loop).
     // This can happen if the user deletes the text between the replaceable element and the bound element.
     if (SimpleSegment.GetOverlap(segment, targetElement.Segment) == SimpleSegment.Invalid)
     {
         int    offset = segment.Offset;
         int    length = segment.Length;
         string text   = boundElement.ConvertText(targetElement.Text);
         if (length != text.Length || text != context.Document.GetText(offset, length))
         {
             // Call replace only if we're actually changing something.
             // Without this check, we would generate an empty undo group when the user pressed undo.
             context.Document.Replace(offset, length, text);
             if (length == 0)
             {
                 // replacing an empty anchor segment with text won't enlarge it, so we have to recreate it
                 segment = new AnchorSegment(context.Document, offset, text.Length);
             }
         }
     }
 }
예제 #27
0
        public ISegment Next(IText text, int offset)
        {
            int textLength = text.TextLength;

            if (offset >= textLength - 1)
            {
                return(SimpleSegment.Invalid);
            }

            var sep1 = _baseNavigator.Next(text, offset);

            int nextOffset = sep1.EndOffset;

            if (SimpleSegment.IsInvalid(sep1))
            {
                return(sep1);
            }

            var sep2 = _baseNavigator.Next(text, nextOffset);

            int endOffset = sep2.Offset;

            if (_baseNavigator is SentenceNavigator)
            {
                endOffset = sep2.EndOffset;
            }
            if (sep2.Offset == -1 || sep2.Length == -1)
            {
                endOffset = textLength;
            }
            int len = endOffset - nextOffset;

            if (len <= 0)
            {
                return(SimpleSegment.Invalid);
            }
            return(new SimpleSegment(nextOffset, len));
        }
예제 #28
0
 void ExtendSelection(SimpleSegment currentSeg)
 {
     if (currentSeg.Offset < selectionStart.Offset) {
         textArea.Caret.Offset = currentSeg.Offset;
         textArea.Selection = new SimpleSelection(currentSeg.Offset, selectionStart.Offset + selectionStart.Length);
     } else {
         textArea.Caret.Offset = currentSeg.Offset + currentSeg.Length;
         textArea.Selection = new SimpleSelection(selectionStart.Offset, currentSeg.Offset + currentSeg.Length);
     }
 }
        // Creates Rndf from an input FileStream
        public IRndf createRndf(FileStream fileStream)
        {
            numWps = 0;

            // File in Read Only mode, convert to stream
            StreamReader r = new StreamReader(fileStream, Encoding.UTF8);

            // Create new queue for input buffer
            Queue  q    = new Queue();
            string word = "";

            // Create the Rndf (with only segments for now, no zones)
            IRndf rndf = new IRndf();

            rndf.Segments = new List <SimpleSegment>();
            rndf.Zones    = new List <SimpleZone>();

            // Loop until reach end of file marker
            while ((word.Length < 8) || (word.Substring(0, 8) != "end_file"))
            {
                // get the next word
                word = parseWord(r, q);

                if (word == "RNDF_name")
                {
                    word      = parseWord(r, q);
                    rndf.Name = word;
                }
                else if (word == "num_segments")
                {
                    word         = parseWord(r, q);
                    rndf.NumSegs = int.Parse(word);
                }
                else if (word == "num_zones")
                {
                    word          = parseWord(r, q);
                    rndf.NumZones = int.Parse(word);
                }
                else if (word == "format_version")
                {
                    word = parseWord(r, q);
                    rndf.FormatVersion = word;
                }
                else if (word == "creation_date")
                {
                    word = parseWord(r, q);
                    rndf.CreationDate = word;
                }
                else if (word == "segment")
                {
                    // create new segment
                    SimpleSegment seg = new SimpleSegment();
                    seg.Lanes = new List <SimpleLane>();

                    word   = parseWord(r, q);
                    seg.Id = word;

                    // run until reach end of segment marker
                    while (word != "end_segment")
                    {
                        // get next word
                        word = parseWord(r, q);

                        if (word == "segment_name")
                        {
                            word     = parseWord(r, q);
                            seg.Name = word;
                        }
                        else if (word == "num_lanes")
                        {
                            word         = parseWord(r, q);
                            seg.NumLanes = int.Parse(word);
                        }
                        else if (word == "end_segment")
                        {
                            // do nothing if at the end
                        }
                        else if (word == "lane")
                        {
                            // Create new lane
                            SimpleLane ln = new SimpleLane();
                            ln.Checkpoints = new List <SimpleCheckpoint>();
                            ln.Waypoints   = new List <SimpleWaypoint>();
                            ln.Stops       = new List <string>();
                            ln.ExitEntries = new List <SimpleExitEntry>();

                            word  = parseWord(r, q);
                            ln.Id = word;

                            // run until reach end of lane
                            while (word != "end_lane")
                            {
                                // get next word
                                word = parseWord(r, q);

                                if (word == "num_waypoints")
                                {
                                    word            = parseWord(r, q);
                                    ln.NumWaypoints = int.Parse(word);
                                }
                                else if (word == "checkpoint")
                                {
                                    // create checkpoint
                                    SimpleCheckpoint cp = new SimpleCheckpoint();

                                    // get waypoint id
                                    string wp = parseWord(r, q);
                                    cp.WaypointId = wp;

                                    // get checkpoint id
                                    string id = parseWord(r, q);
                                    cp.CheckpointId = id;

                                    // add to collection of checkpoints within lane
                                    ln.Checkpoints.Add(cp);
                                }
                                else if (word == "lane_width")
                                {
                                    word         = parseWord(r, q);
                                    ln.LaneWidth = double.Parse(word);
                                }
                                else if (word == "stop")
                                {
                                    word = parseWord(r, q);
                                    ln.Stops.Add(word);
                                }
                                else if (word == "left_boundary")
                                {
                                    word         = parseWord(r, q);
                                    ln.LeftBound = word;
                                }
                                else if (word == "right_boundary")
                                {
                                    word          = parseWord(r, q);
                                    ln.RightBound = word;
                                }
                                else if (word == "exit")
                                {
                                    // create exit-entry pair
                                    SimpleExitEntry exitEntry = new SimpleExitEntry();

                                    // get the exit id
                                    string exit = parseWord(r, q);
                                    exitEntry.ExitId = exit;

                                    // get the entry id
                                    string entry = parseWord(r, q);
                                    exitEntry.EntryId = entry;

                                    // add to collection of exit-entry pairs within lane
                                    ln.ExitEntries.Add(exitEntry);
                                }
                                else if (word == "end_lane")
                                {
                                    // do nothing
                                }
                                // Otherwise we probably have a waypoint
                                else
                                {
                                    // check to make sure a wp by matching lane id to lane identifier of waypoint
                                    int laneIdLength = ln.Id.Length;

                                    // if waypoint matches then create the waypoint
                                    if (word.Length >= laneIdLength + 2 && (word.Substring(0, laneIdLength)).CompareTo(ln.Id) == 0)
                                    {
                                        // create a new waypoint
                                        SimpleWaypoint wp = new SimpleWaypoint();
                                        wp.Position = new UrbanChallenge.Common.Coordinates();

                                        // set its id
                                        wp.ID = word;

                                        // get latitude or X
                                        string lat = parseWord(r, q);
                                        wp.Position.X = double.Parse(lat);

                                        // get longitude or y
                                        string lon = parseWord(r, q);
                                        wp.Position.Y = double.Parse(lon);

                                        // add to lane's collection of waypoints
                                        ln.Waypoints.Add(wp);

                                        numWps += 1;
                                    }
                                    else
                                    {
                                        Console.WriteLine("Unknown identifier: " + word);
                                    }
                                }
                            }
                            seg.Lanes.Add(ln);
                        }
                        else
                        {
                            Console.WriteLine("Unknown identifier: " + word);
                        }
                    }
                    rndf.Segments.Add(seg);
                }
                else if (word == "zone")
                {
                    // create new zone
                    SimpleZone zone = new SimpleZone();
                    zone.ParkingSpots = new List <ParkingSpot>();

                    // get ID
                    word        = parseWord(r, q);
                    zone.ZoneID = word;

                    // run until reach end of segment marker
                    while (word != "end_zone")
                    {
                        // get next word
                        word = parseWord(r, q);

                        if (word == "num_spots")
                        {
                            // get next word
                            word = parseWord(r, q);

                            // set num of parking spots
                            zone.NumParkingSpots = int.Parse(word);
                        }
                        else if (word == "zone_name")
                        {
                            // get next word
                            word = parseWord(r, q);

                            // set zone name
                            zone.Name = word;
                        }
                        else if (word == "perimeter")
                        {
                            // create perimeter
                            zone.Perimeter                 = new ZonePerimeter();
                            zone.Perimeter.ExitEntries     = new List <SimpleExitEntry>();
                            zone.Perimeter.PerimeterPoints = new List <PerimeterPoint>();

                            // set perimeter id
                            zone.Perimeter.PerimeterID = parseWord(r, q);

                            while (word != "end_perimeter")
                            {
                                // get next word
                                word = parseWord(r, q);

                                if (word == "num_perimeterpoints")
                                {
                                    // set num of perimeter points
                                    zone.Perimeter.NumPerimeterPoints = int.Parse(parseWord(r, q));
                                }
                                else if (word == "exit")
                                {
                                    // create new exit,entry
                                    SimpleExitEntry ee = new SimpleExitEntry();

                                    // set exit
                                    ee.ExitId = parseWord(r, q);

                                    // set entry
                                    ee.EntryId = parseWord(r, q);

                                    // add to perimeter exit entries
                                    zone.Perimeter.ExitEntries.Add(ee);
                                }
                                else if (word == "end_perimeter")
                                {
                                    // Do Nothing
                                }
                                else
                                {
                                    // create new perimeter point
                                    PerimeterPoint p = new PerimeterPoint();

                                    // set id
                                    p.ID = word;

                                    // create new coordinate
                                    p.position = new UrbanChallenge.Common.Coordinates();

                                    // setX
                                    p.position.X = Double.Parse(parseWord(r, q));

                                    // setY
                                    p.position.Y = Double.Parse(parseWord(r, q));

                                    // add to perimeter points
                                    zone.Perimeter.PerimeterPoints.Add(p);
                                }
                            }
                        }
                        else if (word == "spot")
                        {
                            // create a new spot
                            ParkingSpot ps = new ParkingSpot();

                            // set spot id
                            ps.SpotID = parseWord(r, q);

                            while (word != "end_spot")
                            {
                                // get next word
                                word = parseWord(r, q);

                                if (word == "spot_width")
                                {
                                    // set spot width
                                    ps.SpotWidth = parseWord(r, q);
                                }
                                else if (word == "checkpoint")
                                {
                                    // get waypoint id that corresponds with checkpoint
                                    ps.CheckpointWaypointID = parseWord(r, q);

                                    // get checkpoint id
                                    ps.CheckpointID = parseWord(r, q);
                                }
                                else if (word == "end_spot")
                                {
                                    // add spot to zone
                                    zone.ParkingSpots.Add(ps);
                                }
                                else
                                {
                                    // SimpleWaypoint 1
                                    #region

                                    // create new waypoint for waypoint1
                                    ps.Waypoint1          = new SimpleWaypoint();
                                    ps.Waypoint1.Position = new UrbanChallenge.Common.Coordinates();

                                    // set id
                                    ps.Waypoint1.ID = word;

                                    // check if id is checkpointWaypointID
                                    if (ps.Waypoint1.ID == ps.CheckpointWaypointID)
                                    {
                                        ps.Waypoint1.IsCheckpoint = true;
                                        ps.Waypoint1.CheckpointID = ps.CheckpointID;
                                    }

                                    // setX
                                    ps.Waypoint1.Position.X = Double.Parse(parseWord(r, q));

                                    // setY
                                    ps.Waypoint1.Position.Y = Double.Parse(parseWord(r, q));

                                    #endregion

                                    // SimpleWaypoint 2
                                    #region

                                    // create new waypoint for waypoint2
                                    ps.Waypoint2          = new SimpleWaypoint();
                                    ps.Waypoint2.Position = new UrbanChallenge.Common.Coordinates();

                                    // set id
                                    ps.Waypoint2.ID = parseWord(r, q);

                                    // check if id is checkpointWaypointID
                                    if (ps.Waypoint2.ID == ps.CheckpointWaypointID)
                                    {
                                        ps.Waypoint2.IsCheckpoint = true;
                                        ps.Waypoint2.CheckpointID = ps.CheckpointID;
                                    }

                                    // setX
                                    ps.Waypoint2.Position.X = Double.Parse(parseWord(r, q));

                                    // setY
                                    ps.Waypoint2.Position.Y = Double.Parse(parseWord(r, q));

                                    #endregion
                                }
                            }
                        }
                        else if (word == "end_zone")
                        {
                            // Do Nothing
                        }
                        else
                        {
                            Console.WriteLine("Unrecognized: " + word);
                        }
                    }

                    // Add zones to zone
                    rndf.Zones.Add(zone);
                }
                else
                {
                    if (word == "end_file")
                    {
                        Console.WriteLine("Rndf Parse :: Successful");
                    }
                    else
                    {
                        Console.WriteLine("Unknown identifier: " + word);
                    }
                }
            }
            return(rndf);
        }
예제 #30
0
        // [DIGITALRUNE] FIX: Check for read-only documents/sections.
        private static bool CanCutSelection(TextArea textArea)
        {
            Debug.Assert(textArea != null);

            var selection = textArea.Selection;
            if (selection.IsEmpty && !textArea.Options.CutCopyWholeLine)
                return false;

            var readOnlySectionProvider = textArea.ReadOnlySectionProvider;
            if (readOnlySectionProvider is ReadOnlySectionDocument)
                return false;

            if (readOnlySectionProvider is NoReadOnlySections)
                return true;

            if (selection.IsEmpty)
            {
                Debug.Assert(textArea.Options.CutCopyWholeLine);
                var documentLine = textArea.Document.GetLineByNumber(textArea.Caret.Line);
                var segment = new SimpleSegment(documentLine.Offset, documentLine.TotalLength);
                return readOnlySectionProvider.GetDeletableSegments(segment).Any();
            }

            return selection.Segments.SelectMany(segment => readOnlySectionProvider.GetDeletableSegments(segment)).Any();
        }
        // Creates Rndf from an input FileStream
        public IRndf createRndf(FileStream fileStream)
        {
            numWps = 0;

            // File in Read Only mode, convert to stream
            StreamReader r = new StreamReader(fileStream, Encoding.UTF8);

            // Create new queue for input buffer
            Queue q = new Queue();
            string word = "";

            // Create the Rndf (with only segments for now, no zones)
            IRndf rndf = new IRndf();
            rndf.Segments = new List<SimpleSegment>();
            rndf.Zones = new List<SimpleZone>();

            // Loop until reach end of file marker
            while ((word.Length < 8) || (word.Substring(0, 8) != "end_file"))
            {
                // get the next word
                word = parseWord(r, q);

                if (word == "RNDF_name")
                {
                    word = parseWord(r, q);
                    rndf.Name = word;
                }
                else if (word == "num_segments")
                {
                    word = parseWord(r, q);
                    rndf.NumSegs = int.Parse(word);
                }
                else if (word == "num_zones")
                {
                    word = parseWord(r, q);
                    rndf.NumZones = int.Parse(word);
                }
                else if (word == "format_version")
                {
                    word = parseWord(r, q);
                    rndf.FormatVersion = word;
                }
                else if (word == "creation_date")
                {
                    word = parseWord(r, q);
                    rndf.CreationDate = word;
                }
                else if (word == "segment")
                {
                    // create new segment
                    SimpleSegment seg = new SimpleSegment();
                    seg.Lanes = new List<SimpleLane>();

                    word = parseWord(r, q);
                    seg.Id = word;

                    // run until reach end of segment marker
                    while (word != "end_segment")
                    {
                        // get next word
                        word = parseWord(r, q);

                        if (word == "segment_name")
                        {
                            word = parseWord(r, q);
                            seg.Name = word;
                        }
                        else if (word == "num_lanes")
                        {
                            word = parseWord(r, q);
                            seg.NumLanes = int.Parse(word);
                        }
                        else if (word == "end_segment")
                        {
                            // do nothing if at the end
                        }
                        else if (word == "lane")
                        {
                            // Create new lane
                            SimpleLane ln = new SimpleLane();
                            ln.Checkpoints = new List<SimpleCheckpoint>();
                            ln.Waypoints = new List<SimpleWaypoint>();
                            ln.Stops = new List<string>();
                            ln.ExitEntries = new List<SimpleExitEntry>();

                            word = parseWord(r, q);
                            ln.Id = word;

                            // run until reach end of lane
                            while (word != "end_lane")
                            {
                                // get next word
                                word = parseWord(r, q);

                                if (word == "num_waypoints")
                                {
                                    word = parseWord(r, q);
                                    ln.NumWaypoints = int.Parse(word);
                                }
                                else if (word == "checkpoint")
                                {
                                    // create checkpoint
                                    SimpleCheckpoint cp = new SimpleCheckpoint();

                                    // get waypoint id
                                    string wp = parseWord(r, q);
                                    cp.WaypointId = wp;

                                    // get checkpoint id
                                    string id = parseWord(r, q);
                                    cp.CheckpointId = id;

                                    // add to collection of checkpoints within lane
                                    ln.Checkpoints.Add(cp);
                                }
                                else if (word == "lane_width")
                                {
                                    word = parseWord(r, q);
                                    ln.LaneWidth = double.Parse(word);
                                }
                                else if (word == "stop")
                                {
                                    word = parseWord(r, q);
                                    ln.Stops.Add(word);
                                }
                                else if (word == "left_boundary")
                                {
                                    word = parseWord(r, q);
                                    ln.LeftBound = word;
                                }
                                else if (word == "right_boundary")
                                {
                                    word = parseWord(r, q);
                                    ln.RightBound = word;
                                }
                                else if (word == "exit")
                                {
                                    // create exit-entry pair
                                    SimpleExitEntry exitEntry = new SimpleExitEntry();

                                    // get the exit id
                                    string exit = parseWord(r, q);
                                    exitEntry.ExitId = exit;

                                    // get the entry id
                                    string entry = parseWord(r, q);
                                    exitEntry.EntryId = entry;

                                    // add to collection of exit-entry pairs within lane
                                    ln.ExitEntries.Add(exitEntry);
                                }
                                else if (word == "end_lane")
                                {
                                    // do nothing
                                }
                                // Otherwise we probably have a waypoint
                                else
                                {
                                    // check to make sure a wp by matching lane id to lane identifier of waypoint
                                    int laneIdLength = ln.Id.Length;

                                    // if waypoint matches then create the waypoint
                                    if (word.Length >= laneIdLength + 2 && (word.Substring(0, laneIdLength)).CompareTo(ln.Id) == 0)
                                    {
                                        // create a new waypoint
                                        SimpleWaypoint wp = new SimpleWaypoint();
                                        wp.Position = new UrbanChallenge.Common.Coordinates();

                                        // set its id
                                        wp.ID = word;

                                        // get latitude or X
                                        string lat = parseWord(r, q);
                                        wp.Position.X = double.Parse(lat);

                                        // get longitude or y
                                        string lon = parseWord(r, q);
                                        wp.Position.Y = double.Parse(lon);

                                        // add to lane's collection of waypoints
                                        ln.Waypoints.Add(wp);

                                        numWps += 1;
                                    }
                                    else
                                    {
                                        Console.WriteLine("Unknown identifier: " + word);
                                    }
                                }
                            }
                            seg.Lanes.Add(ln);
                        }
                        else
                        {
                            Console.WriteLine("Unknown identifier: " + word);
                        }
                    }
                    rndf.Segments.Add(seg);
                }
                else if (word == "zone")
                {
                    // create new zone
                    SimpleZone zone = new SimpleZone();
                    zone.ParkingSpots = new List<ParkingSpot>();

                    // get ID
                    word = parseWord(r, q);
                    zone.ZoneID = word;

                    // run until reach end of segment marker
                    while (word != "end_zone")
                    {
                        // get next word
                        word = parseWord(r, q);

                        if (word == "num_spots")
                        {
                            // get next word
                            word = parseWord(r, q);

                            // set num of parking spots
                            zone.NumParkingSpots = int.Parse(word);
                        }
                        else if (word == "zone_name")
                        {
                            // get next word
                            word = parseWord(r, q);

                            // set zone name
                            zone.Name = word;
                        }
                        else if (word == "perimeter")
                        {
                            // create perimeter
                            zone.Perimeter = new ZonePerimeter();
                            zone.Perimeter.ExitEntries = new List<SimpleExitEntry>();
                            zone.Perimeter.PerimeterPoints = new List<PerimeterPoint>();

                            // set perimeter id
                            zone.Perimeter.PerimeterID = parseWord(r, q);

                            while (word != "end_perimeter")
                            {
                                // get next word
                                word = parseWord(r, q);

                                if (word == "num_perimeterpoints")
                                {
                                    // set num of perimeter points
                                    zone.Perimeter.NumPerimeterPoints = int.Parse(parseWord(r, q));
                                }
                                else if (word == "exit")
                                {
                                    // create new exit,entry
                                    SimpleExitEntry ee = new SimpleExitEntry();

                                    // set exit
                                    ee.ExitId = parseWord(r, q);

                                    // set entry
                                    ee.EntryId = parseWord(r, q);

                                    // add to perimeter exit entries
                                    zone.Perimeter.ExitEntries.Add(ee);
                                }
                                else if (word == "end_perimeter")
                                {
                                    // Do Nothing
                                }
                                else
                                {
                                    // create new perimeter point
                                    PerimeterPoint p = new PerimeterPoint();

                                    // set id
                                    p.ID = word;

                                    // create new coordinate
                                    p.position = new UrbanChallenge.Common.Coordinates();

                                    // setX
                                    p.position.X = Double.Parse(parseWord(r, q));

                                    // setY
                                    p.position.Y = Double.Parse(parseWord(r, q));

                                    // add to perimeter points
                                    zone.Perimeter.PerimeterPoints.Add(p);
                                }
                            }
                        }
                        else if (word == "spot")
                        {
                            // create a new spot
                            ParkingSpot ps = new ParkingSpot();

                            // set spot id
                            ps.SpotID = parseWord(r, q);

                            while (word != "end_spot")
                            {
                                // get next word
                                word = parseWord(r, q);

                                if (word == "spot_width")
                                {
                                    // set spot width
                                    ps.SpotWidth = parseWord(r, q);
                                }
                                else if (word == "checkpoint")
                                {
                                    // get waypoint id that corresponds with checkpoint
                                    ps.CheckpointWaypointID = parseWord(r, q);

                                    // get checkpoint id
                                    ps.CheckpointID = parseWord(r, q);
                                }
                                else if (word == "end_spot")
                                {
                                    // add spot to zone
                                    zone.ParkingSpots.Add(ps);
                                }
                                else
                                {
                                    // SimpleWaypoint 1
                                    #region

                                    // create new waypoint for waypoint1
                                    ps.Waypoint1 = new SimpleWaypoint();
                                    ps.Waypoint1.Position = new UrbanChallenge.Common.Coordinates();

                                    // set id
                                    ps.Waypoint1.ID = word;

                                    // check if id is checkpointWaypointID
                                    if (ps.Waypoint1.ID == ps.CheckpointWaypointID)
                                    {
                                        ps.Waypoint1.IsCheckpoint = true;
                                        ps.Waypoint1.CheckpointID = ps.CheckpointID;
                                    }

                                    // setX
                                    ps.Waypoint1.Position.X = Double.Parse(parseWord(r, q));

                                    // setY
                                    ps.Waypoint1.Position.Y = Double.Parse(parseWord(r, q));

                                    #endregion

                                    // SimpleWaypoint 2
                                    #region

                                    // create new waypoint for waypoint2
                                    ps.Waypoint2 = new SimpleWaypoint();
                                    ps.Waypoint2.Position = new UrbanChallenge.Common.Coordinates();

                                    // set id
                                    ps.Waypoint2.ID = parseWord(r, q);

                                    // check if id is checkpointWaypointID
                                    if (ps.Waypoint2.ID == ps.CheckpointWaypointID)
                                    {
                                        ps.Waypoint2.IsCheckpoint = true;
                                        ps.Waypoint2.CheckpointID = ps.CheckpointID;
                                    }

                                    // setX
                                    ps.Waypoint2.Position.X = Double.Parse(parseWord(r, q));

                                    // setY
                                    ps.Waypoint2.Position.Y = Double.Parse(parseWord(r, q));

                                    #endregion
                                }
                            }
                        }
                        else if (word == "end_zone")
                        {
                            // Do Nothing
                        }
                        else
                        {
                            Console.WriteLine("Unrecognized: " + word);
                        }
                    }

                    // Add zones to zone
                    rndf.Zones.Add(zone);
                }
                else
                {
                    if (word == "end_file")
                        Console.WriteLine("Rndf Parse :: Successful");
                    else
                        Console.WriteLine("Unknown identifier: " + word);
                }
            }
            return rndf;
        }
예제 #32
0
        /// <inheritdoc/>
        public override void ReplaceSelectionWithText(TextArea textArea, string newText)
        {
            if (textArea == null)
            {
                throw new ArgumentNullException("textArea");
            }
            if (newText == null)
            {
                throw new ArgumentNullException("newText");
            }
            using (textArea.Document.RunUpdate()) {
                TextLocation start      = document.GetLocation(StartOffset);
                TextLocation end        = document.GetLocation(EndOffset);
                int          editColumn = Math.Min(start.Column, end.Column);
                if (NewLineFinder.NextNewLine(newText, 0) == SimpleSegment.Invalid)
                {
                    // insert same text into every line
                    foreach (ISegment lineSegment in this.Segments.Reverse())
                    {
                        ReplaceSingleLineText(textArea, lineSegment, newText);
                    }

                    TextLocation newStart = new TextLocation(start.Line, editColumn + newText.Length);
                    TextLocation newEnd   = new TextLocation(end.Line, editColumn + newText.Length);
                    textArea.Caret.Location = newEnd;
                    textArea.Selection      = new RectangleSelection(document, document.GetOffset(newStart), document.GetOffset(newEnd));
                }
                else
                {
                    // convert all segment start/ends to anchors
                    var           segments = this.Segments.Select(s => new AnchorSegment(this.document, s)).ToList();
                    SimpleSegment ds       = NewLineFinder.NextNewLine(newText, 0);
                    // we'll check whether all lines have the same length. If so, we can continue using a rectangular selection.
                    int commonLength = -1;
                    // now insert lines into rectangular selection
                    int  lastDelimiterEnd = 0;
                    bool isAtEnd          = false;
                    int  i;
                    for (i = 0; i < segments.Count; i++)
                    {
                        string lineText;
                        if (ds == SimpleSegment.Invalid || (i == segments.Count - 1))
                        {
                            lineText = newText.Substring(lastDelimiterEnd);
                            isAtEnd  = true;
                            // if we have more lines to insert than this selection is long, we cannot continue using a rectangular selection
                            if (ds != SimpleSegment.Invalid)
                            {
                                commonLength = -1;
                            }
                        }
                        else
                        {
                            lineText = newText.Substring(lastDelimiterEnd, ds.Offset - lastDelimiterEnd);
                        }
                        if (i == 0)
                        {
                            commonLength = lineText.Length;
                        }
                        else if (commonLength != lineText.Length)
                        {
                            commonLength = -1;
                        }
                        ReplaceSingleLineText(textArea, segments[i], lineText);
                        if (isAtEnd)
                        {
                            break;
                        }
                        lastDelimiterEnd = ds.EndOffset;
                        ds = NewLineFinder.NextNewLine(newText, lastDelimiterEnd);
                    }
                    if (commonLength >= 0)
                    {
                        TextLocation newStart = new TextLocation(start.Line, editColumn + commonLength);
                        TextLocation newEnd   = new TextLocation(start.Line + i, editColumn + commonLength);
                        textArea.Selection = new RectangleSelection(document, document.GetOffset(newStart), document.GetOffset(newEnd));
                    }
                    else
                    {
                        textArea.Selection = Selection.Empty;
                    }
                }
            }
        }
예제 #33
0
		const string LineSelectedType = "MSDEVLineSelect";  // This is the type VS 2003 and 2005 use for flagging a whole line copy
		
		static void CopyWholeLine(TextArea textArea, DocumentLine line)
		{
			ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength);
			string text = textArea.Document.GetText(wholeLine);
			// Ensure we use the appropriate newline sequence for the OS
			text = NewLineFinder.NormalizeNewLines(text, Environment.NewLine);
			DataObject data = new DataObject(text);
			
			// Also copy text in HTML format to clipboard - good for pasting text into Word
			// or to the SharpDevelop forums.
			IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter;
			HtmlClipboard.SetHtml(data, HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine, new HtmlOptions(textArea.Options)));
			
			MemoryStream lineSelected = new MemoryStream(1);
			lineSelected.WriteByte(1);
			data.SetData(LineSelectedType, lineSelected, false);
			
			try {
				Clipboard.SetDataObject(data, true);
			} catch (ExternalException) {
				// Apparently this exception sometimes happens randomly.
				// The MS controls just ignore it, so we'll do the same.
				return;
			}
			textArea.OnTextCopied(new TextEventArgs(text));
		}
예제 #34
0
 public override IEnumerable <SimpleSegment> GetSimpleSegments()
 {
     yield return(SimpleSegment.Create(Start, _segment.Point1, _segment.Point2));
 }
		const string LineSelectedType = "MSDEVLineSelect";  // This is the type VS 2003 and 2005 use for flagging a whole line copy
		
		static void CopyWholeLine(TextArea textArea, DocumentLine line)
		{
			ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength);
			string text = textArea.Document.GetText(wholeLine);
			// Ensure we use the appropriate newline sequence for the OS
			DataObject data = new DataObject(NewLineFinder.NormalizeNewLines(text, Environment.NewLine));
			
			// Also copy text in HTML format to clipboard - good for pasting text into Word
			// or to the SharpDevelop forums.
			DocumentHighlighter highlighter = textArea.GetService(typeof(DocumentHighlighter)) as DocumentHighlighter;
			HtmlClipboard.SetHtml(data, HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine, new HtmlOptions(textArea.Options)));
			
			MemoryStream lineSelected = new MemoryStream(1);
			lineSelected.WriteByte(1);
			data.SetData(LineSelectedType, lineSelected, false);
			
			Clipboard.SetDataObject(data, true);
		}