public XamlStylerOptionsPage( Lifetime lifetime, OptionsPageContext optionsPageContext, OptionsSettingsSmartContext optionsSettingsSmartContext, [NotNull] IconHostBase iconHost, [NotNull] ICommonFileDialogs commonFileDialogs) : base(lifetime, optionsPageContext, optionsSettingsSmartContext) { _iconHost = iconHost; #if RIDER // General AddHeader("General"); AddBoolOption((XamlStylerSettings x) => x.FormatOnSave, "Format XAML on save"); #endif // Indentation AddHeader("Indentation"); var indentSizeOption = AddSpinner((XamlStylerSettings x) => x.IndentSize, "Indent size:"); using (Indent()) { AddBoolOption((XamlStylerSettings x) => x.UseIdeIndentSize, "Use IDE value"); } AddBinding(indentSizeOption, BindingStyle.IsEnabledProperty, (XamlStylerSettings x) => x.UseIdeIndentSize, x => !(bool)x); var indentWithTabsOption = AddBoolOption((XamlStylerSettings x) => x.IndentWithTabs, "Indent with tabs"); using (Indent()) { AddBoolOption((XamlStylerSettings x) => x.UseIdeIndentWithTabs, "Use IDE value"); } AddBinding(indentWithTabsOption, BindingStyle.IsEnabledProperty, (XamlStylerSettings x) => x.UseIdeIndentWithTabs, x => !(bool)x); // Attribute formatting AddHeader("Attribute formatting"); AddSpinner((XamlStylerSettings x) => x.AttributesTolerance, "Attribute tolerance:"); AddBoolOption((XamlStylerSettings x) => x.KeepFirstAttributeOnSameLine, "Keep first attribute on same line"); AddSpinner((XamlStylerSettings x) => x.MaxAttributeCharactersPerLine, "Max attribute characters per line:"); AddSpinner((XamlStylerSettings x) => x.MaxAttributesPerLine, "Max attributes per line:"); AddTextBox((XamlStylerSettings x) => x.NoNewLineElements, "Newline exemption elements:"); AddBoolOption((XamlStylerSettings x) => x.PutAttributeOrderRuleGroupsOnSeparateLines, "Separate by groups"); AddSpinner((XamlStylerSettings x) => x.AttributeIndentation, "Attribute indentation:"); AddComboEnum((XamlStylerSettings x) => x.AttributeIndentationStyle, "Attribute indentation style:"); AddBoolOption((XamlStylerSettings x) => x.RemoveDesignTimeReferences, "Remove design-time references"); // Attribute Reordering AddHeader("Attribute reordering"); AddBoolOption((XamlStylerSettings x) => x.EnableAttributeReordering, "Enable attribute reordering"); var attributeOrderingRuleGroupsOption = AddListControl((XamlStylerSettings x) => x.AttributeOrderingRuleGroups, new StylerOptions().AttributeOrderingRuleGroups, "Attribute ordering rule groups"); var firstLineAttributesOption = AddTextBox((XamlStylerSettings x) => x.FirstLineAttributes, "First-line attributes:"); var orderAttributesByNameOption = AddBoolOption((XamlStylerSettings x) => x.OrderAttributesByName, "Order attributes by name"); AddBinding(attributeOrderingRuleGroupsOption, BindingStyle.IsEnabledProperty, (XamlStylerSettings x) => x.EnableAttributeReordering, x => (bool)x); AddBinding(firstLineAttributesOption, BindingStyle.IsEnabledProperty, (XamlStylerSettings x) => x.EnableAttributeReordering, x => (bool)x); AddBinding(orderAttributesByNameOption, BindingStyle.IsEnabledProperty, (XamlStylerSettings x) => x.EnableAttributeReordering, x => (bool)x); // Element formatting AddHeader("Element formatting"); AddBoolOption((XamlStylerSettings x) => x.PutEndingBracketOnNewLine, "Put ending brackets on new line"); AddBoolOption((XamlStylerSettings x) => x.RemoveEndingTagOfEmptyElement, "Remove ending tag of empty element"); AddBoolOption((XamlStylerSettings x) => x.SpaceBeforeClosingSlash, "Space before ending slash in self-closing elements"); AddComboEnum((XamlStylerSettings x) => x.RootElementLineBreakRule, "Root element line breaks between attributes:"); // Element reordering AddHeader("Element reordering"); AddComboEnum((XamlStylerSettings x) => x.ReorderVSM, "Reorder visual state manager:"); AddBoolOption((XamlStylerSettings x) => x.ReorderGridChildren, "Reorder grid panel children"); AddBoolOption((XamlStylerSettings x) => x.ReorderCanvasChildren, "Reorder canvas panel children"); AddComboEnum((XamlStylerSettings x) => x.ReorderSetters, "Reorder setters:"); // Markup extension AddHeader("Markup extension"); AddBoolOption((XamlStylerSettings x) => x.FormatMarkupExtension, "Enable markup extension formatting"); var noNewLineMarkupExtensionsOption = AddTextBox((XamlStylerSettings x) => x.NoNewLineMarkupExtensions, "Keep markup extensions of these types on one line:"); AddBinding(noNewLineMarkupExtensionsOption, BindingStyle.IsEnabledProperty, (XamlStylerSettings x) => x.FormatMarkupExtension, x => (bool)x); // Thickness formatting AddHeader("Thickness formatting"); AddComboEnum((XamlStylerSettings x) => x.ThicknessStyle, "Thickness separator:"); AddTextBox((XamlStylerSettings x) => x.ThicknessAttributes, "Thickness attributes:"); // Misc AddHeader("Misc"); AddSpinner((XamlStylerSettings x) => x.CommentSpaces, "Comment padding:"); // Configuration AddHeader("Configuration"); AddText("External configuration file:"); var configPath = new Property <FileSystemPath>(lifetime, "XamlStylerOptionsPage::configPath"); OptionsSettingsSmartContext.SetBinding(lifetime, (XamlStylerSettings k) => k.ConfigPath, configPath); AddFileChooserOption(configPath, "External configuration file", FileSystemPath.Empty, null, commonFileDialogs, null, false, "", null, null, null, null); AddBoolOption((XamlStylerSettings x) => x.SearchToDriveRoot, "Search to drive root"); AddBoolOption((XamlStylerSettings x) => x.SuppressProcessing, "Suppress processing"); }
/// <summary> /// Initializes a new instance of the StyleCopOptionsPage class. /// </summary> /// <param name="lifetime"> /// The lifetime of the options page. /// </param> /// <param name="settingsSmartContext"> /// Our settings context. /// </param> /// <param name="container"> /// The component container /// </param> /// <param name="fileDialogs"> /// The common file dialogs. /// </param> public StyleCopOptionsPage( Lifetime lifetime, OptionsSettingsSmartContext settingsSmartContext, IComponentContainer container, ICommonFileDialogs fileDialogs) : base(lifetime, settingsSmartContext) { IContextBoundSettingsStoreLive settingsContext = this.OptionsSettingsSmartContext.StoreOptionsTransactionContext; this.originalEnablePlugins = settingsContext.GetValue((StyleCopOptionsSettingsKey options) => options.PluginsEnabled); this.originalPluginsPath = settingsContext.GetValue((StyleCopOptionsSettingsKey options) => options.PluginsPath); this.AddHeader("Version"); Assembly assembly = typeof(StyleCopEnvironment).Assembly; string styleCopFileVersion = GetFileVersionInfo(assembly); this.AddText(string.Format("StyleCop.dll {0} ({1})", assembly.GetName().Version, styleCopFileVersion)); assembly = this.GetType().Assembly; string ourFileVersion = GetFileVersionInfo(assembly); this.AddText(string.Format("StyleCop.ReSharper.dll {0} ({1})", assembly.GetName().Version, ourFileVersion)); if (ourFileVersion != styleCopFileVersion) { TextStyle style = new TextStyle(FontStyle.Bold, Color.Empty, Color.Empty); this.AddRichText( new RichText( "Mismatched StyleCop.dll version! Are you running an older version of the Visual Studio plugin?", style)); } this.AddHeader("Options"); // Note that we have to check to see if the lifetime is terminated before accessing the // settings context because WPF will continue to call our CanExecute until a garbage collection // breaks the weak reference that WPF holds on command this.AddButton( "Reset code style options", new DelegateCommand( () => CodeStyleOptions.CodeStyleOptionsReset(settingsSmartContext), () => !lifetime.IsTerminated && !CodeStyleOptions.CodeStyleOptionsValid(settingsSmartContext))); this.AddHeader("Analysis Performance"); if (DoesHostSupportRoslynAnalzyers(container)) { this.AddText( "Note: Analysis is automatically disabled if the project references the StyleCop.Analyzers NuGet package, which provides StyleCop analysis for Visual Studio 2015 and C# 6."); } this.AddBoolOption( (StyleCopOptionsSettingsKey options) => options.AnalysisEnabled, "Run StyleCop as you type"); BoolOptionViewModel nonUserFiles = this.AddBoolOption( (StyleCopOptionsSettingsKey options) => options.AnalyzeReadOnlyFiles, "Analyze non-user files (not recommended)"); this.AddBinding( nonUserFiles, BindingStyle.IsEnabledProperty, (StyleCopOptionsSettingsKey options) => options.AnalysisEnabled, JetFunc <object> .Identity); this.AddHeader("Headers"); this.AddBoolOption( (StyleCopOptionsSettingsKey options) => options.InsertTextIntoDocumentation, "Insert text into documentation and file headers"); this.AddBoolOption( (StyleCopOptionsSettingsKey options) => options.UseSingleLineDeclarationComments, "Use single lines for declaration headers"); this.AddBoolOption( (StyleCopOptionsSettingsKey options) => options.InsertToDoText, "Insert TODO into headers"); this.AddIntOption( (StyleCopOptionsSettingsKey options) => options.DashesCountInFileHeader, "Number of dashes in file header text:"); this.AddHeader("StyleCop Plugins"); this.AddBoolOption( (StyleCopOptionsSettingsKey options) => options.PluginsEnabled, "Enable StyleCop plugins"); this.AddText("Location of StyleCop plugins:"); Property <FileSystemPath> pluginsPath = this.SetupPluginsPathProperty(lifetime); PathChooserViewModel fileChooser = this.AddFolderChooserOption( pluginsPath, "Location of StyleCop plugins", FileSystemPath.Empty, fileDialogs, FileSystemPath.Empty); fileChooser.IsEnabledProperty.SetValue(true); this.AddBinding( fileChooser, BindingStyle.IsEnabledProperty, (StyleCopOptionsSettingsKey options) => options.PluginsEnabled, JetFunc <object> .Identity); this.AddHeader("Misc"); this.AddBoolOption( (StyleCopOptionsSettingsKey options) => options.UseExcludeFromStyleCopSetting, "Use ExcludeFromStyleCop setting in csproj files"); this.AddStringOption( (StyleCopOptionsSettingsKey options) => options.SuppressStyleCopAttributeJustificationText, "Justification for SuppressMessage attribute:"); // TODO: Add "update file header style" that used to be in code cleanup this.FinishPage(); }