Пример #1
0
        public void TextViewCreated(IWpfTextView textView)
        {
            lock (sessions)
            {
                string filePath = textView.GetDocumentFullPath();
                if (filePath != null)
                {
                    ITextBuffer textBuffer = textView.TextBuffer;
                    if (!sessions.ContainsKey(filePath))
                    {
                        EditingSession editingSession = new EditingSession(filePath, textBuffer, textView);
                        sessions.Add(filePath, editingSession);

                        EventHandler textViewClosed = null;
                        textViewClosed = (o, e) =>
                        {
                            textView.Closed -= textViewClosed;
                            lock (sessions)
                            {
                                sessions.Remove(filePath);
                            }
                        };

                        textView.Closed += textViewClosed;
                    }
                }
            }
        }
        /// <summary>
        /// Creates a square image and attaches an event handler to the layout changed event that
        /// adds the the square in the upper right-hand corner of the TextView via the adornment layer
        /// </summary>
        /// <param name="view">The <see cref="IWpfTextView"/> upon which the adornment will be drawn</param>
        public ConflictPopupAdornment(IWpfTextView view)
        {
            _view           = view;
            _adornmentLayer = view.GetAdornmentLayer("ConflictPopupAdornment");

            string filePath = _view.GetDocumentFullPath();

            if (filePath != null)
            {
                this.editingSession = EditingSessionFactory.WaitForSession(_view.GetDocumentFullPath());
                editingSession.ConflictDataChanged += editingSession_ConflictDataChanged;
            }

            _view.ViewportHeightChanged += delegate { this.onSizeChange(); };
            _view.ViewportWidthChanged  += delegate { this.onSizeChange(); };
        }
        void editingSession_ConflictDataChanged(object sender, ConflictDataChangedEventArgs e)
        {
            IEnumerable <ConflictInfo> conflicts = e.NewConflicts;

            Application.Current.Dispatcher.Invoke(() =>
            {
                if (conflicts != null && conflicts.Any())
                {
                    ConflictPopupViewModel controlViewModel = null;

                    if (control == null)
                    {
                        control             = new ConflictPopup();
                        controlViewModel    = new ConflictPopupViewModel(this.editingSession.SCCService);
                        control.DataContext = controlViewModel;
                    }
                    else
                    {
                        controlViewModel = (ConflictPopupViewModel)control.DataContext;
                    }

                    controlViewModel.ConflictViewModel.LatestVersion = e.LatestVersion;
                    controlViewModel.ConflictViewModel.FilePath      = _view.GetDocumentFullPath();

                    _adornmentLayer.AddAdornment(AdornmentPositioningBehavior.ViewportRelative, null, null, control, null);
                }
                else
                {
                    _adornmentLayer.RemoveAllAdornments();
                }
            });
        }
Пример #4
0
        public ConflictTextAdornment(IWpfTextView view, IEditorFormatMap editorFormatMap)
        {
            _view  = view;
            _layer = view.GetAdornmentLayer("ConflictTextAdornment");

            //Listen to any event that changes the layout (text changes, scrolling, etc)
            _view.LayoutChanged += OnLayoutChanged;

            SolidColorBrush b = (SolidColorBrush)editorFormatMap.GetProperties(ConflictRegionFormatDefinition.Name)[EditorFormatDefinition.BackgroundBrushId];;

            _brush = new SolidColorBrush(Color.FromArgb((byte)(Opacity * 255), b.Color.R, b.Color.G, b.Color.B));
            Brush penBrush = (SolidColorBrush)editorFormatMap.GetProperties(ConflictRegionFormatDefinition.Name)[EditorFormatDefinition.ForegroundBrushId];;

            penBrush.Freeze();
            _pen = new Pen(penBrush, 1);

            string filePath = _view.GetDocumentFullPath();

            if (filePath != null)
            {
                this.editingSession = EditingSessionFactory.WaitForSession(_view.GetDocumentFullPath());
                editingSession.ConflictDataChanged += editingSession_ConflictDataChanged;
            }
        }