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); } }
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); }
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); }
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); }