Example #1
0
        /// <summary>
        /// Generates script when going to Script tab, and prevents returning to Transform tab without a confirmation to lose changes.
        /// </summary>
        private void Items_CurrentChanging(object sender, CurrentChangingEventArgs e)
        {
            if (string.IsNullOrEmpty(encodeSettings.FilePath))
            {
                return;
            }

            SettingsTab.Focus();
            var  item   = ((ICollectionView)sender).CurrentItem;
            bool Cancel = false;

            // Generate script when going to Script tab.
            if (SettingsTab.SelectedIndex == 2 && string.IsNullOrEmpty(encodeSettings.CustomScript))
            {
                if (Validate())
                {
                    business.GenerateCustomScript(encodeSettings);
                }
                else
                {
                    Cancel = true;
                }
            }
            else if (SettingsTab.SelectedIndex == 0 && !string.IsNullOrEmpty(encodeSettings.CustomScript))
            {
                // Ask for confirmation before going back to Transform tab and losing changes.
                if (business.CustomScriptHasChanges(encodeSettings))
                {
                    if (MessageBox.Show("You will lose any changes to your script. Are you sure?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No)
                    {
                        Cancel = true;
                    }
                }
                if (!Cancel)
                {
                    encodeSettings.CustomScript = null;
                }
            }

            // Revert to previously-selected tab.
            if (Cancel)
            {
                e.Cancel = true;
                SettingsTab.SelectedItem = item;
            }
        }