Exemplo n.º 1
0
        protected override void Initialize()
        {
            base.Initialize();

            // Create and initialize the editor
            if (_componentId == default && this.TryGetService <SOleComponentManager, IOleComponentManager>(out var componentManager))
            {
                var componentRegistrationInfo = new[]
                {
                    new OLECRINFO
                    {
                        cbSize            = (uint)Marshal.SizeOf(typeof(OLECRINFO)),
                        grfcrf            = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime,
                        grfcadvf          = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff,
                        uIdleTimeInterval = 100
                    }
                };

                var hr = componentManager.FRegisterComponent(this, componentRegistrationInfo, out _componentId);
                _ = ErrorHandler.Succeeded(hr);
            }

            if (this.TryGetService <SOleUndoManager, IOleUndoManager>(out _undoManager))
            {
                var linkCapableUndoMgr = (IVsLinkCapableUndoManager)_undoManager;
                if (linkCapableUndoMgr is not null)
                {
                    _ = linkCapableUndoMgr.AdviseLinkedUndoClient(this);
                }
            }

            var statusService = _workspace.Services.GetService <IWorkspaceStatusService>();

            if (statusService is not null)
            {
                // This will show the 'Waiting for Intellisense to initalize' message until the workspace is loaded.
                _threadingContext.JoinableTaskFactory.Run(async() =>
                {
                    if (!await statusService.IsFullyLoadedAsync(CancellationToken.None).ConfigureAwait(false))
                    {
                        await statusService.WaitUntilFullyLoadedAsync(CancellationToken.None).ConfigureAwait(false);
                    }
                });
            }

            // hook up our panel
            _control = new SettingsEditorControl(
                GetWhitespaceView(),
                GetCodeStyleView(),
                GetAnalyzerView(),
                _workspace,
                _fileName,
                _threadingContext,
                _vsEditorAdaptersFactoryService,
                _textBuffer);
            Content = _control;

            RegisterIndependentView(true);
            if (this.TryGetService <IMenuCommandService>(out var menuCommandService))
            {
                AddCommand(menuCommandService, GUID_VSStandardCommandSet97, (int)VSStd97CmdID.NewWindow,
                           new EventHandler(OnNewWindow), new EventHandler(OnQueryNewWindow));
                AddCommand(menuCommandService, GUID_VSStandardCommandSet97, (int)VSStd97CmdID.ViewCode,
                           new EventHandler(OnViewCode), new EventHandler(OnQueryViewCode));
            }

            ISettingsEditorView GetWhitespaceView()
            {
                var dataProvider = _settingsDataProviderService.GetSettingsProvider <WhitespaceSetting>(_fileName);

                if (dataProvider is null)
                {
                    throw new InvalidOperationException("Unable to get whitespace settings");
                }

                var viewModel = new WhitespaceViewModel(dataProvider, _controlProvider, _tableMangerProvider);

                return(new WhitespaceSettingsView(viewModel));
            }

            ISettingsEditorView GetCodeStyleView()
            {
                var dataProvider = _settingsDataProviderService.GetSettingsProvider <CodeStyleSetting>(_fileName);

                if (dataProvider is null)
                {
                    throw new InvalidOperationException("Unable to get code style settings");
                }

                var viewModel = new CodeStyleSettingsViewModel(dataProvider, _controlProvider, _tableMangerProvider);

                return(new CodeStyleSettingsView(viewModel));
            }

            ISettingsEditorView GetAnalyzerView()
            {
                var dataProvider = _settingsDataProviderService.GetSettingsProvider <AnalyzerSetting>(_fileName);

                if (dataProvider is null)
                {
                    throw new InvalidOperationException("Unable to get analyzer settings");
                }

                var viewModel = new AnalyzerSettingsViewModel(dataProvider, _controlProvider, _tableMangerProvider);

                return(new AnalyzerSettingsView(viewModel));
            }
        }
Exemplo n.º 2
0
        protected override void Initialize()
        {
            base.Initialize();

            // Create and initialize the editor
            if (_componentId == default && this.TryGetService <SOleComponentManager, IOleComponentManager>(out var componentManager))
            {
                var componentRegistrationInfo = new[]
                {
                    new OLECRINFO
                    {
                        cbSize            = (uint)Marshal.SizeOf(typeof(OLECRINFO)),
                        grfcrf            = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime,
                        grfcadvf          = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff,
                        uIdleTimeInterval = 100
                    }
                };

                var hr = componentManager.FRegisterComponent(this, componentRegistrationInfo, out _componentId);
                _ = ErrorHandler.Succeeded(hr);
            }

            if (this.TryGetService <SOleUndoManager, IOleUndoManager>(out _undoManager))
            {
                var linkCapableUndoMgr = (IVsLinkCapableUndoManager)_undoManager;
                if (linkCapableUndoMgr is not null)
                {
                    _ = linkCapableUndoMgr.AdviseLinkedUndoClient(this);
                }
            }

            // hook up our panel
            _control = new SettingsEditorControl(
                GetFormattingView(),
                GetCodeStyleView(),
                GetAnalyzerView(),
                _workspace,
                _fileName,
                _threadingContext,
                _vsEditorAdaptersFactoryService,
                _textBuffer);
            Content = _control;

            RegisterIndependentView(true);
            if (this.TryGetService <IMenuCommandService>(out var menuCommandService))
            {
                AddCommand(menuCommandService, GUID_VSStandardCommandSet97, (int)VSStd97CmdID.NewWindow,
                           new EventHandler(OnNewWindow), new EventHandler(OnQueryNewWindow));
                AddCommand(menuCommandService, GUID_VSStandardCommandSet97, (int)VSStd97CmdID.ViewCode,
                           new EventHandler(OnViewCode), new EventHandler(OnQueryViewCode));
            }

            ISettingsEditorView GetFormattingView()
            {
                var dataProvider = _settingsDataProviderService.GetSettingsProvider <FormattingSetting>(_fileName);

                if (dataProvider is null)
                {
                    throw new InvalidOperationException("Unable to get formatter settings");
                }

                var viewModel = new FormattingViewModel(dataProvider, _controlProvider, _tableMangerProvider);

                return(new FormattingSettingsView(viewModel));
            }

            ISettingsEditorView GetCodeStyleView()
            {
                var dataProvider = _settingsDataProviderService.GetSettingsProvider <CodeStyleSetting>(_fileName);

                if (dataProvider is null)
                {
                    throw new InvalidOperationException("Unable to get code style settings");
                }

                var viewModel = new CodeStyleSettingsViewModel(dataProvider, _controlProvider, _tableMangerProvider);

                return(new CodeStyleSettingsView(viewModel));
            }

            ISettingsEditorView GetAnalyzerView()
            {
                var dataProvider = _settingsDataProviderService.GetSettingsProvider <AnalyzerSetting>(_fileName);

                if (dataProvider is null)
                {
                    throw new InvalidOperationException("Unable to get analyzer settings");
                }

                var viewModel = new AnalyzerSettingsViewModel(dataProvider, _controlProvider, _tableMangerProvider);

                return(new AnalyzerSettingsView(viewModel));
            }
        }