diff --git a/AddIns/ICSharpCode.SharpDevelop.addin b/AddIns/ICSharpCode.SharpDevelop.addin
index 2b4f785cb6..b452b886dc 100644
--- a/AddIns/ICSharpCode.SharpDevelop.addin
+++ b/AddIns/ICSharpCode.SharpDevelop.addin
@@ -1037,7 +1037,7 @@
class = "ICSharpCode.SharpDevelop.Gui.OptionPanels.SelectStylePanel"/>
+ class = "ICSharpCode.SharpDevelop.Gui.OptionPanels.LoadSaveOptions"/>
diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChooseEncodingDialog.xaml b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChooseEncodingDialog.xaml
index bb446e7942..6b9cf4371a 100644
--- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChooseEncodingDialog.xaml
+++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChooseEncodingDialog.xaml
@@ -13,10 +13,10 @@
Content="{core:Localize Dialog.Options.IDEOptions.TextEditor.General.FontGroupBox.FileEncodingLabel}" />
+ Margin="16,0,8,8">
-
+
diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChooseEncodingDialog.xaml.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChooseEncodingDialog.xaml.cs
index 796fb7c191..90d65f6491 100644
--- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChooseEncodingDialog.xaml.cs
+++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChooseEncodingDialog.xaml.cs
@@ -6,14 +6,11 @@
//
using System;
-using System.Collections.Generic;
+using System.Linq;
using System.Text;
using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
+
+using ICSharpCode.SharpDevelop;
namespace ICSharpCode.AvalonEdit.AddIn
{
@@ -22,138 +19,16 @@ namespace ICSharpCode.AvalonEdit.AddIn
///
public partial class ChooseEncodingDialog : Window
{
- static int[] _wellKnownCodePages = {
- 37, // IBM EBCDIC (US-Canada)
- 437, // OEM United States
- 500, // IBM EBCDIC (International)
- 708, // Arabic (ASMO 708)
- 850, // Western European (DOS)
- 852, // Central European (DOS)
- 855, // Cyrillic (DOS)
- 857, // Turkish (DOS)
- 858, // Western European (DOS with Euro)
- 860, // Portuguese (DOS)
- 861, // Icelandic (DOS)
- 862, // Hebrew (DOS)
- 863, // French Canadian (DOS)
- 864, // Arabic (DOS)
- 865, // Nordic (DOS)
- 866, // Russian (DOS)
- 869, // Greek (DOS)
- 870, // IBM EBCDIC (Latin 2)
- 874, // Thai (Windows)
- 875, // IBM EBCDIC (Greek)
- 932, // Japanese (Shift-JIS)
- 936, // Chinese Simplified (GB2312)
- 949, // Korean
- 950, // Chinese Traditional (Big5)
- 1026, // IBM EBCDIC (Turkish)
- 1047, // IBM EBCDIC (Open Systems Latin 1)
- 1140, // IBM EBCDIC (US-Canada with Euro)
- 1141, // IBM EBCDIC (Germany with Euro)
- 1142, // IBM EBCDIC (Denmark/Norway with Euro)
- 1143, // IBM EBCDIC (Finland/Sweden with Euro)
- 1144, // IBM EBCDIC (Italy with Euro)
- 1145, // IBM EBCDIC (Latin America/Spain with Euro)
- 1146, // IBM EBCDIC (United Kingdom with Euro)
- 1147, // IBM EBCDIC (France with Euro)
- 1148, // IBM EBCDIC (International with Euro)
- 1149, // IBM EBCDIC (Icelandic with Euro)
- 1200, // Unicode (UTF-16 LE)
- 1201, // Unicode (UTF-16 Big-Endian)
- 1250, // Central European (Windows)
- 1251, // Cyrillic (Windows)
- 1252, // Western European (Windows)
- 1253, // Greek (Windows)
- 1254, // Turkish (Windows)
- 1255, // Hebrew (Windows)
- 1256, // Arabic (Windows)
- 1257, // Baltic (Windows)
- 1258, // Vietnamese (Windows)
- 10000, // Western European (Mac)
- 10007, // Cyrillic (Mac)
- 10017, // Ukrainian (Mac)
- 10079, // Icelandic (Mac)
- 12000, // UTF-32 LE
- 12001, // UTF-32 BE
- 20127, // US-ASCII
- 20261, // T.61
- 20273, // IBM EBCDIC (Germany)
- 20277, // IBM EBCDIC (Denmark/Norway)
- 20278, // IBM EBCDIC (Finland/Sweden)
- 20280, // IBM EBCDIC (Italy)
- 20284, // IBM EBCDIC (Latin America/Spain)
- 20285, // IBM EBCDIC (United Kingdom)
- 20290, // IBM EBCDIC (Japanese Katakana Extended)
- 20297, // IBM EBCDIC (France)
- 20420, // IBM EBCDIC (Arabic)
- 20424, // IBM EBCDIC (Hebrew)
- 20866, // Cyrillic (KOI8-R)
- 20871, // IBM EBCDIC (Icelandic)
- 21025, // IBM EBCDIC (Cyrillic - Serbian, Bulgarian)
- 21866, // Ukrainian (KOI8-U)
- 28591, // Western European (ISO)
- 28592, // Central European (ISO)
- 28593, // Latin 3 (ISO)
- 28594, // Baltic (ISO)
- 28595, // Cyrillic (ISO)
- 28596, // Arabic (ISO)
- 28597, // Greek (ISO)
- 28598, // Hebrew (ISO)
- 28599, // Latin 5 (ISO)
- 28605, // Latin 9 (ISO)
- 38598, // Hebrew (ISO Alternative)
- 50220, // Japanese (JIS)
- 50221, // Japanese (JIS-Allow 1 byte Kana)
- 50222, // Japanese (JIS-Allow 1 byte Kana - SO/SI)
- 50225, // Korean (ISO)
- 50227, // Chinese Simplified (ISO-2022)
- 51932, // Japanese (EUC)
- 51936, // Chinese Simplified (EUC)
- 52936, // Chinese Simplified (HZ)
- 54936, // Chinese Simplified (GB18030)
- 57002, // ISCII Devanagari
- 57003, // ISCII Bengali
- 57004, // ISCII Tamil
- 57005, // ISCII Telugu
- 57006, // ISCII Assamese
- 57007, // ISCII Oriya
- 57008, // ISCII Kannada
- 57009, // ISCII Malayalam
- 57010, // ISCII Gujarati
- 57011, // ISCII Punjabi
- 65000, // Unicode (UTF-7)
- 65001 // Unicode (UTF-8)
- };
-
- public static IList GetSupportedEncodings()
- {
- List list = new List();
- foreach (int cp in _wellKnownCodePages) {
- try {
- list.Add(Encoding.GetEncoding(cp));
- } catch (ArgumentException) {
- } catch (NotSupportedException) {
- // ignore possible
- // System.ArgumentException or
- // System.NotSupportedException because
- // .NET fx, mono, rotor & Portable.NET
- // support different sets of encodings
- }
- }
- list.Sort((a,b) => a.EncodingName.CompareTo(b.EncodingName));
- return list;
- }
-
public ChooseEncodingDialog()
{
InitializeComponent();
- encodingComboBox.ItemsSource = GetSupportedEncodings();
+ encodingComboBox.ItemsSource = FileService.AllEncodings;
+ encodingComboBox.SelectedItem = FileService.DefaultFileEncoding;
}
public Encoding Encoding {
- get { return (Encoding)encodingComboBox.SelectedItem; }
- set { encodingComboBox.SelectedItem = value; }
+ get { return ((EncodingInfo)encodingComboBox.SelectedItem).GetEncoding(); }
+ set { encodingComboBox.SelectedItem = FileService.AllEncodings.Single(e => e.CodePage == value.CodePage); }
}
void okButton_Click(object sender, RoutedEventArgs e)
diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
index e94998bd4f..8b9e0844f5 100644
--- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
+++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
@@ -22,6 +22,7 @@ using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Rendering;
+using ICSharpCode.AvalonEdit.Utils;
using ICSharpCode.Core;
using ICSharpCode.Core.Presentation;
using ICSharpCode.SharpDevelop;
@@ -261,7 +262,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
public bool CanSaveWithCurrentEncoding()
{
Encoding encoding = this.Encoding;
- if (encoding == null || Utils.FileReader.IsUnicode(encoding))
+ if (encoding == null || FileReader.IsUnicode(encoding))
return true;
// not a unicode codepage
string text = document.Text;
@@ -277,8 +278,11 @@ namespace ICSharpCode.AvalonEdit.AddIn
primaryTextEditor.Text = reader.ReadToEnd();
}
} else {
- // let AvalonEdit do auto-detection
- primaryTextEditor.Load(stream);
+ // do encoding auto-detection
+ using (StreamReader reader = FileReader.OpenStream(stream, this.Encoding ?? FileService.DefaultFileEncoding.GetEncoding())) {
+ primaryTextEditor.Text = reader.ReadToEnd();
+ this.Encoding = reader.CurrentEncoding;
+ }
}
}
diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
index d4befd81f7..54dd060a6b 100644
--- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
+++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
@@ -185,6 +185,10 @@
OpenWithDialog.cs
+
+ LoadSaveOptions.xaml
+ Code
+
SelectCulturePanel.xaml
Code
@@ -373,9 +377,6 @@
UserControl
-
- UserControl
-
UserControl
@@ -555,7 +556,6 @@
-
@@ -812,6 +812,7 @@
GotoDialog.cs
+
diff --git a/src/Main/Base/Project/Resources/LoadSaveOptionPanel.xfrm b/src/Main/Base/Project/Resources/LoadSaveOptionPanel.xfrm
deleted file mode 100644
index 410b7e20de..0000000000
--- a/src/Main/Base/Project/Resources/LoadSaveOptionPanel.xfrm
+++ /dev/null
@@ -1,98 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSaveOptions.xaml b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSaveOptions.xaml
new file mode 100644
index 0000000000..45c3d95d62
--- /dev/null
+++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSaveOptions.xaml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSaveOptions.xaml.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSaveOptions.xaml.cs
new file mode 100644
index 0000000000..6f6c8a23af
--- /dev/null
+++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSaveOptions.xaml.cs
@@ -0,0 +1,29 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+
+using ICSharpCode.Core;
+
+namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
+{
+ public partial class LoadSaveOptions : OptionPanel
+ {
+ public LoadSaveOptions()
+ {
+ InitializeComponent();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSavePanel.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSavePanel.cs
deleted file mode 100644
index 41a466c516..0000000000
--- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/LoadSavePanel.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-//
-//
-//
-//
-// $Revision$
-//
-
-using System;
-using System.Windows.Forms;
-using ICSharpCode.Core;
-
-namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
-{
- public enum LineTerminatorStyle {
- Windows,
- Macintosh,
- Unix
- }
-
- ///
- /// Summary description for Form1.
- ///
- public class LoadSavePanel : XmlFormsOptionPanel
- {
- const string loadUserDataCheckBox = "loadUserDataCheckBox";
- const string createBackupCopyCheckBox = "createBackupCopyCheckBox";
- const string lineTerminatorStyleComboBox = "lineTerminatorStyleComboBox";
-
- CheckBox autoLoadExternalChangesCheckBox, detectExternalChangesCheckBox, useRecycleBinCheckBox;
-
- public override void LoadPanelContents()
- {
- SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.LoadSaveOptionPanel.xfrm"));
-
- ((CheckBox)ControlDictionary[loadUserDataCheckBox]).Checked = PropertyService.Get("SharpDevelop.LoadDocumentProperties", true);
- ((CheckBox)ControlDictionary[createBackupCopyCheckBox]).Checked = FileService.SaveUsingTemporaryFile;
-
- ((ComboBox)ControlDictionary[lineTerminatorStyleComboBox]).Items.Add(StringParser.Parse("${res:Dialog.Options.IDEOptions.LoadSaveOptions.WindowsRadioButton}"));
- ((ComboBox)ControlDictionary[lineTerminatorStyleComboBox]).Items.Add(StringParser.Parse("${res:Dialog.Options.IDEOptions.LoadSaveOptions.MacintoshRadioButton}"));
- ((ComboBox)ControlDictionary[lineTerminatorStyleComboBox]).Items.Add(StringParser.Parse("${res:Dialog.Options.IDEOptions.LoadSaveOptions.UnixRadioButton}"));
-
- ((ComboBox)ControlDictionary[lineTerminatorStyleComboBox]).SelectedIndex = (int)(LineTerminatorStyle)PropertyService.Get("SharpDevelop.LineTerminatorStyle", LineTerminatorStyle.Windows);
-
- autoLoadExternalChangesCheckBox = Get("autoLoadExternalChanges");
- detectExternalChangesCheckBox = Get("detectExternalChanges");
- useRecycleBinCheckBox = Get("useRecycleBin");
-
- detectExternalChangesCheckBox.CheckedChanged += delegate {
- autoLoadExternalChangesCheckBox.Enabled = detectExternalChangesCheckBox.Checked;
- };
- autoLoadExternalChangesCheckBox.Enabled = detectExternalChangesCheckBox.Checked;
-
- detectExternalChangesCheckBox.Checked = FileChangeWatcher.DetectExternalChangesOption;
- autoLoadExternalChangesCheckBox.Checked = FileChangeWatcher.AutoLoadExternalChangesOption;
- useRecycleBinCheckBox.Checked = FileService.DeleteToRecycleBin;
- }
-
- public override bool StorePanelContents()
- {
- PropertyService.Set("SharpDevelop.LoadDocumentProperties", ((CheckBox)ControlDictionary[loadUserDataCheckBox]).Checked);
- PropertyService.Set("SharpDevelop.LineTerminatorStyle", (LineTerminatorStyle)((ComboBox)ControlDictionary[lineTerminatorStyleComboBox]).SelectedIndex);
-
- FileChangeWatcher.DetectExternalChangesOption = detectExternalChangesCheckBox.Checked;
- FileChangeWatcher.AutoLoadExternalChangesOption = autoLoadExternalChangesCheckBox.Checked;
- FileService.DeleteToRecycleBin = useRecycleBinCheckBox.Checked;
- FileService.SaveUsingTemporaryFile = ((CheckBox)ControlDictionary[createBackupCopyCheckBox]).Checked;
-
- return true;
- }
- }
-}
diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/SelectCulturePanel.xaml b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/SelectCulturePanel.xaml
index e94124455b..55c29d9897 100644
--- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/SelectCulturePanel.xaml
+++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/SelectCulturePanel.xaml
@@ -66,14 +66,14 @@
-
+
\ No newline at end of file
diff --git a/src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs b/src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs
index 45b45bf5d1..61d278c7b3 100644
--- a/src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs
+++ b/src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs
@@ -452,6 +452,11 @@ namespace ICSharpCode.SharpDevelop.Gui
return String.Concat(viewContent.GetType().FullName.GetHashCode().ToString("x", CultureInfo.InvariantCulture), ":", FileUtility.NormalizePath(viewContent.PrimaryFileName).ToUpperInvariant());
}
+ public static bool LoadDocumentProperties {
+ get { return PropertyService.Get("SharpDevelop.LoadDocumentProperties", true); }
+ set { PropertyService.Set("SharpDevelop.LoadDocumentProperties", value); }
+ }
+
///
/// Stores the memento for the view content.
/// Such mementos are automatically loaded in ShowView().
@@ -459,7 +464,7 @@ namespace ICSharpCode.SharpDevelop.Gui
public void StoreMemento(IViewContent viewContent)
{
IMementoCapable mementoCapable = viewContent as IMementoCapable;
- if (mementoCapable != null && PropertyService.Get("SharpDevelop.LoadDocumentProperties", true)) {
+ if (mementoCapable != null && LoadDocumentProperties) {
if (viewContent.PrimaryFileName == null)
return;
@@ -476,7 +481,7 @@ namespace ICSharpCode.SharpDevelop.Gui
void LoadViewContentMemento(IViewContent viewContent)
{
IMementoCapable mementoCapable = viewContent as IMementoCapable;
- if (mementoCapable != null && PropertyService.Get("SharpDevelop.LoadDocumentProperties", true)) {
+ if (mementoCapable != null && LoadDocumentProperties) {
if (viewContent.PrimaryFileName == null)
return;
diff --git a/src/Main/Base/Project/Src/Services/File/FileService.cs b/src/Main/Base/Project/Src/Services/File/FileService.cs
index 5dbee0f97a..4a22df20fe 100644
--- a/src/Main/Base/Project/Src/Services/File/FileService.cs
+++ b/src/Main/Base/Project/Src/Services/File/FileService.cs
@@ -7,9 +7,11 @@
using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.Diagnostics;
-using System.Linq;
using System.IO;
+using System.Linq;
+using System.Text;
using System.Windows.Forms;
using ICSharpCode.Core;
@@ -356,6 +358,27 @@ namespace ICSharpCode.SharpDevelop
}
}
+ public static int DefaultFileEncodingCodePage {
+ get { return PropertyService.Get("SharpDevelop.DefaultFileEncoding", 65001); }
+ set { PropertyService.Set("SharpDevelop.DefaultFileEncoding", value); }
+ }
+
+ static readonly ReadOnlyCollection allEncodings = Encoding.GetEncodings().OrderBy(e => e.DisplayName).ToArray().AsReadOnly();
+
+ public static ReadOnlyCollection AllEncodings {
+ get { return allEncodings; }
+ }
+
+ public static EncodingInfo DefaultFileEncoding {
+ get {
+ int cp = FileService.DefaultFileEncodingCodePage;
+ return allEncodings.Single(e => e.CodePage == cp);
+ }
+ set {
+ FileService.DefaultFileEncodingCodePage = value.CodePage;
+ }
+ }
+
///
/// Removes a file, raising the appropriate events. This method may show message boxes.
///
diff --git a/src/Main/Base/Project/Src/Services/ParserService/ParserService.cs b/src/Main/Base/Project/Src/Services/ParserService/ParserService.cs
index b85e3c231e..b66524bd00 100644
--- a/src/Main/Base/Project/Src/Services/ParserService/ParserService.cs
+++ b/src/Main/Base/Project/Src/Services/ParserService/ParserService.cs
@@ -261,8 +261,7 @@ namespace ICSharpCode.SharpDevelop
///
public static Encoding DefaultFileEncoding {
get {
- // TODO: how to implement without the old editor / so that it's actually thread-safe?
- return DefaultEditor.Gui.Editor.SharpDevelopTextEditorProperties.Instance.Encoding;
+ return Encoding.GetEncoding(FileService.DefaultFileEncodingCodePage);
}
}
diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs
index edeb7d5820..8fd1d93b54 100644
--- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs
+++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs
@@ -289,14 +289,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
}
public string LineTerminator {
get {
- LineTerminatorStyle lineTerminatorStyle = PropertyService.Get("SharpDevelop.LineTerminatorStyle", LineTerminatorStyle.Windows);
- switch (lineTerminatorStyle) {
- case LineTerminatorStyle.Windows:
- return "\r\n";
- case LineTerminatorStyle.Macintosh:
- return "\r";
- }
- return "\n";
+ return "\r\n";
}
set {
throw new System.NotImplementedException();