29 changed files with 1173 additions and 824 deletions
@ -1,132 +0,0 @@
@@ -1,132 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Collections.ObjectModel; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Windows.Shell; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.SharpDevelop |
||||
{ |
||||
/// <summary>
|
||||
/// This class handles the recent open files and the recent open project files of SharpDevelop
|
||||
/// it checks, if the files exists at every creation, and if not it doesn't list them in the
|
||||
/// recent files, and they'll not be saved during the next option save.
|
||||
/// </summary>
|
||||
public sealed class RecentOpen |
||||
{ |
||||
/// <summary>
|
||||
/// This variable is the maximal length of lastfile/lastopen entries
|
||||
/// must be > 0
|
||||
/// </summary>
|
||||
int MAX_LENGTH = 10; |
||||
|
||||
readonly ObservableCollection<string> lastfile = new ObservableCollection<string>(); |
||||
readonly ObservableCollection<string> lastproject = new ObservableCollection<string>(); |
||||
|
||||
public IList<string> RecentFile { |
||||
get { |
||||
return lastfile; |
||||
} |
||||
} |
||||
|
||||
public IList<string> RecentProject { |
||||
get { |
||||
return lastproject; |
||||
} |
||||
} |
||||
|
||||
public RecentOpen() |
||||
{ |
||||
} |
||||
|
||||
public RecentOpen(Properties p) |
||||
{ |
||||
// don't check whether files exist because that might be slow (e.g. if file is on network
|
||||
// drive that's unavailable)
|
||||
|
||||
lastfile.AddRange(p.GetList<string>("Files")); |
||||
lastproject.AddRange(p.GetList<string>("Projects")); |
||||
} |
||||
|
||||
public void AddLastFile(string name) |
||||
{ |
||||
for (int i = 0; i < lastfile.Count; ++i) { |
||||
if (lastfile[i].Equals(name, StringComparison.OrdinalIgnoreCase)) { |
||||
lastfile.RemoveAt(i); |
||||
} |
||||
} |
||||
|
||||
while (lastfile.Count >= MAX_LENGTH) { |
||||
lastfile.RemoveAt(lastfile.Count - 1); |
||||
} |
||||
|
||||
lastfile.Insert(0, name); |
||||
} |
||||
|
||||
public void ClearRecentFiles() |
||||
{ |
||||
lastfile.Clear(); |
||||
} |
||||
|
||||
public void ClearRecentProjects() |
||||
{ |
||||
lastproject.Clear(); |
||||
} |
||||
|
||||
public void AddLastProject(string name) |
||||
{ |
||||
for (int i = 0; i < lastproject.Count; ++i) { |
||||
if (lastproject[i].ToString().Equals(name, StringComparison.OrdinalIgnoreCase)) { |
||||
lastproject.RemoveAt(i); |
||||
} |
||||
} |
||||
|
||||
while (lastproject.Count >= MAX_LENGTH) { |
||||
lastproject.RemoveAt(lastproject.Count - 1); |
||||
} |
||||
|
||||
lastproject.Insert(0, name); |
||||
JumpList.AddToRecentCategory(name); |
||||
} |
||||
|
||||
public static RecentOpen FromXmlElement(Properties properties) |
||||
{ |
||||
return new RecentOpen(properties); |
||||
} |
||||
|
||||
public Properties ToProperties() |
||||
{ |
||||
Properties p = new Properties(); |
||||
p.SetList("Files", lastfile); |
||||
p.SetList("Projects", lastproject); |
||||
return p; |
||||
} |
||||
|
||||
internal void FileRemoved(object sender, FileEventArgs e) |
||||
{ |
||||
for (int i = 0; i < lastfile.Count; ++i) { |
||||
string file = lastfile[i].ToString(); |
||||
if (e.FileName == file) { |
||||
lastfile.RemoveAt(i); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
internal void FileRenamed(object sender, FileRenameEventArgs e) |
||||
{ |
||||
for (int i = 0; i < lastfile.Count; ++i) { |
||||
string file = lastfile[i].ToString(); |
||||
if (e.SourceFile == file) { |
||||
lastfile.RemoveAt(i); |
||||
lastfile.Insert(i, e.TargetFile); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,161 @@
@@ -0,0 +1,161 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Workbench |
||||
{ |
||||
sealed class FileServiceOpenedFile : OpenedFile |
||||
{ |
||||
readonly FileService fileService; |
||||
List<IViewContent> registeredViews = new List<IViewContent>(); |
||||
FileChangeWatcher fileChangeWatcher; |
||||
|
||||
protected override void ChangeFileName(FileName newValue) |
||||
{ |
||||
fileService.OpenedFileFileNameChange(this, this.FileName, newValue); |
||||
base.ChangeFileName(newValue); |
||||
} |
||||
|
||||
internal FileServiceOpenedFile(FileService fileService, FileName fileName) |
||||
{ |
||||
this.fileService = fileService; |
||||
this.FileName = fileName; |
||||
IsUntitled = false; |
||||
fileChangeWatcher = new FileChangeWatcher(this); |
||||
} |
||||
|
||||
internal FileServiceOpenedFile(FileService fileService, byte[] fileData) |
||||
{ |
||||
this.fileService = fileService; |
||||
this.FileName = null; |
||||
SetData(fileData); |
||||
IsUntitled = true; |
||||
MakeDirty(); |
||||
fileChangeWatcher = new FileChangeWatcher(this); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the list of view contents registered with this opened file.
|
||||
/// </summary>
|
||||
public override IList<IViewContent> RegisteredViewContents { |
||||
get { return registeredViews.AsReadOnly(); } |
||||
} |
||||
|
||||
public override void ForceInitializeView(IViewContent view) |
||||
{ |
||||
if (view == null) |
||||
throw new ArgumentNullException("view"); |
||||
if (!registeredViews.Contains(view)) |
||||
throw new ArgumentException("registeredViews must contain view"); |
||||
|
||||
base.ForceInitializeView(view); |
||||
} |
||||
|
||||
public override void RegisterView(IViewContent view) |
||||
{ |
||||
if (view == null) |
||||
throw new ArgumentNullException("view"); |
||||
if (registeredViews.Contains(view)) |
||||
throw new ArgumentException("registeredViews already contains view"); |
||||
|
||||
registeredViews.Add(view); |
||||
|
||||
if (WorkbenchSingleton.Workbench != null) { |
||||
WorkbenchSingleton.Workbench.ActiveViewContentChanged += WorkbenchActiveViewContentChanged; |
||||
if (WorkbenchSingleton.Workbench.ActiveViewContent == view) { |
||||
SwitchedToView(view); |
||||
} |
||||
} |
||||
#if DEBUG
|
||||
view.Disposed += ViewDisposed; |
||||
#endif
|
||||
} |
||||
|
||||
public override void UnregisterView(IViewContent view) |
||||
{ |
||||
if (view == null) |
||||
throw new ArgumentNullException("view"); |
||||
Debug.Assert(registeredViews.Contains(view)); |
||||
|
||||
if (WorkbenchSingleton.Workbench != null) { |
||||
WorkbenchSingleton.Workbench.ActiveViewContentChanged -= WorkbenchActiveViewContentChanged; |
||||
} |
||||
#if DEBUG
|
||||
view.Disposed -= ViewDisposed; |
||||
#endif
|
||||
|
||||
registeredViews.Remove(view); |
||||
if (registeredViews.Count > 0) { |
||||
if (currentView == view) { |
||||
SaveCurrentView(); |
||||
currentView = null; |
||||
} |
||||
} else { |
||||
// all views to the file were closed
|
||||
CloseIfAllViewsClosed(); |
||||
} |
||||
} |
||||
|
||||
public override void CloseIfAllViewsClosed() |
||||
{ |
||||
if (registeredViews.Count == 0) { |
||||
bool wasDirty = this.IsDirty; |
||||
fileService.OpenedFileClosed(this); |
||||
|
||||
FileClosed.RaiseEvent(this, EventArgs.Empty); |
||||
|
||||
if (fileChangeWatcher != null) { |
||||
fileChangeWatcher.Dispose(); |
||||
fileChangeWatcher = null; |
||||
} |
||||
|
||||
if (wasDirty) { |
||||
// We discarded some information when closing the file,
|
||||
// so we need to re-parse it.
|
||||
if (File.Exists(this.FileName)) |
||||
SD.ParserService.ParseAsync(this.FileName).FireAndForget(); |
||||
else |
||||
SD.ParserService.ClearParseInformation(this.FileName); |
||||
} |
||||
} |
||||
} |
||||
|
||||
#if DEBUG
|
||||
void ViewDisposed(object sender, EventArgs e) |
||||
{ |
||||
Debug.Fail("View was disposed while still registered with OpenedFile!"); |
||||
} |
||||
#endif
|
||||
|
||||
void WorkbenchActiveViewContentChanged(object sender, EventArgs e) |
||||
{ |
||||
IViewContent newView = WorkbenchSingleton.Workbench.ActiveViewContent; |
||||
|
||||
if (!registeredViews.Contains(newView)) |
||||
return; |
||||
|
||||
SwitchedToView(newView); |
||||
} |
||||
|
||||
public override void SaveToDisk() |
||||
{ |
||||
try { |
||||
if (fileChangeWatcher != null) |
||||
fileChangeWatcher.Enabled = false; |
||||
base.SaveToDisk(); |
||||
} finally { |
||||
if (fileChangeWatcher != null) |
||||
fileChangeWatcher.Enabled = true; |
||||
} |
||||
} |
||||
|
||||
public override event EventHandler FileClosed; |
||||
} |
||||
} |
||||
@ -0,0 +1,114 @@
@@ -0,0 +1,114 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Collections.ObjectModel; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Windows.Shell; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.SharpDevelop |
||||
{ |
||||
/// <summary>
|
||||
/// This class handles the recent open files and the recent open project files of SharpDevelop
|
||||
/// </summary>
|
||||
sealed class RecentOpen : IRecentOpen |
||||
{ |
||||
/// <summary>
|
||||
/// This variable is the maximal length of lastfile/lastopen entries
|
||||
/// must be > 0
|
||||
/// </summary>
|
||||
int MAX_LENGTH = 10; |
||||
|
||||
ObservableCollection<string> recentFiles = new ObservableCollection<string>(); |
||||
ObservableCollection<string> recentProjects = new ObservableCollection<string>(); |
||||
Properties properties; |
||||
|
||||
public IReadOnlyList<string> RecentFiles { |
||||
get { return recentFiles; } |
||||
} |
||||
|
||||
public IReadOnlyList<string> RecentProjects { |
||||
get { return recentProjects; } |
||||
} |
||||
|
||||
public RecentOpen(Properties p) |
||||
{ |
||||
// don't check whether files exist because that might be slow (e.g. if file is on network
|
||||
// drive that's unavailable)
|
||||
this.properties = p; |
||||
recentFiles.AddRange(p.GetList<string>("Files")); |
||||
recentProjects.AddRange(p.GetList<string>("Projects")); |
||||
} |
||||
|
||||
public void AddRecentFile(string name) |
||||
{ |
||||
for (int i = 0; i < recentFiles.Count; ++i) { |
||||
if (recentFiles[i].Equals(name, StringComparison.OrdinalIgnoreCase)) { |
||||
recentFiles.RemoveAt(i); |
||||
} |
||||
} |
||||
|
||||
while (recentFiles.Count >= MAX_LENGTH) { |
||||
recentFiles.RemoveAt(recentFiles.Count - 1); |
||||
} |
||||
|
||||
recentFiles.Insert(0, name); |
||||
properties.SetList("Files", recentFiles); |
||||
} |
||||
|
||||
public void ClearRecentFiles() |
||||
{ |
||||
recentFiles.Clear(); |
||||
properties.SetList("Files", recentFiles); |
||||
} |
||||
|
||||
public void ClearRecentProjects() |
||||
{ |
||||
recentProjects.Clear(); |
||||
properties.SetList("Projects", recentProjects); |
||||
} |
||||
|
||||
public void AddRecentProject(string name) |
||||
{ |
||||
for (int i = 0; i < recentProjects.Count; ++i) { |
||||
if (recentProjects[i].ToString().Equals(name, StringComparison.OrdinalIgnoreCase)) { |
||||
recentProjects.RemoveAt(i); |
||||
} |
||||
} |
||||
|
||||
while (recentProjects.Count >= MAX_LENGTH) { |
||||
recentProjects.RemoveAt(recentProjects.Count - 1); |
||||
} |
||||
|
||||
recentProjects.Insert(0, name); |
||||
JumpList.AddToRecentCategory(name); |
||||
properties.SetList("Projects", recentProjects); |
||||
} |
||||
|
||||
internal void FileRemoved(object sender, FileEventArgs e) |
||||
{ |
||||
for (int i = 0; i < recentFiles.Count; ++i) { |
||||
string file = recentFiles[i].ToString(); |
||||
if (e.FileName == file) { |
||||
recentFiles.RemoveAt(i); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
internal void FileRenamed(object sender, FileRenameEventArgs e) |
||||
{ |
||||
for (int i = 0; i < recentFiles.Count; ++i) { |
||||
string file = recentFiles[i].ToString(); |
||||
if (e.SourceFile == file) { |
||||
recentFiles.RemoveAt(i); |
||||
recentFiles.Insert(i, e.TargetFile); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue