Ejemplo n.º 1
0
 private void StartDrag(DependencyObject sender, NodeSearchElementViewModel node)
 {
     isDragging = true;
     DragDrop.DoDragDrop(sender, new DragDropNodeSearchElementInfo(node.Model), DragDropEffects.Copy);
     // reset when dragging ends
     Clear();
     isDragging = false;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns a IEnumberable of NodeSearchElementViewModel for respective NodeSearchElements.
 /// </summary>
 private IEnumerable <NodeSearchElementViewModel> GetViewModelForNodeSearchElements(List <NodeSearchElement> searchElementsCache)
 {
     return(searchElementsCache.Select(e =>
     {
         var vm = new NodeSearchElementViewModel(e, this);
         vm.RequestBitmapSource += SearchViewModelRequestBitmapSource;
         return vm;
     }));
 }
Ejemplo n.º 3
0
        public bool ContainsClassOrMember(NodeSearchElement member)
        {
            var memberViewModel = new NodeSearchElementViewModel(member, null);

            // TODO(Vladimir): classes functionality.
            //if (Classes.Any(cl => cl.Equals(member))) return true;

            // Search among member groups.
            return(MemberGroups.Any(group => group.ContainsMember(memberViewModel)));
        }
Ejemplo n.º 4
0
        private static void PlaceInNewCategory(
            NodeSearchElementViewModel entry, NodeCategoryViewModel target,
            IEnumerable <string> categoryNames)
        {
            var newTargets =
                categoryNames.Select(name => new NodeCategoryViewModel(name));

            foreach (var newTarget in newTargets)
            {
                target.SubCategories.Add(newTarget);
                target = newTarget;
            }

            target.Entries.Add(entry);
        }
        internal void PopulateAutoCompleteCandidates()
        {
            if (PortViewModel == null)
            {
                return;
            }

            var searchElements = GetMatchingNodes();

            FilteredResults = searchElements.Select(e =>
            {
                var vm = new NodeSearchElementViewModel(e, this);
                vm.RequestBitmapSource += SearchViewModelRequestBitmapSource;
                return(vm);
            });
        }
Ejemplo n.º 6
0
        internal void AddMemberToGroup(NodeSearchElementViewModel memberNode)
        {
            string categoryWithGroup = AddGroupToCategory(memberNode.Model.FullCategoryName,
                                                          memberNode.Model.Group);
            string shortenedCategory = Nodes.Utilities.ShortenCategoryName(categoryWithGroup);

            var group = memberGroups.FirstOrDefault(mg => mg.FullyQualifiedName == shortenedCategory);

            if (group == null)
            {
                group = new SearchMemberGroup(shortenedCategory, memberNode.Category);
                memberGroups.Add(group);
            }

            group.AddMember(memberNode);
        }
Ejemplo n.º 7
0
        internal void UpdateRootCategories(IEnumerable <SearchCategory> rootTree, NodeSearchElementViewModel topResult = null)
        {
            root = rootTree;

            if (root == null || !root.Any())
            {
                topResult = null;
                return;
            }

            selectedCategoryIndex    = -1;
            selectedMemberGroupIndex = -1;
            selectedMemberIndex      = -1;

            this.topResult = topResult;
        }
Ejemplo n.º 8
0
        internal void UpdateRootCategories(IEnumerable <SearchCategory> rootTree)
        {
            root = rootTree;

            if (root == null || !root.Any())
            {
                selection = null;
                return;
            }

            selectedCategoryIndex    = 0;
            selectedMemberGroupIndex = 0;
            selectedMemberIndex      = 0;

            selection            = GetSelectionFromIndices();
            selection.IsSelected = true;
        }
Ejemplo n.º 9
0
 private void AddEntryToExistingCategory(NodeCategoryViewModel category,
                                         NodeSearchElementViewModel entry)
 {
     category.RequestBitmapSource += SearchViewModelRequestBitmapSource;
     // Check if the category exists already.
     // ex : clockwork package. For clockwork
     // package the category names in dyf is different from what we show it
     // on the tree view. so when you click on the category to populate it
     // triggers an update to category name. on the same instance when you uninstall
     // and insall the clockwork package, the categories are named correctly but
     // every install triggers an update that gives a duplicate entry. so check if the
     // entry is already added (specific to browse).
     if (category.Entries.All(x => x.FullName != entry.FullName))
     {
         category.Entries.Add(entry);
     }
 }
Ejemplo n.º 10
0
        private void UpdateTopResult(SearchMemberGroup memberGroup)
        {
            if (memberGroup == null)
            {
                TopResult = null;
                return;
            }

            var topMemberGroup = new SearchMemberGroup(memberGroup.FullyQualifiedName);

            // Clone top node.
            var topNode = new NodeSearchElementViewModel(memberGroup.Members.FirstOrDefault());

            topNode.IsSelected = true;

            topMemberGroup.AddMember(topNode);
            TopResult = topMemberGroup;

            selectionNavigator.UpdateRootCategories(SearchRootCategories, topNode);
        }
Ejemplo n.º 11
0
        private void PopulateSearchCategories(IEnumerable <NodeSearchElement> nodes)
        {
            foreach (NodeSearchElement node in nodes)
            {
                var rootCategoryName = NodeSearchElement.SplitCategoryName(node.FullCategoryName).FirstOrDefault();

                var category = searchRootCategories.FirstOrDefault(sc => sc.Name == rootCategoryName);
                if (category == null)
                {
                    category = new SearchCategory(rootCategoryName);
                    searchRootCategories.Add(category);
                }

                var elementVM = MakeNodeSearchElementVM(node);
                elementVM.Category = GetCategoryViewModel(libraryRoot, node.Categories);

                category.AddMemberToGroup(elementVM);
            }

            if (nodes.Count() == 0)
            {
                return;
            }

            // Clone top node.
            var topNode = new NodeSearchElementViewModel(MakeNodeSearchElementVM(nodes.First()));

            topNode.IsTopResult = true;

            SortSearchCategoriesChildren();

            var topCategory = new SearchCategory(Dynamo.Wpf.Properties.Resources.SearchViewTopResult, true);

            topCategory.AddMemberToGroup(topNode);
            searchRootCategories.Insert(0, topCategory);

            selectionNavigator.UpdateRootCategories(SearchRootCategories);
        }
Ejemplo n.º 12
0
        public void ElementTypeToBoolConverterTest()
        {
            ElementTypeToBoolConverter converter = new ElementTypeToBoolConverter();
            var NseVM = new NodeSearchElementViewModel(
                new NodeModelSearchElement(new TypeLoadData(typeof(Dynamo.Nodes.Symbol))), null);
            var NcVM  = new NodeCategoryViewModel("");
            var RncVM = new RootNodeCategoryViewModel("");
            var CncVM = new ClassesNodeCategoryViewModel(RncVM);

            object result;

            //1. Element is null.
            //2. Element is NodeSearchElement.
            //3. Element is NodeCategoryViewModel.
            //4. Element is RootNodeCategoryViewModel.
            //5. Element is RootNodeCategoryViewModel with ClassesNodeCategoryViewModel.

            // 1 case
            result = converter.Convert(null, null, null, null);
            Assert.AreEqual(false, result);

            // 2 case
            result = converter.Convert(NseVM, null, null, null);
            Assert.AreEqual(false, result);

            // 3 case
            result = converter.Convert(NcVM, null, null, null);
            Assert.AreEqual(true, result);

            // 4 case
            result = converter.Convert(RncVM, null, null, null);
            Assert.AreEqual(true, result);

            // 5 case
            RncVM.SubCategories.Add(CncVM);
            result = converter.Convert(RncVM, null, null, null);
            Assert.AreEqual(false, result);
        }
Ejemplo n.º 13
0
        private void OnInCanvasSearchKeyDown(object sender, KeyEventArgs e)
        {
            var key = e.Key;

            int index;
            var members = MembersListBox.Items.Cast <NodeSearchElementViewModel>();
            NodeSearchElementViewModel highlightedMember = null;

            if (HighlightedItem != null)
            {
                highlightedMember = HighlightedItem.DataContext as NodeSearchElementViewModel;
            }

            switch (key)
            {
            case Key.Escape:
                OnRequestShowNodeAutoCompleteSearch(ShowHideFlags.Hide);
                break;

            case Key.Enter:
                if (HighlightedItem != null && ViewModel.CurrentMode != SearchViewModel.ViewMode.LibraryView)
                {
                    ExecuteSearchElement(HighlightedItem);
                    OnRequestShowNodeAutoCompleteSearch(ShowHideFlags.Hide);
                }
                break;

            case Key.Up:
                index = MoveToNextMember(false, members, highlightedMember);
                UpdateHighlightedItem(GetListItemByIndex(MembersListBox, index));
                break;

            case Key.Down:
                index = MoveToNextMember(true, members, highlightedMember);
                UpdateHighlightedItem(GetListItemByIndex(MembersListBox, index));
                break;
            }
        }
Ejemplo n.º 14
0
        private void InsertEntry(NodeSearchElementViewModel entry, IEnumerable <string> categoryNames)
        {
            var  nameStack = new Stack <string>(categoryNames.Reverse());
            var  target    = libraryRoot;
            bool isRoot    = true;

            while (nameStack.Any())
            {
                var next       = nameStack.Pop();
                var categories = target.SubCategories;
                var newTarget  = categories.FirstOrDefault(c => c.Name == next);
                if (newTarget == default(NodeCategoryViewModel))
                {
                    newTarget = isRoot ? new RootNodeCategoryViewModel(next) : new NodeCategoryViewModel(next);
                    target.SubCategories.Add(newTarget);
                    PlaceInNewCategory(entry, newTarget, nameStack);
                    return;
                }
                target = newTarget;
                isRoot = false;
            }
            target.Entries.Add(entry);
        }
Ejemplo n.º 15
0
 internal void HandleMouseDown(Point position, NodeSearchElementViewModel node)
 {
     startPosition = position;
     nodeViewModel = node;
 }
Ejemplo n.º 16
0
        private void InsertEntryIntoNewCategory(
            NodeCategoryViewModel category,
            NodeSearchElementViewModel entry,
            IEnumerable <string> categoryNames)
        {
            if (!categoryNames.Any())
            {
                AddEntryToExistingCategory(category, entry);
                return;
            }

            // With the example of 'MyAssembly.MyNamespace.MyClass.Foo', 'path' would have been
            // set to 'MyAssembly' here. The Select statement below would store two entries into
            // 'newTargets' variable:
            //
            //      NodeCategoryViewModel("MyAssembly.MyNamespace")
            //      NodeCategoryViewModel("MyAssembly.MyNamespace.MyClass")
            //
            var path       = category.FullCategoryName;
            var newTargets = categoryNames.Select(name =>
            {
                path = MakeFullyQualifiedName(path, name);

                var cat = new NodeCategoryViewModel(name);
                cat.FullCategoryName = path;
                cat.Assembly         = entry.Assembly;
                return(cat);
            }).ToList();

            // The last entry 'NodeCategoryViewModel' represents a class. For our example the
            // entries in 'newTargets' are:
            //
            //      NodeCategoryViewModel("MyAssembly.MyNamespace")
            //      NodeCategoryViewModel("MyAssembly.MyNamespace.MyClass")
            //
            // Since all class entries are contained under a 'ClassesNodeCategoryViewModel',
            // we need to create a new 'ClassesNodeCategoryViewModel' instance, and insert it
            // right before the class entry itself to get the following list:
            //
            //      NodeCategoryViewModel("MyAssembly.MyNamespace")
            //      ClassesNodeCategoryViewModel("Classes")
            //      NodeCategoryViewModel("MyAssembly.MyNamespace.MyClass")
            //
            int indexToInsertClass = newTargets.Count - 1;
            var classParent        = indexToInsertClass > 0 ? newTargets[indexToInsertClass - 1] : category;
            var newClass           = new ClassesNodeCategoryViewModel(classParent);

            newTargets.Insert(indexToInsertClass, newClass);

            // Here, all the entries in 'newTargets' are added under 'MyAssembly' recursively,
            // resulting in the following hierarchical structure:
            //
            //      NodeCategoryViewModel("MyAssembly")
            //          NodeCategoryViewModel("MyAssembly.MyNamespace")
            //              ClassesNodeCategoryViewModel("Classes")
            //                  NodeCategoryViewModel("MyAssembly.MyNamespace.MyClass")
            //
            foreach (var newTarget in newTargets)
            {
                category.SubCategories.Add(newTarget);
                category = newTarget;
            }

            AddEntryToExistingCategory(category, entry);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Insert a new search element under the category.
        /// </summary>
        /// <param name="entry">This could represent a function of a given
        /// class. For example, 'MyAssembly.MyNamespace.MyClass.Foo'.</param>
        /// <param name="categoryNames">A list of entries that make up the fully qualified
        /// class name that contains function 'Foo', e.g. 'MyAssembly.MyNamespace.MyClass'.
        /// </param>
        internal void InsertEntry(NodeSearchElementViewModel entry, IEnumerable <string> categoryNames)
        {
            var    nameStack = new Stack <string>(categoryNames.Reverse());
            var    target    = libraryRoot;
            string fullyQualifiedCategoryName        = "";
            ClassesNodeCategoryViewModel targetClass = null;

            while (nameStack.Any())
            {
                var next = nameStack.Pop();
                fullyQualifiedCategoryName = MakeFullyQualifiedName(fullyQualifiedCategoryName, next);

                var categories = target.SubCategories;
                NodeCategoryViewModel targetClassSuccessor = null;
                var newTarget = categories.FirstOrDefault(c =>
                {
                    // Each path has one class. We should find and save it.
                    if (c is ClassesNodeCategoryViewModel)
                    {
                        targetClass = c as ClassesNodeCategoryViewModel;
                        // As soon as ClassesNodeCategoryViewModel is found we should search
                        // through all it classes and save result.
                        targetClassSuccessor = c.SubCategories.FirstOrDefault(c2 => c2.Name == next);
                        return(targetClassSuccessor != null);
                    }

                    return(c.Name == next);
                });
                if (newTarget == null)
                {
                    // For the first iteration, this would be 'MyAssembly', and the second iteration 'MyNamespace'.
                    var targetIsRoot = target == libraryRoot;
                    newTarget = targetIsRoot ? new RootNodeCategoryViewModel(next) : new NodeCategoryViewModel(next);
                    newTarget.FullCategoryName = fullyQualifiedCategoryName;
                    newTarget.Assembly         = entry.Assembly;
                    // Situation when we to add only one new category and item as it child.
                    // New category should be added to existing ClassesNodeCategoryViewModel.
                    // Make notice: ClassesNodeCategoryViewModel is always first item in
                    // all subcategories.
                    if (nameStack.Count == 0 && !target.IsClassButton &&
                        target.SubCategories[0] is ClassesNodeCategoryViewModel)
                    {
                        target.SubCategories[0].SubCategories.Add(newTarget);
                        AddEntryToExistingCategory(newTarget, entry);
                        return;
                    }

                    // We are here when target is the class. New category should be added
                    // as child of it. So class will turn into usual category.
                    // Here we are take class, remove it from ClassesNodeCategoryViewModel
                    // and attach to it parrent.
                    if (targetClass != null)
                    {
                        if (targetClass.SubCategories.Remove(target))
                        {
                            targetClass.Parent.SubCategories.Add(target);
                        }
                        // Delete empty classes container.
                        if (targetClass.IsClassButton)
                        {
                            targetClass.Parent.SubCategories.RemoveAt(0);
                        }

                        targetClass.Dispose();
                    }

                    // Situation when we need to add only one new category and item.
                    // Before adding of it we need create new ClassesNodeCategoryViewModel
                    // as soon as new category will be a class.
                    if (nameStack.Count == 0 && !targetIsRoot)
                    {
                        targetClass = new ClassesNodeCategoryViewModel(target);

                        target.SubCategories.Insert(0, targetClass);
                        target.SubCategories[0].SubCategories.Add(newTarget);
                        AddEntryToExistingCategory(newTarget, entry);
                        return;
                    }

                    target.InsertSubCategory(newTarget);

                    // Proceed to insert the new entry under 'newTarget' category with the remaining
                    // name stack. In the first iteration this would have been 'MyNamespace.MyClass'.
                    InsertEntryIntoNewCategory(newTarget, entry, nameStack);
                    return;
                }
                // If we meet ClassesNodecategoryViewModel during the search of newTarget,
                // next newTarget is specified in targetClassSuccessor.
                if (targetClassSuccessor != null)
                {
                    target = targetClassSuccessor;
                }
                else
                {
                    target = newTarget;
                }
            }
            AddEntryToExistingCategory(target, entry);
        }
Ejemplo n.º 18
0
        internal void MoveSelection(NavigationDirection direction)
        {
            if (root == null || !root.Any())
            {
                return;
            }

            var selectedCategory    = root.ElementAt(selectedCategoryIndex);
            var selectedMemberGroup = selectedCategory.MemberGroups.ElementAt(selectedMemberGroupIndex);

            // Clear the current selection, no matter what.
            selection.IsSelected = false;
            selection            = null;

            if (direction == NavigationDirection.Backward)
            {
                if (selectedMemberIndex != 0)
                {
                    selectedMemberIndex--;
                }
                else
                {
                    if (selectedMemberGroupIndex != 0)
                    {
                        selectedMemberGroupIndex--;

                        // Select last member of new member group.
                        var category = root.ElementAt(selectedCategoryIndex);
                        var group    = category.MemberGroups.ElementAt(selectedMemberGroupIndex);
                        selectedMemberIndex = group.Members.Count() - 1;
                    }
                    else
                    {
                        if (selectedCategoryIndex != 0)
                        {
                            selectedCategoryIndex--;

                            // Select last group and last member of this group.
                            var category = root.ElementAt(selectedCategoryIndex);
                            selectedMemberGroupIndex = category.MemberGroups.Count() - 1;

                            var group = category.MemberGroups.ElementAt(selectedMemberGroupIndex);
                            selectedMemberIndex = group.Members.Count() - 1;
                        }
                    }
                }
            }
            else
            {
                // Determine the current group size.
                var members = selectedMemberGroup.Members.Count();

                if (selectedMemberIndex < members - 1) // There's still next member.
                {
                    selectedMemberIndex++;
                }
                else
                {
                    var memberGroups = root.ElementAt(selectedCategoryIndex).MemberGroups.Count();
                    if (selectedMemberGroupIndex < memberGroups - 1) // There's still next group.
                    {
                        selectedMemberIndex = 0;
                        selectedMemberGroupIndex++;
                    }
                    else if (selectedCategoryIndex < root.Count() - 1) // There's still next category.
                    {
                        selectedMemberIndex      = 0;
                        selectedMemberGroupIndex = 0;
                        selectedCategoryIndex++;
                    }
                }
            }

            // Get the new selection and mark it as selected.
            selection            = GetSelectionFromIndices();
            selection.IsSelected = true;
        }
Ejemplo n.º 19
0
 private void AddEntryToExistingCategory(NodeCategoryViewModel category,
                                         NodeSearchElementViewModel entry)
 {
     category.RequestBitmapSource += SearchViewModelRequestBitmapSource;
     category.Entries.Add(entry);
 }
Ejemplo n.º 20
0
        internal int MoveToNextMember(bool moveForward,
                                      IEnumerable <NodeSearchElementViewModel> members, NodeSearchElementViewModel selectedMember)
        {
            int selectedMemberIndex = -1;

            for (int i = 0; i < members.Count(); i++)
            {
                var member = members.ElementAt(i);
                if (member.Equals(selectedMember))
                {
                    selectedMemberIndex = i;
                    break;
                }
            }

            int nextselectedMemberIndex = selectedMemberIndex;

            if (moveForward)
            {
                nextselectedMemberIndex++;
            }
            else
            {
                nextselectedMemberIndex--;
            }

            if (nextselectedMemberIndex < 0 || (nextselectedMemberIndex >= members.Count()))
            {
                return(selectedMemberIndex);
            }

            return(nextselectedMemberIndex);
        }
Ejemplo n.º 21
0
 internal void AddMember(NodeSearchElementViewModel node)
 {
     members.Add(node);
 }
Ejemplo n.º 22
0
 internal bool ContainsMember(NodeSearchElementViewModel member)
 {
     return(Members.Any(m => m.Model.FullName == member.Model.FullName));
 }
Ejemplo n.º 23
0
 private void StartDrag(FrameworkElement sender, NodeSearchElementViewModel node)
 {
     isDragging = true;
     DragDrop.DoDragDrop(sender, new DragDropNodeSearchElementInfo(node.Model), DragDropEffects.Copy);
     isDragging = false;
 }
Ejemplo n.º 24
0
 internal void Clear()
 {
     startPosition = new Point();
     nodeViewModel = null;
 }