// // Copyright 2014 Perforce Software Inc. // using Perforce.Helper; using Perforce.Model; using Perforce.View; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; namespace Perforce.ViewModel { public class SearchSelectorViewModel : SidebarSelectorViewModelBase { private string _searchStr; public SearchSelectorViewModel(SidebarSelector view) : base(view) { //SelectedTags = new List(); //Utility.SetProperty(Constants.TAG_FILTERS, string.Empty); } public string SearchStr { get { return _searchStr; } set { _searchStr = value; OnPropertyChanged("SearchStr"); } } private bool _allFilesLocation = true; public bool AllFilesLocation { get { return _allFilesLocation; } set { _allFilesLocation = value; OnPropertyChanged("AllFilesLocation"); } } private bool _myWorkspaceLocation = false; public bool MyWorkspaceLocation { get { return _myWorkspaceLocation; } set { _myWorkspaceLocation = value; OnPropertyChanged("MyWorkspaceLocation"); } } private bool _restrictSearchToFolder = false; public bool RestrictSearchToFolder { get { return _restrictSearchToFolder; } set { _restrictSearchToFolder = value; OnPropertyChanged("RestrictSearchToFolder"); } } private bool _fileSearch = true; public bool FileSearch { get { return _fileSearch; } set { _fileSearch = value; OnPropertyChanged("FileSearch"); } } private bool _contentSearch = true; public bool ContentSearch { get { return _contentSearch; } set { _contentSearch = value; OnPropertyChanged("ContentSearch"); } } private bool _tagSearch = true; public bool TagSearch { get { return _tagSearch; } set { _tagSearch = value; OnPropertyChanged("TagSearch"); } } private string _depotPath = string.Empty; public string DepotPath { get { return _depotPath; } set { _depotPath = value; OnPropertyChanged("SelectedFolderName"); OnPropertyChanged("DepotPathSelected"); } } public bool DepotPathSelected { get { return _depotPath.Trim().Length > 0; } } public string SelectedFolderName { get { var label = string.Empty; if (!string.IsNullOrEmpty(_depotPath)) { label = string.Format("\" {0} \"", _depotPath.Substring(_depotPath.LastIndexOf("/")+1)); } return label; } } private SortedSet _tagFilters; public SortedSet TagFilters { get { return _tagFilters; } set { _tagFilters = value; OnPropertyChanged("TagListText"); } } public void AddTagFilter(string tag) { if (_tagFilters == null) { _tagFilters = new SortedSet(); } _tagFilters.Add(tag); OnPropertyChanged("TagListText"); } public void RemoveTagFilter(string tag) { if (_tagFilters != null) { _tagFilters.Remove(tag); OnPropertyChanged("TagListText"); } } public string TagListText { set { } get { if (_tagFilters != null && _tagFilters.Count > 0) { return string.Join(",", _tagFilters); } else { return "-- select tag filter --"; } } } private ObservableCollection> _tagList; public ObservableCollection> TagList { get { SortedSet tags = new SortedSet(); if (View.Model.CurrentColumn != null) { foreach (var item in View.Model.CurrentColumn.Listing.Items) { var md = (item as FileItem).Metadata; if (md != null && md.Attributes.ContainsKey("tags")) { var hexTags = md.Attributes["tags"] as string; var tagList = ListingHelper.HexToString(hexTags); foreach (var t in tagList.Split(',')) { tags.Add(t); } } } } if (_tagList == null) { _tagList = new ObservableCollection>(); } else { _tagList.Clear(); } if (tags.Count > 0) { foreach (var t in tags) { var selected = false; if (_tagFilters != null) { selected = _tagFilters.Contains(t); } _tagList.Add(new SelectableObject(t, selected)); } } return _tagList; } } //public List SelectedTags; public void ForceReload(string propname) { OnPropertyChanged(propname); } public override SELECTOR_TYPE SelectorType { get { return SELECTOR_TYPE.SEARCH; } } public override void Refresh() { if (!string.IsNullOrEmpty(_searchStr)) { GridHelper.InitializeGrid(View); } } } public class SelectableObject { public bool IsSelected { get; set; } public T ObjectData { get; set; } public SelectableObject(T objectData) { ObjectData = objectData; } public SelectableObject(T objectData, bool isSelected) { IsSelected = isSelected; ObjectData = objectData; } } }