private static bool IsDropAllowed(DirectionalDropArea dropArea, NamingRuleTreeItemViewModel target, NamingRuleTreeItemViewModel source)
        {
            switch (dropArea)
            {
                case DirectionalDropArea.On:
                    // Naming Rules can't be dropped on themselves or on any of their descendants.
                    if (source == target || source.IsAncestorOfMe(target))
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                case DirectionalDropArea.Above:
                case DirectionalDropArea.Below:
                    // Naming Rules can't be dropped on themselves, or on any of their descendants.
                    if (source == target || source.IsAncestorOfMe(target))
                    {
                        return false;
                    }

                    // There must always be a single root Naming Rule
                    if (target.Parent == null)
                    {
                        return false;
                    }

                    // Insertions that would lead to the same order don't make sense
                    int direction = dropArea == DirectionalDropArea.Above ? -1 : 1;
                    return source.Parent != target.Parent || source.Parent.Children.IndexOf(source) != target.Parent.Children.IndexOf(target) + direction;
                default:
                    return false;
            }
        }
Example #2
0
        public void OnDrop(DirectionalDropArea dropArea, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(NamingRuleTreeItemViewModel)))
            {
                NamingRuleTreeItemViewModel namingRule = e.Data.GetData(typeof(NamingRuleTreeItemViewModel)) as NamingRuleTreeItemViewModel;
                if (!namingRule.IsAncestorOfMe(this))
                {
                    switch (dropArea)
                    {
                    case DirectionalDropArea.On:
                        namingRule.Parent.Children.Remove(namingRule);
                        this.Children.Add(namingRule);
                        break;

                    case DirectionalDropArea.Above:
                        namingRule.Parent.Children.Remove(namingRule);
                        this.Parent.Children.Insert(this.Parent.Children.IndexOf(this), namingRule);
                        break;

                    case DirectionalDropArea.Below:
                        namingRule.Parent.Children.Remove(namingRule);
                        this.Parent.Children.Insert(this.Parent.Children.IndexOf(this) + 1, namingRule);
                        break;
                    }
                }
            }
        }
 internal void DeleteRule(NamingRuleTreeItemViewModel a)
 {
     if (!a.HasChildren && a.Parent != null)
     {
         a.Parent.Children.Remove(a);
     }
 }
        private NamingRuleTreeItemViewModel CreateRoot(SerializableNamingStylePreferencesInfo info)
        {
            var root = new NamingRuleTreeItemViewModel("Naming Rules:");

            CreateRootHelper(root, info.NamingRules);
            return(root);
        }
        private IEnumerable <object> GetParent(object item)
        {
            NamingRuleTreeItemViewModel viewModel = item as NamingRuleTreeItemViewModel;

            if (viewModel != null && viewModel.Parent != null)
            {
                yield return(viewModel.Parent);
            }
        }
Example #6
0
 public RenameTransaction(NamingRuleTreeItemViewModel namingRule, object container, Func <IRenameItemTransaction, IRenameItemValidationResult> validator)
     : base(namingRule, container, validator)
 {
     this.RenameLabel = namingRule.Title;
     this.Completed  += (s, e) =>
     {
         namingRule.Title = this.RenameLabel;
     };
 }
 public RenameTransaction(NamingRuleTreeItemViewModel namingRule, object container, Func<IRenameItemTransaction, IRenameItemValidationResult> validator)
     : base(namingRule, container, validator)
 {
     this.RenameLabel = namingRule.Title;
     this.Completed += (s, e) =>
     {
         namingRule.Title = this.RenameLabel;
     };
 }
 internal NamingStylesOptionPageControlViewModel(SerializableNamingStylePreferencesInfo info, string languageName, ImmutableArray<string> categories, INotificationService notificationService)
 {
     this._languageName = languageName;
     this.categories = categories;
     this.notificationService = notificationService;
     this.SymbolSpecificationList = new ObservableCollection<SymbolSpecificationViewModel>(info.SymbolSpecifications.Select(s => new SymbolSpecificationViewModel(languageName, categories, s, notificationService)));
     this.NamingStyleList = new ObservableCollection<NamingStyleViewModel>(info.NamingStyles.Select(s => new NamingStyleViewModel(s, this.notificationService)));
     this.rootNamingRule = CreateRoot(info);
 }
 internal NamingStylesOptionPageControlViewModel(SerializableNamingStylePreferencesInfo info, string languageName, ImmutableArray <string> categories, INotificationService notificationService)
 {
     this._languageName           = languageName;
     this.categories              = categories;
     this.notificationService     = notificationService;
     this.SymbolSpecificationList = new ObservableCollection <SymbolSpecificationViewModel>(info.SymbolSpecifications.Select(s => new SymbolSpecificationViewModel(languageName, categories, s, notificationService)));
     this.NamingStyleList         = new ObservableCollection <NamingStyleViewModel>(info.NamingStyles.Select(s => new NamingStyleViewModel(s, this.notificationService)));
     this.rootNamingRule          = CreateRoot(info);
 }
Example #10
0
 private void UpdateAllowedEffects(DirectionalDropArea dropArea, DragEventArgs e)
 {
     if (e.Data.GetDataPresent(typeof(NamingRuleTreeItemViewModel)))
     {
         NamingRuleTreeItemViewModel namingRule = e.Data.GetData(typeof(NamingRuleTreeItemViewModel)) as NamingRuleTreeItemViewModel;
         if (namingRule != null && IsDropAllowed(dropArea, target: this, source: namingRule))
         {
             e.Effects = DragDropEffects.All;
         }
     }
 }
        internal List <NamingRuleTreeItemViewModel> CreateAllowableParentList(NamingRuleTreeItemViewModel excludedSubtree = null)
        {
            var ruleList = new List <NamingRuleTreeItemViewModel>();

            foreach (var child in rootNamingRule.Children)
            {
                CreateAllowableParentListHelper(child, ruleList, excludedSubtree);
            }

            return(ruleList);
        }
        private void CreateAllowableParentListHelper(NamingRuleTreeItemViewModel ruleToProcess, List <NamingRuleTreeItemViewModel> ruleList, NamingRuleTreeItemViewModel excludedSubtree)
        {
            if (ruleToProcess == excludedSubtree)
            {
                return;
            }

            ruleList.Add(ruleToProcess);
            foreach (var child in ruleToProcess.Children)
            {
                CreateAllowableParentListHelper(child, ruleList, excludedSubtree);
            }
        }
        private void CreateRootHelper(NamingRuleTreeItemViewModel rule, List<SerializableNamingRule> children)
        {            
            foreach (var child in children)
            {
                var newRule = new NamingRuleTreeItemViewModel(
                    child.Title,
                    SymbolSpecificationList.SingleOrDefault(s => s.ID == child.SymbolSpecificationID),
                    NamingStyleList.SingleOrDefault(s => s.ID == child.NamingStyleID),
                    new EnforcementLevel(child.EnforcementLevel),
                    this);

                CreateRootHelper(newRule, child.Children);
                rule.Children.Add(newRule);
            }
        }
        private void CreateRootHelper(NamingRuleTreeItemViewModel rule, List <SerializableNamingRule> children)
        {
            foreach (var child in children)
            {
                var newRule = new NamingRuleTreeItemViewModel(
                    child.Title,
                    SymbolSpecificationList.SingleOrDefault(s => s.ID == child.SymbolSpecificationID),
                    NamingStyleList.SingleOrDefault(s => s.ID == child.NamingStyleID),
                    new EnforcementLevel(child.EnforcementLevel),
                    this);

                CreateRootHelper(newRule, child.Children);
                rule.Children.Add(newRule);
            }
        }
Example #15
0
        public bool IsAncestorOfMe(NamingRuleTreeItemViewModel rule)
        {
            NamingRuleTreeItemViewModel potentialAncestor = rule.Parent;

            while (potentialAncestor != null)
            {
                if (potentialAncestor == this)
                {
                    return(true);
                }

                potentialAncestor = potentialAncestor.Parent;
            }

            return(false);
        }
        private void EnsureAncestorsExpanded(NamingRuleTreeItemViewModel item)
        {
            Stack<NamingRuleTreeItemViewModel> models = new Stack<NamingRuleTreeItemViewModel>();
            NamingRuleTreeItemViewModel iter = item.Parent;
            while (iter != null)
            {
                models.Push(iter);
                iter = iter.Parent;
            }

            while (models.Count > 0)
            {
                NamingRuleTreeItemViewModel manager = models.Pop();
                IVirtualizingTreeNode managerNode = this.RootTreeView.GetFirstTreeNode(manager);
                managerNode.IsExpanded = true;
            }
        }
        private void EnsureAncestorsExpanded(NamingRuleTreeItemViewModel item)
        {
            Stack <NamingRuleTreeItemViewModel> models = new Stack <NamingRuleTreeItemViewModel>();
            NamingRuleTreeItemViewModel         iter   = item.Parent;

            while (iter != null)
            {
                models.Push(iter);
                iter = iter.Parent;
            }

            while (models.Count > 0)
            {
                NamingRuleTreeItemViewModel manager     = models.Pop();
                IVirtualizingTreeNode       managerNode = this.RootTreeView.GetFirstTreeNode(manager);
                managerNode.IsExpanded = true;
            }
        }
        internal void AddNamingRule(NamingRuleDialogViewModel viewModel)
        {
            var newNode = new NamingRuleTreeItemViewModel(
                viewModel.Title,
                viewModel.SymbolSpecificationList.GetItemAt(viewModel.SelectedSymbolSpecificationIndex) as SymbolSpecificationViewModel,
                viewModel.NamingStyleList.GetItemAt(viewModel.NamingStyleIndex) as NamingStyleViewModel,
                viewModel.EnforcementLevelsList[viewModel.EnforcementLevelIndex],
                this);

            if (viewModel.ParentRuleIndex == 0)
            {
                rootNamingRule.Children.Add(newNode);
            }
            else
            {
                var parent = viewModel.ParentRuleList.GetItemAt(viewModel.ParentRuleIndex) as NamingRuleTreeItemViewModel;
                parent.Children.Add(newNode);
            }
        }
        internal void AddNamingRule(NamingRuleDialogViewModel viewModel)
        {
            var newNode = new NamingRuleTreeItemViewModel(
                viewModel.Title,
                viewModel.SymbolSpecificationList.GetItemAt(viewModel.SelectedSymbolSpecificationIndex) as SymbolSpecificationViewModel,
                viewModel.NamingStyleList.GetItemAt(viewModel.NamingStyleIndex) as NamingStyleViewModel,
                viewModel.EnforcementLevelsList[viewModel.EnforcementLevelIndex],
                this);

            if (viewModel.ParentRuleIndex == 0)
            {
                rootNamingRule.Children.Add(newNode);
            }
            else
            {
                var parent = viewModel.ParentRuleList.GetItemAt(viewModel.ParentRuleIndex) as NamingRuleTreeItemViewModel;
                parent.Children.Add(newNode);
            }
        }
        public NamingRuleDialogViewModel(
            string title,
            SymbolSpecificationViewModel symbolSpecification,
            IList <SymbolSpecificationViewModel> symbolSpecificationList,
            NamingStyleViewModel namingStyle,
            IList <NamingStyleViewModel> namingStyleList,
            NamingRuleTreeItemViewModel parent,
            IList <NamingRuleTreeItemViewModel> allowableParentList,
            EnforcementLevel enforcementLevel,
            INotificationService notificationService)
        {
            this._notificationService = notificationService;

            this._title = title;

            this._symbolSpecificationList          = new CollectionView(symbolSpecificationList);
            this._selectedSymbolSpecificationIndex = symbolSpecificationList.IndexOf(symbolSpecification);

            this._namingStyleList  = new CollectionView(namingStyleList);
            this._namingStyleIndex = namingStyleList.IndexOf(namingStyle);

            allowableParentList.Insert(0, new NamingRuleTreeItemViewModel("-- None --"));
            this._parentRuleList  = new CollectionView(allowableParentList);
            this._parentRuleIndex = parent != null?allowableParentList.IndexOf(parent) : 0;

            if (_parentRuleIndex < 0)
            {
                _parentRuleIndex = 0;
            }

            _enforcementLevelsList = new List <EnforcementLevel>
            {
                new EnforcementLevel(DiagnosticSeverity.Hidden),
                new EnforcementLevel(DiagnosticSeverity.Info),
                new EnforcementLevel(DiagnosticSeverity.Warning),
                new EnforcementLevel(DiagnosticSeverity.Error),
            };

            _enforcementLevelIndex = _enforcementLevelsList.IndexOf(_enforcementLevelsList.Single(e => e.Value == enforcementLevel.Value));
        }
        public NamingRuleDialogViewModel(
            string title,
            SymbolSpecificationViewModel symbolSpecification,
            IList<SymbolSpecificationViewModel> symbolSpecificationList,
            NamingStyleViewModel namingStyle,
            IList<NamingStyleViewModel> namingStyleList,
            NamingRuleTreeItemViewModel parent,
            IList<NamingRuleTreeItemViewModel> allowableParentList,
            EnforcementLevel enforcementLevel,
            INotificationService notificationService)
        {
            this._notificationService = notificationService;

            this._title = title;
            
            this._symbolSpecificationList = new CollectionView(symbolSpecificationList);
            this._selectedSymbolSpecificationIndex = symbolSpecificationList.IndexOf(symbolSpecification);

            this._namingStyleList = new CollectionView(namingStyleList);
            this._namingStyleIndex = namingStyleList.IndexOf(namingStyle);

            allowableParentList.Insert(0, new NamingRuleTreeItemViewModel("-- None --"));
            this._parentRuleList = new CollectionView(allowableParentList);
            this._parentRuleIndex = parent != null ? allowableParentList.IndexOf(parent) : 0;
            if (_parentRuleIndex < 0)
            {
                _parentRuleIndex = 0;
            }

            _enforcementLevelsList = new List<EnforcementLevel>
                {
                    new EnforcementLevel(DiagnosticSeverity.Hidden),
                    new EnforcementLevel(DiagnosticSeverity.Info),
                    new EnforcementLevel(DiagnosticSeverity.Warning),
                    new EnforcementLevel(DiagnosticSeverity.Error),
                };

            _enforcementLevelIndex = _enforcementLevelsList.IndexOf(_enforcementLevelsList.Single(e => e.Value == enforcementLevel.Value));
        }
Example #22
0
        private static bool IsDropAllowed(DirectionalDropArea dropArea, NamingRuleTreeItemViewModel target, NamingRuleTreeItemViewModel source)
        {
            switch (dropArea)
            {
            case DirectionalDropArea.On:
                // Naming Rules can't be dropped on themselves or on any of their descendants.
                if (source == target || source.IsAncestorOfMe(target))
                {
                    return(false);
                }
                else
                {
                    return(true);
                }

            case DirectionalDropArea.Above:
            case DirectionalDropArea.Below:
                // Naming Rules can't be dropped on themselves, or on any of their descendants.
                if (source == target || source.IsAncestorOfMe(target))
                {
                    return(false);
                }

                // There must always be a single root Naming Rule
                if (target.Parent == null)
                {
                    return(false);
                }

                // Insertions that would lead to the same order don't make sense
                int direction = dropArea == DirectionalDropArea.Above ? -1 : 1;
                return(source.Parent != target.Parent || source.Parent.Children.IndexOf(source) != target.Parent.Children.IndexOf(target) + direction);

            default:
                return(false);
            }
        }
        internal List<NamingRuleTreeItemViewModel> CreateAllowableParentList(NamingRuleTreeItemViewModel excludedSubtree = null)
        {
            var ruleList = new List<NamingRuleTreeItemViewModel>();
            foreach (var child in rootNamingRule.Children)
            {
                CreateAllowableParentListHelper(child, ruleList, excludedSubtree);
            }

            return ruleList;
        }
        private void CreateAllowableParentListHelper(NamingRuleTreeItemViewModel ruleToProcess, List<NamingRuleTreeItemViewModel> ruleList, NamingRuleTreeItemViewModel excludedSubtree)
        {
            if (ruleToProcess == excludedSubtree)
            {
                return;
            }

            ruleList.Add(ruleToProcess);
            foreach (var child in ruleToProcess.Children)
            {
                CreateAllowableParentListHelper(child, ruleList, excludedSubtree);
            }
        }
 private bool NamingStyleUsedInTree(NamingStyleViewModel a, NamingRuleTreeItemViewModel c)
 {
     return(c.Children.Any(child => child.namingStyle == a || NamingStyleUsedInTree(a, child)));
 }
 private bool SymbolSpecUsedInTree(SymbolSpecificationViewModel a, NamingRuleTreeItemViewModel c)
 {
     return(c.Children.Any(child => child.symbolSpec == a || SymbolSpecUsedInTree(a, child)));
 }
 internal void DeleteRule(NamingRuleTreeItemViewModel a)
 {
     if (!a.HasChildren && a.Parent != null)
     {
         a.Parent.Children.Remove(a);
     }
 }
 private bool SymbolSpecUsedInTree(SymbolSpecificationViewModel a, NamingRuleTreeItemViewModel c)
 {
     return c.Children.Any(child => child.symbolSpec == a || SymbolSpecUsedInTree(a, child));
 }
 private bool NamingStyleUsedInTree(NamingStyleViewModel a, NamingRuleTreeItemViewModel c)
 {
     return c.Children.Any(child => child.namingStyle == a || NamingStyleUsedInTree(a, child));
 }
 private NamingRuleTreeItemViewModel CreateRoot(SerializableNamingStylePreferencesInfo info)
 {
     var root = new NamingRuleTreeItemViewModel("Naming Rules:");
     CreateRootHelper(root, info.NamingRules);
     return root;
 }