private void PropertiesViewModelHandler(object sender, PropertyChangedEventArgs e) { if (e.PropertyName != "SelectedLayerType") { return; } // Store the brush in case the user wants to reuse it var oldBrush = ProposedLayer.Properties.Brush; // Update the model if (ProposedLayer.LayerType.GetType() != SelectedLayerType.GetType()) { ProposedLayer.LayerType = SelectedLayerType; ProposedLayer.SetupProperties(); } // Let the layer type handle the viewmodel setup LayerPropertiesViewModel = ProposedLayer.LayerType.SetupViewModel(this, LayerPropertiesViewModel); if (oldBrush != null) { ProposedLayer.Properties.Brush = oldBrush; } NotifyOfPropertyChange(() => LayerPropertiesViewModel); }
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); }
private void PropertiesViewModelHandler(object sender, PropertyChangedEventArgs e) { if (e.PropertyName != "LayerType") { return; } // Store the brush in case the user wants to reuse it var oldBrush = LayerPropertiesViewModel?.GetAppliedProperties().Brush; // Update the model if (ProposedLayer.LayerType != LayerType) { ProposedLayer.LayerType = LayerType; ProposedLayer.SetupProperties(); } if (oldBrush != null) { ProposedLayer.Properties.Brush = oldBrush; } // Update the KeyboardPropertiesViewModel if it's being used var model = LayerPropertiesViewModel as KeyboardPropertiesViewModel; if (model != null) { model.IsGif = LayerType == LayerType.KeyboardGif; } // Apply the proper PropertiesViewModel if ((LayerType == LayerType.Keyboard || LayerType == LayerType.KeyboardGif) && !(LayerPropertiesViewModel is KeyboardPropertiesViewModel)) { LayerPropertiesViewModel = new KeyboardPropertiesViewModel(_dataModel, ProposedLayer.Properties) { IsGif = LayerType == LayerType.KeyboardGif }; } else if (LayerType == LayerType.Mouse && !(LayerPropertiesViewModel is MousePropertiesViewModel)) { LayerPropertiesViewModel = new MousePropertiesViewModel(_dataModel, ProposedLayer.Properties); } else if (LayerType == LayerType.Headset && !(LayerPropertiesViewModel is HeadsetPropertiesViewModel)) { LayerPropertiesViewModel = new HeadsetPropertiesViewModel(_dataModel, ProposedLayer.Properties); } else if (LayerType == LayerType.Folder && !(LayerPropertiesViewModel is FolderPropertiesViewModel)) { LayerPropertiesViewModel = new FolderPropertiesViewModel(_dataModel, ProposedLayer.Properties); } NotifyOfPropertyChange(() => LayerPropertiesViewModel); }