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);
        }
Example #2
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 #3
0
        private void BindContentTypeSpecificAssets(IContentType beforeContentType, IContentType afterContentType)
        {
            // Notify the Text view creation listeners
            var extensions = UIExtensionSelector.SelectMatchingExtensions(_factoryService.TextViewCreationListeners, afterContentType, beforeContentType, _roles);

            foreach (var extension in extensions)
            {
                string deferOptionName = extension.Metadata.OptionName;
                if (!string.IsNullOrEmpty(deferOptionName) && Options.IsOptionDefined(deferOptionName, false))
                {
                    object value = Options.GetOptionValue(deferOptionName);
                    if (value is bool)
                    {
                        if (!(bool)value)
                        {
                            if (_deferredTextViewListeners == null)
                            {
                                _deferredTextViewListeners = new List <Lazy <ITextViewCreationListener, IDeferrableContentTypeAndTextViewRoleMetadata> >();
                            }
                            _deferredTextViewListeners.Add(extension);
                            continue;
                        }
                    }
                }

                var instantiatedExtension = _factoryService.GuardedOperations.InstantiateExtension(extension, extension);
                if (instantiatedExtension != null)
                {
                    _factoryService.GuardedOperations.CallExtensionPoint(instantiatedExtension,
                                                                         () => instantiatedExtension.TextViewCreated(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);
        }
Example #5
0
        public ConnectionManager(ITextView textView,
                                 ICollection <Lazy <ITextViewConnectionListener, IContentTypeAndTextViewRoleMetadata> > textViewConnectionListeners,
                                 IGuardedOperations guardedOperations)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }
            if (textViewConnectionListeners == null)
            {
                throw new ArgumentNullException("textViewConnectionListeners");
            }
            if (guardedOperations == null)
            {
                throw new ArgumentNullException("guardedOperations");
            }

            _textView          = textView;
            _guardedOperations = guardedOperations;

            List <Lazy <ITextViewConnectionListener, IContentTypeAndTextViewRoleMetadata> > filteredListeners =
                UIExtensionSelector.SelectMatchingExtensions(textViewConnectionListeners, _textView.Roles);

            if (filteredListeners.Count > 0)
            {
                foreach (var listenerExport in filteredListeners)
                {
                    if (!allowedTextViewConnectionListeners.Contains(listenerExport.Value.ToString()))
                    {
                        continue;
                    }

                    Listener listener = new Listener(listenerExport, guardedOperations);
                    this.listeners.Add(listener);

                    Collection <ITextBuffer> subjectBuffers =
                        textView.BufferGraph.GetTextBuffers(buffer => (Match(listenerExport.Metadata, buffer.ContentType)));

                    if (subjectBuffers.Count > 0)
                    {
                        var instance = listener.Instance;
                        if (instance != null)
                        {
                            _guardedOperations.CallExtensionPoint(instance,
                                                                  () => instance.SubjectBuffersConnected(_textView, ConnectionReason.TextViewLifetime, subjectBuffers));
                        }
                    }
                }

                if (listeners.Count > 0)
                {
                    textView.BufferGraph.GraphBuffersChanged           += OnGraphBuffersChanged;
                    textView.BufferGraph.GraphBufferContentTypeChanged += OnGraphBufferContentTypeChanged;
                }
            }
        }
Example #6
0
        protected override async Task <Control> OnGetViewControlAsync(CancellationToken token, DocumentViewContent view)
        {
            // FIXME: move this to the end of the .ctor after fixing margin options responsiveness
            UpdateLineNumberMarginOption();

            var fileModel = (TextBufferFileModel)Model;

            TextDocument = fileModel.TextDocument;
            TextBuffer   = TextDocument.TextBuffer;

            UpdateTextBufferRegistration();

            var roles = GetAllPredefinedRoles();

            //we have multiple copies of VacuousTextDataModel for back-compat reasons
#pragma warning disable CS0436 // Type conflicts with imported type
            var dataModel = new VacuousTextDataModel(TextBuffer);
            var viewModel = UIExtensionSelector.InvokeBestMatchingFactory(
                Imports.TextViewModelProviders,
                dataModel.ContentType,
                roles,
                provider => provider.CreateTextViewModel(dataModel, roles),
                Imports.ContentTypeRegistryService,
                Imports.GuardedOperations,
                this) ?? new VacuousTextViewModel(dataModel);
#pragma warning restore CS0436 // Type conflicts with imported type

            TextView = CreateTextView(viewModel, roles);
            control  = CreateControl();

            commandService   = Imports.EditorCommandHandlerServiceFactory.GetService(TextView);
            EditorOperations = (EditorOperationsInterface)Imports.EditorOperationsProvider.GetEditorOperations(TextView);
            EditorOptions    = Imports.EditorOptionsFactoryService.GetOptions(TextView);
            UpdateTextEditorOptions(this, EventArgs.Empty);
            contentProviders = new List <IEditorContentProvider> (Imports.EditorContentProviderService.GetContentProvidersForView(TextView));

            TextView.Properties [typeof(DocumentController)] = this;

            infoBarPresenter = Imports.InfoBarPresenterFactory?.TryGetInfoBarPresenter(TextView);

            InstallAdditionalEditorOperationsCommands();

            UpdateBufferOptions();
            SubscribeToEvents();

            // Set up this static event handling just once
            if (globalOptions == null)
            {
                globalOptions = Imports.EditorOptionsFactoryService.GlobalOptions;

                // From Mono.TextEditor.TextEditorOptions
                const double ZOOM_FACTOR  = 1.1f;
                const int    ZOOM_MIN_POW = -4;
                const int    ZOOM_MAX_POW = 8;
                var          ZOOM_MIN     = Math.Pow(ZOOM_FACTOR, ZOOM_MIN_POW);
                var          ZOOM_MAX     = Math.Pow(ZOOM_FACTOR, ZOOM_MAX_POW);

#if !WINDOWS
                globalOptions.SetMinZoomLevel(ZOOM_MIN * 100);
                globalOptions.SetMaxZoomLevel(ZOOM_MAX * 100);
#endif

                OnConfigurationZoomLevelChanged(null, EventArgs.Empty);

                globalOptions.OptionChanged += OnGlobalOptionsChanged;
                // Check for option changing in old editor
                TextEditorFactory.ZoomLevel.Changed += OnConfigurationZoomLevelChanged;
            }

            // Content providers can provide additional content
            NotifyContentChanged();

            await Load(false);

            return(control);
        }