public bool RemovePinEntry(MRUEntryVM mruEntry) { try { if (this.mListOfMRUEntries == null) { return(false); } MRUEntryVM e = this.mListOfMRUEntries.Single(mru => mru.PathFileName == mruEntry.PathFileName); this.mListOfMRUEntries.Remove(e); //// this.NotifyPropertyChanged(() => this.ListOfMRUEntries); return(true); } catch (Exception exp) { Msg.Show(this.AppName + " encountered an error when removing an entry:" + Environment.NewLine + Environment.NewLine + exp.ToString(), "Error when pinning an MRU entry", MsgBoxButtons.OK, MsgBoxImage.Error); } return(false); }
public void AddMRUEntry(MRUEntryVM newEntry) { if (newEntry == null) { return; } try { if (this.mListOfMRUEntries == null) { this.mListOfMRUEntries = new ObservableCollection <MRUEntryVM>(); } // Remove all entries that point to the path we are about to insert MRUEntryVM e = this.mListOfMRUEntries.SingleOrDefault(item => newEntry.PathFileName == item.PathFileName); if (e != null) { // Do not change an entry that has already been pinned -> its pinned in place :) if (e.IsPinned == true) { return; } this.mListOfMRUEntries.Remove(e); } // Remove last entry if list has grown too long if (this.MaxMruEntryCount <= this.mListOfMRUEntries.Count) { this.mListOfMRUEntries.RemoveAt(this.mListOfMRUEntries.Count - 1); } // Add model entry in ViewModel collection (First pinned entry or first unpinned entry) if (newEntry.IsPinned == true) { this.mListOfMRUEntries.Insert(0, new MRUEntryVM(newEntry)); } else { this.mListOfMRUEntries.Insert(this.CountPinnedEntries(), new MRUEntryVM(newEntry)); } } catch (Exception exp) { Msg.Show(exp.ToString(), "An error has occurred", MsgBoxButtons.OK, MsgBoxImage.Error); } ////finally ////{ //// this.NotifyPropertyChanged(() => this.ListOfMRUEntries); ////} }
/// <summary> /// /// </summary> /// <param name="bPinOrUnPinMruEntry"></param> /// <param name="mruEntry"></param> public bool PinUnpinEntry(bool bPinOrUnPinMruEntry, MRUEntryVM mruEntry) { try { if (this.mListOfMRUEntries == null) { return(false); } int pinnedMruEntryCount = this.CountPinnedEntries(); // pin an MRU entry into the next available pinned mode spot if (bPinOrUnPinMruEntry == true) { MRUEntryVM e = this.mListOfMRUEntries.Single(mru => mru.IsPinned == false && mru.PathFileName == mruEntry.PathFileName); if (this.PinSortMode == MRUSortMethod.PinnedEntriesFirst) { this.mListOfMRUEntries.Remove(e); } e.IsPinned = true; if (this.PinSortMode == MRUSortMethod.PinnedEntriesFirst) { this.mListOfMRUEntries.Insert(pinnedMruEntryCount, e); } pinnedMruEntryCount += 1; //// this.NotifyPropertyChanged(() => this.ListOfMRUEntries); return(true); } else { // unpin an MRU entry into the next available unpinned spot MRUEntryVM e = this.mListOfMRUEntries.Single(mru => mru.IsPinned == true && mru.PathFileName == mruEntry.PathFileName); if (this.PinSortMode == MRUSortMethod.PinnedEntriesFirst) { this.mListOfMRUEntries.Remove(e); } e.IsPinned = false; pinnedMruEntryCount -= 1; if (this.PinSortMode == MRUSortMethod.PinnedEntriesFirst) { this.mListOfMRUEntries.Insert(pinnedMruEntryCount, e); } //// this.NotifyPropertyChanged(() => this.ListOfMRUEntries); return(true); } } catch (Exception exp) { Msg.Show(this.AppName + " encountered an error when pinning an entry:" + Environment.NewLine + Environment.NewLine + exp.ToString(), "Error when pinning an MRU entry", MsgBoxButtons.OK, MsgBoxImage.Error); } return(false); }
/// <summary> /// Copy constructor /// </summary> /// <param name="copySource"></param> public MRUEntryVM(MRUEntryVM copySource) : this() { this.mMRUEntry = new Model.MRUEntry(copySource.mMRUEntry); this.IsPinned = copySource.IsPinned; }