Example #1
0
        public TestTextView(ITextBuffer textBuffer, TextViewFactoryService factoryService)
        {
            _textBuffer     = textBuffer;
            _factoryService = factoryService;

            Options = factoryService.EditorOptionsFactory.CreateOptions(true);
            factoryService.EditorOptionsFactory.TryBindToScope(Options, this);

            TextSnapshot         = textBuffer.CurrentSnapshot;
            TextDataModel        = new VacuousTextDataModel(textBuffer);
            TextViewModel        = new VacuousTextViewModel(TextDataModel);
            MultiSelectionBroker = _factoryService.MultiSelectionBrokerFactory.CreateBroker(this);

            CreateLines();

            Selection = new TestTextSelection(this, MultiSelectionBroker);
            _caret    = new TestTextCaret(this, _factoryService.SmartIndentationService, MultiSelectionBroker);

            textBuffer.ChangedLowPriority += TextBufferChangedLowPriority;

            var listeners = UIExtensionSelector.SelectMatchingExtensions(
                _factoryService.TextViewCreationListeners, _textBuffer.ContentType, null, Roles);

            foreach (var listener in listeners)
            {
                listener.Value.TextViewCreated(this);
            }
        }
Example #2
0
        // This method should only be called once (it is normally called from the ctor unless we're using
        // ITextEditorFactoryService2.CreateTextViewHostWithoutInitialization on the factory to delay initialization).
        internal void Initialize()
        {
            if (_hasInitializeBeenCalled)
            {
                throw new InvalidOperationException("Attempted to Initialize a WpfTextViewHost twice");
            }

            _hasInitializeBeenCalled = true;

            var documentFactoryService     = CompositionManager.GetExportedValue <Microsoft.VisualStudio.Text.ITextDocumentFactoryService>();
            var contentTypeRegistryService = CompositionManager.GetExportedValue <Microsoft.VisualStudio.Utilities.IContentTypeRegistryService>();
            var contentType = contentTypeRegistryService.GetContentType("Text");
            var textBuffer  = PlatformCatalog.Instance.TextBufferFactoryService.CreateTextBuffer(@"
class Test
{
    public static void Main (string[] args)
    {
        
    }
}            
", contentType);
            var document    = documentFactoryService.CreateTextDocument(textBuffer, "/a.cs");
            var dataModel   = new VacuousTextDataModel(document.TextBuffer);
            var viewModel   = new VacuousTextViewModel(dataModel);
            var textFactory = (TextEditorFactoryService)PlatformCatalog.Instance.TextEditorFactoryService;

            TextView = new SkiaTextView(viewModel, textFactory.AllPredefinedRoles, textFactory.EditorOptionsFactoryService.GlobalOptions, textFactory);
        }