diff --git a/src/MoBi.Presentation/DTO/ObjectBaseDTO.cs b/src/MoBi.Presentation/DTO/ObjectBaseDTO.cs index d893a5e8f..e17b8e2a5 100644 --- a/src/MoBi.Presentation/DTO/ObjectBaseDTO.cs +++ b/src/MoBi.Presentation/DTO/ObjectBaseDTO.cs @@ -2,16 +2,17 @@ using System.ComponentModel; using System.Linq; using MoBi.Assets; -using OSPSuite.Utility.Extensions; -using OSPSuite.Utility.Reflection; -using OSPSuite.Utility.Validation; using MoBi.Core.Domain.Model; using MoBi.Core.Helper; +using OSPSuite.Assets; using OSPSuite.Core.Domain; using OSPSuite.Core.Domain.Builder; using OSPSuite.Core.Domain.Data; using OSPSuite.Presentation.Core; using OSPSuite.Presentation.DTO; +using OSPSuite.Utility.Extensions; +using OSPSuite.Utility.Reflection; +using OSPSuite.Utility.Validation; namespace MoBi.Presentation.DTO { @@ -80,6 +81,14 @@ public virtual void HandlePropertyChanged(object sender, PropertyChangedEventArg private static class AllRules { + private static bool nameDoesNotContainerIllegalCharacters(string name) + { + if (string.IsNullOrEmpty(name)) + return true; + + return !Constants.ILLEGAL_CHARACTERS.Any(name.Contains); + } + private static IBusinessRule notEmptyNameRule { get; } = CreateRule.For() .Property(x => x.Name) .WithRule((dto, name) => dto.IsNameDefined(name)) @@ -90,9 +99,15 @@ private static class AllRules .WithRule((dto, name) => dto.IsNameUnique(name)) .WithError(AppConstants.Validation.NameAlreadyUsed); + private static IBusinessRule nameDoesNotContainIllegalCharacters { get; } = CreateRule.For() + .Property(item => item.Name) + .WithRule((dto, name) => nameDoesNotContainerIllegalCharacters(name)) + .WithError(Error.NameCannotContainIllegalCharacters(Constants.ILLEGAL_CHARACTERS)); + public static IEnumerable All() { yield return notEmptyNameRule; + yield return nameDoesNotContainIllegalCharacters; yield return uniqueNameRule; } } @@ -136,7 +151,6 @@ public class FavoritesNodeViewItem : ObjectBaseDTO public class UserDefinedNodeViewItem : ObjectBaseDTO { - } public class BuildingBlockInfoViewItem : ObjectBaseDTO diff --git a/src/MoBi.Presentation/Tasks/Interaction/ObjectBaseTask.cs b/src/MoBi.Presentation/Tasks/Interaction/ObjectBaseTask.cs index 21bd54051..f183248b6 100644 --- a/src/MoBi.Presentation/Tasks/Interaction/ObjectBaseTask.cs +++ b/src/MoBi.Presentation/Tasks/Interaction/ObjectBaseTask.cs @@ -1,23 +1,22 @@ using System.Collections.Generic; using System.Linq; using MoBi.Assets; -using OSPSuite.Core.Commands.Core; -using OSPSuite.Utility.Extensions; using MoBi.Core.Commands; using MoBi.Core.Domain; using MoBi.Core.Domain.Model; -using MoBi.Core.Services; using MoBi.Presentation.Presenter; +using OSPSuite.Core.Commands.Core; using OSPSuite.Core.Domain; using OSPSuite.Core.Domain.Builder; using OSPSuite.Core.Domain.Services; -using OSPSuite.Core.Services; +using OSPSuite.Presentation.Presenters; +using OSPSuite.Utility.Extensions; namespace MoBi.Presentation.Tasks.Interaction { public interface IObjectBaseTask { - IMoBiCommand Rename(IObjectBase objectBase, IEnumerable allreadyNames, IBuildingBlock buildingBlock); + IMoBiCommand Rename(IObjectBase objectBase, IEnumerable alreadyUsedNames, IBuildingBlock buildingBlock); /// /// Search for usages of in the project and asks the user if they should be renamed as well @@ -40,23 +39,27 @@ internal class ObjectBaseTask : IObjectBaseTask private readonly IMoBiContext _context; private readonly ICheckNameVisitor _checkNamesVisitor; private readonly IMoBiApplicationController _applicationController; - private readonly IDialogCreator _dialogCreator; - public ObjectBaseTask(IObjectTypeResolver objectTypeResolver, IMoBiContext context, ICheckNameVisitor checkNamesVisitor, IMoBiApplicationController applicationController, IDialogCreator dialogCreator) + public ObjectBaseTask(IObjectTypeResolver objectTypeResolver, IMoBiContext context, ICheckNameVisitor checkNamesVisitor, IMoBiApplicationController applicationController) { _objectTypeResolver = objectTypeResolver; _context = context; _checkNamesVisitor = checkNamesVisitor; _applicationController = applicationController; - _dialogCreator = dialogCreator; } - public IMoBiCommand Rename(IObjectBase objectBase, IEnumerable allreadyNames, IBuildingBlock buildingBlock) + public IMoBiCommand Rename(IObjectBase objectBase, IEnumerable alreadyUsedNames, IBuildingBlock buildingBlock) { - var unallowedNames = new List(allreadyNames); + var unallowedNames = new List(alreadyUsedNames); unallowedNames.AddRange(AppConstants.UnallowedNames); var objectName = _objectTypeResolver.TypeFor(objectBase); - string newName = _dialogCreator.AskForInput(AppConstants.Dialog.AskForNewName(objectBase.Name), AppConstants.Captions.NewName, objectBase.Name, unallowedNames); + + string newName; + using (var renameObjectPresenter = _applicationController.Start()) + { + newName = renameObjectPresenter.NewNameFrom(objectBase, unallowedNames); + } + if (string.IsNullOrEmpty(newName)) return new MoBiEmptyCommand();