/// <summary> /// Sets the given property on the add-in. /// </summary> /// <param name="settings"> /// The settings. /// </param> /// <param name="property"> /// The property to set. /// </param> public void SetSetting(WritableSettings settings, PropertyValue property) { Param.RequireNotNull(settings, "settings"); Param.RequireNotNull(property, "property"); settings.SetAddInSetting(this, property); }
/// <summary> /// Initializes a new instance of the PropertyDialog class. /// </summary> /// <param name="pages">The array of pages to display on the property control.</param> /// <param name="settingsFile">The file that contains the settings being edited.</param> /// <param name="id">A unique ID that describes this set of property pages.</param> /// <param name="core">The StyleCop core instance.</param> /// <param name="helpCallback">Callback method for help, or null for no help.</param> /// <param name="context">The context to the send to the property page control.</param> public PropertyDialog( IList <IPropertyControlPage> pages, WritableSettings settingsFile, string id, StyleCopCore core, Help helpCallback, params object[] context) { Param.Assert(pages != null && pages.Count > 0, "pages", "Cannot be null or empty"); Param.Assert(settingsFile != null && settingsFile.Loaded, "settingsFile", "The settings file must be loaded."); Param.AssertValidString(id, "id"); Param.AssertNotNull(core, "core"); Param.Ignore(helpCallback); Param.Ignore(context); this.pages = pages; this.settingsFile = settingsFile; this.id = id; this.core = core; this.helpCallback = helpCallback; this.context = context; this.InitializeComponent(); this.core.Registry.RestoreWindowPosition(this.id, this, this.Location, this.Size); }
/// <summary> /// Clears the given property for the add-in. /// </summary> /// <param name="settings"> /// The settings. /// </param> /// <param name="propertyName"> /// The name of the property to clear. /// </param> public void ClearSetting(WritableSettings settings, string propertyName) { Param.RequireNotNull(settings, "settings"); Param.RequireValidString(propertyName, "propertyName"); settings.ClearAddInSetting(this, propertyName); }
/// <summary> /// Saves the settings file at the path specified within the settings document. /// </summary> /// <param name="settings"> /// The settings to save. /// </param> /// <param name="exception"> /// If the document could not be saved, this returns the /// resulting exception information. /// </param> /// <returns> /// Returns true if the file was successfully saved. /// </returns> public override bool SaveSettings(WritableSettings settings, out Exception exception) { Param.Ignore(settings); // The default object-based environment does not support the ability to save modified settings. exception = new NotSupportedException(); return(false); }
/// <summary> /// Saves the settings document at the path specified within the document. /// </summary> /// <param name="settings"> /// The settings to save. /// </param> /// <returns> /// Returns true if the document was successfully saved. /// </returns> public bool SaveSettings(WritableSettings settings) { Param.Ignore(settings); Exception exception; return(this.SaveSettings(settings, out exception)); }
public XmlDocument WriteSettingsToDocument(StyleCopEnvironment environment) { Param.RequireNotNull(environment, "environment"); // Create a new document for the settings. XmlDocument document = WritableSettings.NewDocument(); this.SaveSettingsIntoXmlDocument(document, environment, document.DocumentElement, this); return(document); }
/// <summary> /// Loads or creates the settings at the given path, and returns them in writable mode. /// </summary> /// <param name="settingsPath">The path to the settings.</param> /// <param name="exception">Returns an exception if one occured loading or creating the settings.</param> /// <returns>Returns the settings.</returns> public override WritableSettings GetWritableSettings(string settingsPath, out Exception exception) { Param.RequireValidString(settingsPath, "settingsPath"); WritableSettings localSettings = this.LoadSettingsDocument(settingsPath, false, out exception) as WritableSettings; if (localSettings == null) { if (exception is FileNotFoundException) { localSettings = this.CreateSettingsDocument(settingsPath, out exception); } } return(localSettings); }
/// <summary> /// Saves the settings file at the path specified within the settings document. /// </summary> /// <param name="settings">The settings to save.</param> /// <param name="exception">If the document could not be saved, this returns the /// resulting exception information.</param> /// <returns>Returns true if the file was successfully saved.</returns> public override bool SaveSettings(WritableSettings settings, out Exception exception) { Param.RequireNotNull(settings, "settings"); exception = null; if (settings.Path == null || settings.Contents == null) { throw new InvalidOperationException(Strings.SettingsFileHasNotBeenLoaded); } // Write the new settings to the document. XmlDocument document = settings.WriteSettingsToDocument(this); try { // Save the file. document.Save(settings.Path); // Update the write time. settings.WriteTime = File.GetLastWriteTime(settings.Path); return(true); } catch (IOException ioex) { exception = ioex; } catch (SecurityException secex) { exception = secex; } catch (UnauthorizedAccessException unauthex) { exception = unauthex; } catch (XmlException xmlex) { exception = xmlex; } return(false); }
/// <summary> /// Creates an empty settings file at the given path. /// </summary> /// <param name="path">The path to the document to create.</param> /// <param name="exception">If the document could not be created, this returns the /// resulting exception information.</param> /// <returns>Returns the document if it was successfully saved.</returns> private WritableSettings CreateSettingsDocument(string path, out Exception exception) { Param.AssertValidString(path, "path"); exception = null; try { XmlDocument document = WritableSettings.NewDocument(); document.Save(path); // Get the last write time for the file. DateTime writeTime = File.GetLastWriteTime(path); return(new WritableSettings(this.Core, path, Path.GetDirectoryName(path), document, writeTime)); } catch (ArgumentException argex) { exception = argex; } catch (IOException ioex) { exception = ioex; } catch (SecurityException secex) { exception = secex; } catch (UnauthorizedAccessException unauthex) { exception = unauthex; } catch (XmlException xmlex) { exception = xmlex; } return(null); }
/// <summary> /// The control must be initialized by calling this method during the host's OnLoad event. /// </summary> /// <param name="hostInstance"> /// Interface implemented by the host object. /// </param> /// <param name="propertyPages"> /// The array of pages to display on the tab control. /// </param> /// <param name="settings"> /// The settings to read from and write to. /// </param> /// <param name="coreInstance"> /// The StyleCop core instance. /// </param> /// <param name="contextItem"> /// The context for the property control. /// </param> internal void Initialize( IPropertyControlHost hostInstance, IList<IPropertyControlPage> propertyPages, WritableSettings settings, StyleCopCore coreInstance, params object[] contextItem) { Param.AssertNotNull(hostInstance, "hostInstance"); Param.Assert(propertyPages != null && propertyPages.Count > 0, "propertyPages", "Cannot be null or empty"); Param.AssertNotNull(settings, "settings"); Param.AssertNotNull(coreInstance, "coreInstance"); Param.Ignore(contextItem); // Make sure we haven't already been intialized. if (this.host != null) { throw new StyleCopException(Strings.PropertyControlAlreadyInitialized); } this.host = hostInstance; this.pageInterfaces = propertyPages; this.localSettings = settings; this.core = coreInstance; this.context = contextItem; // Set the contents of the parent settings file. SettingsMerger merger = new SettingsMerger(this.localSettings, this.core.Environment); this.parentSettings = merger.ParentMergedSettings; this.mergedSettings = merger.MergedSettings; // Set up the settings comparer. this.settingsComparer = new SettingsComparer(this.localSettings, this.parentSettings); // Make sure the context is non-null. if (this.context == null) { this.context = new object[] { }; } this.tabPages = new TabPage[propertyPages.Count]; this.pages = new UserControl[propertyPages.Count]; // Add each of the property pages. int pageCount = 0; // Initialize the settings pages. for (int i = 0; i < propertyPages.Count; ++i) { this.pages[pageCount] = (UserControl)this.pageInterfaces[i]; TabPage tabPage = new TabPage(this.pageInterfaces[i].TabName); this.tabPages[pageCount] = tabPage; tabPage.Controls.Add(this.pages[i]); this.Controls.Add(tabPage); this.pages[i].Dock = DockStyle.Fill; this.SizePage(i); // The first page has already been initialized. this.pageInterfaces[i].Initialize(this); ++pageCount; } // Activate the first page. if (this.TabPages[0] != null) { this.SelectedTab = this.tabPages[0]; this.pageInterfaces[0].Activate(true); } this.SizeChanged += this.OnSizeChanged; }
/// <summary> /// Sets the given property on the add-in. /// </summary> /// <param name="settings">The settings.</param> /// <param name="property">The property to set.</param> public void SetSetting(WritableSettings settings, PropertyValue property) { Param.RequireNotNull(settings, "settings"); Param.RequireNotNull(property, "property"); settings.SetAddInSetting(this, property); }
/// <summary> /// Saves the settings document at the path specified within the document. /// </summary> /// <param name="settings"> /// The settings to save. /// </param> /// <returns> /// Returns true if the document was successfully saved. /// </returns> public bool SaveSettings(WritableSettings settings) { Param.Ignore(settings); Exception exception; return this.SaveSettings(settings, out exception); }
public abstract bool SaveSettings(WritableSettings settings, out Exception exception);
/// <summary> /// Initializes a new instance of the PropertyDialog class. /// </summary> /// <param name="pages"> /// The array of pages to display on the property control. /// </param> /// <param name="settingsFile"> /// The file that contains the settings being edited. /// </param> /// <param name="id"> /// A unique ID that describes this set of property pages. /// </param> /// <param name="core"> /// The StyleCop core instance. /// </param> /// <param name="helpCallback"> /// Callback method for help, or null for no help. /// </param> /// <param name="context"> /// The context to the send to the property page control. /// </param> public PropertyDialog(IList<IPropertyControlPage> pages, WritableSettings settingsFile, string id, StyleCopCore core, Help helpCallback, params object[] context) { Param.Assert(pages != null && pages.Count > 0, "pages", "Cannot be null or empty"); Param.Assert(settingsFile != null && settingsFile.Loaded, "settingsFile", "The settings file must be loaded."); Param.AssertValidString(id, "id"); Param.AssertNotNull(core, "core"); Param.Ignore(helpCallback); Param.Ignore(context); this.pages = pages; this.settingsFile = settingsFile; this.id = id; this.core = core; this.helpCallback = helpCallback; this.context = context; this.InitializeComponent(); this.core.Registry.RestoreWindowPosition(this.id, this, this.Location, this.Size); }
/// <summary> /// Displays a settings dialog for a project. /// </summary> /// <param name="settings">The settings manager.</param> /// <param name="pages">The list of pages to display on the settings dialog.</param> /// <param name="id">A unique identifier string for the property page group.</param> /// <returns>Returns true if at least one settings change was made.</returns> internal bool ShowProjectSettings( WritableSettings settings, IList<IPropertyControlPage> pages, string id) { Param.AssertNotNull(settings, "settings"); Param.AssertNotNull(pages, "pages"); Param.AssertValidString(id, "id"); // Create the properties dialog object. using (PropertyDialog properties = new PropertyDialog(pages, settings, id, this, null)) { string styleCopTitleText = settings.DefaultSettings ? Strings.SettingsDialogTitleDefault : Strings.SettingsDialogTitleLocal; styleCopTitleText = string.Format(styleCopTitleText, this.VersionNumberMajorMinor + " (" + this.VersionNumberFull + ")"); // Set the dialog title. properties.Text = string.Format(Strings.SettingsDialogTitleFormat, styleCopTitleText, settings.Location); // Make sure that we're not running in a non-UI mode. if (!this.displayUI) { throw new InvalidOperationException(Strings.CannotDisplaySettingsInNonUIMode); } // Show the dialog. properties.ShowDialog(); // Always fire the event regardless of whether any settings were changed. This ensures // that everything is always updated properly when settings change. this.OnProjectSettingsChanged(new EventArgs()); // Return true if one or more properties were changed. return properties.SettingsChanged; } }
/// <summary> /// The control must be initialized by calling this method during the host's OnLoad event. /// </summary> /// <param name="hostInstance">Interface implemented by the host object.</param> /// <param name="propertyPages">The array of pages to display on the tab control.</param> /// <param name="settings">The settings to read from and write to.</param> /// <param name="coreInstance">The StyleCop core instance.</param> /// <param name="contextItem">The context for the property control.</param> internal void Initialize( IPropertyControlHost hostInstance, IList <IPropertyControlPage> propertyPages, WritableSettings settings, StyleCopCore coreInstance, params object[] contextItem) { Param.AssertNotNull(hostInstance, "hostInstance"); Param.Assert(propertyPages != null && propertyPages.Count > 0, "propertyPages", "Cannot be null or empty"); Param.AssertNotNull(settings, "settings"); Param.AssertNotNull(coreInstance, "coreInstance"); Param.Ignore(contextItem); // Make sure we haven't already been intialized. if (this.host != null) { throw new StyleCopException(Strings.PropertyControlAlreadyInitialized); } this.host = hostInstance; this.pageInterfaces = propertyPages; this.localSettings = settings; this.core = coreInstance; this.context = contextItem; // Set the contents of the parent settings file. SettingsMerger merger = new SettingsMerger(this.localSettings, this.core.Environment); this.parentSettings = merger.ParentMergedSettings; this.mergedSettings = merger.MergedSettings; // Set up the settings comparer. this.settingsComparer = new SettingsComparer(this.localSettings, this.parentSettings); // Make sure the context is non-null. if (this.context == null) { this.context = new object[] { }; } this.tabPages = new TabPage[propertyPages.Count]; this.pages = new UserControl[propertyPages.Count]; // Add each of the property pages. int pageCount = 0; // Initialize the settings pages. for (int i = 0; i < propertyPages.Count; ++i) { this.pages[pageCount] = (UserControl)this.pageInterfaces[i]; TabPage tabPage = new TabPage(this.pageInterfaces[i].TabName); this.tabPages[pageCount] = tabPage; tabPage.Controls.Add(this.pages[i]); this.Controls.Add(tabPage); this.pages[i].Dock = DockStyle.Fill; this.SizePage(i); // The first page has already been initialized. this.pageInterfaces[i].Initialize(this); ++pageCount; } // Activate the first page. if (this.TabPages[0] != null) { this.SelectedTab = this.tabPages[0]; this.pageInterfaces[0].Activate(true); } this.SizeChanged += new System.EventHandler(this.OnSizeChanged); }
/// <summary> /// Clears the given property for the add-in. /// </summary> /// <param name="settings">The settings.</param> /// <param name="propertyName">The name of the property to clear.</param> public void ClearSetting(WritableSettings settings, string propertyName) { Param.RequireNotNull(settings, "settings"); Param.RequireValidString(propertyName, "propertyName"); settings.ClearAddInSetting(this, propertyName); }
/// <summary> /// Saves the settings file at the path specified within the settings document. /// </summary> /// <param name="settings"> /// The settings to save. /// </param> /// <param name="exception"> /// If the document could not be saved, this returns the /// resulting exception information. /// </param> /// <returns> /// Returns true if the file was successfully saved. /// </returns> public override bool SaveSettings(WritableSettings settings, out Exception exception) { Param.Ignore(settings); // The default object-based environment does not support the ability to save modified settings. exception = new NotSupportedException(); return false; }
public XmlDocument WriteSettingsToDocument(StyleCopEnvironment environment) { Param.RequireNotNull(environment, "environment"); // Create a new document for the settings. XmlDocument document = WritableSettings.NewDocument(); // Get the parent settings if there are any. SettingsMerger merger = new SettingsMerger(this, environment); Settings parentSettings = merger.ParentMergedSettings; // Add the global settings if there are any. if (this.GlobalSettings != null && this.GlobalSettings.Count > 0) { // Get the global settings from the parent. PropertyCollection parentGlobalSettings = null; if (parentSettings != null) { parentGlobalSettings = parentSettings.GlobalSettings; } SavePropertyCollection(document.DocumentElement, "GlobalSettings", this.GlobalSettings, parentGlobalSettings, true, null); } // Add the parser settings if there are any. if (this.ParserSettings.Count > 0) { bool parserSettingsAdded = false; XmlElement parsersNode = document.CreateElement("Parsers"); foreach (AddInPropertyCollection parserSettings in this.ParserSettings) { // Add the settings for this parser if there are any. if (parserSettings.Count > 0) { // Create a node for this parser. XmlElement parserNode = document.CreateElement("Parser"); XmlAttribute parserIdAttribute = document.CreateAttribute("ParserId"); parserIdAttribute.Value = parserSettings.AddIn.Id; parserNode.Attributes.Append(parserIdAttribute); // Get the parser settings from the parent. PropertyCollection parentParserSettings = null; if (parentSettings != null) { parentParserSettings = parentSettings.GetAddInSettings(parserSettings.AddIn); } if (SavePropertyCollection(parserNode, "ParserSettings", parserSettings, parentParserSettings, true, null)) { parsersNode.AppendChild(parserNode); parserSettingsAdded = true; } } } if (parserSettingsAdded) { document.DocumentElement.AppendChild(parsersNode); } } // Add the analyzer settings if there are any. if (this.AnalyzerSettings.Count > 0) { bool analyzerSettingsAdded = false; XmlElement analyzersNode = document.CreateElement("Analyzers"); foreach (AddInPropertyCollection analyzerSettings in this.AnalyzerSettings) { // Add the settings for this analyzer if there are any. if (analyzerSettings.Count > 0) { // Create a node for this analzyer. XmlElement analyzerNode = document.CreateElement("Analyzer"); XmlAttribute analyzerIdAttribute = document.CreateAttribute("AnalyzerId"); analyzerIdAttribute.Value = analyzerSettings.AddIn.Id; analyzerNode.Attributes.Append(analyzerIdAttribute); // Get the analyzer settings from the parent. PropertyCollection parentAnalyzerSettings = null; if (parentSettings != null) { parentAnalyzerSettings = parentSettings.GetAddInSettings(analyzerSettings.AddIn); } if (SavePropertyCollection(analyzerNode, "AnalyzerSettings", analyzerSettings, parentAnalyzerSettings, true, null)) { analyzersNode.AppendChild(analyzerNode); analyzerSettingsAdded = true; } } } if (analyzerSettingsAdded) { document.DocumentElement.AppendChild(analyzersNode); } } return(document); }
/// <summary> /// Saves the settings file at the path specified within the settings document. /// </summary> /// <param name="settings">The settings to save.</param> /// <param name="exception">If the document could not be saved, this returns the /// resulting exception information.</param> /// <returns>Returns true if the file was successfully saved.</returns> public override bool SaveSettings(WritableSettings settings, out Exception exception) { Param.RequireNotNull(settings, "settings"); exception = null; if (settings.Path == null || settings.Contents == null) { throw new InvalidOperationException(Strings.SettingsFileHasNotBeenLoaded); } // Write the new settings to the document. XmlDocument document = settings.WriteSettingsToDocument(this); try { // Save the file. document.Save(settings.Path); // Update the write time. settings.WriteTime = File.GetLastWriteTime(settings.Path); return true; } catch (IOException ioex) { exception = ioex; } catch (SecurityException secex) { exception = secex; } catch (UnauthorizedAccessException unauthex) { exception = unauthex; } catch (XmlException xmlex) { exception = xmlex; } return false; }
/// <summary> /// Displays a settings dialog for a project. /// </summary> /// <param name="settings">The settings manager.</param> /// <param name="pages">The list of pages to display on the settings dialog.</param> /// <param name="caption">The caption for the dialog.</param> /// <param name="id">A unique identifier string for the property page group.</param> /// <returns>Returns true if at least one settings change was made.</returns> internal bool ShowProjectSettings( WritableSettings settings, IList<IPropertyControlPage> pages, string caption, string id) { Param.AssertNotNull(settings, "settings"); Param.AssertNotNull(pages, "pages"); Param.AssertValidString(caption, "caption"); Param.AssertValidString(id, "id"); // Create the properties dialog object. using (PropertyDialog properties = new PropertyDialog(pages, settings, id, this, null)) { // Set the dialog title. properties.Text = caption; // Make sure that we're not running in a non-UI mode. if (!this.displayUI) { throw new InvalidOperationException(Strings.CannotDisplaySettingsInNonUIMode); } // Show the dialog. properties.ShowDialog(); // Always fire the event regardless of whether any settings were changed. This ensures // that everything is always updated properly when settings change. this.OnProjectSettingsChanged(new EventArgs()); // Return true if one or more properties were changed. return properties.SettingsChanged; } }