diff --git a/ANAConversationStudio/Controls/ChatContentCollectionControl.cs b/ANAConversationStudio/Controls/ChatContentCollectionControl.cs index cbc86ef..d31c77a 100644 --- a/ANAConversationStudio/Controls/ChatContentCollectionControl.cs +++ b/ANAConversationStudio/Controls/ChatContentCollectionControl.cs @@ -65,49 +65,84 @@ public object ChatContentOwner public ChatContentCollectionControl() { ItemAdding += ItemAddingEventHandler; - ItemAdded += ItemAddedEventHandler; - ItemDeleted += ItemDeletedEventHandler; + //ItemAdded += ItemAddedEventHandler; + //ItemDeleted += ItemDeletedEventHandler; + Items.CollectionChanged += Items_CollectionChanged; } - private void ItemDeletedEventHandler(object sender, ItemEventArgs e) + private void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { - var c = e.Item as BaseContent; - var content = MongoHelper.Current.Contents.FirstOrDefault(x => x._id == c._id); - if (content != null) - MongoHelper.Current.Contents.Remove(content); + switch (e.Action) + { + case System.Collections.Specialized.NotifyCollectionChangedAction.Add: + if (e.NewItems?.Count > 0) + { + var contentItem = e.NewItems.Cast().First(); + MongoHelper.Current.Contents.Add(contentItem as BaseContent); + } + break; + case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: + if (e.OldItems?.Count > 0) + { + var c = e.OldItems.Cast().First() as BaseContent; + var content = MongoHelper.Current.Contents.FirstOrDefault(x => x._id == c._id); + if (content != null) + MongoHelper.Current.Contents.Remove(content); + } + break; + default: + break; + } } - private void ItemAddedEventHandler(object sender, ItemEventArgs e) - { - MongoHelper.Current.Contents.Add(e.Item as BaseContent); - } + //private void ItemDeletedEventHandler(object sender, ItemEventArgs e) + //{ + // var c = e.Item as BaseContent; + // var content = MongoHelper.Current.Contents.FirstOrDefault(x => x._id == c._id); + // if (content != null) + // MongoHelper.Current.Contents.Remove(content); + //} + + //private void ItemAddedEventHandler(object sender, ItemEventArgs e) + //{ + // MongoHelper.Current.Contents.Add(e.Item as BaseContent); + //} private void ItemAddingEventHandler(object sender, ItemAddingEventArgs e) { - var Item = e.Item; + PreProccessAddingItem(e.Item); + } - if (Item is BaseIdEntity) - (Item as BaseIdEntity)._id = ObjectId.GenerateNewId().ToString(); - if (Item is BaseEntity) - (Item as BaseEntity).Alias = "New " + Item.GetType().Name; + public void PreProccessAddingItem(object item) + { + if (item is BaseIdEntity) + (item as BaseIdEntity)._id = ObjectId.GenerateNewId().ToString(); + if (item is BaseEntity) + (item as BaseEntity).Alias = "New " + item.GetType().Name; - if (Item is BaseIdTimeStampEntity) + if (item is BaseIdTimeStampEntity) { - (Item as BaseIdTimeStampEntity).CreatedOn = DateTime.Now; - (Item as BaseIdTimeStampEntity).UpdatedOn = DateTime.Now; + (item as BaseIdTimeStampEntity).CreatedOn = DateTime.Now; + (item as BaseIdTimeStampEntity).UpdatedOn = DateTime.Now; } - if (Item is BaseContent && ParentChatNode != null) - (Item as BaseContent).NodeId = ParentChatNode.Id; + if (item is BaseContent && ParentChatNode != null) + (item as BaseContent).NodeId = ParentChatNode.Id; - if ((Item is SectionContent || Item is ButtonContent) && ChatContentOwner != null) + if ((item is SectionContent || item is ButtonContent) && ChatContentOwner != null) { - if (ChatContentOwner is Section && Item is SectionContent) - (Item as SectionContent).SectionId = (ChatContentOwner as Section)._id; - else if (ChatContentOwner is Button && Item is ButtonContent) - (Item as ButtonContent).ButtonId = (ChatContentOwner as Button)._id; + if (ChatContentOwner is Section && item is SectionContent) + { + (item as SectionContent).SectionId = (ChatContentOwner as Section)._id; + //if (item is TextSectionContent tsItem) + // tsItem.SectionText = (ChatContentOwner as Section).Alias; + } + else if (ChatContentOwner is Button && item is ButtonContent) + { + (item as ButtonContent).ButtonId = (ChatContentOwner as Button)._id; + //(item as ButtonContent).ButtonText = (ChatContentOwner as Button).Alias; + } } } - } } diff --git a/ANAConversationStudio/Controls/ChatNodeCollectionEditor.cs b/ANAConversationStudio/Controls/ChatNodeCollectionEditor.cs index a35a4da..d4a427c 100644 --- a/ANAConversationStudio/Controls/ChatNodeCollectionEditor.cs +++ b/ANAConversationStudio/Controls/ChatNodeCollectionEditor.cs @@ -12,6 +12,7 @@ using Xceed.Wpf.Toolkit.PropertyGrid; using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; using Xceed.Wpf.Toolkit.PropertyGrid.Editors; +using System.Threading.Tasks; namespace ANAConversationStudio.Controls { @@ -44,8 +45,8 @@ protected override void ResolveValueBinding(PropertyItem propertyItem) } _collectionControl.Loaded += _collectionControl_Loaded; - _collectionControl.ItemAdding += ItemAdding; ; - _collectionControl.ItemAdded += ItemCollectionChanged; + _collectionControl.ItemAdding += ItemAdding; + _collectionControl.ItemAdded += ItemAdded; _collectionControl.ItemDeleted += ItemCollectionChanged; _collectionControl.ItemMovedDown += ItemCollectionChanged; _collectionControl.ItemMovedUp += ItemCollectionChanged; @@ -55,10 +56,31 @@ protected override void ResolveValueBinding(PropertyItem propertyItem) { InvalidatePropertyGrid(); MainWindow.Current.NodeCollectionControl = _collectionControl; + if (MainWindow.Current.SectionButtonEditorLayoutAnchorable != null) + MainWindow.Current.SectionButtonEditorLayoutAnchorable.IsActive = true; }; base.ResolveValueBinding(_propertyItem); } + private void ItemAdded(object sender, ItemEventArgs e) + { + InvalidateSource(); + Task.Delay(1000).ContinueWith(async (s) => + { + await App.Current.Dispatcher.InvokeAsync(() => + { + var editor = MainWindow.Current.ChatContentCollectionEditor; + if (editor != null && editor.NewItemTypes?.Count > 0 && editor.Items.Count == 0) + { + var newItem = Activator.CreateInstance(editor.NewItemTypes.First()); + editor.PreProccessAddingItem(newItem); + editor.Items.Add(newItem); + editor.SelectedItem = newItem; + } + }); + }); + } + private void _collectionControl_Loaded(object sender, RoutedEventArgs e) { _collectionControl.PropertyGrid.PropertyValueChanged -= PropertyGrid_PropertyValueChanged; @@ -68,6 +90,21 @@ private void _collectionControl_Loaded(object sender, RoutedEventArgs e) private void PropertyGrid_PropertyValueChanged(object sender, PropertyValueChangedEventArgs e) { InvalidateSource(); + + if ((e.Source as PropertyGrid).SelectedObject is BaseEntity bEntity && (e.OriginalSource is PropertyItem pItem)) + { + if (pItem.PropertyName == nameof(bEntity.Alias)) //If name of the property changed is 'Alias' + { + var editor = MainWindow.Current.ChatContentCollectionEditor; + if (editor.SelectedItem != null) //copy alias to content only when 1 content is present + { + if (editor.SelectedItem is ButtonContent bContent && string.IsNullOrWhiteSpace(bContent.ButtonText)) + bContent.ButtonText = e.NewValue as string; + else if (editor.SelectedItem is TextSectionContent txtContent && string.IsNullOrWhiteSpace(txtContent.SectionText)) + txtContent.SectionText = e.NewValue as string; + } + } + } } private void InvalidatePropertyGrid() { diff --git a/ANAConversationStudio/Models/Chat/BaseContent.cs b/ANAConversationStudio/Models/Chat/BaseContent.cs index de8db4c..7b6c7e3 100644 --- a/ANAConversationStudio/Models/Chat/BaseContent.cs +++ b/ANAConversationStudio/Models/Chat/BaseContent.cs @@ -28,6 +28,7 @@ public string NodeName } private string _NodeId; + [ReadOnly(true)] public string NodeId { get { return _NodeId; } @@ -75,6 +76,7 @@ public string NodeHeaderText public class SectionContent : BaseContent { private string _SectionId; + [ReadOnly(true)] public string SectionId { get { return _SectionId; } @@ -227,8 +229,8 @@ public string CoordinateText } public class ButtonContent : BaseContent { - private string _ButtonId; + [ReadOnly(true)] public string ButtonId { get { return _ButtonId; } @@ -242,20 +244,6 @@ public string ButtonId } } - private string _ButtonName; - public string ButtonName - { - get { return _ButtonName; } - set - { - if (_ButtonName != value) - { - _ButtonName = value; - OnPropertyChanged(); - } - } - } - private string _ButtonText; [Category("Important")] public string ButtonText diff --git a/ANAConversationStudio/Models/Chat/BaseEntity.cs b/ANAConversationStudio/Models/Chat/BaseEntity.cs index 4fb2bb3..2a211f8 100644 --- a/ANAConversationStudio/Models/Chat/BaseEntity.cs +++ b/ANAConversationStudio/Models/Chat/BaseEntity.cs @@ -27,6 +27,7 @@ public string _id public class BaseIdTimeStampEntity : BaseIdEntity { private DateTime _CreatedOn; + [ReadOnly(true)] public DateTime CreatedOn { get { return _CreatedOn; } @@ -41,6 +42,7 @@ public DateTime CreatedOn } private DateTime _UpdatedOn; + [ReadOnly(true)] public DateTime UpdatedOn { get { return _UpdatedOn; } diff --git a/ANAConversationStudio/Models/Chat/Button.cs b/ANAConversationStudio/Models/Chat/Button.cs index 7dc0ebd..fdcb351 100644 --- a/ANAConversationStudio/Models/Chat/Button.cs +++ b/ANAConversationStudio/Models/Chat/Button.cs @@ -25,21 +25,6 @@ public ButtonTypeEnum ButtonType } } } - - private string _NextNodeId; - [Category("Important")] - public string NextNodeId - { - get { return _NextNodeId; } - set - { - if (_NextNodeId != value) - { - _NextNodeId = value; - OnPropertyChanged(); - } - } - } #endregion #region For ButtonType Get[X] @@ -193,7 +178,22 @@ public bool Hidden OnPropertyChanged(); } } - } + } + + private string _NextNodeId; + [ReadOnly(true)] + public string NextNodeId + { + get { return _NextNodeId; } + set + { + if (_NextNodeId != value) + { + _NextNodeId = value; + OnPropertyChanged(); + } + } + } #endregion public override string ToString() @@ -203,7 +203,6 @@ public override string ToString() } public enum ButtonTypeEnum { - None, PostText, OpenUrl, GetText, @@ -218,6 +217,5 @@ public enum ButtonTypeEnum NextNode, DeepLink, GetAgent, - ApiCall } } \ No newline at end of file diff --git a/ANAConversationStudio/Models/Chat/ChatNode.cs b/ANAConversationStudio/Models/Chat/ChatNode.cs index ee2bca7..d59f23e 100644 --- a/ANAConversationStudio/Models/Chat/ChatNode.cs +++ b/ANAConversationStudio/Models/Chat/ChatNode.cs @@ -89,6 +89,7 @@ public NodeTypeEnum NodeType #region Misc private string _Id; [Category("Misc")] + [ReadOnly(true)] public string Id { get { return _Id; } diff --git a/ANAConversationStudio/Views/MainWindow.xaml b/ANAConversationStudio/Views/MainWindow.xaml index dda75b6..624047d 100644 --- a/ANAConversationStudio/Views/MainWindow.xaml +++ b/ANAConversationStudio/Views/MainWindow.xaml @@ -810,7 +810,8 @@ MouseDown="networkControl_MouseDown" MouseUp="networkControl_MouseUp" MouseMove="networkControl_MouseMove" - MouseWheel="networkControl_MouseWheel" + MouseWheel="networkControl_MouseWheel" + MouseDoubleClick="networkControl_MouseDoubleClick" />