Example #1
0
        private void ImportOptionsButton_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog()
            {
                Filter          = "All Files  (*.*)|*.*|Config Files (*.config)|*.config",
                CheckPathExists = true,
                Multiselect     = false,
            };

            if (dialog.ShowDialog() != true)
            {
                return;
            }

            CodeAnalysisConfiguration configuration = CodeAnalysisConfiguration.LoadAndCatchIfThrows(dialog.FileName, ShowErrorMessage);

            AbstractPackage package = AbstractPackage.Instance;

            package.RefactoringsOptionsPage.Load();
            package.CodeFixesOptionsPage.Load();

            PrefixFieldIdentifierWithUnderscore = configuration.PrefixFieldIdentifierWithUnderscore;

            Update(package.RefactoringsOptionsPage, configuration.GetDisabledRefactorings().ToHashSet());
            Update(package.CodeFixesOptionsPage, configuration.GetDisabledCodeFixes().ToHashSet());
        private void ImportOptionsButton_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog()
            {
                Filter          = "All Files  (*.*)|*.*|Config Files (*.config)|*.config",
                CheckPathExists = true,
                Multiselect     = false,
            };

            if (dialog.ShowDialog() != true)
            {
                return;
            }

            Settings settings = null;

            try
            {
                settings = Settings.Load(dialog.FileName);
            }
            catch (Exception ex) when(ex is IOException ||
                                      ex is UnauthorizedAccessException ||
                                      ex is XmlException)
            {
                ShowErrorMessage(ex);
                return;
            }

            AbstractPackage package = AbstractPackage.Instance;

            package.GlobalSuppressionsOptionsPage.Load();
            package.RefactoringsOptionsPage.Load();
            package.CodeFixesOptionsPage.Load();

            PrefixFieldIdentifierWithUnderscore = settings.PrefixFieldIdentifierWithUnderscore;

            foreach (BaseModel model in package.GlobalSuppressionsOptionsPage.Control.Items)
            {
                model.Enabled = settings.GlobalSuppressions.Contains(model.Id);
            }

            Update(package.RefactoringsOptionsPage, settings.Refactorings);
            Update(package.CodeFixesOptionsPage, settings.CodeFixes);

            void Update(BaseOptionsPage optionsPage, Dictionary <string, bool> dic)
            {
                var disabledIds = new HashSet <string>(dic.Where(f => !f.Value).Select(f => f.Key));

                foreach (BaseModel model in optionsPage.Control.Items)
                {
                    model.Enabled = !disabledIds.Contains(model.Id);
                }
            }
        }
Example #3
0
        private void ExportOptionsButton_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new SaveFileDialog()
            {
                Filter          = "All Files  (*.*)|*.*|Config Files (*.config)|*.config",
                FileName        = Path.GetFileName(Settings.ConfigFileName),
                DefaultExt      = "config",
                AddExtension    = true,
                CheckPathExists = true,
                OverwritePrompt = true,
            };

            if (dialog.ShowDialog() != true)
            {
                return;
            }

            IEnumerable <string> globalSuppressions = null;

            AbstractPackage package = AbstractPackage.Instance;

            if (package.GlobalSuppressionsOptionsPage.IsLoaded)
            {
                globalSuppressions = package.GlobalSuppressionsOptionsPage
                                     .Control
                                     .Items
                                     .Where(f => f.Enabled)
                                     .Select(f => f.Id);
            }
            else
            {
                globalSuppressions = package.GlobalSuppressionsOptionsPage.GetDisabledItems();
            }

            IEnumerable <string> disabledRefactorings = null;

            if (package.RefactoringsOptionsPage.IsLoaded)
            {
                disabledRefactorings = package.RefactoringsOptionsPage
                                       .Control
                                       .Items
                                       .Where(f => !f.Enabled)
                                       .Select(f => f.Id);
            }
            else
            {
                disabledRefactorings = package.RefactoringsOptionsPage.GetDisabledItems();
            }

            IEnumerable <string> disabledCodeFixes = null;

            if (package.CodeFixesOptionsPage.IsLoaded)
            {
                disabledCodeFixes = package.CodeFixesOptionsPage
                                    .Control
                                    .Items
                                    .Where(f => !f.Enabled)
                                    .Select(f => f.Id);
            }
            else
            {
                disabledCodeFixes = package.CodeFixesOptionsPage.GetDisabledItems();
            }

            var settings = new Settings(
                refactorings: disabledRefactorings.Select(f => new KeyValuePair <string, bool>(f, false)),
                codeFixes: disabledCodeFixes.Select(f => new KeyValuePair <string, bool>(f, false)),
                globalSuppressions: globalSuppressions,
                prefixFieldIdentifierWithUnderscore: PrefixFieldIdentifierWithUnderscore);

            try
            {
                settings.Save(dialog.FileName);
            }
            catch (Exception ex)
            {
                if (ex is IOException ||
                    ex is UnauthorizedAccessException)
                {
                    ShowErrorMessage(ex);
                }
                else
                {
                    throw;
                }
            }
        }