Inheritance: NSTextView
		private static void LinkSourceRanges(TextView TheView, SourceRange CurrentSelection, IEnumerable<SourceRange> Ranges)
		{
			CodeRush.LinkedIdentifiers.BreakAllLinks();
			var List = CodeRush.LinkedIdentifiers.GetStorage(TheView.TextDocument).NewList();
			if (!CurrentSelection.IsPoint)
			{
				List.Add(CurrentSelection);
			}
			foreach (var Selection in Ranges)
			{
				List.Add(Selection);
			}
		}
		private static void LinkOriginalRange(TextView TheView, SourceRange CurrentSelection, IEnumerable<SourceRange> ExistingSelections)
		{
			SourceRange FirstRange;
			if (CurrentSelection.IsPoint)
			{
				FirstRange = ExistingSelections.FirstOrDefault();
			}
			else
			{
				FirstRange = CurrentSelection;
			}
			TheView.Selection.Set(FirstRange);
		}
		internal TextBoxHelper ()
		{
			this.AutohidesScrollers = true;
			this.BorderType = NSBorderType.BezelBorder;
			this.HasVerticalScroller = false;
			this.HasHorizontalScroller = true;
			TextView = new TextView ();
			TextView.Host = this;
			TextView.TextContainerInset = new SizeF (5f, 5f);
			TextView.AutoresizingMask = (NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable);
			TextView.TextContainer.ContainerSize = new SizeF (float.MaxValue, float.MaxValue);
			this.DocumentView = TextView;
			
			//TextView.EnclosingScrollView.HasHorizontalScroller = true;
		}
        /// <summary>
        /// Adds the selection in the specified TextView to this view's MultiSelect list.
        /// </summary>
        /// <param name="textView">The TextView containing the MultiSelect list to add to.</param>
        public void Add(TextView textView)
        {
            if (textView == null)
                return;
            MultiSelect multiSelect = Get(textView);
            if (multiSelect == null)
            {
                multiSelect = new MultiSelect();
                multiSelect.FileName = textView.FileNode.Name;
                multiSelect.Language = textView.TextDocument.Language;
                multiSelect.TypeName = CodeRush.Source.ActiveTypeName;
                Set(textView, multiSelect);
            }
            else if (multiSelect.TypeName != CodeRush.Source.ActiveTypeName)		// Inconsistent class names, so let's clear it out.
                multiSelect.TypeName = String.Empty;

            MultiSelect redoMultiSelect = GetRedo(textView);
            if (redoMultiSelect != null)
                redoMultiSelect.Selections.Clear();

            multiSelect.AddSelection(textView);
        }
Exemple #5
0
        public void Draw(TextView textView, System.Windows.Media.DrawingContext drawingContext) {
            if (markers == null || !textView.VisualLinesValid) {
                return;
            }
            var visualLines = textView.VisualLines;
            if (visualLines.Count == 0) {
                return;
            }
            int viewStart = visualLines.First().FirstDocumentLine.Offset;
            int viewEnd = visualLines.Last().LastDocumentLine.EndOffset;
            foreach (TextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart)) {
                if (marker.BackgroundColor != null) {
                    var geoBuilder = new BackgroundGeometryBuilder { AlignToWholePixels = true, CornerRadius = 3 };
                    geoBuilder.AddSegment(textView, marker);
                    System.Windows.Media.Geometry geometry = geoBuilder.CreateGeometry();
                    if (geometry != null) {
                        System.Windows.Media.Color color = marker.BackgroundColor.Value;
                        var brush = new System.Windows.Media.SolidColorBrush(color);
                        brush.Freeze();
                        drawingContext.DrawGeometry(brush, null, geometry);
                    }
                }
                foreach (System.Windows.Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker)) {
                    var startPoint = r.BottomLeft;
                    var endPoint = r.BottomRight;

                    var usedPen = new System.Windows.Media.Pen(new System.Windows.Media.SolidColorBrush(marker.MarkerColor), 1);
                    usedPen.Freeze();
                    const double offset = 2.5;

                    int count = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);

                    var geometry = new System.Windows.Media.StreamGeometry();

                    using (System.Windows.Media.StreamGeometryContext ctx = geometry.Open()) {
                        ctx.BeginFigure(startPoint, false, false);
                        ctx.PolyLineTo(CreatePoints(startPoint, endPoint, offset, count).ToArray(), true, false);
                    }

                    geometry.Freeze();

                    drawingContext.DrawGeometry(System.Windows.Media.Brushes.Transparent, usedPen, geometry);
                    break;
                }
            }
        }
 /// <summary>
 /// Clears the multi-selection and removes it from the specified TextView.
 /// </summary>
 /// <param name="textView">The TextView containing the multi-selection to remove.</param>
 public void Clear(TextView textView)
 {
     MultiSelect multiSelect = Get(textView);
     if (multiSelect == null)
         return;
     multiSelect.Clear();
     Remove(textView);
 }
 /// <summary>
 /// Returns true if a multi-select Undo operation is available for the specified TextView.
 /// </summary>
 /// <param name="textView">The TextView to check.</param>
 public bool UndoIsAvailable(TextView textView)
 {
     MultiSelect multiSelect = Get(textView);
     return multiSelect != null && multiSelect.Selections.Count > 0;
 }
 /// <summary>
 /// Copies the MultiSelect object from the specified TextView to the clipboard.
 /// </summary>
 /// <param name="textView">The TextView containing the MultiSelect object to copy.</param>
 /// <returns>The MultiSelect object from the active TextView.</returns>
 public MultiSelect CopyToClipboard(TextView textView)
 {
     MultiSelect multiSelect = Get(textView);
     if (multiSelect != null)
         multiSelect.CopyToClipboard();
     return multiSelect;
 }
        public void Undo(TextView activeTextView)
        {
            MultiSelect multiSelect = Get(activeTextView);
            if (multiSelect == null || multiSelect.Selections.Count == 0)
                return;

            MultiSelect redoMultiSelect = GetRedo(activeTextView);
            if (redoMultiSelect == null)
            {
                redoMultiSelect = new MultiSelect();
                SetRedo(activeTextView, redoMultiSelect);
            }

            int lastIndex = multiSelect.Selections.Count - 1;
            PartialSelection selectionToRemove = multiSelect.GetSelectionAt(lastIndex);
            redoMultiSelect.Selections.Add(selectionToRemove);
            selectionToRemove.RemoveHighlighter();
            activeTextView.Caret.MoveTo(selectionToRemove.CaretPosition);
            multiSelect.RemoveSelectionAt(lastIndex);
        }
 /// <summary>
 /// Returns true if the specified TextView contains a MultiSelect object with at least one selection defined.
 /// </summary>
 /// <param name="textView">The TextView to check.</param>
 public bool SelectionExists(TextView textView)
 {
     MultiSelect multiSelect = Get(textView);
     if (multiSelect == null)
         return false;
     return multiSelect.Selections.Count > 0;
 }
Exemple #11
0
        public HexEditor (string tagName, byte[] data, int bytesPerElem)
        {
            InitializeComponent();

            EditView textView = new TextView(statusStrip1, bytesPerElem);
            textView.Initialize();
            textView.SetRawData(data);
            textView.Modified += (s, e) => { _modified = true; };

            _views.Add(textView.TabPage, textView);
            viewTabs.TabPages.Add(textView.TabPage);

            EditView hexView = null;

            if (!IsMono()) {
                hexView = new HexView(statusStrip1, bytesPerElem);
                hexView.Initialize();
                hexView.SetRawData(data);
                hexView.Modified += (s, e) => { _modified = true; };

                _views.Add(hexView.TabPage, hexView);
                viewTabs.TabPages.Add(hexView.TabPage);
            }

            if (bytesPerElem > 1 || IsMono()) {
                textView.Activate();
                viewTabs.SelectedTab = textView.TabPage;
            }
            else {
                hexView.Activate();
                viewTabs.SelectedTab = hexView.TabPage;
            }

            viewTabs.Deselected += (o, e) => { _previousPage = e.TabPage; };
            viewTabs.Selecting += HandleTabChanged;

            this.Text = "Editing: " + tagName;

            _bytesPerElem = bytesPerElem;

            _data = new byte[data.Length];
            Array.Copy(data, _data, data.Length);
        }
 /// <summary>
 /// Returns true if a multi-select Redo operation is available for the specified TextView.
 /// </summary>
 /// <param name="textView">The TextView to check.</param>
 public bool RedoIsAvailable(TextView textView)
 {
     MultiSelect redoMultiSelect = GetRedo(textView);
     return redoMultiSelect != null && redoMultiSelect.Selections.Count > 0;
 }
 public void Remove(TextView textView)
 {
     textView.Storage.RemoveObject(STR_MultiSelectList);
     textView.Storage.RemoveObject(STR_RedoMultiSelectList);
 }
        public void Redo(TextView textView)
        {
            MultiSelect redoMultiSelect = CodeRushPlaceholder.MultiSelect.GetRedo(textView);
            if (redoMultiSelect == null || redoMultiSelect.Selections.Count <= 0)
                return;

            MultiSelect multiSelect = CodeRushPlaceholder.MultiSelect.Get(textView);
            if (multiSelect == null)
                return;

            int lastIndex = redoMultiSelect.Selections.Count - 1;
            multiSelect.AddSelection(textView, redoMultiSelect.Selections[lastIndex]);
            redoMultiSelect.Selections.RemoveAt(lastIndex);
        }
 public MultiSelect GetRedo(TextView textView)
 {
     return textView.Storage.GetObject(STR_RedoMultiSelectList) as MultiSelect;
 }
 /// <summary>
 /// Copies the MultiSelect object from the specified TextView to the clipboard and removes all selections.
 /// </summary>
 /// <param name="textView">The TextView containing the MultiSelect object to cut.</param>
 /// <returns>The MultiSelect object from the active TextView.</returns>
 public MultiSelect CutToClipboard(TextView textView)
 {
     MultiSelect multiSelect = Get(textView);
     if (multiSelect != null)
     {
         multiSelect.WasCut = true;
         multiSelect.CopyToClipboard();
     }
     return multiSelect;
 }
        List<Line> CollectLines(TextView textView, int width_divisor)
        {
            List<Line> lines = new List<Line>();
            if (shutting_down) return lines;

            int start = 0;
            int end = 0;
            string tabs = new string(' ', textView.TextDocument.TabSize);

            string line_comment_start;
            if (textView.TextDocument.Language == "Basic")
                line_comment_start = "'";
            else
                line_comment_start = "//";

            for (int l = 0; l < textView.TextDocument.LineCount; l++)
            {
                string txt = textView.TextDocument.GetLine(l).TrimEnd();
                string org_txt = txt;
                if (txt.IndexOf('\t') >= 0)
                    txt = txt.Replace("\t", tabs);

                string ltr = txt.TrimStart();
                start = (txt.Length - ltr.Length);
                end = txt.Length;

                int start_of_comment = txt.IndexOf(line_comment_start);
                int end_of_comment = -2;
                if (start_of_comment >= 0)
                {
                    end_of_comment = end;
                    end = start_of_comment - 1;
                }
                //int word_start = txt.IndexOf(selected_double_click, StringComparison.InvariantCultureIgnoreCase);
                Line line = new Line(l, start, end, start_of_comment, end_of_comment, CollectWordIndexes(ref org_txt));

                line.DivideWidth(width_divisor);
                line.PressIntoWidth(Width);

                try
                {
                    EnvDTE.Breakpoint bp = CodeRush.Breakpoint.Get(textView.TextDocument.FullName, l);
                    if (bp != null && bp.Enabled)
                        line.HasBreakpoint = true;
                }
                catch (Exception)
                {
                }
                lines.Add(line);
            }

            foreach (IMarker item in CodeRush.Markers)
            {
                if (textView.TextDocument.FullName.Equals(item.FileName, StringComparison.InvariantCultureIgnoreCase))
                {
                    if (lines.Count >= item.Line && item.Hidden == false)
                        lines[item.Line].MarkerPosition = item.Column / width_divisor;
                }
            }

            return lines;
        }
 private Rectangle GetRectangle(TextView activeDocument)
 {
     var top = new Point(activeDocument.Bounds.Width - imageList1.ImageSize.Width, activeDocument.Bounds.Top + 20);
     var r = new Rectangle(top, new Size(imageList1.ImageSize.Width, imageList1.ImageSize.Height));
     return r;
 }
 public void Draw(TextView textView, DrawingContext drawingContext)
 {
   if (textView.Document.TextLength <= 0)
   {
     var text = new FormattedText(this.PlaceholderText
       , CultureInfo.CurrentCulture
       , System.Windows.FlowDirection.LeftToRight
       , new Typeface(_sansSerif
         , System.Windows.FontStyles.Normal
         , System.Windows.FontWeights.Normal
         , System.Windows.FontStretches.Normal)
       , textView.DefaultLineHeight - 2
       , System.Windows.Media.Brushes.DimGray);
     drawingContext.DrawText(text, new System.Windows.Point(1, 1));
   }
 }
 private void ShowTestPopupMenu(TextView textView, Tile tile)
 {
     if (TileIsOurs(tile) && _hoveredTest == null)
     {
         _hoveredTest = tile.Object as ITestDetail;
         Point tilePoint = new Point(tile.Bounds.Left, tile.Bounds.Bottom);
         Point menuPoint = textView.ToScreenPoint(tilePoint);
         CodeRush.SmartTags.ShowPopupMenu(menuPoint, _hoveredTest.SmartTagProvider);
     }
 }
 public void Set(TextView textView, MultiSelect multiSelect)
 {
     textView.Storage.AttachObject(STR_MultiSelectList, multiSelect);
 }
        private void Restore(LanguageElement element, TextView textView)
        {
            _ChangingInternally = true;
            try
            {
                SourcePoint caret = _Caret.GetBestLocation(element);

                if (_Anchor != null)
                {
                    SourcePoint anchor = _Anchor.GetBestLocation(element);
                    textView.Selection.Set(anchor, caret);
                }
                else
                    textView.Caret.MoveTo(caret);
            }
            finally
            {
                _ChangingInternally = false;
            }
        }
 public void SetRedo(TextView textView, MultiSelect redoMultiSelect)
 {
     textView.Storage.AttachObject(STR_RedoMultiSelectList, redoMultiSelect);
 }
 public ExtTextOutMatrixView()
 {
     host.Child = view = new TextView() { parent = this };
 }