You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.9 KiB
70 lines
1.9 KiB
// <file> |
|
// <copyright see="prj:///doc/copyright.txt"/> |
|
// <license see="prj:///doc/license.txt"/> |
|
// <author name="Daniel Grunwald"/> |
|
// <version>$Revision$</version> |
|
// </file> |
|
|
|
using System; |
|
using System.IO; |
|
using System.Text; |
|
|
|
using ICSharpCode.AvalonEdit.Highlighting; |
|
using ICSharpCode.AvalonEdit.Utils; |
|
using ICSharpCode.Core; |
|
using ICSharpCode.SharpDevelop; |
|
using ICSharpCode.SharpDevelop.Gui; |
|
|
|
namespace ICSharpCode.AvalonEdit.AddIn |
|
{ |
|
public class AvalonEditDisplayBinding : IDisplayBinding |
|
{ |
|
static bool addInHighlightingDefinitionsRegistered; |
|
|
|
internal static void RegisterAddInHighlightingDefinitions() |
|
{ |
|
WorkbenchSingleton.AssertMainThread(); |
|
if (!addInHighlightingDefinitionsRegistered) { |
|
foreach (AddInTreeSyntaxMode syntaxMode in AddInTree.BuildItems<AddInTreeSyntaxMode>(SyntaxModeDoozer.Path, null, false)) { |
|
syntaxMode.Register(HighlightingManager.Instance); |
|
} |
|
addInHighlightingDefinitionsRegistered = true; |
|
} |
|
} |
|
|
|
public bool CanCreateContentForFile(string fileName) |
|
{ |
|
return true; |
|
} |
|
|
|
public IViewContent CreateContentForFile(OpenedFile file) |
|
{ |
|
return new AvalonEditViewContent(file); |
|
} |
|
} |
|
|
|
public class ChooseEncodingDisplayBinding : IDisplayBinding |
|
{ |
|
public bool CanCreateContentForFile(string fileName) |
|
{ |
|
return true; |
|
} |
|
|
|
public IViewContent CreateContentForFile(OpenedFile file) |
|
{ |
|
ChooseEncodingDialog dlg = new ChooseEncodingDialog(); |
|
dlg.Owner = WorkbenchSingleton.MainWindow; |
|
using (Stream stream = file.OpenRead()) { |
|
using (StreamReader reader = FileReader.OpenStream(stream, FileService.DefaultFileEncoding.GetEncoding())) { |
|
reader.Peek(); // force reader to auto-detect encoding |
|
dlg.Encoding = reader.CurrentEncoding; |
|
} |
|
} |
|
if (dlg.ShowDialog() == true) { |
|
return new AvalonEditViewContent(file, dlg.Encoding); |
|
} else { |
|
return null; |
|
} |
|
} |
|
} |
|
}
|
|
|