/// <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); }
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; }
/// <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); }
/// <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); } }
/// <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); } }
public BrowserItem TryGetSubCategory(BrowserItem category, string catName) { return(category.Items.FirstOrDefault(x => x.Name == catName)); }
public NationalInstrumentsBrowserItem(BrowserItem browserItem) { _browserItem = browserItem; }
/// <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); }
/// <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); } }
public BrowserItem TryGetSubCategory(BrowserItem category, string catName) { return category.Items.FirstOrDefault(x => x.Name == catName); }
/// <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; }
//Constructor for when the BrowserItem parent is passed public BrowserItemDerived(string name, BrowserItem parent) { this._name = name; this.Parent = parent; }
//Subscribed method to the BrowserItemHandler event private void OldParent_Executed(BrowserItem ele) { ele.Height = 100; }
/// <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; }
/// <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); } }
internal static BrowserItemViewModel Wrap(BrowserItem item) { dynamic itemDyn = item; return(WrapExplicit(itemDyn)); }
public BrowserInternalElement(string name, BrowserItem parent) { this._name = name; this.Parent = parent; this.OldParent = null; }