コード例 #1
0
ファイル: TextCaretLayer.cs プロジェクト: pashav15/pashav
 public TextCaretLayer(TextCaret textCaret, IAdornmentLayer layer, IClassificationFormatMap classificationFormatMap)
 {
     if (textCaret == null)
     {
         throw new ArgumentNullException(nameof(textCaret));
     }
     if (layer == null)
     {
         throw new ArgumentNullException(nameof(layer));
     }
     if (classificationFormatMap == null)
     {
         throw new ArgumentNullException(nameof(classificationFormatMap));
     }
     this.textCaret = textCaret;
     this.layer     = layer;
     this.classificationFormatMap = classificationFormatMap;
     caretGeometry = new CaretGeometry();
     layer.TextView.LayoutChanged += TextView_LayoutChanged;
     layer.TextView.Selection.SelectionChanged += Selection_SelectionChanged;
     layer.TextView.VisualElement.AddHandler(GotKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(VisualElement_GotKeyboardFocus), true);
     layer.TextView.VisualElement.AddHandler(LostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(VisualElement_LostKeyboardFocus), true);
     layer.TextView.VisualElement.IsVisibleChanged += VisualElement_IsVisibleChanged;
     classificationFormatMap.ClassificationFormatMappingChanged += ClassificationFormatMap_ClassificationFormatMappingChanged;
     AddAdornment();
 }
コード例 #2
0
ファイル: WpfTextView.cs プロジェクト: dandanyouxiang/dnSpy
        public void Close()
        {
            if (IsClosed)
            {
                throw new InvalidOperationException();
            }
            mouseHoverHelper.OnClosed();
            StopRefreshTimer();
            RegisteredCommandElement.Unregister();
            TextViewModel.Dispose();
            IsClosed = true;
            Closed?.Invoke(this, EventArgs.Empty);
            (aggregateClassifier as IDisposable)?.Dispose();
            TextCaret.Dispose();
            Selection.Dispose();
            (FormattedLineSource as IDisposable)?.Dispose();
            physicalLineCache.Dispose();
            textLayer.Dispose();
            foreach (var physLine in visiblePhysicalLines)
            {
                physLine.Dispose();
            }
            visiblePhysicalLines.Clear();
            (__lineTransformProvider as IDisposable)?.Dispose();

            Loaded -= WpfTextView_Loaded;
            Options.OptionChanged         -= EditorOptions_OptionChanged;
            TextBuffer.ChangedLowPriority -= TextBuffer_ChangedLowPriority;
            TextViewModel.DataModel.ContentTypeChanged -= DataModel_ContentTypeChanged;
            aggregateClassifier.ClassificationChanged  -= AggregateClassifier_ClassificationChanged;
            textAndAdornmentSequencer.SequenceChanged  -= TextAndAdornmentSequencer_SequenceChanged;
            classificationFormatMap.ClassificationFormatMappingChanged -= ClassificationFormatMap_ClassificationFormatMappingChanged;
            editorFormatMap.FormatMappingChanged -= EditorFormatMap_FormatMappingChanged;
            if (metroWindow != null)
            {
                metroWindow.WindowDPIChanged -= MetroWindow_WindowDPIChanged;
            }
        }
コード例 #3
0
ファイル: WpfTextView.cs プロジェクト: dandanyouxiang/dnSpy
#pragma warning restore 0169

        public WpfTextView(ITextViewModel textViewModel, ITextViewRoleSet roles, IEditorOptions parentOptions, IEditorOptionsFactoryService editorOptionsFactoryService, ICommandManager commandManager, ISmartIndentationService smartIndentationService, IFormattedTextSourceFactoryService formattedTextSourceFactoryService, IViewClassifierAggregatorService viewClassifierAggregatorService, ITextAndAdornmentSequencerFactoryService textAndAdornmentSequencerFactoryService, IClassificationFormatMapService classificationFormatMapService, IEditorFormatMapService editorFormatMapService, IAdornmentLayerDefinitionService adornmentLayerDefinitionService, ILineTransformProviderService lineTransformProviderService, Lazy <IWpfTextViewCreationListener, IDeferrableContentTypeAndTextViewRoleMetadata>[] wpfTextViewCreationListeners)
        {
            if (textViewModel == null)
            {
                throw new ArgumentNullException(nameof(textViewModel));
            }
            if (roles == null)
            {
                throw new ArgumentNullException(nameof(roles));
            }
            if (parentOptions == null)
            {
                throw new ArgumentNullException(nameof(parentOptions));
            }
            if (editorOptionsFactoryService == null)
            {
                throw new ArgumentNullException(nameof(editorOptionsFactoryService));
            }
            if (commandManager == null)
            {
                throw new ArgumentNullException(nameof(commandManager));
            }
            if (smartIndentationService == null)
            {
                throw new ArgumentNullException(nameof(smartIndentationService));
            }
            if (formattedTextSourceFactoryService == null)
            {
                throw new ArgumentNullException(nameof(formattedTextSourceFactoryService));
            }
            if (viewClassifierAggregatorService == null)
            {
                throw new ArgumentNullException(nameof(viewClassifierAggregatorService));
            }
            if (textAndAdornmentSequencerFactoryService == null)
            {
                throw new ArgumentNullException(nameof(textAndAdornmentSequencerFactoryService));
            }
            if (classificationFormatMapService == null)
            {
                throw new ArgumentNullException(nameof(classificationFormatMapService));
            }
            if (editorFormatMapService == null)
            {
                throw new ArgumentNullException(nameof(editorFormatMapService));
            }
            if (adornmentLayerDefinitionService == null)
            {
                throw new ArgumentNullException(nameof(adornmentLayerDefinitionService));
            }
            if (lineTransformProviderService == null)
            {
                throw new ArgumentNullException(nameof(lineTransformProviderService));
            }
            if (wpfTextViewCreationListeners == null)
            {
                throw new ArgumentNullException(nameof(wpfTextViewCreationListeners));
            }
            this.mouseHoverHelper     = new MouseHoverHelper(this);
            this.physicalLineCache    = new PhysicalLineCache(32);
            this.visiblePhysicalLines = new List <PhysicalLine>();
            this.invalidatedRegions   = new List <SnapshotSpan>();
            this.formattedTextSourceFactoryService = formattedTextSourceFactoryService;
            this.zoomLevel = ZoomConstants.DefaultZoom;
            this.adornmentLayerDefinitionService  = adornmentLayerDefinitionService;
            this.lineTransformProviderService     = lineTransformProviderService;
            this.wpfTextViewCreationListeners     = wpfTextViewCreationListeners.Where(a => roles.ContainsAny(a.Metadata.TextViewRoles)).ToArray();
            this.recreateLineTransformProvider    = true;
            this.normalAdornmentLayerCollection   = new AdornmentLayerCollection(this, LayerKind.Normal);
            this.overlayAdornmentLayerCollection  = new AdornmentLayerCollection(this, LayerKind.Overlay);
            this.underlayAdornmentLayerCollection = new AdornmentLayerCollection(this, LayerKind.Underlay);
            Properties                     = new PropertyCollection();
            TextViewModel                  = textViewModel;
            Roles                          = roles;
            Options                        = editorOptionsFactoryService.GetOptions(this);
            Options.Parent                 = parentOptions;
            ViewScroller                   = new ViewScroller(this);
            hasKeyboardFocus               = this.IsKeyboardFocusWithin;
            oldViewState                   = new ViewState(this);
            this.aggregateClassifier       = viewClassifierAggregatorService.GetClassifier(this);
            this.textAndAdornmentSequencer = textAndAdornmentSequencerFactoryService.Create(this);
            this.classificationFormatMap   = classificationFormatMapService.GetClassificationFormatMap(this);
            this.editorFormatMap           = editorFormatMapService.GetEditorFormatMap(this);

            this.textLayer = new TextLayer(GetAdornmentLayer(PredefinedAdornmentLayers.Text));
            Selection      = new TextSelection(this, GetAdornmentLayer(PredefinedAdornmentLayers.Selection), editorFormatMap);
            TextCaret      = new TextCaret(this, GetAdornmentLayer(PredefinedAdornmentLayers.Caret), smartIndentationService, classificationFormatMap);

            Children.Add(underlayAdornmentLayerCollection);
            Children.Add(normalAdornmentLayerCollection);
            Children.Add(overlayAdornmentLayerCollection);
            this.Cursor           = Cursors.IBeam;
            this.Focusable        = true;
            this.FocusVisualStyle = null;
            InitializeOptions();

            Options.OptionChanged         += EditorOptions_OptionChanged;
            TextBuffer.ChangedLowPriority += TextBuffer_ChangedLowPriority;
            TextViewModel.DataModel.ContentTypeChanged += DataModel_ContentTypeChanged;
            aggregateClassifier.ClassificationChanged  += AggregateClassifier_ClassificationChanged;
            textAndAdornmentSequencer.SequenceChanged  += TextAndAdornmentSequencer_SequenceChanged;
            classificationFormatMap.ClassificationFormatMappingChanged += ClassificationFormatMap_ClassificationFormatMappingChanged;
            editorFormatMap.FormatMappingChanged += EditorFormatMap_FormatMappingChanged;

            UpdateBackground();
            CreateFormattedLineSource(ViewportWidth);
            InitializeZoom();
            UpdateRemoveExtraTextLineVerticalPixels();

            if (Roles.Contains(PredefinedTextViewRoles.Interactive))
            {
                RegisteredCommandElement = commandManager.Register(VisualElement, this);
            }
            else
            {
                RegisteredCommandElement = NullRegisteredCommandElement.Instance;
            }

            NotifyTextViewCreated(TextViewModel.DataModel.ContentType, null);
        }
コード例 #4
0
ファイル: TextCaretLayer.cs プロジェクト: manojdjoshi/dnSpy
		public TextCaretLayer(TextCaret textCaret, IAdornmentLayer layer, IClassificationFormatMap classificationFormatMap) {
			if (textCaret == null)
				throw new ArgumentNullException(nameof(textCaret));
			if (layer == null)
				throw new ArgumentNullException(nameof(layer));
			if (classificationFormatMap == null)
				throw new ArgumentNullException(nameof(classificationFormatMap));
			this.textCaret = textCaret;
			this.layer = layer;
			this.classificationFormatMap = classificationFormatMap;
			caretGeometry = new CaretGeometry();
			layer.TextView.LayoutChanged += TextView_LayoutChanged;
			layer.TextView.Selection.SelectionChanged += Selection_SelectionChanged;
			layer.TextView.VisualElement.AddHandler(GotKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(VisualElement_GotKeyboardFocus), true);
			layer.TextView.VisualElement.AddHandler(LostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(VisualElement_LostKeyboardFocus), true);
			layer.TextView.VisualElement.IsVisibleChanged += VisualElement_IsVisibleChanged;
			classificationFormatMap.ClassificationFormatMappingChanged += ClassificationFormatMap_ClassificationFormatMappingChanged;
			AddAdornment();
		}
コード例 #5
0
ファイル: WpfTextView.cs プロジェクト: manojdjoshi/dnSpy
#pragma warning restore 0169

		public WpfTextView(ITextViewModel textViewModel, ITextViewRoleSet roles, IEditorOptions parentOptions, IEditorOptionsFactoryService editorOptionsFactoryService, ICommandService commandService, ISmartIndentationService smartIndentationService, IFormattedTextSourceFactoryService formattedTextSourceFactoryService, IViewClassifierAggregatorService viewClassifierAggregatorService, ITextAndAdornmentSequencerFactoryService textAndAdornmentSequencerFactoryService, IClassificationFormatMapService classificationFormatMapService, IEditorFormatMapService editorFormatMapService, IAdornmentLayerDefinitionService adornmentLayerDefinitionService, ILineTransformProviderService lineTransformProviderService, ISpaceReservationStackProvider spaceReservationStackProvider, IWpfTextViewConnectionListenerServiceProvider wpfTextViewConnectionListenerServiceProvider, IBufferGraphFactoryService bufferGraphFactoryService, Lazy<IWpfTextViewCreationListener, IDeferrableContentTypeAndTextViewRoleMetadata>[] wpfTextViewCreationListeners) {
			if (textViewModel == null)
				throw new ArgumentNullException(nameof(textViewModel));
			if (roles == null)
				throw new ArgumentNullException(nameof(roles));
			if (parentOptions == null)
				throw new ArgumentNullException(nameof(parentOptions));
			if (editorOptionsFactoryService == null)
				throw new ArgumentNullException(nameof(editorOptionsFactoryService));
			if (commandService == null)
				throw new ArgumentNullException(nameof(commandService));
			if (smartIndentationService == null)
				throw new ArgumentNullException(nameof(smartIndentationService));
			if (formattedTextSourceFactoryService == null)
				throw new ArgumentNullException(nameof(formattedTextSourceFactoryService));
			if (viewClassifierAggregatorService == null)
				throw new ArgumentNullException(nameof(viewClassifierAggregatorService));
			if (textAndAdornmentSequencerFactoryService == null)
				throw new ArgumentNullException(nameof(textAndAdornmentSequencerFactoryService));
			if (classificationFormatMapService == null)
				throw new ArgumentNullException(nameof(classificationFormatMapService));
			if (editorFormatMapService == null)
				throw new ArgumentNullException(nameof(editorFormatMapService));
			if (adornmentLayerDefinitionService == null)
				throw new ArgumentNullException(nameof(adornmentLayerDefinitionService));
			if (lineTransformProviderService == null)
				throw new ArgumentNullException(nameof(lineTransformProviderService));
			if (spaceReservationStackProvider == null)
				throw new ArgumentNullException(nameof(spaceReservationStackProvider));
			if (wpfTextViewCreationListeners == null)
				throw new ArgumentNullException(nameof(wpfTextViewCreationListeners));
			if (wpfTextViewConnectionListenerServiceProvider == null)
				throw new ArgumentNullException(nameof(wpfTextViewConnectionListenerServiceProvider));
			if (bufferGraphFactoryService == null)
				throw new ArgumentNullException(nameof(bufferGraphFactoryService));
			mouseHoverHelper = new MouseHoverHelper(this);
			physicalLineCache = new PhysicalLineCache(32);
			visiblePhysicalLines = new List<PhysicalLine>();
			invalidatedRegions = new List<SnapshotSpan>();
			this.formattedTextSourceFactoryService = formattedTextSourceFactoryService;
			zoomLevel = ZoomConstants.DefaultZoom;
			DsImage.SetZoom(VisualElement, zoomLevel / 100);
			this.adornmentLayerDefinitionService = adornmentLayerDefinitionService;
			this.lineTransformProviderService = lineTransformProviderService;
			this.wpfTextViewCreationListeners = wpfTextViewCreationListeners.Where(a => roles.ContainsAny(a.Metadata.TextViewRoles)).ToArray();
			recreateLineTransformProvider = true;
			normalAdornmentLayerCollection = new AdornmentLayerCollection(this, LayerKind.Normal);
			overlayAdornmentLayerCollection = new AdornmentLayerCollection(this, LayerKind.Overlay);
			underlayAdornmentLayerCollection = new AdornmentLayerCollection(this, LayerKind.Underlay);
			IsVisibleChanged += WpfTextView_IsVisibleChanged;
			Properties = new PropertyCollection();
			TextViewModel = textViewModel;
			BufferGraph = bufferGraphFactoryService.CreateBufferGraph(TextViewModel.VisualBuffer);
			Roles = roles;
			Options = editorOptionsFactoryService.GetOptions(this);
			Options.Parent = parentOptions;
			ViewScroller = new ViewScroller(this);
			hasKeyboardFocus = IsKeyboardFocusWithin;
			oldViewState = new ViewState(this);
			aggregateClassifier = viewClassifierAggregatorService.GetClassifier(this);
			textAndAdornmentSequencer = textAndAdornmentSequencerFactoryService.Create(this);
			classificationFormatMap = classificationFormatMapService.GetClassificationFormatMap(this);
			editorFormatMap = editorFormatMapService.GetEditorFormatMap(this);
			spaceReservationStack = spaceReservationStackProvider.Create(this);

			textLayer = new TextLayer(GetAdornmentLayer(PredefinedAdornmentLayers.Text));
			Selection = new TextSelection(this, GetAdornmentLayer(PredefinedAdornmentLayers.Selection), editorFormatMap);
			TextCaret = new TextCaret(this, GetAdornmentLayer(PredefinedAdornmentLayers.Caret), smartIndentationService, classificationFormatMap);

			Children.Add(underlayAdornmentLayerCollection);
			Children.Add(normalAdornmentLayerCollection);
			Children.Add(overlayAdornmentLayerCollection);
			Cursor = Cursors.IBeam;
			Focusable = true;
			FocusVisualStyle = null;
			InitializeOptions();

			Options.OptionChanged += EditorOptions_OptionChanged;
			TextBuffer.ChangedLowPriority += TextBuffer_ChangedLowPriority;
			TextViewModel.DataModel.ContentTypeChanged += DataModel_ContentTypeChanged;
			aggregateClassifier.ClassificationChanged += AggregateClassifier_ClassificationChanged;
			textAndAdornmentSequencer.SequenceChanged += TextAndAdornmentSequencer_SequenceChanged;
			classificationFormatMap.ClassificationFormatMappingChanged += ClassificationFormatMap_ClassificationFormatMappingChanged;
			editorFormatMap.FormatMappingChanged += EditorFormatMap_FormatMappingChanged;
			spaceReservationStack.GotAggregateFocus += SpaceReservationStack_GotAggregateFocus;
			spaceReservationStack.LostAggregateFocus += SpaceReservationStack_LostAggregateFocus;

			UpdateBackground();
			CreateFormattedLineSource(ViewportWidth);
			InitializeZoom();
			UpdateRemoveExtraTextLineVerticalPixels();

			if (Roles.Contains(PredefinedTextViewRoles.Interactive))
				RegisteredCommandElement = commandService.Register(VisualElement, this);
			else
				RegisteredCommandElement = NullRegisteredCommandElement.Instance;

			wpfTextViewConnectionListenerServiceProvider.Create(this);
			NotifyTextViewCreated(TextViewModel.DataModel.ContentType, null);
		}