// // Copyright 2014 Perforce Software Inc. // using Perforce.Model; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Perforce.ViewModel { public class BreadcrumbBarViewModel : ViewModelBase { private ObservableCollection _breadcrumbItems; public void UpdatePath(params ListingItem[] selection) { string depotPath = null; var isFolder = true; if (selection != null) { if (selection.Count() == 1) { depotPath = selection[0].DepotPath; isFolder = selection[0].Type.Equals(ListingItem.TYPE.FOLDER); } else if (selection.Count() > 1) { depotPath = selection[0].DepotPath; depotPath = depotPath.Substring(0, depotPath.LastIndexOf('/')); isFolder = true; } } if (depotPath == null) depotPath = "/"; var items = new List(); var parts = depotPath.Split('/'); var last = depotPath.LastIndexOf('/'); while (last > 0) { var name = depotPath.Substring(last + 1); items.Add(new BreadCrumbItem { Label = name, Path = depotPath, IsFolder = isFolder }); depotPath = depotPath.Substring(0, last); last = depotPath.LastIndexOf('/'); isFolder = true; } items.Reverse(); ObservableCollection update = new ObservableCollection(); foreach (var item in items) { update.Add(item); } BreadcrumbItems = update; } public ObservableCollection BreadcrumbItems { get { return _breadcrumbItems; } set { _breadcrumbItems = value; OnPropertyChanged("BreadcrumbItems"); } } } public class BreadCrumbItem { public string Label { get; set; } public string Path { get; set; } public bool IsFolder { get; set; } } }