1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Collections.Generic;
6
using System.Collections.ObjectModel;
9
using System.Windows.Shell;
10
using ICSharpCode.Core;
12
namespace ICSharpCode.SharpDevelop
15
/// This class handles the recent open files and the recent open project files of SharpDevelop
16
/// it checks, if the files exists at every creation, and if not it doesn't list them in the
17
/// recent files, and they'll not be saved during the next option save.
19
public sealed class RecentOpen
22
/// This variable is the maximal length of lastfile/lastopen entries
27
readonly ObservableCollection<string> lastfile = new ObservableCollection<string>();
28
readonly ObservableCollection<string> lastproject = new ObservableCollection<string>();
30
public IList<string> RecentFile {
36
public IList<string> RecentProject {
46
public RecentOpen(Properties p)
48
// don't check whether files exist because that might be slow (e.g. if file is on network
49
// drive that's unavailable)
51
// if one of these entries is a string, then it's from a previous SharpDevelop version - don't try loading it
52
if (p.Contains("Files") && !(p.Get("Files") is string)) {
53
lastfile.AddRange(p.Get("Files", new string[0]));
56
if (p.Contains("Projects") && !(p.Get("Files") is string)) {
57
lastproject.AddRange(p.Get("Projects", new string[0]));
61
public void AddLastFile(string name)
63
for (int i = 0; i < lastfile.Count; ++i) {
64
if (lastfile[i].Equals(name, StringComparison.OrdinalIgnoreCase)) {
69
while (lastfile.Count >= MAX_LENGTH) {
70
lastfile.RemoveAt(lastfile.Count - 1);
73
lastfile.Insert(0, name);
76
public void ClearRecentFiles()
81
public void ClearRecentProjects()
86
public void AddLastProject(string name)
88
for (int i = 0; i < lastproject.Count; ++i) {
89
if (lastproject[i].ToString().Equals(name, StringComparison.OrdinalIgnoreCase)) {
90
lastproject.RemoveAt(i);
94
while (lastproject.Count >= MAX_LENGTH) {
95
lastproject.RemoveAt(lastproject.Count - 1);
98
lastproject.Insert(0, name);
99
JumpList.AddToRecentCategory(name);
102
public static RecentOpen FromXmlElement(Properties properties)
104
return new RecentOpen(properties);
107
public Properties ToProperties()
109
Properties p = new Properties();
110
p.Set("Files", lastfile.ToArray());
111
p.Set("Projects", lastproject.ToArray());
115
internal void FileRemoved(object sender, FileEventArgs e)
117
for (int i = 0; i < lastfile.Count; ++i) {
118
string file = lastfile[i].ToString();
119
if (e.FileName == file) {
120
lastfile.RemoveAt(i);
126
internal void FileRenamed(object sender, FileRenameEventArgs e)
128
for (int i = 0; i < lastfile.Count; ++i) {
129
string file = lastfile[i].ToString();
130
if (e.SourceFile == file) {
131
lastfile.RemoveAt(i);
132
lastfile.Insert(i, e.TargetFile);