// // Copyright 2014 Perforce Software Inc. // using Perforce.Helper; using Perforce.View; using Perforce.ViewModel; using System; using System.Collections.ObjectModel; using System.Windows; using System.Windows.Controls; namespace Perforce.Model { public abstract class ListingItem : ViewModelBase, IEquatable, IComparable { public enum TYPE { FOLDER, FILE } private string _labelText; public string LabelText { get { return _labelText; } set { _labelText = value; } } private bool _isSelected; public bool IsSelected { get { return _isSelected; } set { _isSelected = value;} } public void RefreshSelected() { OnPropertyChanged("IsSelected"); } private bool _isIgnored; public bool IsIgnored { get { return _isIgnored; } set { _isIgnored = value; } } //private int _viewColumn; //public int ViewColumn { // get { return _viewColumn; } // set { _viewColumn = value; } //} private ColumnDisplay _columnContext; public ColumnDisplay ColumnContext { get { return _columnContext; } set { _columnContext = value; } } public void RefreshContextMenu() { OnPropertyChanged("ItemContextMenu"); } public ObservableCollection ItemContextMenu { get { return ContextMenuHelper.GetContextMenu(this); } } public abstract string DepotPath { get; set; } public abstract string ClientPath { get; set; } public abstract bool IsMapped { get; set; } public abstract TYPE Type { get; } public abstract string Icon { get; } public virtual void Refresh() { OnPropertyChanged(string.Empty); } public override int GetHashCode() { if (DepotPath != null) { return DepotPath.GetHashCode(); } else if (ClientPath != null) { return ClientPath.GetHashCode(); } else { return LabelText.GetHashCode(); } } public bool Equals(ListingItem obj) { var same = false; if (obj != null && obj is ListingItem) { var other = obj as ListingItem; if (DepotPath != null) { same = DepotPath.Equals(other.DepotPath, StringComparison.CurrentCultureIgnoreCase); } else if (ClientPath != null) { same = ClientPath.Equals(other.ClientPath, StringComparison.CurrentCultureIgnoreCase); } else { same = LabelText.Equals(other.LabelText, StringComparison.CurrentCultureIgnoreCase); } } return same; } public int CompareTo(ListingItem obj) { int result = 0; if (DepotPath != null) { result = DepotPath.ToLowerInvariant().CompareTo(obj.DepotPath.ToLowerInvariant()); } else if (ClientPath != null) { result = ClientPath.ToLowerInvariant().CompareTo(obj.ClientPath.ToLowerInvariant()); } else { result = LabelText.ToLowerInvariant().CompareTo(obj.LabelText.ToLowerInvariant()); } return result; } public override string ToString() { return LabelText; } } }