/////////////////////////////////////////////////////////////////////////////////////////////////////
        // PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Adds an adornment to the <see cref="AdornmentLayer"/>.
        /// </summary>
        /// <param name="reason">An <see cref="AdornmentChangeReason"/> indicating the add reason.</param>
        /// <param name="viewLine">The current <see cref="ITextViewLine"/> being examined.</param>
        /// <param name="tagRange">The <see cref="ITag"/> and the range it covers.</param>
        /// <param name="bounds">The text bounds in which to render an adornment.</param>
        protected override void AddAdornment(AdornmentChangeReason reason, ITextViewLine viewLine, TagSnapshotRange <CollapsedRegionTag> tagRange, TextBounds bounds)
        {
            // Create a border
            Border outerBorder = new Border();

            outerBorder.Background          = Brushes.Transparent;
            outerBorder.BorderBrush         = Brushes.Gray;
            outerBorder.BorderThickness     = new Thickness(1.0);
            outerBorder.CornerRadius        = new CornerRadius(2.0);
            outerBorder.Cursor              = Cursors.Arrow;
            outerBorder.SnapsToDevicePixels = true;
            outerBorder.Width  = bounds.Width;
            outerBorder.Height = bounds.Height;
            this.AdornmentLayer.AddAdornment(reason, outerBorder, new Point(Math.Round(bounds.Left), Math.Round(bounds.Top)), tagRange.Tag.Key, null);

            // Create the text adornment
            TextBlock element = new TextBlock();

            element.IsHitTestVisible = false;
            element.Text             = tagRange.Tag.Text;
            element.FontFamily       = this.View.SyntaxEditor.FontFamily;
            element.FontSize         = this.View.SyntaxEditor.FontSize;
            element.Foreground       = Brushes.Gray;
            element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            // Get the location
            Point location = new Point(Math.Round(bounds.Left), Math.Round(bounds.Top + (bounds.Height - element.DesiredSize.Height) / 2));

            // Add the text adornment to the layer
            this.AdornmentLayer.AddAdornment(reason, element, location, tagRange.Tag.Key, null);
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Adds an adornment to the <see cref="AdornmentLayer"/>.
        /// </summary>
        /// <param name="reason">An <see cref="AdornmentChangeReason"/> indicating the add reason.</param>
        /// <param name="viewLine">The current <see cref="ITextViewLine"/> being examined.</param>
        /// <param name="tagRange">The <see cref="ITag"/> and the range it covers.</param>
        /// <param name="bounds">The text bounds in which to render an adornment.</param>
        protected override void AddAdornment(AdornmentChangeReason reason, ITextViewLine viewLine, TagSnapshotRange <CustomTag> tagRange, TextBounds bounds)
        {
            // Create the adornment
            UIElement element  = CustomAdornmentManager.CreateDecorator(bounds.Width);
            Point     location = new Point(Math.Round(bounds.Left), bounds.Bottom - 2);

            // Add the adornment to the layer
            this.AdornmentLayer.AddAdornment(reason, element, location, null, viewLine, tagRange.SnapshotRange, TextRangeTrackingModes.ExpandBothEdges, null);
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Adds an adornment to the <see cref="AdornmentLayer"/>.
        /// </summary>
        /// <param name="reason">An <see cref="AdornmentChangeReason"/> indicating the add reason.</param>
        /// <param name="viewLine">The current <see cref="ITextViewLine"/> being examined.</param>
        /// <param name="tagRange">The <see cref="ITag"/> and the range it covers.</param>
        /// <param name="bounds">The text bounds in which to render an adornment.</param>
        protected override void AddAdornment(AdornmentChangeReason reason, ITextViewLine viewLine, TagSnapshotRange <ColorPreviewTag> tagRange, TextBounds bounds)
        {
            // Round off the bounds to integers to help ensure crispness
            var adornmentBounds = new Rect(Math.Round(bounds.Left, MidpointRounding.AwayFromZero), Math.Round(bounds.Top, MidpointRounding.AwayFromZero),
                                           Math.Round(bounds.Width, MidpointRounding.AwayFromZero), Math.Round(bounds.Height, MidpointRounding.AwayFromZero));

            // Add the adornment to the layer
            this.AdornmentLayer.AddAdornment(reason, OnDrawHighlightAdornment, adornmentBounds, tagRange.Tag, viewLine, tagRange.SnapshotRange, TextRangeTrackingModes.ExpandBothEdges, null);
        }
Esempio n. 4
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Adds an adornment to the <see cref="AdornmentLayer"/>.
        /// </summary>
        /// <param name="reason">An <see cref="AdornmentChangeReason"/> indicating the add reason.</param>
        /// <param name="viewLine">The current <see cref="ITextViewLine"/> being examined.</param>
        /// <param name="tagRange">The <see cref="ITag"/> and the range it covers.</param>
        /// <param name="bounds">The text bounds in which to render an adornment.</param>
        protected override void AddAdornment(AdornmentChangeReason reason, ITextViewLine viewLine, TagSnapshotRange <IntraTextNoteTag> tagRange, TextBounds bounds)
        {
            // Create the adornment
            var image = new DynamicImage();

            image.Width  = 16;
            image.Height = 16;
            image.SnapsToDevicePixels = true;
            image.Source  = new BitmapImage(new Uri("/Images/Icons/Notes16.png", UriKind.Relative));
            image.Stretch = Stretch.Fill;

            // Create a popup button
            PopupButton button = new PopupButton();

            button.Content     = image;
            button.Cursor      = Cursors.Arrow;
            button.DisplayMode = PopupButtonDisplayMode.Merged;
            button.Focusable   = false;
            button.IsTabStop   = false;
            button.IsTransparencyModeEnabled = true;
            button.Margin  = new Thickness(0);
            button.Padding = new Thickness(-1);
            button.ToolTip = new HtmlContentProvider(String.Format("<span style=\"color: green;\">{0}</span><br/>Created at <b>{1}</b> by <span style=\"color: blue;\">{2}</span><br/>Status: <b>{3}</b>",
                                                                   tagRange.Tag.Message, tagRange.Tag.Created.ToShortTimeString(), tagRange.Tag.Author, tagRange.Tag.Status)).GetContent();

            // Add a context menu
            ContextMenu contextMenu = new ContextMenu();

            button.PopupMenu = contextMenu;

            MenuItem removeItem = new MenuItem();

            removeItem.Header = "Remove Note";
            removeItem.Tag    = tagRange;
            removeItem.Click += new RoutedEventHandler(OnRemoveNote);
            contextMenu.Items.Add(removeItem);

            contextMenu.Items.Add(new Separator());

            MenuItem pendingItem = new MenuItem();

            pendingItem.Header    = "Mark as Pending";
            pendingItem.IsChecked = (tagRange.Tag.Status == ReviewStatus.Pending);
            pendingItem.Tag       = tagRange;
            pendingItem.Click    += new RoutedEventHandler(OnMarkNoteAsPending);
            contextMenu.Items.Add(pendingItem);

            MenuItem acceptedItem = new MenuItem();

            acceptedItem.Header    = "Mark as Accepted";
            acceptedItem.IsChecked = (tagRange.Tag.Status == ReviewStatus.Accepted);
            acceptedItem.Tag       = tagRange;
            acceptedItem.Click    += new RoutedEventHandler(OnMarkNoteAsAccpeted);
            contextMenu.Items.Add(acceptedItem);

            MenuItem rejectedItem = new MenuItem();

            rejectedItem.Header    = "Mark as Rejected";
            rejectedItem.IsChecked = (tagRange.Tag.Status == ReviewStatus.Rejected);
            rejectedItem.Tag       = tagRange;
            rejectedItem.Click    += new RoutedEventHandler(OnMarkNoteAsRejected);
            contextMenu.Items.Add(rejectedItem);

            // Get the location
            Point location = new Point(Math.Round(bounds.Left) + 1, Math.Round(bounds.Top + (bounds.Height - tagRange.Tag.Size.Height) / 2));

            // Add the adornment to the layer
            this.AdornmentLayer.AddAdornment(reason, button, location, tagRange.Tag.Key, null);
        }