Browse Source

Fixed encoding autodetection in ChooseEncodingDisplayBinding to match that when normally opening a file.

LoadSolutionProjectThread: Send progress report for the number of files parsed.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5637 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
526c8bd679
  1. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditDisplayBinding.cs
  2. 6
      src/Main/Base/Project/Src/Services/File/FileService.cs
  3. 29
      src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs
  4. 16
      src/Main/Base/Project/Src/Services/ProjectService/ParseableFileContentEnumerator.cs
  5. 2
      src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditDisplayBinding.cs

@ -55,7 +55,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
ChooseEncodingDialog dlg = new ChooseEncodingDialog(); ChooseEncodingDialog dlg = new ChooseEncodingDialog();
dlg.Owner = WorkbenchSingleton.MainWindow; dlg.Owner = WorkbenchSingleton.MainWindow;
using (Stream stream = file.OpenRead()) { using (Stream stream = file.OpenRead()) {
using (StreamReader reader = FileReader.OpenStream(stream, Encoding.UTF8)) { using (StreamReader reader = FileReader.OpenStream(stream, FileService.DefaultFileEncoding.GetEncoding())) {
reader.Peek(); // force reader to auto-detect encoding reader.Peek(); // force reader to auto-detect encoding
dlg.Encoding = reader.CurrentEncoding; dlg.Encoding = reader.CurrentEncoding;
} }

6
src/Main/Base/Project/Src/Services/File/FileService.cs

@ -315,11 +315,11 @@ namespace ICSharpCode.SharpDevelop
/// Gets a list of the names of the files that are open as primary files /// Gets a list of the names of the files that are open as primary files
/// in view contents. /// in view contents.
/// </summary> /// </summary>
public static IList<string> GetOpenFiles() public static IList<FileName> GetOpenFiles()
{ {
List<string> fileNames = new List<string>(); List<FileName> fileNames = new List<FileName>();
foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) { foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) {
string contentName = content.PrimaryFileName; FileName contentName = content.PrimaryFileName;
if (contentName != null && !fileNames.Contains(contentName)) if (contentName != null && !fileNames.Contains(contentName))
fileNames.Add(contentName); fileNames.Add(contentName);
} }

29
src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs

@ -9,12 +9,13 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using System.Threading;
namespace ICSharpCode.SharpDevelop namespace ICSharpCode.SharpDevelop
{ {
@ -246,7 +247,6 @@ namespace ICSharpCode.SharpDevelop
internal void Initialize2(IProgressMonitor progressMonitor) internal void Initialize2(IProgressMonitor progressMonitor)
{ {
if (!initializing) return; if (!initializing) return;
//int progressStart = progressMonitor.WorkDone;
try { try {
IProjectContent[] referencedContents; IProjectContent[] referencedContents;
lock (this.ReferencedContents) { lock (this.ReferencedContents) {
@ -261,20 +261,33 @@ namespace ICSharpCode.SharpDevelop
} }
ParseableFileContentFinder finder = new ParseableFileContentFinder(); ParseableFileContentFinder finder = new ParseableFileContentFinder();
var fileContents = var fileContents = (
from p in project.Items.AsParallel().WithCancellation(progressMonitor.CancellationToken) from p in project.Items.AsParallel().WithCancellation(progressMonitor.CancellationToken)
where !ItemType.NonFileItemTypes.Contains(p.ItemType) && !String.IsNullOrEmpty(p.FileName) where !ItemType.NonFileItemTypes.Contains(p.ItemType) && !String.IsNullOrEmpty(p.FileName)
select finder.Create(p); select FileName.Create(p.FileName)
fileContents.ForAll( ).ToList();
entry => {
object progressLock = new object();
double fileCountInverse = 1.0 / fileContents.Count;
Parallel.ForEach(
fileContents,
fileName => {
ParseableFileContentEntry entry = finder.Create(fileName);
// Don't read files we don't have a parser for.
// This avoids loading huge files (e.g. sdps) when we have no intention of parsing them.
if (ParserService.GetParser(fileName) != null) {
ITextBuffer content = entry.GetContent(); ITextBuffer content = entry.GetContent();
if (content != null) if (content != null)
ParserService.ParseFile(this, entry.FileName, content); ParserService.ParseFile(this, fileName, content);
}
lock (progressLock) {
progressMonitor.Progress += fileCountInverse;
}
} }
); );
} finally { } finally {
initializing = false; initializing = false;
//progressMonitor.WorkDone = progressStart + enumerator.ItemCount; progressMonitor.Progress = 1;
} }
} }

16
src/Main/Base/Project/Src/Services/ProjectService/ParseableFileContentEnumerator.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.SharpDevelop.Project
{ {
public class ParseableFileContentEntry public class ParseableFileContentEntry
{ {
public string FileName { get; private set; } public FileName FileName { get; private set; }
ITextBuffer openContent; ITextBuffer openContent;
public ITextBuffer GetContent() public ITextBuffer GetContent()
@ -38,12 +38,12 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
internal ParseableFileContentEntry(ProjectItem item, IList<string> viewContentFileNamesCollection) internal ParseableFileContentEntry(FileName fileName, FileName[] viewContentFileNamesCollection)
{ {
this.FileName = item.FileName; this.FileName = fileName;
foreach (string name in viewContentFileNamesCollection) { foreach (FileName name in viewContentFileNamesCollection) {
if (FileUtility.IsEqualFileName(name, this.FileName)) { if (FileUtility.IsEqualFileName(name, this.FileName)) {
openContent = WorkbenchSingleton.SafeThreadFunction(ParserService.GetParseableFileContent, this.FileName); openContent = WorkbenchSingleton.SafeThreadFunction(ParserService.GetParseableFileContent, this.FileName.ToString());
break; break;
} }
} }
@ -56,14 +56,14 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary> /// </summary>
public class ParseableFileContentFinder public class ParseableFileContentFinder
{ {
IList<string> viewContentFileNamesCollection = WorkbenchSingleton.SafeThreadFunction(FileService.GetOpenFiles); FileName[] viewContentFileNamesCollection = WorkbenchSingleton.SafeThreadFunction(FileService.GetOpenFiles).ToArray();
/// <summary> /// <summary>
/// Retrieves the file contents for the specified project items. /// Retrieves the file contents for the specified project items.
/// </summary> /// </summary>
public ParseableFileContentEntry Create(ProjectItem p) public ParseableFileContentEntry Create(FileName fileName)
{ {
return new ParseableFileContentEntry(p, viewContentFileNamesCollection); return new ParseableFileContentEntry(fileName, viewContentFileNamesCollection);
} }
} }
} }

2
src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs

@ -159,7 +159,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
progressMonitor.TaskName = StringParser.Parse("${res:SharpDevelop.Refactoring.FindingReferences}"); progressMonitor.TaskName = StringParser.Parse("${res:SharpDevelop.Refactoring.FindingReferences}");
foreach (ProjectItem item in files) { foreach (ProjectItem item in files) {
var entry = finder.Create(item); var entry = finder.Create(FileName.Create(item.FileName));
if (progressMonitor != null) { if (progressMonitor != null) {
progressMonitor.Progress += 1.0 / files.Count; progressMonitor.Progress += 1.0 / files.Count;

Loading…
Cancel
Save