Пример #1
0
        private ITextView CreateCSharpTextView(params string[] lines)
        {
            var contentType = GetOrCreateContentType(Constants.CSharpContentType, "code");
            var textBuffer  = CreateTextBuffer(contentType, lines);

            return(TextEditorFactoryService.CreateTextView(textBuffer));
        }
Пример #2
0
        /// <summary>
        /// Create a Visual Studio simulation with the specified set of lines
        /// </summary>
        private void CreateCore(bool simulateResharper, bool usePeekRole, params string[] lines)
        {
            if (usePeekRole)
            {
                _textBuffer = CreateTextBuffer(lines);
                _textView   = TextEditorFactoryService.CreateTextView(
                    _textBuffer,
                    TextEditorFactoryService.CreateTextViewRoleSet(PredefinedTextViewRoles.Document, PredefinedTextViewRoles.Editable, Constants.TextViewRoleEmbeddedPeekTextView));
            }
            else
            {
                _textView   = CreateTextView(lines);
                _textBuffer = _textView.TextBuffer;
            }
            _vimBuffer         = Vim.CreateVimBuffer(_textView);
            _bufferCoordinator = new VimBufferCoordinator(_vimBuffer);
            _vsSimulation      = new VsSimulation(
                _bufferCoordinator,
                simulateResharper: simulateResharper,
                simulateStandardKeyMappings: false,
                editorOperationsFactoryService: EditorOperationsFactoryService,
                keyUtil: KeyUtil);

            VimHost.TryCustomProcessFunc = (textView, insertCommand) =>
            {
                if (textView == _textView)
                {
                    return(_vsSimulation.VsCommandTarget.TryCustomProcess(insertCommand));
                }

                return(false);
            };
        }
Пример #3
0
 private ITextView CreateWithRoles(params string[] textViewRoles)
 {
     Create();
     return(TextEditorFactoryService.CreateTextView(
                CreateTextBuffer(),
                TextEditorFactoryService.CreateTextViewRoleSet(textViewRoles)));
 }
        protected CommandMarginControllerTest()
        {
            _factory       = new MockRepository(MockBehavior.Strict);
            _marginControl = new CommandMarginControl();
            _marginControl.CommandLineTextBox.Text = string.Empty;

            _search = _factory.Create <IIncrementalSearch>();
            _search.SetupGet(x => x.InSearch).Returns(false);
            _search.SetupGet(x => x.InPasteWait).Returns(false);
            _vimBuffer = new MockVimBuffer
            {
                IncrementalSearchImpl = _search.Object,
                VimImpl         = MockObjectFactory.CreateVim(factory: _factory).Object,
                CommandModeImpl = _factory.Create <ICommandMode>(MockBehavior.Loose).Object
            };
            var textBuffer = CreateTextBuffer(new[] { "" });

            _vimBuffer.TextViewImpl = TextEditorFactoryService.CreateTextView(textBuffer);

            _globalSettings = new Mock <IVimGlobalSettings>();
            _vimBuffer.GlobalSettingsImpl = _globalSettings.Object;

            var editorFormatMap = _factory.Create <IEditorFormatMap>(MockBehavior.Loose);

            editorFormatMap.Setup(x => x.GetProperties(It.IsAny <string>())).Returns(new ResourceDictionary());

            var parentVisualElement = _factory.Create <FrameworkElement>();

            _controller = new CommandMarginController(
                _vimBuffer,
                parentVisualElement.Object,
                _marginControl,
                VimEditorHost.EditorFormatMapService.GetEditorFormatMap(_vimBuffer.TextView),
                VimEditorHost.ClassificationFormatMapService.GetClassificationFormatMap(_vimBuffer.TextView));
        }
Пример #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.textArea.TextViewLines = new MdTextViewLineCollection(this);
            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();
            }
        }
Пример #6
0
 public VimRcTest()
 {
     _vim                = (Vim)Vim;
     _globalSettings     = Vim.GlobalSettings;
     _fileSystem         = new Mock <IFileSystem>();
     _originalFileSystem = _vim._fileSystem;
     _vim._fileSystem    = _fileSystem.Object;
     VimHost.CreateHiddenTextViewFunc = () => TextEditorFactoryService.CreateTextView();
 }
Пример #7
0
 public VimRcTest()
 {
     _vim            = (Vim)Vim;
     _globalSettings = Vim.GlobalSettings;
     _fileSystem     = new Mock <IFileSystem>();
     _fileSystem.Setup(x => x.GetVimRcDirectories()).Returns(new string[] { });
     _originalFileSystem = _vim.FileSystem;
     _vim.FileSystem     = _fileSystem.Object;
     VimHost.CreateHiddenTextViewFunc = () => TextEditorFactoryService.CreateTextView();
 }
Пример #8
0
        public void HostWontCreateVimBuffer()
        {
            var textView        = CreateTextView();
            var wpfTextViewHost = TextEditorFactoryService.CreateTextViewHost(textView, setFocus: false);

            IVimBuffer vimBuffer = null;

            _vim.Setup(x => x.TryGetOrCreateVimBufferForHost(textView, out vimBuffer)).Returns(false);
            Assert.Null(_commandMarginProvider.CreateMargin(wpfTextViewHost, _factory.Create <IWpfTextViewMargin>().Object));
        }
Пример #9
0
        private void CreateTextViewHost(string text, string filePath)
        {
            if (text == null)
            {
                text = string.Empty;
            }

            var diskBuffer = TextBufferFactoryService.CreateTextBuffer(text, ContentType);

            _editorIntance = EditorInstanceFactory.CreateEditorInstance(diskBuffer, _compositionService);

            ITextDataModel textDataModel;

            if (_editorIntance != null)
            {
                textDataModel = new TextDataModel(diskBuffer, _editorIntance.ViewBuffer);
            }
            else
            {
                textDataModel = new TextDataModel(diskBuffer, diskBuffer);
            }

            var textBuffer = textDataModel.DocumentBuffer;

            TextDocument = TextDocumentFactoryService.CreateTextDocument(textBuffer, filePath);

            SetGlobalEditorOptions();

            var textView = TextEditorFactoryService.CreateTextView(textDataModel,
                                                                   new DefaultTextViewRoleSet(),
                                                                   GlobalOptions);

            _wpftextViewHost = TextEditorFactoryService.CreateTextViewHost(textView, true);

            ApplyDefaultSettings();

            _contentControl.Content = _wpftextViewHost.HostControl;

            var baseController = new BaseController();

            BaseController = baseController;

            if (_editorIntance != null)
            {
                CommandTarget = _editorIntance.GetCommandTarget(textView);
                var controller = CommandTarget as Microsoft.Languages.Editor.Controller.Controller;
                controller.ChainedController = baseController;
            }
            else
            {
                CommandTarget = baseController;
            }

            baseController.Initialize(textView, EditorOperations, UndoManager, _coreShell);
        }
Пример #10
0
        protected void UpdateLayout(ITextView textView, int? tabStop = null)
        {
            if (tabStop.HasValue)
            {
                textView.Options.SetOptionValue(DefaultOptions.TabSizeOptionId, tabStop.Value);
            }

            // Need to force a layout here to get it to respect the tab settings
            var host = TextEditorFactoryService.CreateTextViewHost((IWpfTextView)textView, setFocus: false);
            host.HostControl.UpdateLayout();
        }
Пример #11
0
        /// <summary>
        /// Create the WPF text editor Control
        /// </summary>
        public SkiaTextViewHost(bool setFocus, bool initialize = true)
        {
            _factory  = (TextEditorFactoryService)PlatformCatalog.Instance.TextEditorFactoryService;
            _setFocus = setFocus;

            if (initialize)
            {
                // Initialize UI
                this.Initialize();
            }
        }
Пример #12
0
        /// <summary>
        /// Create the WPF text editor Control
        /// </summary>
        public SkiaTextViewHost(bool setFocus, ITextEditorFactoryService factory, bool initialize = true)
        {
            _factory  = (TextEditorFactoryService)factory;
            _setFocus = setFocus;

            if (initialize)
            {
                // Initialize UI
                this.Initialize();
            }
        }
Пример #13
0
        protected WpfTextViewDisplay CreateTextViewDisplay(IWpfTextView textView, bool setFocus = true, bool show = true)
        {
            var host    = TextEditorFactoryService.CreateTextViewHost(textView, setFocus);
            var display = new WpfTextViewDisplay(host);

            if (show)
            {
                display.Show();
            }

            return(display);
        }
Пример #14
0
        private IVimBuffer CreateVimBufferForMindScape(params string[] lines)
        {
            var contentType = ContentTypeRegistryService.GetContentType("scss");

            if (contentType == null)
            {
                contentType = ContentTypeRegistryService.AddContentType("scss", new[] { "text " });
            }

            var textBuffer = CreateTextBuffer(contentType, lines);
            var textView   = TextEditorFactoryService.CreateTextView(textBuffer);

            return(Vim.CreateVimBuffer(textView));
        }
Пример #15
0
            public void SharedAcrossBuffers()
            {
                Create("cat", "dog", "fish");
                _textView.MoveCaretToLine(1);
                _vimBuffer.ProcessNotation("big <Esc>");

                var textViewRoleSet = TextEditorFactoryService.CreateTextViewRoleSet(
                    PredefinedTextViewRoles.PrimaryDocument,
                    PredefinedTextViewRoles.Document,
                    PredefinedTextViewRoles.Interactive,
                    PredefinedTextViewRoles.Editable);
                var altTextView  = TextEditorFactoryService.CreateTextView(_textBuffer, textViewRoleSet);
                var altVimBuffer = CreateVimBuffer(CreateVimBufferData(altTextView));

                altVimBuffer.ProcessNotation("'^");
                Assert.Equal(_textBuffer.GetLine(1).Start, altTextView.GetCaretPoint());
            }
Пример #16
0
        public void UndoTransactionSimple()
        {
            var textBuffer   = CreateTextBuffer("");
            var textView     = TextEditorFactoryService.CreateTextView(textBuffer);
            var weakTextView = new WeakReference(textView);

            DoWork(
                () =>
            {
                var undoManager = TextBufferUndoManagerProvider.GetTextBufferUndoManager(textBuffer);
                using (var transaction = undoManager.TextBufferUndoHistory.CreateTransaction("Test Edit"))
                {
                    textBuffer.SetText("hello world");
                    transaction.Complete();
                }
            });

            textView.Close();
            textView = null;
            RunGarbageCollector();
            Assert.Null(weakTextView.Target);
        }
Пример #17
0
 /// <summary>
 /// Create a Visual Studio simulation with the specified set of lines
 /// </summary>
 private void CreateCore(bool simulateResharper, bool usePeekRole, params string[] lines)
 {
     if (usePeekRole)
     {
         _textBuffer = CreateTextBuffer(lines);
         _textView   = TextEditorFactoryService.CreateTextView(
             _textBuffer,
             TextEditorFactoryService.CreateTextViewRoleSet(PredefinedTextViewRoles.Document, PredefinedTextViewRoles.Editable, Constants.TextViewRoleEmbeddedPeekTextView));
     }
     else
     {
         _textView   = CreateTextView(lines);
         _textBuffer = _textView.TextBuffer;
     }
     _vimBuffer         = Vim.CreateVimBuffer(_textView);
     _bufferCoordinator = new VimBufferCoordinator(_vimBuffer);
     _vsSimulation      = new VsSimulation(
         _bufferCoordinator,
         simulateResharper: simulateResharper,
         simulateStandardKeyMappings: false,
         editorOperationsFactoryService: EditorOperationsFactoryService,
         keyUtil: KeyUtil);
 }
Пример #18
0
        public IWpfTextView CreateTextView(IContentType contentType, params string[] lines)
        {
            var textBuffer = TextBufferFactoryService.CreateTextBuffer(contentType, lines);

            return(TextEditorFactoryService.CreateTextView(textBuffer));
        }
Пример #19
0
        /// <summary>
        /// Create an ITextView instance with the given lines
        /// </summary>
        public IWpfTextView CreateTextView(params string[] lines)
        {
            var textBuffer = CreateTextBuffer(lines);

            return(TextEditorFactoryService.CreateTextView(textBuffer));
        }
Пример #20
0
        public IWpfTextViewHost CreateProjectionEditor(string filePath, int start, int length, bool isReadonly = true)
        {
            //IVsInvisibleEditors are in-memory represenations of typical Visual Studio editors.
            //Language services, highlighting and error squiggles are hooked up to these editors
            //for us once we convert them to WpfTextViews.
            var invisibleEditor = GetInvisibleEditor(filePath);

            var  docDataPointer   = IntPtr.Zero;
            Guid guidIVsTextLines = typeof(IVsTextLines).GUID;

            ErrorHandler.ThrowOnFailure(invisibleEditor.GetDocData(
                                            fEnsureWritable: 1
                                            , riid: ref guidIVsTextLines
                                            , ppDocData: out docDataPointer));

            IVsTextLines docData = (IVsTextLines)Marshal.GetObjectForIUnknown(docDataPointer);

            // This will actually be defined as _codewindowbehaviorflags2.CWB_DISABLEDIFF once the latest version of
            // Microsoft.VisualStudio.TextManager.Interop.16.0.DesignTime is published. Setting the flag will have no effect
            // on releases prior to d16.0.
            const _codewindowbehaviorflags CWB_DISABLEDIFF = (_codewindowbehaviorflags)0x04;

            //Create a code window adapter
            var codeWindow = EditorAdaptersFactoryService.CreateVsCodeWindowAdapter(OLEServiceProvider);

            // You need to disable the dropdown, splitter and -- for d16.0 -- diff since you are extracting the code window's TextViewHost and using it.
            ((IVsCodeWindowEx)codeWindow).Initialize((uint)_codewindowbehaviorflags.CWB_DISABLESPLITTER | (uint)_codewindowbehaviorflags.CWB_DISABLEDROPDOWNBAR | (uint)CWB_DISABLEDIFF,
                                                     VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter,
                                                     string.Empty,
                                                     string.Empty,
                                                     0,
                                                     new INITVIEW[1]);

            ErrorHandler.ThrowOnFailure(codeWindow.SetBuffer(docData));

            //Get a text view for our editor which we will then use to get the WPF control for that editor.
            IVsTextView textView;

            ErrorHandler.ThrowOnFailure(codeWindow.GetPrimaryView(out textView));

            //We add our own role to this text view. Later this will allow us to selectively modify
            //this editor without getting in the way of Visual Studio's normal editors.
            var roles = TextEditorFactoryService.DefaultRoles.Concat(new string[] { DCI_BABY_IDE });

            var vsTextBuffer = docData as IVsTextBuffer;
            var textBuffer   = EditorAdaptersFactoryService.GetDataBuffer(vsTextBuffer);

            if (textBuffer.Properties.ContainsProperty("StartPosition"))
            {
                textBuffer.Properties.RemoveProperty("StartPosition");
            }
            if (textBuffer.Properties.ContainsProperty("EndPosition"))
            {
                textBuffer.Properties.RemoveProperty("EndPosition");
            }

            textBuffer.Properties.AddProperty("StartPosition", start);
            textBuffer.Properties.AddProperty("EndPosition", start + length);
            var guid = VSConstants.VsTextBufferUserDataGuid.VsTextViewRoles_guid;

            ((IVsUserData)codeWindow).SetData(ref guid, TextEditorFactoryService.CreateTextViewRoleSet(roles).ToString());

            var textViewHost = EditorService.EditorAdaptersFactoryService.GetWpfTextViewHost(textView);

            return(textViewHost);
        }
Пример #21
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();
            }
        }