REcent Files - roll back last check in I did, oops.

This commit is contained in:
adelikat 2013-08-01 00:37:18 +00:00
parent f0889537af
commit b1c5181b5f
1 changed files with 23 additions and 27 deletions

View File

@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
@ -7,57 +6,54 @@ namespace BizHawk.MultiClient
public class RecentFiles public class RecentFiles
{ {
private readonly int MAX_RECENT_FILES; //Maximum number of files private readonly int MAX_RECENT_FILES; //Maximum number of files
private readonly List<string> _recent_list; //List of recent files private readonly List<string> recentlist; //List of recent files
public RecentFiles()
: this(8) { }
public RecentFiles() : this(8) { }
public RecentFiles(int max) public RecentFiles(int max)
{ {
_recent_list = new List<string>(); recentlist = new List<string>();
MAX_RECENT_FILES = max; MAX_RECENT_FILES = max;
} }
public void Clear() public void Clear()
{ {
_recent_list.Clear(); recentlist.Clear();
} }
public bool Empty public bool Empty
{ {
get { return _recent_list.Count == 0; } get { return recentlist.Count == 0; }
} }
public int Count public int Count
{ {
get { return _recent_list.Count; } get { return recentlist.Count; }
} }
public void Add(string newFile) public void Add(string newFile)
{ {
foreach (string recent in _recent_list) for (int x = 0; x < recentlist.Count; x++)
{
if (String.Compare(newFile, recent, true) == 0)
{
_recent_list.Remove(newFile); //intentionally keeps iterating after this to remove duplicate instances, though those should never exist in the first place
}
}
_recent_list.Insert(0, newFile);
if (_recent_list.Count > MAX_RECENT_FILES)
{ {
_recent_list.Remove(_recent_list[_recent_list.Count - 1]); if (string.Compare(newFile, recentlist[x]) == 0)
{
recentlist.Remove(newFile); //intentionally keeps iterating after this to remove duplicate instances, though those should never exist in the first place
}
}
recentlist.Insert(0, newFile);
if (recentlist.Count > MAX_RECENT_FILES)
{
recentlist.Remove(recentlist[recentlist.Count - 1]);
} }
} }
public bool Remove(string newFile) public bool Remove(string newFile)
{ {
bool removed = false; bool removed = false;
foreach(string recent in _recent_list) for (int x = 0; x < recentlist.Count; x++)
{ {
if (string.Compare(newFile, recent, true) == 0) if (string.Compare(newFile, recentlist[x]) == 0)
{ {
_recent_list.Remove(newFile); //intentionally keeps iterating after this to remove duplicate instances, though those should never exist in the first place recentlist.Remove(newFile); //intentionally keeps iterating after this to remove duplicate instances, though those should never exist in the first place
removed = true; removed = true;
} }
} }
@ -67,14 +63,14 @@ namespace BizHawk.MultiClient
public List<string> GetRecentListTruncated(int length) public List<string> GetRecentListTruncated(int length)
{ {
//iterate through list, truncating each item to length, and return the result in a List<string> //iterate through list, truncating each item to length, and return the result in a List<string>
return _recent_list.Select(t => t.Substring(0, length)).ToList(); return recentlist.Select(t => t.Substring(0, length)).ToList();
} }
public string GetRecentFileByPosition(int position) public string GetRecentFileByPosition(int position)
{ {
if (_recent_list.Count > 0) if (recentlist.Count > 0)
{ {
return _recent_list[position]; return recentlist[position];
} }
else else
{ {