Beispiel #1
0
        /// <summary>
        /// Negates the pin entry state for a given mru list entry.
        /// </summary>
        /// <param name="val"></param>
        private void PinUnpinEntry(IMRUEntryViewModel val)
        {
            var newIsPinnedValue = (val.IsPinned == 0 ? _NextIsPinnedValue : 0);

            var oldIsPinnedValue = val.IsPinned;

            val.SetIsPinned(newIsPinnedValue);

            if (newIsPinnedValue != 0)     // Increment next IsPinned order entry
            {
                _NextIsPinnedValue += 1;   // If this entry is a newly pinned enty

                // Update all entries if this entry is the first entry to be pinned
                if (_NextIsPinnedValue == 2 && Entries.Count > 0)
                {
                    List <IMRUEntryViewModel> values = new List <IMRUEntryViewModel>();

                    foreach (var item in Entries.Values)
                    {
                        values.Add(item);
                    }

                    foreach (var item in values)
                    {
                        UpdateEntry(item);
                    }
                }
            }
            else
            {
                DecrementPinnedValues(oldIsPinnedValue);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Removes an <see cref="IMRUEntryViewModel"/> from the <see cref="MRUModel"/>.
        /// </summary>
        /// <param name="entry">
        /// The <see cref="IMRUEntryViewModel"/> to remove.
        /// </param>
        public void RemoveMRUItem(IMRUEntryViewModel entry)
        {
            MRUModel.RemoveEntry(entry);
            SaveMRU();

            OnPropertyChanged(nameof(MRUModel));
        }
Beispiel #3
0
        /// <summary>
        /// Exchange the spots of pinned items <paramref name="item1"/>
        /// and <paramref name="item2"/> via exchange of IsPinned values
        /// and direct add/remove in viewmodel collection.
        /// </summary>
        /// <param name="item1"></param>
        /// <param name="item2"></param>
        /// <returns></returns>
        private bool ExchangePinnedSpots(IMRUEntryViewModel item1
                                         , IMRUEntryViewModel item2)
        {
            if (item1 != null && item2 != null)
            {
                if (item1.IsPinned == 0 || item2.IsPinned == 0)
                {
                    return(false);
                }

                this.Entries.Remove(item2.PathFileName);
                this.Entries.Remove(item1.PathFileName);

                var isPinnedBack = item1.IsPinned;
                item1.SetIsPinned(item2.IsPinned);
                item2.SetIsPinned(isPinnedBack);

                this.Entries.Add(item2.PathFileName, item2);
                this.Entries.Add(item1.PathFileName, item1);

                return(true);
            }

            return(false);
        }
Beispiel #4
0
        private bool MoveItemDown(IMRUEntryViewModel param)
        {
            // Get all pinned entries
            var list = this.Entries.Where(x => x.Value.IsPinned != 0).ToList();

            if (list.Count <= 1)
            {
                return(false);
            }

            // Find the item that is before the item that is to be moved
            IMRUEntryViewModel lowerItem = null;

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Value.IsPinned > param.IsPinned)
                {
                    if (lowerItem == null)
                    {
                        lowerItem = list[i].Value;
                    }
                    else
                    {
                        if (list[i].Value.IsPinned < lowerItem.IsPinned)
                        {
                            lowerItem = list[i].Value;
                        }
                    }
                }
            }

            // Exchange spots via exchange of IsPinned values and direct add/remove
            return(ExchangePinnedSpots(lowerItem, param));
        }
Beispiel #5
0
        /// <summary>
        /// Method adds an entry if the given path was not available until now.
        /// Otherwise, elements properties (IsPinned) are updated only.
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="isPinned"></param>
        /// <param name="bUpdate"></param>
        /// <returns>true if update or insert was performd, false otherwise.</returns>
        public bool UpdateEntry(string filepath
                                , bool isPinned = false
                                , bool bUpdate  = false)
        {
            DateTime lastUpdate = DateTime.Now;
            var      pathFile   = PathModel.NormalizePath(filepath);

            if (this.Entries.Contains(pathFile) == true)
            {
                if (bUpdate == false)
                {
                    return(false);
                }

                IMRUEntryViewModel item = FindEntry(pathFile);

                PinUnpinEntry(item, isPinned);
                item.SetLastUpdate(lastUpdate);

                UpdateItem(item);

                return(true);
            }

            // Remove last entry if list has grown too long
            if (this.MaxMruEntryCount <= this.Entries.Count)
            {
                this.Entries.RemoveAt(this.Entries.Count - 1);
            }

            this.AddEntry(pathFile, new MRUEntryViewModel(pathFile));

            return(true);
        }
Beispiel #6
0
        /// <summary>
        /// Moves a pinned MRU Item up/down in the group of pinned items.
        /// </summary>
        /// <param name="direction"></param>
        /// <param name="param"></param>
        public void MovePinnedEntry(MoveMRUItem direction, IMRUEntryViewModel param)
        {
            if (param == null)
            {
                return;
            }

            if (param.IsPinned == 0)  // Move only within the list group of pinned items
            {
                return;
            }

            switch (direction)
            {
            case MoveMRUItem.Up:
                MoveItemUp(param);
                break;

            case MoveMRUItem.Down:
                MoveItemDown(param);
                break;

            default:
                throw new NotSupportedException(direction.ToString());
            }
        }
Beispiel #7
0
        /// <summary>
        /// This is invoked when an existing item's peroperties have changed -
        /// that is the item was already in the list but a sort criteria has changed.
        ///
        /// To make that change visible we are removing and inserting the item in the list.
        /// There does not seem any other way to get that update across(?):
        /// https://social.msdn.microsoft.com/Forums/vstudio/en-US/cb7c5c62-7ca9-49b5-91a0-379581b1c1aa/listview-sorting-not-updating-when-items-in-the-itemssource-changes?forum=wpf
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private bool UpdateItem(IMRUEntryViewModel item)
        {
            if (item != null)
            {
                this.Entries.Remove(item.PathFileName);
                this.Entries.Add(item.PathFileName, item);

                return(true);
            }

            return(false);
        }
Beispiel #8
0
        /// <summary>
        /// Adds a new entry into the list of MRU entries and
        /// ensures the correct pin counter states.
        /// </summary>
        /// <param name="pathFile"></param>
        /// <param name="emp"></param>
        private void AddEntry(string pathFile,
                              IMRUEntryViewModel emp)
        {
            // Add a completely new entry
            var newobj           = new MRUEntryViewModel(emp as MRUEntryViewModel);
            var newIsPinnedValue = (newobj.IsPinned == 0 ? false : true);

            // Reset pin counter on item to make sure its correctly placed in the sorted list
            if (newIsPinnedValue == true)
            {
                this.PinUnpinEntry(newobj, newIsPinnedValue);
            }

            this.Entries.Add(pathFile, newobj);
        }
Beispiel #9
0
        /// <summary>
        /// Sets the pinning entry mode for this filenamepath entry.
        /// </summary>
        /// <param name="isPinned"></param>
        /// <param name="filepath"></param>
        /// <returns></returns>
        public bool PinUnpinEntry(bool isPinned, string filepath)
        {
            var pathFile = PathModel.NormalizePath(filepath);

            if (this.Entries.Contains(pathFile) == true)
            {
                IMRUEntryViewModel obj = FindEntry(pathFile);

                PinUnpinEntry(obj, isPinned);

                return(true);
            }

            return(false);
        }
Beispiel #10
0
        /// <summary>
        /// Remove any entry (whether its pinned or not) based on a viewmodel item.
        /// </summary>
        /// <param name="mruEntry"></param>
        /// <returns>true if item was succesfully removed, otherwise false.</returns>
        public bool RemoveEntry(IMRUEntryViewModel mruEntry)
        {
            if (mruEntry == null)
            {
                return(false);
            }

            if (mruEntry.IsPinned != 0)
            {
                PinUnpinEntry(mruEntry, false);
            }

            this.Entries.Remove(mruEntry.PathFileName);

            return(true);
        }
Beispiel #11
0
        /// <summary>
        /// Method adds an entry if the given path was not available until now.
        /// Otherwise, elements properties (IsPinned) are updated only.
        /// </summary>
        /// <param name="emp"></param>
        public void UpdateEntry(IMRUEntryViewModel emp)
        {
            if (emp == null)
            {
                return;
            }

            if ((emp is MRUEntryViewModel) == false)
            {
                throw new NotSupportedException("Parameter emp cannot be updated since it is not of a known internal viewmodel type. Consider using a different UpdateEntry() method.");
            }

            var pathFile = PathModel.NormalizePath(emp.File.Path);

            if (this.Entries.Contains(pathFile) == true)
            {
                IMRUEntryViewModel item;
                this.Entries.TryGetValue(pathFile, out item);

                // Assumption: We have noting to pin or unpin if both,
                // old and new value, indicate the same pin state
                if (item.IsPinned != 0 && emp.IsPinned == 0)
                {
                    this.PinUnpinEntry(false, item);     // Remove existing pin
                }
                else
                {
                    if (item.IsPinned == 0 && emp.IsPinned != 0)
                    {
                        this.PinUnpinEntry(true, item);        // Set new pin
                    }
                }

                item.SetLastUpdate(emp.LastUpdate);
                UpdateItem(item);

                return;
            }

            // Remove last entry if list has grown too long
            if (this.MaxMruEntryCount <= this.Entries.Count)
            {
                this.Entries.RemoveAt(this.Entries.Count - 1); // Remove last existing pin
            }
            // Add a completely new entry
            this.AddEntry(pathFile, emp);
        }
Beispiel #12
0
        /// <summary>
        /// Method should be called on application start-up to read MRU
        /// data from persisted session object into its associated viewmodel.
        /// </summary>
        /// <param name="sessionData"></param>
        public void ReadMruFromSession(IProfile sessionData)
        {
            try  // Read back MRU data information
            {
                List.Entries.Clear();
                foreach (var item in sessionData.LastActiveSourceFiles)
                {
                    IMRUEntryViewModel mruItem =
                        MRULib.MRU_Service.Create_Entry(item.path,
                                                        item.LastTimeOfEdit);
                    mruItem.SetIsPinned(item.IsPinned);

                    List.UpdateEntry(mruItem);
                }
            }
            catch
            {
            }
        }
Beispiel #13
0
        /// <summary>
        /// Pin or unpines an entry depending on the <paramref name="isPinned"/> parameter.
        /// </summary>
        /// <param name="val"></param>
        /// <param name="isPinned"></param>
        private void PinUnpinEntry(IMRUEntryViewModel val, bool isPinned)
        {
            var oldIsPinnedValue = val.IsPinned;

            if (isPinned == true)
            {
                var newIsPinnedValue = _NextIsPinnedValue;

                val.SetIsPinned(newIsPinnedValue);

                // Increment next IsPinned order entry
                _NextIsPinnedValue += 1;   // since this entry is a newly pinned enty
            }
            else
            {
                val.SetIsPinned(0);

                DecrementPinnedValues(oldIsPinnedValue);
            }
        }
Beispiel #14
0
        private bool MoveItemUp(IMRUEntryViewModel param)
        {
            // Nothing to move if Item is already in first spot
            if (param.IsPinned <= 1)
            {
                return(false);
            }

            // Get all pinned entries
            var list = this.Entries.Where(x => x.Value.IsPinned != 0).ToList();

            if (list.Count <= 1)
            {
                return(false);
            }

            // Find the item that is before the item that is to be moved
            IMRUEntryViewModel upperItem = null;

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Value.IsPinned < param.IsPinned)
                {
                    if (upperItem == null)
                    {
                        upperItem = list[i].Value;
                    }
                    else
                    {
                        if (list[i].Value.IsPinned > upperItem.IsPinned)
                        {
                            upperItem = list[i].Value;
                        }
                    }
                }
            }


            // Exchange spots via exchange of IsPinned values and direct add/remove
            return(ExchangePinnedSpots(upperItem, param));
        }
Beispiel #15
0
 /// <summary>
 /// Sets the pinning entry mode for this filenamepath entry.
 /// </summary>
 /// <param name="isPinned"></param>
 /// <param name="e"></param>
 /// <returns></returns>
 public bool PinUnpinEntry(bool isPinned, IMRUEntryViewModel e)
 {
     return(this.PinUnpinEntry(isPinned, e.PathFileName));
 }
Beispiel #16
0
        /// <summary>
        /// Determines whether this object equals the other object or not.
        /// </summary>
        /// <param name="obj"></param>
        public override bool Equals(object obj)
        {
            var other = obj as MRUListViewModel;

            if (other == null)
            {
                return(false);
            }

            if (this.MaxMruEntryCount != other.MaxMruEntryCount)
            {
                return(false);
            }

            if (this.Entries.Count != other.Entries.Count)
            {
                return(false);
            }

            for (int i = 0; i < Entries.Count; i++)
            {
                if (Entries[i].Key != other.Entries[i].Key)
                {
                    return(false);
                }

                IMRUEntryViewModel entry = null;
                Entries.TryGetValue(Entries[i].Key, out entry);

                IMRUEntryViewModel otherEntry = null;
                if (other.Entries.TryGetValue(Entries[i].Key, out otherEntry) == false)
                {
                    return(false);
                }
                else
                {
                    if (entry == null)
                    {
                        return(false);
                    }

                    if (otherEntry.File.Path != entry.File.Path)
                    {
                        return(false);
                    }

                    if (otherEntry.PathFileName != entry.PathFileName)
                    {
                        return(false);
                    }

                    if (otherEntry.PathfileNameUri != entry.PathfileNameUri)
                    {
                        return(false);
                    }

                    if (otherEntry.IsPinned != entry.IsPinned)
                    {
                        return(false);
                    }

                    if (entry.LastUpdate.Equals(Entries[i].Value.LastUpdate) == false)
                    {
                        return(false);
                    }

                    if (otherEntry.GroupItem.Equals(entry.GroupItem) == false)
                    {
                        return(false);
                    }

                    if (otherEntry.DisplayPathFileName != entry.DisplayPathFileName)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }