Example #1
0
        /// <summary>
        /// Use this to get a save config token. You should already know the filename and file type.
        /// An existing save config token is optional and will be used to pre-populate the config dialog.
        /// </summary>
        /// <param name="fileType"></param>
        /// <param name="saveConfigToken"></param>
        /// <param name="newSaveConfigToken"></param>
        /// <returns>false if the user cancelled, otherwise true</returns>
        private bool GetSaveConfigToken(
            FileType currentFileType, 
            SaveConfigToken currentSaveConfigToken, 
            out SaveConfigToken newSaveConfigToken, 
            Surface saveScratchSurface)
        {
            if (currentFileType.SupportsConfiguration)
            {
                using (SaveConfigDialog scd = new SaveConfigDialog())
                {
                    scd.ScratchSurface = saveScratchSurface;

                    ProgressEventHandler peh = delegate(object sender, ProgressEventArgs e)
                    {
                        if (e.Percent < 0 || e.Percent >= 100)
                        {
                            AppWorkspace.Widgets.StatusBarProgress.ResetProgressStatusBar();
                            AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBar();
                        }
                        else
                        {
                            AppWorkspace.Widgets.StatusBarProgress.SetProgressStatusBar(e.Percent);
                        }
                    };

                    //if (currentFileType.SavesWithProgress)
                    {
                        scd.Progress += peh;
                    }

                    scd.Document = Document;
                    scd.FileType = currentFileType;

                    SaveConfigToken token = currentFileType.GetLastSaveConfigToken();
                    if (currentSaveConfigToken != null &&
                        token.GetType() == currentSaveConfigToken.GetType())
                    {
                        scd.SaveConfigToken = currentSaveConfigToken;
                    }

                    scd.EnableInstanceOpacity = false;

                    // show configuration/preview dialog
                    DialogResult dr = scd.ShowDialog(this);

                    //if (currentFileType.SavesWithProgress)
                    {
                        scd.Progress -= peh;
                        AppWorkspace.Widgets.StatusBarProgress.ResetProgressStatusBar();
                        AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBar();
                    }

                    if (dr == DialogResult.OK)
                    {
                        newSaveConfigToken = scd.SaveConfigToken;
                        return true;
                    }
                    else
                    {
                        newSaveConfigToken = null;
                        return false;
                    }
                }
            }
            else
            {
                newSaveConfigToken = currentFileType.GetLastSaveConfigToken();
                return true;
            }
        }