Ejemplo n.º 1
0
        /// <summary>
        /// Called when the user clicks the Apply button.
        /// </summary>
        /// <param name="sender">
        /// The event sender.
        /// </param>
        /// <param name="e">
        /// The event arguments.
        /// </param>
        private void ApplyClick(object sender, EventArgs e)
        {
            Param.Ignore(sender, e);

            bool changed;
            PropertyControlSaveResult result = this.properties.Apply(out changed);

            if (changed)
            {
                this.settingsChanged = true;
            }

            // The dialog is closed when an error occurs while saving the settings.
            // This can result in an undesirable user experience, since the settings
            // changes may be lost when a save error occurs, however, this is the best
            // solution for now until the property pages can recover from a save error
            // and save themselves properly a second or third time.
            if (result == PropertyControlSaveResult.SaveError)
            {
                this.Close();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called when the user clicks the OK button.
        /// </summary>
        /// <param name="sender">
        /// The event sender.
        /// </param>
        /// <param name="e">
        /// The event arguments.
        /// </param>
        private void OkClick(object sender, EventArgs e)
        {
            Param.Ignore(sender, e);

            bool changed;
            PropertyControlSaveResult result = this.properties.Apply(out changed);

            if (changed)
            {
                this.settingsChanged = true;
            }

            // The dialog is closed whenever the settings were successfully saved,
            // or when an error occurred while saving the settings. This can result
            // in an undesirable user experience, since the settings changes may
            // be lost when a save error occurs, however, this is the best solution
            // for now until the property pages can recover from a save error and
            // save themselves properly a second or third time.
            if (result == PropertyControlSaveResult.Success)
            {
                this.Close();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Applies the data on the property pages.
        /// </summary>
        /// <param name="dirtyPages">Returns true if any pages were dirty.</param>
        /// <returns>Returns false if any page returned false from it's apply call, in which case
        /// the apply failed.</returns>
        internal PropertyControlSaveResult Apply(out bool dirtyPages)
        {
            dirtyPages = false;

            // Call the apply method for each of the pages.
            PropertyControlSaveResult result = PropertyControlSaveResult.Success;
            bool cancel = false;

            bool[] pageDirtyState = new bool[this.pageInterfaces.Count];

            // Pre-apply the pages.
            for (int i = 0; i < this.pageInterfaces.Count; ++i)
            {
                if (this.pageInterfaces[i] != null)
                {
                    pageDirtyState[i] = this.pageInterfaces[i].Dirty;
                    if (!this.pageInterfaces[i].PreApply())
                    {
                        cancel = true;
                        break;
                    }
                }
            }

            if (!cancel)
            {
                // Apply the pages.
                int breakIndex = -1;
                for (int i = 0; i < this.pageInterfaces.Count; ++i)
                {
                    if (this.pageInterfaces[i] != null && this.pageInterfaces[i].Dirty)
                    {
                        dirtyPages = true;

                        if (!this.pageInterfaces[i].Apply())
                        {
                            result     = PropertyControlSaveResult.PageAbort;
                            breakIndex = i;
                            break;
                        }
                    }
                }

                // Post-apply the pages.
                int lastIndex = breakIndex == -1 ? this.pageInterfaces.Count - 1 : breakIndex;
                for (int i = 0; i <= lastIndex; ++i)
                {
                    if (this.pageInterfaces[i] != null)
                    {
                        this.pageInterfaces[i].PostApply(pageDirtyState[i]);
                    }
                }

                if (breakIndex == -1)
                {
                    // Save the settings files.
                    Exception exception = null;
                    if (!this.core.Environment.SaveSettings(this.localSettings, out exception))
                    {
                        AlertDialog.Show(
                            this.core,
                            this,
                            string.Format(CultureInfo.CurrentUICulture, Strings.CouldNotSaveSettingsFile, exception.Message),
                            Strings.Title,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);

                        result = PropertyControlSaveResult.SaveError;

                        // Reset the dirty flag on each page.
                        for (int i = 0; i < this.pageInterfaces.Count; ++i)
                        {
                            if (this.pageInterfaces[i] != null)
                            {
                                this.pageInterfaces[i].Dirty = pageDirtyState[i];
                            }
                        }
                    }
                    else
                    {
                        this.dirty = false;
                        this.host.Dirty(false);
                    }
                }
            }

            return(result);
        }