Base class for most NodeXL's user settings classes.
This is the base class for all of NodeXL's user settings classes except those used to save dialog positions, which are derived from .

This class saves user settings to the workbook so that the settings travel with the workbook. It does this by intercepting calls to the property, the Save method, and the method. Within each intercept, the workbook settings are copied to the file that the base class uses to store settings, the base class is allowed to do its usual work on the file, and if appropriate, the file is then copied back to the workbook settings. The net result is that the base class effectively reads and writes the workbook settings. The actual file settings are used by NodeXL only when a new workbook is created.

This is much easier than creating a custom settings provider, which is not well documented and far from trivial. That's especially true when settings groups are used, as they are in NodeXL.

In this class, the file that the base class uses to store settings is called the "standard settings file", and the settings stored in the workbook are called the "workbook settings."

Inheritance: System.Configuration.ApplicationSettingsBase
Ejemplo n.º 1
0
        btnOptions_Click
        (
            object sender,
            EventArgs e
        )
        {
            AssertValid();

            // These are shared by several cases below.

            Form oUserSettingsDialog = null;
            NodeXLApplicationSettingsBase oUserSettings = null;

            switch ((AutomationTasks)clbTasksToRun.SelectedValue)
            {
            case AutomationTasks.MergeDuplicateEdges:

                oUserSettings = new MergeDuplicateEdgesUserSettings();

                oUserSettingsDialog =
                    new MergeDuplicateEdgesUserSettingsDialog(
                        MergeDuplicateEdgesUserSettingsDialog.DialogMode.EditOnly,
                        (MergeDuplicateEdgesUserSettings)oUserSettings,
                        m_oThisWorkbook.InnerObject);

                break;

            case AutomationTasks.CalculateClusters:

                oUserSettings = new ClusterUserSettings();

                oUserSettingsDialog = new ClusterUserSettingsDialog(
                    ClusterUserSettingsDialog.DialogMode.EditOnly,
                    (ClusterUserSettings)oUserSettings);

                break;

            case AutomationTasks.CalculateGraphMetrics:

                (new GraphMetricsDialog(
                     GraphMetricsDialog.DialogMode.EditOnly,
                     m_oThisWorkbook.InnerObject)).ShowDialog();

                break;

            case AutomationTasks.AutoFillWorkbook:

                // ThisWorkbook manages the modeless AutoFillWorkbookDialog, so
                // tell ThisWorkbook to open the dialog.

                m_oThisWorkbook.AutoFillWorkbook(
                    AutoFillWorkbookDialog.DialogMode.EditOnly);

                break;

            case AutomationTasks.CreateSubgraphImages:

                (new CreateSubgraphImagesDialog(
                     CreateSubgraphImagesDialog.DialogMode.EditOnly, null,
                     null)).ShowDialog();

                break;

            case AutomationTasks.ReadWorkbook:

                oUserSettings = new GeneralUserSettings();

                oUserSettingsDialog = new GeneralUserSettingsDialog(
                    (GeneralUserSettings)oUserSettings,
                    m_oThisWorkbook.InnerObject);

                break;

            case AutomationTasks.SaveWorkbookIfNeverSaved:

                EditFolderToSaveWorkbookTo();

                break;

            case AutomationTasks.SaveGraphImageFile:

                oUserSettings = new AutomatedGraphImageUserSettings();

                oUserSettingsDialog =
                    new AutomatedGraphImageUserSettingsDialog(
                        (AutomatedGraphImageUserSettings)oUserSettings);

                break;

            case AutomationTasks.ExportToNodeXLGraphGallery:

                (new ExportToNodeXLGraphGalleryDialog(
                     ExportToNodeXLGraphGalleryDialog.DialogMode.EditOnly,
                     m_oThisWorkbook.InnerObject, null)).ShowDialog();

                break;

            case AutomationTasks.ExportToEmail:

                (new ExportToEmailDialog(
                     ExportToEmailDialog.DialogMode.EditOnly,
                     m_oThisWorkbook.InnerObject, null)).ShowDialog();

                break;

            default:

                Debug.Assert(false);
                break;
            }

            if (oUserSettingsDialog != null)
            {
                Debug.Assert(oUserSettings != null);

                if (oUserSettingsDialog.ShowDialog() == DialogResult.OK)
                {
                    oUserSettings.Save();
                }
            }
        }