コード例 #1
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);
        }