コード例 #1
0
        /// <summary>
        /// Add a single category as a child of a category.  If the category already exists, just return that one.
        /// </summary>
        /// <param name="parent">The parent category </param>
        /// <param name="childCategoryName">The name of the child category (can't be nested)</param>
        /// <returns>The newly created category</returns>
        public BrowserItem TryAddChildCategory(BrowserItem parent, string childCategoryName)
        {
            var newCategoryName = parent.Name + CATEGORY_DELIMITER + childCategoryName;

            // support long nested categories like Math.Math.StaticMembers.Abs
            var parentItem = parent as BrowserInternalElement;

            while (parentItem != null)
            {
                var grandParent = parentItem.Parent;
                if (null == grandParent)
                {
                    break;
                }

                newCategoryName = grandParent.Name + CATEGORY_DELIMITER + newCategoryName;
                parentItem      = grandParent as BrowserInternalElement;
            }

            if (ContainsCategory(newCategoryName))
            {
                return(GetCategoryByName(newCategoryName));
            }

            var tempCat = new BrowserInternalElement(childCategoryName, parent);

            parent.AddChild(tempCat);

            return(tempCat);
        }
コード例 #2
0
        protected BrowserItemViewModel(BrowserItem model)
        {
            Model = model;
            ToggleIsExpandedCommand = new DelegateCommand(Model.Execute);
            Items = new ObservableCollection <BrowserItemViewModel>();

            foreach (var item in Model.Items)
            {
                Items.Add(Wrap(item));
            }

            Model.Items.CollectionChanged += ItemsOnCollectionChanged;
        }
コード例 #3
0
ファイル: SearchViewModel.cs プロジェクト: jimmplan/Dynamo
        /// <summary>
        /// Add a single category as a child of a category.  If the category already exists, just return that one.
        /// </summary>
        /// <param name="parent">The parent category </param>
        /// <param name="childCategoryName">The name of the child category (can't be nested)</param>
        /// <returns>The newly created category</returns>
        public BrowserItem TryAddChildCategory(BrowserItem parent, string childCategoryName)
        {
            var newCategoryName = parent.Name + CATEGORY_DELIMITER + childCategoryName;

            if (ContainsCategory(newCategoryName))
            {
                return(GetCategoryByName(newCategoryName));
            }

            var tempCat = new BrowserInternalElement(childCategoryName, parent);

            parent.AddChild(tempCat);

            return(tempCat);
        }
コード例 #4
0
        /// <summary>
        /// Remove an empty category from browser and search.  Useful when a single item is removed.
        /// </summary>
        /// <param name="ele"></param>
        public void RemoveEmptyCategory(BrowserItem ele)
        {
            if (ele is BrowserRootElement && ele.Items.Count == 0)
            {
                RemoveEmptyRootCategory(ele as BrowserRootElement);
                return;
            }

            if (ele is BrowserInternalElement && ele.Items.Count == 0)
            {
                var internalEle = ele as BrowserInternalElement;

                internalEle.Parent.Items.Remove(internalEle);
                RemoveEmptyCategory(internalEle.Parent);
            }
        }
コード例 #5
0
        /// <summary>
        /// Remove a category and all its children from the browser and search.  The category does
        /// not have to be empty.
        /// </summary>
        /// <param name="ele"></param>
        public void RemoveCategory(BrowserItem ele)
        {
            var nodes = ele.Items.Where(x => x is NodeSearchElement)
                        .Cast <NodeSearchElement>().ToList();

            var cats = ele.Items.Where(x => x is BrowserInternalElement)
                       .Cast <BrowserInternalElement>().ToList();

            nodes.Select(x => x.Name).ToList().ForEach(RemoveNode);
            cats.ToList().ForEach(RemoveCategory);

            ele.Items.Clear();

            if (ele is BrowserRootElement)
            {
                BrowserRootCategories.Remove(ele as BrowserRootElement);
            }
            else if (ele is BrowserInternalElement)
            {
                (ele as BrowserInternalElement).Parent.Items.Remove(ele);
            }
        }
コード例 #6
0
 public BrowserItem TryGetSubCategory(BrowserItem category, string catName)
 {
     return(category.Items.FirstOrDefault(x => x.Name == catName));
 }
コード例 #7
0
 public NationalInstrumentsBrowserItem(BrowserItem browserItem)
 {
     _browserItem = browserItem;
 }
コード例 #8
0
        /// <summary>
        /// Get the directories top-level content
        /// </summary>
        /// <param name="fullPath">The full path to the directory</param>
        /// <returns></returns>
        public static List <BrowserItem> GetDirectoryContents(string fullPath)
        {
            var items = new List <BrowserItem>();

            #region Get folders

            try
            {
                var dirs = Directory.GetDirectories(fullPath);

                if (dirs.Length > 0)
                {
                    foreach (var d in dirs)
                    {
                        DirectoryInfo di = new DirectoryInfo(d);

                        // Filter hidden directories
                        if (di.Attributes.HasFlag(FileAttributes.Hidden) == false)
                        {
                            items.Add(new BrowserItem {
                                FullPath = d, Type = BrowserItemType.Folder
                            });
                        }
                    }
                }
            }
            catch
            {
            }

            #endregion

            #region Get files

            try
            {
                var fs = Directory.GetFiles(fullPath);

                if (fs.Length > 0)
                {
                    foreach (var f in fs)
                    {
                        DirectoryInfo di = new DirectoryInfo(f);

                        // Filter out hidden directories
                        if (di.Attributes.HasFlag(FileAttributes.Hidden) == false)
                        {
                            BrowserItem bi = new BrowserItem {
                                FullPath = f
                            };

                            // Check type to add specific icon
                            if (f.EndsWith(".dwg"))
                            {
                                bi.Type = BrowserItemType.Dwg;
                            }
                            else if (f.ToLower().EndsWith(".pdf"))
                            {
                                bi.Type = BrowserItemType.Pdf;
                            }
                            else if (f.ToLower().EndsWith(".jpg") || f.ToLower().EndsWith(".png") ||
                                     f.ToLower().EndsWith(".jpeg") || f.ToLower().EndsWith(".tiff"))
                            {
                                bi.Type = BrowserItemType.Image;
                            }
                            else if (f.ToLower().EndsWith(".txt"))
                            {
                                bi.Type = BrowserItemType.Txt;
                            }
                            else if (f.ToLower().EndsWith(".xls") || f.ToLower().EndsWith(".xlsx"))
                            {
                                bi.Type = BrowserItemType.Xls;
                            }
                            else if (f.ToLower().EndsWith(".rvt") || f.ToLower().EndsWith(".rfa"))
                            {
                                bi.Type = BrowserItemType.Revit;
                            }
                            else
                            {
                                bi.Type = BrowserItemType.File;
                            }

                            // Add file to dispaly list
                            items.Add(bi);
                        }
                    }
                }
            }
            catch
            {
            }

            #endregion

            return(items);
        }
コード例 #9
0
        /// <summary>
        /// Remove a category and all its children from the browser and search.  The category does
        /// not have to be empty.
        /// </summary>
        /// <param name="ele"></param>
        public void RemoveCategory(BrowserItem ele)
        {
            var nodes = ele.Items.Where(x => x is NodeSearchElement)
                           .Cast<NodeSearchElement>().ToList();

            var cats = ele.Items.Where(x => x is BrowserInternalElement)
                           .Cast<BrowserInternalElement>().ToList();

            nodes.Select(x => x.Name).ToList().ForEach(RemoveNode);
            cats.ToList().ForEach(RemoveCategory);

            ele.Items.Clear();

            if (ele is BrowserRootElement)
            {
                BrowserRootCategories.Remove(ele as BrowserRootElement);
            }
            else if (ele is BrowserInternalElement)
            {
                (ele as BrowserInternalElement).Parent.Items.Remove(ele);
            }
        }
コード例 #10
0
 public BrowserItem TryGetSubCategory(BrowserItem category, string catName)
 {
     return category.Items.FirstOrDefault(x => x.Name == catName);
 }
コード例 #11
0
        /// <summary>
        /// Add a single category as a child of a category.  If the category already exists, just return that one.
        /// </summary>
        /// <param name="parent">The parent category </param>
        /// <param name="childCategoryName">The name of the child category (can't be nested)</param>
        /// <returns>The newly created category</returns>
        public BrowserItem TryAddChildCategory(BrowserItem parent, string childCategoryName)
        {
            var newCategoryName = parent.Name + CATEGORY_DELIMITER + childCategoryName;

            // support long nested categories like Math.Math.StaticMembers.Abs
            var parentItem  = parent as BrowserInternalElement;
            while (parentItem != null)
            {
                var grandParent = parentItem.Parent;
                if (null == grandParent)
                    break;

                newCategoryName = grandParent.Name + CATEGORY_DELIMITER + newCategoryName;
                parentItem = grandParent as BrowserInternalElement;
            }

            if (ContainsCategory(newCategoryName))
            {
                return GetCategoryByName(newCategoryName);
            }

            var tempCat = new BrowserInternalElement(childCategoryName, parent);
            parent.AddChild(tempCat);

            return tempCat;
        }
コード例 #12
0
ファイル: BrowserItemTest.cs プロジェクト: zeusongit/Dynamo
 //Constructor for when the BrowserItem parent is passed
 public BrowserItemDerived(string name, BrowserItem parent)
 {
     this._name  = name;
     this.Parent = parent;
 }
コード例 #13
0
ファイル: BrowserItemTest.cs プロジェクト: zeusongit/Dynamo
 //Subscribed method to the BrowserItemHandler event
 private void OldParent_Executed(BrowserItem ele)
 {
     ele.Height = 100;
 }
コード例 #14
0
        /// <summary>
        /// Add a single category as a child of a category.  If the category already exists, just return that one.
        /// </summary>
        /// <param name="parent">The parent category </param>
        /// <param name="childCategoryName">The name of the child category (can't be nested)</param>
        /// <returns>The newly created category</returns>
        public BrowserItem TryAddChildCategory(BrowserItem parent, string childCategoryName)
        {
            var newCategoryName = parent.Name + CATEGORY_DELIMITER + childCategoryName;
            if (ContainsCategory(newCategoryName))
            {
                return GetCategoryByName(newCategoryName);
            }

            var tempCat = new BrowserInternalElement(childCategoryName, parent);
            parent.AddChild(tempCat);

            return tempCat;
        }
コード例 #15
0
        /// <summary>
        /// Remove an empty category from browser and search.  Useful when a single item is removed.
        /// </summary>
        /// <param name="ele"></param>
        public void RemoveEmptyCategory(BrowserItem ele)
        {
            if (ele is BrowserRootElement && ele.Items.Count == 0)
            {
                RemoveEmptyRootCategory(ele as BrowserRootElement);
                return;
            }

            if (ele is BrowserInternalElement && ele.Items.Count == 0)
            {
                var internalEle = ele as BrowserInternalElement;

                internalEle.Parent.Items.Remove(internalEle);
                RemoveEmptyCategory(internalEle.Parent);
            }
        }
コード例 #16
0
        internal static BrowserItemViewModel Wrap(BrowserItem item)
        {
            dynamic itemDyn = item;

            return(WrapExplicit(itemDyn));
        }
コード例 #17
0
 public BrowserInternalElement(string name, BrowserItem parent)
 {
     this._name = name;
     this.Parent = parent;
     this.OldParent = null;
 }