SearchSelectorViewModel.cs #1

  • //
  • guest/
  • christoph_leithner/
  • piper/
  • main/
  • windows/
  • R1.1/
  • Perforce/
  • ViewModel/
  • SearchSelectorViewModel.cs
  • View
  • Commits
  • Open Download .zip Download (6 KB)
//
// 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<string>();
            //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<string> _tagFilters;
        public SortedSet<string> TagFilters {
            get { return _tagFilters; }
            set {
                _tagFilters = value;
                OnPropertyChanged("TagListText");
            }
        }

        public void AddTagFilter(string tag) {
            if (_tagFilters == null) {
                _tagFilters = new SortedSet<string>();
            }
            _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<SelectableObject<string>> _tagList;
        public ObservableCollection<SelectableObject<string>> TagList {
            get {
                SortedSet<string> tags = new SortedSet<string>();
                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<SelectableObject<string>>();
                } 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<string>(t, selected));
                    }
                }
                return _tagList;
            }
        }

        //public List<string> 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<T> {
        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;
        }
    }
   
}
# Change User Description Committed
#1 16817 christoph_leithner "Forking branch Main of perforce-software-piper to christoph_leithner-piper."
//guest/perforce_software/piper/main/windows/R1.1/Perforce/ViewModel/SearchSelectorViewModel.cs
#1 16507 perforce_software Move to main branch.
//guest/perforce_software/piper/windows/R1.1/Perforce/ViewModel/SearchSelectorViewModel.cs
#2 13572 alan_petersen updating R1.1
#1 11256 alan_petersen Populate //guest/perforce_software/piper/windows/R1.1/...
from //guest/perforce_software/piper/windows/main/....
//guest/perforce_software/piper/windows/main/Perforce/ViewModel/SearchSelectorViewModel.cs
#1 11255 alan_petersen Rename/move file(s)
//guest/perforce_software/piper/windows/Perforce/ViewModel/SearchSelectorViewModel.cs
#1 10761 alan_petersen initial drop of Piper for Windows....

this version still has _many_ bugs (er... i mean "unintended features") but I will be updating it over the next week as more stability is added.