예제 #1
0
        void HandleDeleteOptionsShow(Windows.DeleteOptionsWindow deleteWindow, object objectToDelete)
        {
            var objectAsInstance = objectToDelete as InstanceSave;

            if (objectAsInstance != null)
            {
                var parentContainer = objectAsInstance.ParentContainer;

                var allVariables = parentContainer.AllStates.SelectMany(item => item.Variables);
                var instanceName = objectAsInstance.Name;

                var anyVariableSetsParentToThis = allVariables.Any(item =>
                                                                   item.SetsValue &&
                                                                   item.Value != null &&
                                                                   item.Value is string &&
                                                                   (string)item.Value == instanceName &&
                                                                   item.GetRootName() == "Parent");

                if (anyVariableSetsParentToThis)
                {
                    deleteWindow.MainStackPanel.Children.Add(deleteGroupBox);

                    deleteJustParent.IsChecked          = true;
                    deleteAllContainedObjects.IsChecked = false;
                }
            }

            if (objectToDelete is InstanceSave == false)
            {
                deleteWindow.MainStackPanel.Children.Add(deleteXmlCheckBox);
                deleteXmlCheckBox.Content = "Delete XML file";
                deleteXmlCheckBox.Width   = 220;
            }
        }
예제 #2
0
        void HandleDeleteConfirm(Windows.DeleteOptionsWindow deleteOptionsWindow, object deletedObject)
        {
            var asInstance = deletedObject as InstanceSave;

            if (asInstance != null)
            {
                PerformInstanceDeleteLogic(asInstance);
            }

            if (deleteXmlCheckBox.IsChecked == true)
            {
                string fileName = GetFileNameForObject(deletedObject);

                if (!string.IsNullOrEmpty(fileName) && System.IO.File.Exists(fileName))
                {
                    try
                    {
                        System.IO.File.Delete(fileName);
                    }
                    catch
                    {
                        System.Windows.Forms.MessageBox.Show("Could not delete the file\n" + fileName);
                    }
                }
            }

            if (deleteOptionsWindow.MainStackPanel.Children.Contains(deleteXmlCheckBox))
            {
                deleteOptionsWindow.MainStackPanel.Children.Remove(deleteXmlCheckBox);
            }

            if (deleteOptionsWindow.MainStackPanel.Children.Contains(deleteGroupBox))
            {
                deleteOptionsWindow.MainStackPanel.Children.Remove(deleteGroupBox);
            }
        }