Beispiel #1
0
		public TextViewModel(ITextDataModel textDataModel, ITextBuffer editBuffer) {
			if (textDataModel == null)
				throw new ArgumentNullException(nameof(textDataModel));
			if (editBuffer == null)
				throw new ArgumentNullException(nameof(editBuffer));
			Properties = new PropertyCollection();
			DataModel = textDataModel;
			EditBuffer = editBuffer;
		}
Beispiel #2
0
 public static Mock<ITextView> CreateTextView(
     ITextBuffer textBuffer = null,
     ITextCaret caret = null,
     ITextSelection selection = null,
     ITextViewRoleSet textViewRoleSet = null,
     ITextViewModel textViewModel = null,
     IEditorOptions editorOptions = null,
     IBufferGraph bufferGraph = null,
     ITextDataModel textDataModel = null,
     PropertyCollection propertyCollection = null,
     MockRepository factory = null)
 {
     factory = factory ?? new MockRepository(MockBehavior.Strict);
     textBuffer = textBuffer ?? CreateTextBuffer(100, factory: factory).Object;
     caret = caret ?? CreateCaret(factory: factory).Object;
     selection = selection ?? CreateSelection(factory: factory).Object;
     propertyCollection = propertyCollection ?? new PropertyCollection();
     textViewRoleSet = textViewRoleSet ?? CreateTextViewRoleSet(factory: factory).Object;
     editorOptions = editorOptions ?? CreateEditorOptions(factory: factory).Object;
     bufferGraph = bufferGraph ?? CreateBufferGraph(factory: factory).Object;
     textViewModel = textViewModel ?? CreateTextViewModel(textBuffer: textBuffer, factory: factory).Object;
     textDataModel = textDataModel ?? CreateTextDataModel(textBuffer: textBuffer, factory: factory).Object;
     var textView = factory.Create<ITextView>();
     textView.SetupGet(x => x.Caret).Returns(caret);
     textView.SetupGet(x => x.Selection).Returns(selection);
     textView.SetupGet(x => x.TextBuffer).Returns(textBuffer);
     textView.SetupGet(x => x.TextSnapshot).Returns(() => textBuffer.CurrentSnapshot);
     textView.SetupGet(x => x.Properties).Returns(propertyCollection);
     textView.SetupGet(x => x.Roles).Returns(textViewRoleSet);
     textView.SetupGet(x => x.Options).Returns(editorOptions);
     textView.SetupGet(x => x.BufferGraph).Returns(bufferGraph);
     textView.SetupGet(x => x.TextViewModel).Returns(textViewModel);
     textView.SetupGet(x => x.TextDataModel).Returns(textDataModel);
     return textView;
 }
Beispiel #3
0
		public TextViewModel(ITextDataModel textDataModel)
			: this(textDataModel, textDataModel.DataBuffer) {
		}
Beispiel #4
0
 public TextViewModel(ITextDataModel textDataModel)
     : this(textDataModel, textDataModel.DataBuffer)
 {
 }
 public IWpfTextView CreateTextView(ITextDataModel dataModel, ITextViewRoleSet roles, IEditorOptions parentOptions) =>
 CreateTextView(dataModel, roles, parentOptions, null);
		public IDsWpfTextView CreateTextView(ITextDataModel dataModel, ITextViewRoleSet roles, IEditorOptions parentOptions, TextViewCreatorOptions options) {
			if (dataModel == null)
				throw new ArgumentNullException(nameof(dataModel));
			if (roles == null)
				throw new ArgumentNullException(nameof(roles));
			if (parentOptions == null)
				throw new ArgumentNullException(nameof(parentOptions));
			return CreateTextView(CreateTextViewModel(dataModel, roles), roles, parentOptions, options);
		}
		ITextViewModel CreateTextViewModel(ITextDataModel dataModel, ITextViewRoleSet roles) {
			if (providerSelector == null)
				providerSelector = new ProviderSelector<ITextViewModelProvider, IContentTypeAndTextViewRoleMetadata>(contentTypeRegistryService, textViewModelProviders);
			var contentType = dataModel.ContentType;
			foreach (var p in providerSelector.GetProviders(contentType)) {
				var model = p.Value.CreateTextViewModel(dataModel, roles);
				if (model != null)
					return model;
			}
			return new TextViewModel(dataModel);
		}
Beispiel #8
0
 public TextViewModel(ITextDataModel textDataModel, ITextBuffer editBuffer)
 {
     Properties = new PropertyCollection();
     DataModel  = textDataModel ?? throw new ArgumentNullException(nameof(textDataModel));
     EditBuffer = editBuffer ?? throw new ArgumentNullException(nameof(editBuffer));
 }
		public IWpfTextView CreateTextView(ITextDataModel dataModel, ITextViewRoleSet roles, IEditorOptions parentOptions) =>
			CreateTextView(dataModel, roles, parentOptions, null);
 public VacuousTextViewModel(ITextDataModel dataModel, ITextBuffer editBuffer)
 {
     this.dataModel  = dataModel;
     this.editBuffer = editBuffer;
     this.Properties = new PropertyCollection();
 }
Beispiel #11
0
 public VacuousTextViewModel(ITextBuffer buffer, ITextDataModel dataModel)
 {
     this.buffer     = buffer;
     this.dataModel  = dataModel;
     this.Properties = new PropertyCollection();
 }
 public VacuousTextViewModel(ITextDataModel dataModel) : this(dataModel, dataModel.DataBuffer)
 {
 }
 public ProjectionTextViewModel(ITextDataModel dataModel, IProjectionBuffer projectionBuffer)
 {
     this._dataModel = dataModel;
     this._projectionBuffer = projectionBuffer;
     this._properties = new PropertyCollection();
 }
 public ITextViewModel CreateTextViewModel(ITextDataModel dataModel, ITextViewRoleSet roles)
 {
     //Create a projection buffer based on the specified start and end position.
     var projectionBuffer = CreateProjectionBuffer(dataModel);
     //Display this projection buffer in the visual buffer, while still maintaining
     //the full file buffer as the underlying data buffer.
     var textViewModel = new ProjectionTextViewModel(dataModel, projectionBuffer);
     return textViewModel;
 }
        public IProjectionBuffer CreateProjectionBuffer(ITextDataModel dataModel)
        {
            //retrieve start and end position that we saved in MyToolWindow.CreateEditor()
            var startPosition = (int)dataModel.DataBuffer.Properties.GetProperty("StartPosition");
            var endPosition = (int)dataModel.DataBuffer.Properties.GetProperty("EndPosition");
            var length = endPosition - startPosition;

            //Take a snapshot of the text within these indices.
            var textSnapshot = dataModel.DataBuffer.CurrentSnapshot;
            var trackingSpan = textSnapshot.CreateTrackingSpan(startPosition, length, SpanTrackingMode.EdgeExclusive);

            //Create the actual projection buffer
            var projectionBuffer = ProjectionBufferFactory.CreateProjectionBuffer(
                null
                , new List<object>() { trackingSpan }
                , ProjectionBufferOptions.None
                );
            return projectionBuffer;
        }
        public BufferBar(ITextBuffer textBuffer, IWpfTextViewHost textViewHost, IEditorOperations editorOperations, ITextEditorFactoryService factory)
        {
            InitializeComponent();
            DataContext       = this;
            this.textBuffer   = textBuffer;
            this.projBuffer   = textBuffer as IProjectionBuffer;
            this.elBuffer     = textBuffer as IElisionBuffer;
            this.prevVersion  = textBuffer.CurrentSnapshot.Version;
            this.textView     = textViewHost.TextView;
            this.textViewHost = textViewHost;

            this.factory          = factory;
            this.editorOperations = editorOperations;
            this.snapshots.Add(new WeakReference(textBuffer.CurrentSnapshot));

            SolidColorBrush brush = new SolidColorBrush(textBuffer is IElisionBuffer ? Colors.LightBlue : (textBuffer is IProjectionBuffer ? Colors.LightGreen : Colors.LightGray));

            brush.Freeze();
            //Background = brush;

            ITextDataModel tdm = this.textView.TextDataModel;
            ITextViewModel tvm = this.textView.TextViewModel;

            StringBuilder tip = new StringBuilder();

            if (textBuffer == tdm.DocumentBuffer)
            {
                tip.Append("Document Buffer,");
            }
            if (textBuffer == tdm.DataBuffer)
            {
                tip.Append("Data Buffer,");
            }
            if (textBuffer == tvm.EditBuffer)
            {
                tip.Append("Edit Buffer,");
            }
            if (textBuffer == tvm.VisualBuffer)
            {
                tip.Append("Visual Buffer,");
            }
            if (tip.Length > 0)
            {
                tip.Remove(tip.Length - 1, 1);
                TipText = tip.ToString();
            }
            else
            {
                TipText = "Uncategorized Buffer";
            }

            if (this.projBuffer != null || this.elBuffer != null)
            {
                if (this.projBuffer != null)
                {
                    this.projBuffer.SourceSpansChanged += OnProjectionSourceSpansChanged;
                }
                else
                {
                    this.elBuffer.SourceSpansChanged += OnElisionSourceSpansChanged;
                }
            }
            else
            {
                this.SpansLabel.Visibility = Visibility.Collapsed;
            }

            if (this.textBuffer.Properties.TryGetProperty <ITextDocument>(typeof(ITextDocument), out this.document))
            {
                UpdateEncoding();
                this.document.EncodingChanged += OnEncodingChanged;
            }
            else
            {
                this.EncodingLabel.Visibility = Visibility.Collapsed;
            }

            this.textBuffer.ContentTypeChanged       += OnContentTypeChanged;
            this.textBuffer.Changed                  += OnTextChanged;
            this.textView.Caret.PositionChanged      += OnCaretPositionChanged;
            this.textView.Selection.SelectionChanged += OnSelectionChanged;

            this.SelectionLabel.Background  = Brushes.Transparent;
            this.SelectionLabel.BorderBrush = Brushes.Transparent;
            this.SelectionLabel.Padding     = new Thickness(3.0);
            this.SelectionCombo.Background  = Brushes.Transparent;
            this.SelectionCombo.BorderBrush = Brushes.Transparent;
            this.SelectionCombo.Padding     = new Thickness(3.0);
            this.SelectionPanel.Children.Add(this.SelectionLabel);
            this.selectionLabelInstalled = true;

            UpdateAll();
        }