Browse Source

Fix usage of ErrorFallbackBinding.

filemodels
Daniel Grunwald 11 years ago
parent
commit
c38a76cd7f
  1. 1
      src/Main/SharpDevelop/SharpDevelop.csproj
  2. 2
      src/Main/SharpDevelop/Workbench/DisplayBinding/AutoDetectDisplayBinding.cs
  3. 59
      src/Main/SharpDevelop/Workbench/DisplayBinding/ErrorFallbackBinding.cs
  4. 34
      src/Main/SharpDevelop/Workbench/FileService.cs

1
src/Main/SharpDevelop/SharpDevelop.csproj

@ -202,6 +202,7 @@ @@ -202,6 +202,7 @@
<Compile Include="Workbench\DisplayBinding\AutoDetectDisplayBinding.cs" />
<Compile Include="Workbench\DisplayBinding\DisplayBindingDoozer.cs" />
<Compile Include="Workbench\DisplayBinding\DisplayBindingService.cs" />
<Compile Include="Workbench\DisplayBinding\ErrorFallbackBinding.cs" />
<Compile Include="Workbench\DisplayBinding\OpenWithDialog.cs" />
<Compile Include="Workbench\DisplayBinding\OpenWithDialog.Designer.cs">
<DependentUpon>OpenWithDialog.cs</DependentUpon>

2
src/Main/SharpDevelop/Workbench/DisplayBinding/AutoDetectDisplayBinding.cs

@ -68,7 +68,7 @@ namespace ICSharpCode.SharpDevelop.Workbench @@ -68,7 +68,7 @@ namespace ICSharpCode.SharpDevelop.Workbench
}
if (bestMatch == null)
return null;
return ErrorFallbackBinding.CouldNotFindDisplayBindingFor(file.FileName).CreateContentForFile(file);
return bestMatch.Binding.CreateContentForFile(file);
}

59
src/Main/SharpDevelop/Workbench/DisplayBinding/ErrorFallbackBinding.cs

@ -0,0 +1,59 @@ @@ -0,0 +1,59 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Workbench
{
sealed class ErrorFallbackBinding : IDisplayBinding
{
public static ErrorFallbackBinding CouldNotFindDisplayBindingFor(FileName fileName)
{
return new ErrorFallbackBinding("Could not find any display binding for " + fileName.GetFileName());
}
string errorMessage;
public ErrorFallbackBinding(string errorMessage)
{
this.errorMessage = errorMessage;
}
public bool CanCreateContentForFile(FileName fileName)
{
return true;
}
public IViewContent CreateContentForFile(OpenedFile file)
{
return new SimpleViewContent(errorMessage) { TitleName = file.FileName.GetFileName() };
}
public bool IsPreferredBindingForFile(FileName fileName)
{
return false;
}
public double AutoDetectFileContent(FileName fileName, Stream fileContent, string detectedMimeType)
{
return double.NegativeInfinity;
}
}
}

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

@ -311,7 +311,7 @@ namespace ICSharpCode.SharpDevelop.Workbench @@ -311,7 +311,7 @@ namespace ICSharpCode.SharpDevelop.Workbench
{
return OpenFile(fileName, true);
}
/// <inheritdoc/>
public IViewContent OpenFile(FileName fileName, bool switchToOpenedView)
{
@ -328,7 +328,7 @@ namespace ICSharpCode.SharpDevelop.Workbench @@ -328,7 +328,7 @@ namespace ICSharpCode.SharpDevelop.Workbench
IDisplayBinding binding = SD.DisplayBindingService.GetBindingPerFileName(fileName);
if (binding == null) {
binding = new ErrorFallbackBinding("Could not find any display binding for " + Path.GetFileName(fileName));
binding = ErrorFallbackBinding.CouldNotFindDisplayBindingFor(fileName);
}
if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new LoadFileWrapper(binding, switchToOpenedView).Invoke), fileName) == FileOperationResult.OK) {
RecentOpen.AddRecentFile(fileName);
@ -438,36 +438,6 @@ namespace ICSharpCode.SharpDevelop.Workbench @@ -438,36 +438,6 @@ namespace ICSharpCode.SharpDevelop.Workbench
return null;
}
sealed class ErrorFallbackBinding : IDisplayBinding
{
string errorMessage;
public ErrorFallbackBinding(string errorMessage)
{
this.errorMessage = errorMessage;
}
public bool CanCreateContentForFile(FileName fileName)
{
return true;
}
public IViewContent CreateContentForFile(OpenedFile file)
{
return new SimpleViewContent(errorMessage) { TitleName = Path.GetFileName(file.FileName) };
}
public bool IsPreferredBindingForFile(FileName fileName)
{
return false;
}
public double AutoDetectFileContent(FileName fileName, Stream fileContent, string detectedMimeType)
{
return double.NegativeInfinity;
}
}
/// <inheritdoc/>
public IViewContent JumpToFilePosition(FileName fileName, int line, int column)
{

Loading…
Cancel
Save