Exemple #1
0
        private Task OnSettingsChanged(object sender, EventArgs e)
        {
            if (_isDisposed)
            {
                return(Task.CompletedTask);
            }

            // The SettingsChanged event is raised frequently, often regarding
            // changes that don't affect us. We cache the settings that we
            // care about, and check if those have changed, then raise our
            // own changed events as applicable.
            bool interpreterChanged = false;
            bool searchPathsChanged = false;

            lock (_cacheLock) {
                var oldInterpreter = _interpreter;
                var oldSearchPaths = _searchPaths;

                _interpreter = ReadInterpreterSetting();
                _searchPaths = ReadSearchPathsSetting();

                interpreterChanged = oldInterpreter != _interpreter;
                searchPathsChanged = !oldSearchPaths.SequenceEqual(_searchPaths);
            }

            if (interpreterChanged)
            {
                // Avoid potentially raising more than one ActiveInterpreterChanged
                // by unregistering from events that could raise that event.
                _optionsService.DefaultInterpreterChanged -= OnDefaultInterpreterChanged;
                _registryService.InterpretersChanged      -= OnInterpretersChanged;
                try {
                    InterpreterSettingChanged?.Invoke(this, EventArgs.Empty);
                } finally {
                    _optionsService.DefaultInterpreterChanged += OnDefaultInterpreterChanged;
                    _registryService.InterpretersChanged      += OnInterpretersChanged;
                }

                var oldFactory = CurrentFactory;
                RefreshCurrentFactory();

                if (oldFactory != CurrentFactory)
                {
                    ActiveInterpreterChanged?.Invoke(this, EventArgs.Empty);
                }
            }

            if (searchPathsChanged)
            {
                SearchPathsSettingChanged?.Invoke(this, EventArgs.Empty);
            }

            return(Task.CompletedTask);
        }
 public void SimulateChangeInterpreterSetting(string setting)
 {
     _interpreterSetting = setting;
     InterpreterSettingChanged?.Invoke(this, EventArgs.Empty);
 }