Browse Source

Move remaining portions of FileService to IFileService interface.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
e7b28cb8f1
  1. 4
      src/Main/Base/Project/Src/Bookmarks/Commands/MenuCommands.cs
  2. 16
      src/Main/Base/Project/Src/Commands/FileCommands.cs
  3. 2
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/DefaultFileNodeCommands.cs
  4. 3
      src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs
  5. 49
      src/Main/Base/Project/Src/Services/File/FileService.cs
  6. 9
      src/Main/Base/Project/Src/Services/File/IFileService.cs
  7. 30
      src/Main/Core/Project/ICSharpCode.Core.csproj
  8. 4
      src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/ServiceDoozer.cs
  9. 5
      src/Main/SharpDevelop/Parser/ParserService.cs
  10. 53
      src/Main/SharpDevelop/Workbench/FileService.cs

4
src/Main/Base/Project/Src/Bookmarks/Commands/MenuCommands.cs

@ -55,7 +55,7 @@ namespace ICSharpCode.SharpDevelop.Bookmarks
bookmark = bookmarks[bookmarks.Count - 1]; // jump around to last bookmark bookmark = bookmarks[bookmarks.Count - 1]; // jump around to last bookmark
} }
if (bookmark != null) { if (bookmark != null) {
FileService.JumpToFilePosition(bookmark.FileName, bookmark.LineNumber, bookmark.ColumnNumber); SD.FileService.JumpToFilePosition(bookmark.FileName, bookmark.LineNumber, bookmark.ColumnNumber);
} }
} }
} }
@ -71,7 +71,7 @@ namespace ICSharpCode.SharpDevelop.Bookmarks
bookmark = bookmarks[0]; // jump around to first bookmark bookmark = bookmarks[0]; // jump around to first bookmark
} }
if (bookmark != null) { if (bookmark != null) {
FileService.JumpToFilePosition(bookmark.FileName, bookmark.LineNumber, bookmark.ColumnNumber); SD.FileService.JumpToFilePosition(bookmark.FileName, bookmark.LineNumber, bookmark.ColumnNumber);
} }
} }
} }

16
src/Main/Base/Project/Src/Commands/FileCommands.cs

@ -247,22 +247,22 @@ namespace ICSharpCode.SharpDevelop.Commands
fdiag.CheckFileExists = true; fdiag.CheckFileExists = true;
if (fdiag.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainWin32Window) == DialogResult.OK) { if (fdiag.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainWin32Window) == DialogResult.OK) {
OpenFiles(fdiag.FileNames); OpenFiles(Array.ConvertAll(fdiag.FileNames, FileName.Create));
} }
} }
} }
protected virtual void OpenFiles(string[] fileNames) protected virtual void OpenFiles(FileName[] fileNames)
{ {
foreach (string name in fileNames) { foreach (var name in fileNames) {
FileService.OpenFile(name); SD.FileService.OpenFile(name);
} }
} }
} }
public class OpenFileWith : OpenFile public class OpenFileWith : OpenFile
{ {
protected override void OpenFiles(string[] fileNames) protected override void OpenFiles(FileName[] fileNames)
{ {
OpenFilesWith(fileNames); OpenFilesWith(fileNames);
} }
@ -270,7 +270,7 @@ namespace ICSharpCode.SharpDevelop.Commands
/// <summary> /// <summary>
/// Shows the OpenWith dialog for the specified files. /// Shows the OpenWith dialog for the specified files.
/// </summary> /// </summary>
public static void OpenFilesWith(string[] fileNames) public static void OpenFilesWith(FileName[] fileNames)
{ {
if (fileNames.Length == 0) if (fileNames.Length == 0)
return; return;
@ -288,8 +288,8 @@ namespace ICSharpCode.SharpDevelop.Commands
defaultCodonIndex = 0; defaultCodonIndex = 0;
using (OpenWithDialog dlg = new OpenWithDialog(codons, defaultCodonIndex, Path.GetExtension(fileNames[0]))) { using (OpenWithDialog dlg = new OpenWithDialog(codons, defaultCodonIndex, Path.GetExtension(fileNames[0]))) {
if (dlg.ShowDialog(WorkbenchSingleton.MainWin32Window) == DialogResult.OK) { if (dlg.ShowDialog(WorkbenchSingleton.MainWin32Window) == DialogResult.OK) {
foreach (string fileName in fileNames) { foreach (var fileName in fileNames) {
FileUtility.ObservedLoad(new FileService.LoadFileWrapper(dlg.SelectedBinding.Binding, true).Invoke, fileName); SD.FileService.OpenFileWith(fileName, dlg.SelectedBinding.Binding, true);
} }
} }
} }

2
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/DefaultFileNodeCommands.cs

@ -69,7 +69,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
/// </summary> /// </summary>
static void OpenWith(string fileName) static void OpenWith(string fileName)
{ {
ICSharpCode.SharpDevelop.Commands.OpenFileWith.OpenFilesWith(new string[] { fileName }); ICSharpCode.SharpDevelop.Commands.OpenFileWith.OpenFilesWith(new [] { FileName.Create(fileName) });
} }
} }

3
src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs

@ -70,7 +70,6 @@ namespace ICSharpCode.SharpDevelop.Gui
LanguageService.ValidateLanguage(); LanguageService.ValidateLanguage();
DisplayBindingService.InitializeService(); DisplayBindingService.InitializeService();
FileService.InitializeService();
TaskService.Initialize(); TaskService.Initialize();
Bookmarks.BookmarkManager.Initialize(); Bookmarks.BookmarkManager.Initialize();
Project.CustomToolsService.Initialize(); Project.CustomToolsService.Initialize();
@ -123,8 +122,6 @@ namespace ICSharpCode.SharpDevelop.Gui
NavigationService.Unload(); NavigationService.Unload();
WorkbenchUnloaded(null, EventArgs.Empty); WorkbenchUnloaded(null, EventArgs.Empty);
FileService.Unload();
} }
} }

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

@ -18,22 +18,6 @@ namespace ICSharpCode.SharpDevelop
{ {
public static class FileService public static class FileService
{ {
static bool serviceInitialized;
internal static void Unload()
{
SD.ParserService.LoadSolutionProjectsThread.Finished -= ParserServiceLoadSolutionProjectsThreadEnded;
serviceInitialized = false;
}
internal static void InitializeService()
{
if (!serviceInitialized) {
SD.ParserService.LoadSolutionProjectsThread.Finished += ParserServiceLoadSolutionProjectsThreadEnded;
serviceInitialized = true;
}
}
/// <summary> /// <summary>
/// Checks if the path is valid <b>and shows a MessageBox if it is not valid</b>. /// Checks if the path is valid <b>and shows a MessageBox if it is not valid</b>.
/// Do not use in non-UI methods. /// Do not use in non-UI methods.
@ -53,39 +37,6 @@ namespace ICSharpCode.SharpDevelop
return SD.FileService.CheckDirectoryEntryName(name); return SD.FileService.CheckDirectoryEntryName(name);
} }
internal sealed class LoadFileWrapper
{
readonly IDisplayBinding binding;
readonly bool switchToOpenedView;
public LoadFileWrapper(IDisplayBinding binding, bool switchToOpenedView)
{
this.binding = binding;
this.switchToOpenedView = switchToOpenedView;
}
public void Invoke(string fileName)
{
OpenedFile file = SD.FileService.GetOrCreateOpenedFile(FileName.Create(fileName));
try {
IViewContent newContent = binding.CreateContentForFile(file);
if (newContent != null) {
DisplayBindingService.AttachSubWindows(newContent, false);
WorkbenchSingleton.Workbench.ShowView(newContent, switchToOpenedView);
}
} finally {
file.CloseIfAllViewsClosed();
}
}
}
static void ParserServiceLoadSolutionProjectsThreadEnded(object sender, EventArgs e)
{
foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection.ToArray()) {
DisplayBindingService.AttachSubWindows(content, true);
}
}
public static bool IsOpen(string fileName) public static bool IsOpen(string fileName)
{ {
return SD.FileService.IsOpen(FileName.Create(fileName)); return SD.FileService.IsOpen(FileName.Create(fileName));

9
src/Main/Base/Project/Src/Services/File/IFileService.cs

@ -151,6 +151,15 @@ namespace ICSharpCode.SharpDevelop
/// <returns>The existing or opened <see cref="IViewContent"/> for the specified file.</returns> /// <returns>The existing or opened <see cref="IViewContent"/> for the specified file.</returns>
IViewContent OpenFile(FileName fileName, bool switchToOpenedView = true); IViewContent OpenFile(FileName fileName, bool switchToOpenedView = true);
/// <summary>
/// Opens a view content for the specified file using the specified display binding.
/// </summary>
/// <param name="fileName">The name of the file to open.</param>
/// <param name="displayBinding">The display binding to use for opening the file.</param>
/// <param name="switchToOpenedView">Specifies whether to switch to the view for the specified file.</param>
/// <returns>The existing or opened <see cref="IViewContent"/> for the specified file.</returns>
IViewContent OpenFileWith(FileName fileName, IDisplayBinding displayBinding, bool switchToOpenedView = true);
/// <summary> /// <summary>
/// Opens a new unsaved file. /// Opens a new unsaved file.
/// </summary> /// </summary>

30
src/Main/Core/Project/ICSharpCode.Core.csproj

@ -24,26 +24,10 @@
<SourceAnalysisOverrideSettingsFile>C:\Users\daniel\AppData\Roaming\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile> <SourceAnalysisOverrideSettingsFile>C:\Users\daniel\AppData\Roaming\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
<TargetFrameworkProfile> <TargetFrameworkProfile>
</TargetFrameworkProfile> </TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<OutputPath>..\..\..\..\bin\</OutputPath> <OutputPath>..\..\..\..\bin\</OutputPath>
<WarningLevel>4</WarningLevel>
<DebugType>Full</DebugType>
<DocumentationFile>..\..\..\..\bin\ICSharpCode.Core.xml</DocumentationFile> <DocumentationFile>..\..\..\..\bin\ICSharpCode.Core.xml</DocumentationFile>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<NoWarn>1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<OutputPath>..\..\..\..\bin\</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DebugType>None</DebugType> <NoWarn>1591</NoWarn>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> <PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<RegisterForComInterop>False</RegisterForComInterop> <RegisterForComInterop>False</RegisterForComInterop>
@ -53,6 +37,18 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<StartAction>Program</StartAction> <StartAction>Program</StartAction>
<DebugType>Full</DebugType>
<DebugSymbols>true</DebugSymbols>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugType>PdbOnly</DebugType>
<DebugSymbols>false</DebugSymbols>
<DefineConstants>TRACE</DefineConstants>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />

4
src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/ServiceDoozer.cs

@ -33,9 +33,13 @@ namespace ICSharpCode.Core
Type interfaceType = args.AddIn.FindType(args.Codon.Id); Type interfaceType = args.AddIn.FindType(args.Codon.Id);
if (interfaceType != null) { if (interfaceType != null) {
string className = args.Codon.Properties["class"]; string className = args.Codon.Properties["class"];
bool serviceLoading = false;
// Use ServiceCreatorCallback to lazily create the service // Use ServiceCreatorCallback to lazily create the service
container.AddService( container.AddService(
interfaceType, delegate { interfaceType, delegate {
if (serviceLoading)
throw new InvalidOperationException("Found cyclic dependency when initializating " + className);
serviceLoading = true;
return args.AddIn.CreateObject(className); return args.AddIn.CreateObject(className);
}); });
} }

5
src/Main/SharpDevelop/Parser/ParserService.cs

@ -2,15 +2,12 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Threading;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.NRefactory; using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Editor; using ICSharpCode.NRefactory.Editor;

53
src/Main/SharpDevelop/Workbench/FileService.cs

@ -19,6 +19,18 @@ namespace ICSharpCode.SharpDevelop.Workbench
{ {
sealed class FileService : IFileService sealed class FileService : IFileService
{ {
public FileService()
{
SD.ParserService.LoadSolutionProjectsThread.Finished += ParserServiceLoadSolutionProjectsThreadEnded;
}
void ParserServiceLoadSolutionProjectsThreadEnded(object sender, EventArgs e)
{
foreach (IViewContent content in SD.Workbench.ViewContentCollection.ToArray()) {
DisplayBindingService.AttachSubWindows(content, true);
}
}
#region Options #region Options
/// <summary>used for OptionBinding</summary> /// <summary>used for OptionBinding</summary>
public static FileService Instance { public static FileService Instance {
@ -288,12 +300,49 @@ namespace ICSharpCode.SharpDevelop.Workbench
if (binding == null) { if (binding == null) {
binding = new ErrorFallbackBinding("Could not find any display binding for " + Path.GetFileName(fileName)); binding = new ErrorFallbackBinding("Could not find any display binding for " + Path.GetFileName(fileName));
} }
if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new SharpDevelop.FileService.LoadFileWrapper(binding, switchToOpenedView).Invoke), fileName) == FileOperationResult.OK) { if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new LoadFileWrapper(binding, switchToOpenedView).Invoke), fileName) == FileOperationResult.OK) {
SD.FileService.RecentOpen.AddRecentFile(fileName); RecentOpen.AddRecentFile(fileName);
} }
return GetOpenFile(fileName); return GetOpenFile(fileName);
} }
/// <inheritdoc/>
public IViewContent OpenFileWith(FileName fileName, IDisplayBinding displayBinding, bool switchToOpenedView)
{
if (displayBinding == null)
throw new ArgumentNullException("displayBinding");
if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new LoadFileWrapper(displayBinding, switchToOpenedView).Invoke), fileName) == FileOperationResult.OK) {
RecentOpen.AddRecentFile(fileName);
}
return GetOpenFile(fileName);
}
sealed class LoadFileWrapper
{
readonly IDisplayBinding binding;
readonly bool switchToOpenedView;
public LoadFileWrapper(IDisplayBinding binding, bool switchToOpenedView)
{
this.binding = binding;
this.switchToOpenedView = switchToOpenedView;
}
public void Invoke(string fileName)
{
OpenedFile file = SD.FileService.GetOrCreateOpenedFile(FileName.Create(fileName));
try {
IViewContent newContent = binding.CreateContentForFile(file);
if (newContent != null) {
DisplayBindingService.AttachSubWindows(newContent, false);
WorkbenchSingleton.Workbench.ShowView(newContent, switchToOpenedView);
}
} finally {
file.CloseIfAllViewsClosed();
}
}
}
/// <inheritdoc/> /// <inheritdoc/>
public IViewContent NewFile(string defaultName, string content) public IViewContent NewFile(string defaultName, string content)
{ {

Loading…
Cancel
Save