Beispiel #1
0
        /// <summary>
        /// Adds a new item to the recents list in the appropriate position.
        /// </summary>
        /// <param name="newRecent"></param>
        /// <param name="isLoading"></param>
        public void AddRecent(string newRecent, bool isLoading)
        {
            if (isLoading)
            {
                RecentPaths.Add(newRecent); //in order
            }
            else
            {
                // Remove the new recent from the list if it exists - as we will re-insert it (at the front)
                RecentPaths.ReplaceAll(RecentPaths.Where(x =>
                                                         !x.Equals(newRecent, StringComparison.InvariantCultureIgnoreCase)).ToList());
                RecentPaths.Insert(0, newRecent); //put at front
            }
            while (RecentPaths.Count > 10)
            {
                RecentPaths.RemoveAt(10); //Just remove trailing items
            }

            RecentsMenu.IsEnabled = true; //An item exists in the menu
            if (!isLoading)
            {
                RefreshRecentsMenu();
                SaveRecentList(true);
            }
        }
 private void ShrinkList()
 {
     if (RecentPaths.Count > 10)
     {
         RecentPaths = RecentPaths.Take(10).ToList();
     }
 }
 internal void InsertInRecentFilesList(string filePath)
 {
     RecentPaths.RemoveAll(s => s == filePath);
     RecentPaths.Insert(0, filePath);
     ShrinkList();
     SaveRecentFilesList();
 }
        /// <summary>
        /// Requires PathValidationRequested to be handled.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Item_Click(object sender, EventArgs e)
        {
            var    item = (MenuItem)sender;
            string txt  = item.Header as string;

            if (txt == "Clear list")
            {
                RecentPaths.Clear();
                SaveRecentFilesList();
                return;
            }

            var ea = new PathValidationEventArgs()
            {
                Path = item.ToolTip as string
            };

            PathValidationRequested?.Invoke(this, ea);
            if (!ea.Valid)
            {
                RemovePath(item.ToolTip as string);
            }
            else
            {
                InsertInRecentFilesList(item.ToolTip as string);
            }
        }
Beispiel #5
0
 /// <summary>
 /// Sets the whole recents list. Does not propogate.
 /// </summary>
 /// <param name="recents"></param>
 private void SetRecents(IEnumerable <string> recents)
 {
     RecentPaths.ClearEx();
     foreach (string referencedFile in recents)
     {
         if (File.Exists(referencedFile))
         {
             AddRecent(referencedFile, true);
         }
     }
     RefreshRecentsMenu();
 }
Beispiel #6
0
        /// <summary>
        /// 從最近記錄檔中刪除指定的路徑(通常用於檔案或路徑已經不存在時)
        /// </summary>
        /// <param name="path"></param>
        public void RemoveFromRecentPaths(string path)
        {
            if (RecentPaths == null || !RecentPaths.Any())
            {
                return;
            }

            int pos = RecentPaths.FindIndex(x => x.Path == path);

            if (pos >= 0)
            {
                RecentPaths.RemoveAt(pos);
            }
        }
Beispiel #7
0
        public void RememberRecentPath(string path, DisplayMode mode)
        {
            if (RecentPaths == null)
            {
                RecentPaths = new List <WordPath>();
            }

            // 如果之前已經有存過了,就先刪掉.
            RemoveFromRecentPaths(path);

            // 最新的加在開頭
            RecentPaths.Insert(0, new WordPath()
            {
                Path     = path,
                PathMode = mode
            });

            //如果已經記錄超過了最大限制,就刪掉最後一個(最不常開的)
            if (RecentPaths.Count > MaxRememberPathCount)
            {
                RecentPaths.RemoveAt(MaxRememberPathCount);
            }
        }
 internal void RemovePath(string p)
 {
     RecentPaths.Remove(p);
 }