private NorthArrowAdornmentDeserializer(SerializationInfo info, StreamingContext context)
        {
            string alias    = info.GetString("_alias");
            string mapAlias = info.GetString("_mapAlias");

            // See if the "same" map exists.
            MapInfo.Mapping.Map map = MapInfo.Engine.Session.Current.MapFactory[mapAlias];
            if (map == null)
            {
                throw new SerializationException(MapInfo.Engine.Session.Current.Resources.GetString("MapInfo.Serialization.AdornmentMapNotFound", alias, mapAlias));
            }

            IAdornment adornment = map.Adornments[alias];

            if (adornment != null)
            {
                if (adornment is NorthArrowAdornment)
                {
                    _adornment = (NorthArrowAdornment)adornment;
                }
                else
                {
                    map.Adornments.Remove(alias);
                    _adornment = null;
                    adornment  = null;
                }
            }
            // The "same" adornment doesn't exist. Create it from scratch.
            if (adornment == null)
            {
                _adornment = new NorthArrowAdornment(alias, mapAlias);
                //adornment = _adornment;
                map.Adornments.Append(_adornment);
            }

            _adornment.SetObjectData(info, context);
        }
Beispiel #2
0
        public PowerModeAdornment(IWpfTextView view)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            this.view      = view;
            adornmentLayer = view.GetAdornmentLayer("PowerModeAdornment");

            streakCounterAdornment = new StreakCounterAdornment();
            screenShakeAdornment   = new ScreenShakeAdornment();
            particlesAdornment     = new ParticlesAdornment();

            generalSettings   = SettingsService.GetGeneralSettings();
            comboModeSettings = SettingsService.GetComboModeSettings();

            this.view.TextBuffer.Changed    += TextBuffer_Changed;
            this.view.ViewportHeightChanged += View_ViewportSizeChanged;
            this.view.ViewportWidthChanged  += View_ViewportSizeChanged;

            PropertyChangedEventManager.AddHandler(generalSettings, GeneralSettingModelPropertyChanged, "");
            PropertyChangedEventManager.AddHandler(comboModeSettings, ComboModeSettingsModelPropertyChanged, "");
        }
        /// <summary>
        /// Occurs when the adornment needs to be drawn.
        /// </summary>
        /// <param name="context">The <see cref="TextViewDrawContext"/> to use for rendering.</param>
        /// <param name="adornment">The <see cref="IAdornment"/> to draw.</param>
        private void OnDrawAdornment(TextViewDrawContext context, IAdornment adornment)
        {
            var color = Color.FromArgb(0x20, 0x80, 0x80, 0x80);

            context.FillRectangle(new Rect(adornment.Location, adornment.Size), color);
        }
    /// <summary>
    /// Adds a particular adornment onto this's text view's adornment layer.
    /// </summary>
    public void AddAdornment(IAdornment adornment, object tag) {
      Contract.Requires(adornment != null);

      Adornments[tag] = adornment;
      CreateVisual(adornment, tag);
      EvaluateAdornmentRegionDepth(adornment);
    }
    void EvaluateAdornmentRegionDepth(IAdornment adornment) {
      Contract.Requires(adornment != null && adornment.Span != null);
      Contract.Requires(_outliningManager != null);
      Contract.Requires(_textView != null);

      try {
        var workingSnapshot = _textView.TextSnapshot;
        var collapsedRegionsAdornmentIsIn = _outliningManager.GetCollapsedRegions(adornment.Span.GetSpan(workingSnapshot));
        Contract.Assume(collapsedRegionsAdornmentIsIn != null, "Let's make the assumption explicit");
        adornment.CollapsedRegionDepth = collapsedRegionsAdornmentIsIn.Count();
      } catch (ObjectDisposedException e) {
        if (e.ObjectName == "OutliningManager")
          _logger.WriteToLog("Error: The 'OutliningManager' is disposed, adornments may not be formatted correctly.");
        else
          throw e;
      }
    }
 /// <summary>
 /// Adds a particular adornment onto this's text view's adornment layer.
 /// </summary>
 void CreateVisual(ITextViewLine line, IAdornment adornment, object tag) {
   FrameworkElement elem = adornment.Visual;
   var span = adornment.Span.GetSpan(_textView.TextSnapshot);
   Geometry g = _textView.TextViewLines.GetMarkerGeometry(new SnapshotSpan(_textView.TextSnapshot, Span.FromBounds(span.Start, line.End)));
   if (g != null) {
     //position the adornment such that it is at the top left corner of the line
     Canvas.SetLeft(elem, g.Bounds.Left);
     Canvas.SetTop(elem, g.Bounds.Top - adornment.Visual.ActualHeight);
   } else {
     _logger.WriteToLog("Failed to get marker geometry for adornment.");
   }
   AddAdornment(elem, line.Extent, tag);
 }
 /// <summary>
 /// Adds a particular adornment onto this's text view's adornment layer.
 /// </summary>
 void CreateVisual(IAdornment adornment, object tag) {
   ITextViewLine line = _textView.TextViewLines.GetTextViewLineContainingBufferPosition(adornment.Span.GetStartPoint(_textView.TextSnapshot));
   if (line == null)
     return;
   CreateVisual(line, adornment, tag);
 }
        /// <summary>
        /// Creates isntance of <c>DragDropFeedbacker</c> class.
        /// </summary>
        /// <param name="adornment">Drag and drop adornment to show below cursor.</param>
        public DragDropFeedbacker(IAdornment adornment)
        {
            Debug.Assert(adornment != null);

            _adornment = adornment;

            // Subscribe on feedback from drag and drop.
            this.GiveFeedback += new GiveFeedbackEventHandler(_GiveFeedbackHandler);
        }