Ejemplo n.º 1
0
        public override async void CanClose(Action <bool> callback)
        {
            // Create a fake layer and apply the properties to it
            LayerPropertiesViewModel?.ApplyProperties();
            // TODO: EventPropVM must have layer too
            if (EventPropertiesViewModel != null)
            {
                ProposedLayer.EventProperties = EventPropertiesViewModel.GetAppliedProperties();
            }

            ProposedLayer.Properties.Conditions.Clear();
            foreach (var conditionViewModel in LayerConditionVms)
            {
                ProposedLayer.Properties.Conditions.Add(conditionViewModel.ConditionModel);
            }

            ProposedLayer.Properties.LayerKeybindModels.Clear();
            foreach (var layerKeybindViewModel in LayerKeybindVms)
            {
                ProposedLayer.Properties.LayerKeybindModels.Add(layerKeybindViewModel.LayerKeybindModel);
            }

            // Ignore this property as it isn't user input
            ProposedLayer.RenderAllowed = Layer.RenderAllowed;

            // If not a keyboard, ignore size and position
            if ((ProposedLayer.LayerType.DrawType != DrawType.Keyboard) || !ProposedLayer.LayerType.ShowInEdtor)
            {
                ProposedLayer.Properties.Width   = Layer.Properties.Width;
                ProposedLayer.Properties.Height  = Layer.Properties.Height;
                ProposedLayer.Properties.X       = Layer.Properties.X;
                ProposedLayer.Properties.Y       = Layer.Properties.Y;
                ProposedLayer.Properties.Contain = Layer.Properties.Contain;
            }

            // Ignore the children, can't just temporarily add them to the proposed layer because
            // that would upset the child layers' relations (sounds like Dr. Phil amirite?)
            var currentObj = GeneralHelpers.Clone(Layer);

            currentObj.Children.Clear();

            // Apply the IsEvent boolean
            currentObj.SetupCondition();
            ProposedLayer.SetupCondition();

            var current  = JsonConvert.SerializeObject(currentObj, Formatting.Indented);
            var proposed = JsonConvert.SerializeObject(ProposedLayer, Formatting.Indented);

            if (current.Equals(proposed))
            {
                callback(true);
                return;
            }

            var close = await DialogService.ShowQuestionMessageBox("Unsaved changes", "Do you want to discard your changes?");

            callback(close.Value);
        }