示例#1
0
 public PropertyDialog(IList<IPropertyControlPage> pages, WritableSettings settingsFile, string id, StyleCopCore core, Help helpCallback, params object[] 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, base.Location, base.Size);
 }
示例#2
0
        /// <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);
        }
示例#3
0
        /// <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);
        }
示例#4
0
        /// <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>
        /// 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;
        }
 public bool SaveSettings(WritableSettings settings)
 {
     Exception exception;
     return this.SaveSettings(settings, out exception);
 }
 public abstract bool SaveSettings(WritableSettings settings, out Exception exception);
示例#8
0
        /// <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;
            }
        }
        /// <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>
        /// 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);
        }
        /// <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;
        }
示例#12
0
 internal bool ShowProjectSettings(WritableSettings settings, IList<IPropertyControlPage> pages, string caption, string id)
 {
     PropertyDialog dialog = new PropertyDialog(pages, settings, id, this, null, new object[0]);
     dialog.Text = caption;
     if (!this.displayUI)
     {
         throw new InvalidOperationException(Strings.CannotDisplaySettingsInNonUIMode);
     }
     dialog.ShowDialog();
     this.OnProjectSettingsChanged(new EventArgs());
     return dialog.SettingsChanged;
 }
 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);
     }
     XmlDocument document = settings.WriteSettingsToDocument(this);
     try
     {
         document.Save(settings.Path);
         settings.WriteTime = File.GetLastWriteTime(settings.Path);
         return true;
     }
     catch (IOException exception2)
     {
         exception = exception2;
     }
     catch (SecurityException exception3)
     {
         exception = exception3;
     }
     catch (UnauthorizedAccessException exception4)
     {
         exception = exception4;
     }
     catch (XmlException exception5)
     {
         exception = exception5;
     }
     return false;
 }