Beispiel #1
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,
            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;
            var view = factory.Create <ITextView>();

            view.SetupGet(x => x.Caret).Returns(caret);
            view.SetupGet(x => x.Selection).Returns(selection);
            view.SetupGet(x => x.TextBuffer).Returns(textBuffer);
            view.SetupGet(x => x.TextSnapshot).Returns(() => textBuffer.CurrentSnapshot);
            view.SetupGet(x => x.Properties).Returns(propertyCollection);
            view.SetupGet(x => x.Roles).Returns(textViewRoleSet);
            view.SetupGet(x => x.Options).Returns(editorOptions);
            view.SetupGet(x => x.BufferGraph).Returns(bufferGraph);
            view.SetupGet(x => x.TextViewModel).Returns(textViewModel);
            return(view);
        }
Beispiel #2
0
        /// <summary>
        /// Text View constructor.
        /// </summary>
        /// <param name="textViewModel">The text view model that provides the text to visualize.</param>
        /// <param name="roles">Roles for this view.</param>
        /// <param name="parentOptions">Parent options for this view.</param>
        /// <param name="factoryService">Our handy text editor factory service.</param>
        internal TextView(TextEditor textEditor, ITextViewModel textViewModel, ITextViewRoleSet roles, IEditorOptions parentOptions, TextEditorFactoryService factoryService, bool initialize = true)
        {
            _textEditor = textEditor;

            _roles = roles;

            _factoryService = factoryService;

            this.TextDataModel = textViewModel.DataModel;
            this.TextViewModel = textViewModel;

            _textBuffer = textViewModel.EditBuffer;
            //			_visualBuffer = textViewModel.VisualBuffer;

            //			_textSnapshot = _textBuffer.CurrentSnapshot;
            //			_visualSnapshot = _visualBuffer.CurrentSnapshot;

            _editorOptions        = _factoryService.EditorOptionsFactoryService.GetOptions(this);
            _editorOptions.Parent = parentOptions;

            if (initialize)
            {
                this.Initialize();
            }
        }
Beispiel #3
0
 private void deleteButtonTab_Click(object sender, EventArgs e) //deletes texts from the system in tab1
 {
     if (fileListViewTab1.SelectedItems.Count > 0)
     {
         ListViewItem item     = fileListViewTab1.SelectedItems[0];
         string       textName = item.SubItems[1].Text;
         if (_activeItemNames.Contains(textName))
         {
             _activeItemNames.Remove(textName);
         }
         ITextViewModel model = _textController.GetTextByName(textName);
         //List<IGroupViewModel> groupList = _groupController.GetAllGroups();
         //foreach (IGroupViewModel groupEntry in groupList)
         //{
         //    if (_groupController.Contains(groupEntry.GetName(), textName))
         //    {
         //        _groupController.RemoveItemFromGroup(groupEntry, _textController.GetTextByName(textName));
         //    }
         //}
         _textController.DeleteText(model.GetName());
         updateListViews();
         updateAnalysisGroups();
         groupComboBox_SelectedIndexChanged(sender, e);
     }
     else
     {
         string errorMessage = "You need to select an item to delete it first";
         var    form2        = new ErrorMessageDisplay(errorMessage);
         form2.Show(this);
     }
 }
        public ITextView CreateTextView(MonoDevelop.Ide.Editor.TextEditor textEditor)
        {
            if (textEditor == null)
            {
                throw new ArgumentNullException("textEditor");
            }

            var roles = _defaultRoles;

            ITextBuffer    textBuffer = textEditor.GetContent <Mono.TextEditor.ITextEditorDataProvider>().GetTextEditorData().Document.TextBuffer;
            ITextDataModel dataModel  = new VacuousTextDataModel(textBuffer);

            var providers = TextViewModelProviders
                            .Where(t => allowedTextViewModelProviders.Contains(t.Value.ToString()))
                            .ToArray();

            ITextViewModel viewModel = UIExtensionSelector.InvokeBestMatchingFactory
                                           (providers,
                                           dataModel.ContentType,
                                           roles,
                                           (provider) => (provider.CreateTextViewModel(dataModel, roles)),
                                           ContentTypeRegistryService,
                                           this.GuardedOperations,
                                           this) ?? new VacuousTextViewModel(dataModel);

            var view = ((MonoDevelop.SourceEditor.SourceEditorView)textEditor.Implementation).TextEditor;

            view.Initialize(viewModel, roles, this.EditorOptionsFactoryService.GlobalOptions, this);
            view.Properties.AddProperty(typeof(MonoDevelop.Ide.Editor.TextEditor), textEditor);

            this.TextViewCreated?.Invoke(this, new TextViewCreatedEventArgs(view));

            return(view);
        }
Beispiel #5
0
        /// <summary>
        /// Text View constructor.
        /// </summary>
        /// <param name="textViewModel">The text view model that provides the text to visualize.</param>
        /// <param name="roles">Roles for this view.</param>
        /// <param name="parentOptions">Parent options for this view.</param>
        /// <param name="factoryService">Our handy text editor factory service.</param>
        internal void Initialize(ITextViewModel textViewModel, ITextViewRoleSet roles, IEditorOptions parentOptions, TextEditorFactoryService factoryService, bool initialize = true)
        {
            this.roles = roles;

            this.factoryService    = factoryService;
            GuardedOperations      = this.factoryService.GuardedOperations;
            _spaceReservationStack = new SpaceReservationStack(this.factoryService.OrderedSpaceReservationManagerDefinitions, this);

            this.TextDataModel = textViewModel.DataModel;
            this.TextViewModel = textViewModel;

            textBuffer = textViewModel.EditBuffer;
            //			_visualBuffer = textViewModel.VisualBuffer;

            //			_textSnapshot = _textBuffer.CurrentSnapshot;
            //			_visualSnapshot = _visualBuffer.CurrentSnapshot;

            editorOptions        = this.factoryService.EditorOptionsFactoryService.GetOptions(this);
            editorOptions.Parent = parentOptions;

            if (initialize)
            {
                this.Initialize();
            }
        }
        public IWpfTextView CreateTextView(MonoDevelop.Ide.Editor.TextEditor textEditor, ITextViewRoleSet roles = null, IEditorOptions parentOptions = null)
        {
            if (textEditor == null)
            {
                throw new ArgumentNullException("textEditor");
            }

            if (roles == null)
            {
                roles = _defaultRoles;
            }

            ITextBuffer    textBuffer = textEditor.GetContent <Mono.TextEditor.ITextEditorDataProvider>().GetTextEditorData().Document.TextBuffer;
            ITextDataModel dataModel  = new VacuousTextDataModel(textBuffer);

            ITextViewModel viewModel = UIExtensionSelector.InvokeBestMatchingFactory
                                           (TextViewModelProviders,
                                           dataModel.ContentType,
                                           roles,
                                           (provider) => (provider.CreateTextViewModel(dataModel, roles)),
                                           ContentTypeRegistryService,
                                           this.GuardedOperations,
                                           this) ?? new VacuousTextViewModel(dataModel);

            TextView view = new TextView(textEditor, viewModel, roles ?? this.DefaultRoles, parentOptions ?? this.EditorOptionsFactoryService.GlobalOptions, this);

            view.Properties.AddProperty(typeof(MonoDevelop.Ide.Editor.TextEditor), textEditor);

            this.TextViewCreated?.Invoke(this, new TextViewCreatedEventArgs(view));

            return(view);
        }
Beispiel #7
0
 public MainViewModel(
     ChannelFactoryService?channelFactory,
     DirectoryFactoryService?directoryFactory,
     ConfigCache?config,
     ITextViewModel?text)
 {
     _channelFactory   = channelFactory ?? throw new ArgumentNullException(nameof(channelFactory));
     _directoryFactory = directoryFactory ?? throw new ArgumentNullException(nameof(directoryFactory));
     _config           = config ?? throw new ArgumentNullException(nameof(config));
     Text = text ?? throw new ArgumentNullException(nameof(text));
     RegisterForConfigUpdates();
 }
Beispiel #8
0
        public FormPopUpFileEdit(ITextViewModel _model, ITextController textController, IGroupController groupController, Form1 _form1)
        {
            _textController  = textController;
            _groupController = groupController;
            form1            = _form1;
            model            = _model;

            InitializeComponent();

            quotesCheckbox.Checked  = model.GetIncludeQuotes();
            newAuthorTextBox.Text   = model.GetAuthor();
            newFileNameTextbox.Text = model.GetName();
        }
        IDnSpyWpfTextView CreateTextViewImpl(ITextViewModel textViewModel, ITextViewRoleSet roles, IEditorOptions parentOptions, TextViewCreatorOptions options, Func <IGuidObjectsProvider> createGuidObjectsProvider = null)
        {
            var guidObjectsProvider = new GuidObjectsProvider(options?.CreateGuidObjects, createGuidObjectsProvider?.Invoke());
            var wpfTextView         = new WpfTextView(textViewModel, roles, parentOptions, editorOptionsFactoryService, commandManager, smartIndentationService, formattedTextSourceFactoryService, viewClassifierAggregatorService, textAndAdornmentSequencerFactoryService, classificationFormatMapService, editorFormatMapService, adornmentLayerDefinitionService, lineTransformProviderService, spaceReservationStackProvider, wpfTextViewConnectionListenerServiceProvider, bufferGraphFactoryService, wpfTextViewCreationListeners);

            guidObjectsProvider.WpfTextView = wpfTextView;

            if (options?.MenuGuid != null)
            {
                menuManager.InitializeContextMenu(wpfTextView.VisualElement, options.MenuGuid.Value, guidObjectsProvider, new ContextMenuInitializer(wpfTextView));
            }

            TextViewCreated?.Invoke(this, new TextViewCreatedEventArgs(wpfTextView));

            return(wpfTextView);
        }
 public IDsWpfTextView CreateTextView(ITextViewModel viewModel, ITextViewRoleSet roles, IEditorOptions parentOptions, TextViewCreatorOptions?options)
 {
     if (viewModel is null)
     {
         throw new ArgumentNullException(nameof(viewModel));
     }
     if (roles is null)
     {
         throw new ArgumentNullException(nameof(roles));
     }
     if (parentOptions is null)
     {
         throw new ArgumentNullException(nameof(parentOptions));
     }
     return(CreateTextViewImpl(viewModel, roles, parentOptions, options));
 }
Beispiel #11
0
        private void saveButtonTab1_Click(object sender, EventArgs e)
        {
            try
            {
                StreamReader input = new StreamReader(fileLocationTextBox.Text);
                if (initialAuthorTextBox.Text == "Name of Author")
                {
                    initialAuthorTextBox.Text = "";
                }

                _textController.CreateText(initialFileNameTextBox.Text, input, UniversalConstants.CountSize, initialAuthorTextBox.Text); //creates the text in the db
                ITextViewModel model = _textController.GetTextByName(initialFileNameTextBox.Text);
                updateTextListView(fileListViewTab1);
                initialFileNameTextBox.Text = "New File Name";
                initialAuthorTextBox.Text   = "Name of Author";
                fileLocationTextBox.Text    = "File location";
            }
            catch (System.IO.FileNotFoundException)
            {
                string errorMessage = "You need to select a valid .txt file";
                var    form2        = new ErrorMessageDisplay(errorMessage);
                form2.Show(this);
            }
            catch
            {
                if (initialFileNameTextBox.Text == "")
                {
                    string errorMessage = "You cannot add a text without a file name";
                    var    form2        = new ErrorMessageDisplay(errorMessage);
                    form2.Show(this);
                }
                else if (_textController.GetTextByName(initialFileNameTextBox.Text) != null)
                {
                    string errorMessage = "You cannot add a file with the same name as another file";
                    var    form2        = new ErrorMessageDisplay(errorMessage);
                    form2.Show(this);
                }
            }
            if (filesRadioButton.Checked == true)
            {
                updateTextListView(fileGroupListViewTab2);
            }
            if (filesRadioButtonTab3.Checked == true)
            {
                updateTextListView(fileGroupListViewTab3);
            }
        }
			public LayoutHelper(ILineTransformProvider lineTransformProvider, double newViewportTop, HashSet<ITextViewLine> oldVisibleLines, List<PhysicalLine> oldLines, IFormattedLineSource formattedLineSource, ITextViewModel textViewModel, ITextSnapshot visualSnapshot, ITextSnapshot editSnapshot) {
				this.lineTransformProvider = lineTransformProvider;
				requestedViewportTop = newViewportTop;
				this.oldLines = oldLines;
				this.formattedLineSource = formattedLineSource;
				this.textViewModel = textViewModel;
				this.visualSnapshot = visualSnapshot;
				toPhysicalLine = new Dictionary<IFormattedLine, PhysicalLine>();
				this.oldVisibleLines = oldVisibleLines;

				Debug.Assert(oldLines.All(a => a.BufferSpan.Snapshot == editSnapshot));
				foreach (var physLine in oldLines) {
					physLine.TranslateLinesTo(visualSnapshot, editSnapshot);
					foreach (var line in physLine.Lines)
						toPhysicalLine[line] = physLine;
				}
			}
Beispiel #13
0
 private void editButton_Click(object sender, EventArgs e)
 {
     if (fileListViewTab1.SelectedItems.Count > 0)   // opens a new window so that the user can edit the details of the selected text
     {
         ListViewItem   item     = fileListViewTab1.SelectedItems[0];
         string         textName = item.SubItems[1].Text;
         ITextViewModel model    = _textController.GetTextByName(textName);
         var            form     = new FormPopUpFileEdit(model, _textController, _groupController, this);
         form.Show(this);
     }
     else
     {
         string errorMessage = "You need to select an item to edit it first";
         var    form2        = new ErrorMessageDisplay(errorMessage);
         form2.Show(this);
     }
 }
        IDsWpfTextView CreateTextViewImpl(ITextViewModel textViewModel, ITextViewRoleSet roles, IEditorOptions parentOptions, TextViewCreatorOptions?options)
        {
            var wpfTextView = new WpfTextView(textViewModel, roles, parentOptions, editorOptionsFactoryService, commandService, smartIndentationService, formattedTextSourceFactoryService, viewClassifierAggregatorService, textAndAdornmentSequencerFactoryService, classificationFormatMapService, editorFormatMapService, adornmentLayerDefinitionService, lineTransformProviderService, spaceReservationStackProvider, wpfTextViewConnectionListenerServiceProvider, bufferGraphFactoryService, wpfTextViewCreationListeners, textViewCreationListeners);

            if (!(options?.MenuGuid is null))
            {
                var guidObjectsProvider = new GuidObjectsProvider(wpfTextView, options.CreateGuidObjects);
                menuService.InitializeContextMenu(wpfTextView.VisualElement, options.MenuGuid.Value, guidObjectsProvider, new ContextMenuInitializer(wpfTextView));
            }

            if (options?.EnableUndoHistory != false)
            {
                textViewUndoManagerProvider.Value.GetTextViewUndoManager(wpfTextView);
            }

            TextViewCreated?.Invoke(this, new TextViewCreatedEventArgs(wpfTextView));

            return(wpfTextView);
        }
            public LayoutHelper(ILineTransformProvider lineTransformProvider, double newViewportTop, HashSet <ITextViewLine> oldVisibleLines, List <PhysicalLine> oldLines, IFormattedLineSource formattedLineSource, ITextViewModel textViewModel, ITextSnapshot visualSnapshot, ITextSnapshot editSnapshot)
            {
                this.lineTransformProvider = lineTransformProvider;
                requestedViewportTop       = newViewportTop;
                this.oldLines            = oldLines;
                this.formattedLineSource = formattedLineSource;
                this.textViewModel       = textViewModel;
                this.visualSnapshot      = visualSnapshot;
                toPhysicalLine           = new Dictionary <IFormattedLine, PhysicalLine>();
                this.oldVisibleLines     = oldVisibleLines;

                Debug.Assert(oldLines.All(a => a.BufferSpan.Snapshot == editSnapshot));
                foreach (var physLine in oldLines)
                {
                    physLine.TranslateLinesTo(visualSnapshot, editSnapshot);
                    foreach (var line in physLine.Lines)
                    {
                        toPhysicalLine[line] = physLine;
                    }
                }
            }
Beispiel #16
0
        private void UpdateAdornmentsWorker()
        {
            //var analysisLines = Analysis.Lines;
            //if (Analysis.Snapshot != View.TextSnapshot) {
            //    var task = Analysis.Update();
            //    if (task != null) {
            //        UpdateAdornments(task);
            //    }
            //    return;
            //} else if (analysisLines == null) {
            //    UpdateAdornments(Analysis.Reset());
            //    return;
            //}

            if (!GlobalVisible)
            {
                Canvas.Visibility = Visibility.Collapsed;
                return;
            }

            Canvas.Visibility = Visibility.Visible;

            ITextSnapshot  snapshot  = View.TextSnapshot;
            ITextViewModel viewModel = View.TextViewModel;

            if (snapshot == null || viewModel == null)
            {
                return;
            }

            ITextViewLine firstVisibleLine = View.TextViewLines.FirstOrDefault(line => line.IsFirstTextViewLineForSnapshotLine);

            if (firstVisibleLine == null)
            {
                return;
            }
            ITextViewLine lastVisibleLine = View.TextViewLines.LastOrDefault(line => line.IsLastTextViewLineForSnapshotLine);

            if (lastVisibleLine == null)
            {
                return;
            }

            IEnumerable <LineSpan> analysisLines = Analysis.GetLines(
                firstVisibleLine.Start.GetContainingLine().LineNumber,
                lastVisibleLine.Start.GetContainingLine().LineNumber
                );

            if (!analysisLines.Any())
            {
                return;
            }


#if PERFORMANCE
            object cookie = null;
            try {
                PerformanceLogger.Start(ref cookie);
                UpdateAdornments_Performance(
                    snapshot,
                    viewModel,
                    firstVisibleLine,
                    analysisLines
                    );
            } catch (OperationCanceledException) {
                PerformanceLogger.Mark("Cancel");
                throw;
            } finally {
                PerformanceLogger.End(cookie);
            }
        }
		void UpdateAdornments_Performance(
			ITextSnapshot snapshot,
			ITextViewModel viewModel,
			ITextViewLine firstVisibleLine,
			IEnumerable<LineSpan> analysisLines
		) {
#endif
			double spaceWidth = firstVisibleLine.VirtualSpaceWidth;
			if (spaceWidth <= 0.0) return;
			double horizontalOffset = firstVisibleLine.TextLeft;

			var unusedLines = new HashSet<LineSpan>(Lines.Keys);

			var caret = CaretHandlerBase.FromName(Theme.CaretHandler, View.Caret.Position.VirtualBufferPosition, Analysis.TabSize);

			object perfCookie = null;
			PerformanceLogger.Start(ref perfCookie);
#if DEBUG
			var initialCount = Lines.Count;
#endif
			foreach (var line in analysisLines.Concat(GetPageWidthLines()))
			{
				double top = View.ViewportTop;
				double bottom = View.ViewportBottom;
				double left = line.Indent * spaceWidth + horizontalOffset;

				Line adornment;
				unusedLines.Remove(line);

				if (line.Type == LineSpanType.PageWidthMarker)
				{
					line.Highlight = (Analysis.LongestLine > line.Indent);
					if (!Lines.TryGetValue(line, out adornment))
					{
						Lines[line] = adornment = CreateGuide(Canvas);
					}
					UpdateGuide(line, adornment, left, top, bottom);
					continue;
				}

				if (Lines.TryGetValue(line, out adornment))
				{
					adornment.Visibility = Visibility.Hidden;
				}

				caret.AddLine(line, willUpdateImmediately: true);

				if (line.FirstLine >= 0 && line.LastLine < int.MaxValue)
				{
					var firstLineNumber = line.FirstLine;
					var lastLineNumber = line.LastLine;
					ITextSnapshotLine firstLine, lastLine;
					try
					{
						firstLine = snapshot.GetLineFromLineNumber(firstLineNumber);
						lastLine = snapshot.GetLineFromLineNumber(lastLineNumber);
					}
					catch (Exception ex)
					{
						Trace.TraceError("In GetLineFromLineNumber:\n{0}", ex);
						continue;
					}

					if (firstLine.Start > View.TextViewLines.LastVisibleLine.Start ||
						lastLine.Start < View.TextViewLines.FirstVisibleLine.Start)
					{
						continue;
					}

					while (
						!viewModel.IsPointInVisualBuffer(firstLine.Start, PositionAffinity.Successor) &&
						++firstLineNumber < lastLineNumber
					)
					{
						try
						{
							firstLine = snapshot.GetLineFromLineNumber(firstLineNumber);
						}
						catch (Exception ex)
						{
							Trace.TraceError("In GetLineFromLineNumber:\n{0}", ex);
							firstLine = null;
							break;
						}
					}

					while (
						!viewModel.IsPointInVisualBuffer(lastLine.Start, PositionAffinity.Predecessor) &&
						--lastLineNumber > firstLineNumber
					)
					{
						try
						{
							lastLine = snapshot.GetLineFromLineNumber(lastLineNumber);
						}
						catch (Exception ex)
						{
							Trace.TraceError("In GetLineFromLineNumber:\n{0}", ex);
							lastLine = null;
							break;
						}
					}
					if (firstLine == null || lastLine == null || firstLineNumber > lastLineNumber)
					{
						continue;
					}


					IWpfTextViewLine firstView, lastView;
					try
					{
						firstView = View.GetTextViewLineContainingBufferPosition(firstLine.Start);
						lastView = View.GetTextViewLineContainingBufferPosition(lastLine.End);
					}
					catch (Exception ex)
					{
						Trace.TraceError("UpdateAdornments GetTextViewLineContainingBufferPosition failed\n{0}", ex);
						continue;
					}

					string extentText;
					if (!string.IsNullOrWhiteSpace((extentText = firstView.Extent.GetText())) &&
						line.Indent > extentText.LeadingWhitespace(Analysis.TabSize)
					)
					{
						continue;
					}

					if (firstView.VisibilityState != VisibilityState.Unattached)
					{
						top = firstView.Top;
					}
					if (lastView.VisibilityState != VisibilityState.Unattached)
					{
						bottom = lastView.Bottom;
					}
				}

				if (!Lines.TryGetValue(line, out adornment))
				{
					Lines[line] = adornment = CreateGuide(Canvas);
				}
				UpdateGuide(line, adornment, left, top, bottom);
			}

			PerformanceLogger.End(perfCookie);
#if DEBUG
			Debug.WriteLine("Added {0} guides", Lines.Count - initialCount);
			Debug.WriteLine("Removed {0} guides", unusedLines.Count);
			Debug.WriteLine("{0} guides active", Lines.Count - unusedLines.Count);
			Debug.WriteLine("");
#endif

			foreach (var line in unusedLines)
			{
				Line adornment;
				if (Lines.TryGetValue(line, out adornment))
				{
					Canvas.Children.Remove(adornment);
					Lines.Remove(line);
				}
			}
			foreach (var line in caret.GetModified())
			{
				Line adornment;
				if (Lines.TryGetValue(line, out adornment))
				{
					UpdateGuide(line, adornment);
				}
			}
		}
		public IDsWpfTextView CreateTextView(ITextViewModel viewModel, ITextViewRoleSet roles, IEditorOptions parentOptions, TextViewCreatorOptions options) {
			if (viewModel == null)
				throw new ArgumentNullException(nameof(viewModel));
			if (roles == null)
				throw new ArgumentNullException(nameof(roles));
			if (parentOptions == null)
				throw new ArgumentNullException(nameof(parentOptions));
			return CreateTextViewImpl(viewModel, roles, parentOptions, options);
		}
 protected override ICocoaTextView CreateTextView(ITextViewModel viewModel, ITextViewRoleSet roles)
 => Imports.TextEditorFactoryService.CreateTextView(viewModel, roles, Imports.EditorOptionsFactoryService.GlobalOptions);
 public IWpfTextView CreateTextView(ITextViewModel viewModel, ITextViewRoleSet roles, IEditorOptions parentOptions) =>
 CreateTextView(viewModel, roles, parentOptions, null);
Beispiel #21
0
		static PhysicalLine CreatePhysicalLineNoCache(IFormattedLineSource formattedLineSource, ITextViewModel textViewModel, ITextSnapshot visualSnapshot, SnapshotPoint bufferPosition) {
			var visualPoint = textViewModel.GetNearestPointInVisualSnapshot(bufferPosition, visualSnapshot, PointTrackingMode.Positive);
			var lines = formattedLineSource.FormatLineInVisualBuffer(visualPoint.GetContainingLine());
			Debug.Assert(lines.Count > 0);
			return new PhysicalLine(bufferPosition.GetContainingLine(), lines);
		}
Beispiel #22
0
        void UpdateAdornments_Performance(
            ITextSnapshot snapshot,
            ITextViewModel viewModel,
            ITextViewLine firstVisibleLine,
            IEnumerable <LineSpan> analysisLines
            )
        {
#endif
            double spaceWidth = firstVisibleLine.VirtualSpaceWidth;
            if (spaceWidth <= 0.0)
            {
                return;
            }
            double horizontalOffset = firstVisibleLine.TextLeft;

            var unusedLines = new HashSet <LineSpan>(Lines.Keys);

            var caret = CaretHandlerBase.FromName(Theme.CaretHandler, View.Caret.Position.VirtualBufferPosition, Analysis.TabSize);

            object perfCookie = null;
            PerformanceLogger.Start(ref perfCookie);
#if DEBUG
            var initialCount = Lines.Count;
#endif
            foreach (var line in analysisLines.Concat(GetPageWidthLines()))
            {
                double top    = View.ViewportTop;
                double bottom = View.ViewportBottom;
                double left   = line.Indent * spaceWidth + horizontalOffset;

                Line adornment;
                unusedLines.Remove(line);

                if (line.Type == LineSpanType.PageWidthMarker)
                {
                    line.Highlight = (Analysis.LongestLine > line.Indent);
                    if (!Lines.TryGetValue(line, out adornment))
                    {
                        Lines[line] = adornment = CreateGuide(Canvas);
                    }
                    UpdateGuide(line, adornment, left, top, bottom);
                    continue;
                }

                if (Lines.TryGetValue(line, out adornment))
                {
                    adornment.Visibility = Visibility.Hidden;
                }

                caret.AddLine(line, willUpdateImmediately: true);

                if (line.FirstLine >= 0 && line.LastLine < int.MaxValue)
                {
                    var firstLineNumber = line.FirstLine;
                    var lastLineNumber = line.LastLine;
                    ITextSnapshotLine firstLine, lastLine;
                    try
                    {
                        firstLine = snapshot.GetLineFromLineNumber(firstLineNumber);
                        lastLine  = snapshot.GetLineFromLineNumber(lastLineNumber);
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("In GetLineFromLineNumber:\n{0}", ex);
                        continue;
                    }

                    if (firstLine.Start > View.TextViewLines.LastVisibleLine.Start ||
                        lastLine.Start < View.TextViewLines.FirstVisibleLine.Start)
                    {
                        continue;
                    }

                    while (
                        !viewModel.IsPointInVisualBuffer(firstLine.Start, PositionAffinity.Successor) &&
                        ++firstLineNumber < lastLineNumber
                        )
                    {
                        try
                        {
                            firstLine = snapshot.GetLineFromLineNumber(firstLineNumber);
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceError("In GetLineFromLineNumber:\n{0}", ex);
                            firstLine = null;
                            break;
                        }
                    }

                    while (
                        !viewModel.IsPointInVisualBuffer(lastLine.Start, PositionAffinity.Predecessor) &&
                        --lastLineNumber > firstLineNumber
                        )
                    {
                        try
                        {
                            lastLine = snapshot.GetLineFromLineNumber(lastLineNumber);
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceError("In GetLineFromLineNumber:\n{0}", ex);
                            lastLine = null;
                            break;
                        }
                    }
                    if (firstLine == null || lastLine == null || firstLineNumber > lastLineNumber)
                    {
                        continue;
                    }


                    IWpfTextViewLine firstView, lastView;
                    try
                    {
                        firstView = View.GetTextViewLineContainingBufferPosition(firstLine.Start);
                        lastView  = View.GetTextViewLineContainingBufferPosition(lastLine.End);
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("UpdateAdornments GetTextViewLineContainingBufferPosition failed\n{0}", ex);
                        continue;
                    }

                    string extentText;
                    if (!string.IsNullOrWhiteSpace((extentText = firstView.Extent.GetText())) &&
                        line.Indent > extentText.LeadingWhitespace(Analysis.TabSize)
                        )
                    {
                        continue;
                    }

                    if (firstView.VisibilityState != VisibilityState.Unattached)
                    {
                        top = firstView.Top;
                    }
                    if (lastView.VisibilityState != VisibilityState.Unattached)
                    {
                        bottom = lastView.Bottom;
                    }
                }

                if (!Lines.TryGetValue(line, out adornment))
                {
                    Lines[line] = adornment = CreateGuide(Canvas);
                }
                UpdateGuide(line, adornment, left, top, bottom);
            }

            PerformanceLogger.End(perfCookie);
#if DEBUG
            Debug.WriteLine("Added {0} guides", Lines.Count - initialCount);
            Debug.WriteLine("Removed {0} guides", unusedLines.Count);
            Debug.WriteLine("{0} guides active", Lines.Count - unusedLines.Count);
            Debug.WriteLine("");
#endif

            foreach (var line in unusedLines)
            {
                Line adornment;
                if (Lines.TryGetValue(line, out adornment))
                {
                    Canvas.Children.Remove(adornment);
                    Lines.Remove(line);
                }
            }
            foreach (var line in caret.GetModified())
            {
                Line adornment;
                if (Lines.TryGetValue(line, out adornment))
                {
                    UpdateGuide(line, adornment);
                }
            }
        }
Beispiel #23
0
#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);
        }
Beispiel #24
0
        static PhysicalLine CreatePhysicalLineNoCache(IFormattedLineSource formattedLineSource, ITextViewModel textViewModel, ITextSnapshot visualSnapshot, SnapshotPoint bufferPosition)
        {
            var visualPoint = textViewModel.GetNearestPointInVisualSnapshot(bufferPosition, visualSnapshot, PointTrackingMode.Positive);
            var lines       = formattedLineSource.FormatLineInVisualBuffer(visualPoint.GetContainingLine());

            Debug.Assert(lines.Count > 0);
            return(new PhysicalLine(bufferPosition.GetContainingLine(), lines));
        }
Beispiel #25
0
        public SkiaTextView(ITextViewModel textViewModel, ITextViewRoleSet roles, IEditorOptions parentOptions, TextEditorFactoryService factoryService, bool initialize = true) : this()
        {
            this._factoryService = factoryService;
            this.TextDataModel   = textViewModel.DataModel;
            this.TextViewModel   = textViewModel;

            _textBuffer   = textViewModel.EditBuffer;
            _visualBuffer = textViewModel.VisualBuffer;

            _textSnapshot   = _textBuffer.CurrentSnapshot;
            _visualSnapshot = _visualBuffer.CurrentSnapshot;

            classifiedPaints = new Dictionary <string, TextStyle> {
                [""] = new TextStyle(new SKPaint {
                    Color = SKColors.Black, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true
                }),
                ["comment"] = new TextStyle(new SKPaint {
                    Color = SKColors.Gray, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true
                }),
                ["keyword"] = new TextStyle(new SKPaint {
                    Color = SKColors.Blue, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true
                }),
                ["class name"] = new TextStyle(new SKPaint {
                    Color = SKColors.Yellow, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true
                }),
                ["identifier"] = new TextStyle(new SKPaint {
                    Color = SKColors.Orange, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true
                }),
                ["punctuation"] = new TextStyle(new SKPaint {
                    Color = SKColors.AliceBlue, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true
                }),
                ["operator"] = new TextStyle(new SKPaint {
                    Color = SKColors.AliceBlue, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true
                }),
                ["number"] = new TextStyle(new SKPaint {
                    Color = SKColors.Purple, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true
                }),
                ["string"] = new TextStyle(new SKPaint {
                    Color = SKColors.Brown, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true
                }),
                ["interface name"] = new TextStyle(new SKPaint {
                    Color = SKColors.GreenYellow, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true
                }),
                //[""] = new TextStyle(new SKPaint { Color = SKColors.Black, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true }),
                //[""] = new TextStyle(new SKPaint { Color = SKColors.Black, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true }),
                //[""] = new TextStyle(new SKPaint { Color = SKColors.Black, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true }),
                //[""] = new TextStyle(new SKPaint { Color = SKColors.Black, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true }),
                //[""] = new TextStyle(new SKPaint { Color = SKColors.Black, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true }),
                //[""] = new TextStyle(new SKPaint { Color = SKColors.Black, Typeface = this.Typeface, TextSize = FontSize, LcdRenderText = true, IsAntialias = true, SubpixelText = true }),
            };
            InitializeRendering();

            InitializeITextView();

            _editorOptions        = _factoryService.EditorOptionsFactoryService.GetOptions(this);
            _editorOptions.Parent = parentOptions;

            if (initialize)
            {
                Initialize();
            }
            else
            {
                throw new NotImplementedException();
            }
        }
		IDsWpfTextView CreateTextViewImpl(ITextViewModel textViewModel, ITextViewRoleSet roles, IEditorOptions parentOptions, TextViewCreatorOptions options) {
			var wpfTextView = new WpfTextView(textViewModel, roles, parentOptions, editorOptionsFactoryService, commandService, smartIndentationService, formattedTextSourceFactoryService, viewClassifierAggregatorService, textAndAdornmentSequencerFactoryService, classificationFormatMapService, editorFormatMapService, adornmentLayerDefinitionService, lineTransformProviderService, spaceReservationStackProvider, wpfTextViewConnectionListenerServiceProvider, bufferGraphFactoryService, wpfTextViewCreationListeners);

			if (options?.MenuGuid != null) {
				var guidObjectsProvider = new GuidObjectsProvider(wpfTextView, options?.CreateGuidObjects);
				menuService.InitializeContextMenu(wpfTextView.VisualElement, options.MenuGuid.Value, guidObjectsProvider, new ContextMenuInitializer(wpfTextView));
			}

			if (options?.EnableUndoHistory != false)
				textViewUndoManagerProvider.Value.GetTextViewUndoManager(wpfTextView);

			TextViewCreated?.Invoke(this, new TextViewCreatedEventArgs(wpfTextView));

			return wpfTextView;
		}
		public IWpfTextView CreateTextView(ITextViewModel viewModel, ITextViewRoleSet roles, IEditorOptions parentOptions) =>
			CreateTextView(viewModel, roles, parentOptions, null);
Beispiel #28
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,
     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;
     var view = factory.Create<ITextView>();
     view.SetupGet(x => x.Caret).Returns(caret);
     view.SetupGet(x => x.Selection).Returns(selection);
     view.SetupGet(x => x.TextBuffer).Returns(textBuffer);
     view.SetupGet(x => x.TextSnapshot).Returns(() => textBuffer.CurrentSnapshot);
     view.SetupGet(x => x.Properties).Returns(propertyCollection);
     view.SetupGet(x => x.Roles).Returns(textViewRoleSet);
     view.SetupGet(x => x.Options).Returns(editorOptions);
     view.SetupGet(x => x.BufferGraph).Returns(bufferGraph);
     view.SetupGet(x => x.TextViewModel).Returns(textViewModel);
     return view;
 }
Beispiel #29
0
#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);
		}
Beispiel #30
0
 protected abstract TView CreateTextView(ITextViewModel viewModel, ITextViewRoleSet roles);
        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();
        }