diff --git a/src/AddIns/Misc/CodeCoverage/Project/Src/CodeCoverageOptionsPanel.cs b/src/AddIns/Misc/CodeCoverage/Project/Src/CodeCoverageOptionsPanel.cs
index 32863575d2..1c0fa689e3 100644
--- a/src/AddIns/Misc/CodeCoverage/Project/Src/CodeCoverageOptionsPanel.cs
+++ b/src/AddIns/Misc/CodeCoverage/Project/Src/CodeCoverageOptionsPanel.cs
@@ -92,8 +92,9 @@ namespace ICSharpCode.CodeCoverage
void SelectCustomColour(ColorPickerComboBox comboBox)
{
- using (ColorDialog colorDialog = new ColorDialog()) {
+ using (SharpDevelopColorDialog colorDialog = new SharpDevelopColorDialog()) {
colorDialog.FullOpen = true;
+ colorDialog.Color = comboBox.SelectedColor;
if (colorDialog.ShowDialog() == DialogResult.OK) {
comboBox.SelectedColor = colorDialog.Color;
}
diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
index bd4e241ebe..d37b519adb 100644
--- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
+++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
@@ -710,6 +710,7 @@
+
diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/SharpDevelopColorDialog.cs b/src/Main/Base/Project/Src/Gui/Dialogs/SharpDevelopColorDialog.cs
new file mode 100644
index 0000000000..e5ca2b14fa
--- /dev/null
+++ b/src/Main/Base/Project/Src/Gui/Dialogs/SharpDevelopColorDialog.cs
@@ -0,0 +1,85 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using ICSharpCode.Core;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows.Forms;
+
+namespace ICSharpCode.SharpDevelop.Gui
+{
+ ///
+ /// A ColorDialog that remembers any custom colors defined.
+ ///
+ public class SharpDevelopColorDialog : ColorDialog
+ {
+ const string CustomColorsPropertyName = "SharpDevelopColorDialog.CustomColors";
+
+ public SharpDevelopColorDialog()
+ {
+ LoadCustomColors();
+ }
+
+ ///
+ /// Converts a string of colors separated by the '|' character
+ /// into an array of colors.
+ ///
+ public static int[] CustomColorsFromString(string s)
+ {
+ if (String.IsNullOrEmpty(s)) {
+ return null;
+ }
+
+ string[] items = s.Split('|');
+ List colors = new List();
+ foreach (string item in items) {
+ int color;
+ if (Int32.TryParse(item, out color)) {
+ colors.Add(color);
+ }
+ }
+ return colors.ToArray();
+ }
+
+ ///
+ /// Converts an integer array of colors into a string.
+ ///
+ public static string CustomColorsToString(int[] colors)
+ {
+ if (colors == null) {
+ return String.Empty;
+ }
+
+ StringBuilder s = new StringBuilder();
+ for (int i = 0; i < colors.Length; ++i) {
+ if (i != 0) {
+ s.Append('|');
+ }
+ s.Append(colors[i]);
+ }
+ return s.ToString();
+ }
+
+ protected override bool RunDialog(IntPtr hwndOwner)
+ {
+ bool result = base.RunDialog(hwndOwner);
+ SaveCustomColors();
+ return result;
+ }
+
+ void LoadCustomColors()
+ {
+ CustomColors = CustomColorsFromString(PropertyService.Get(CustomColorsPropertyName));
+ }
+
+ void SaveCustomColors()
+ {
+ PropertyService.Set(CustomColorsPropertyName, CustomColorsToString(CustomColors));
+ }
+ }
+}
diff --git a/src/Main/Base/Project/Src/TextEditor/Commands/ToolCommands.cs b/src/Main/Base/Project/Src/TextEditor/Commands/ToolCommands.cs
index 89ca92c5cf..1a6529fad0 100644
--- a/src/Main/Base/Project/Src/TextEditor/Commands/ToolCommands.cs
+++ b/src/Main/Base/Project/Src/TextEditor/Commands/ToolCommands.cs
@@ -39,7 +39,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
}
TextEditorControl textarea = ((ITextEditorControlProvider)window.ViewContent).TextEditorControl;
- using (ColorDialog cd = new ColorDialog()) {
+ using (SharpDevelopColorDialog cd = new SharpDevelopColorDialog()) {
if (cd.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK) {
string ext = Path.GetExtension(textarea.FileName).ToLowerInvariant();
string colorstr;
diff --git a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj
index cdca3b3fe0..38f7ad6be2 100644
--- a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj
+++ b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj
@@ -87,6 +87,7 @@
+
diff --git a/src/Main/Base/Test/SharpDevelopColorDialogTests.cs b/src/Main/Base/Test/SharpDevelopColorDialogTests.cs
new file mode 100644
index 0000000000..10b59be558
--- /dev/null
+++ b/src/Main/Base/Test/SharpDevelopColorDialogTests.cs
@@ -0,0 +1,82 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using ICSharpCode.SharpDevelop.Gui;
+using NUnit.Framework;
+using System;
+
+namespace ICSharpCode.SharpDevelop.Tests
+{
+ [TestFixture]
+ public class SharpDevelopColorDialogTests
+ {
+ [Test]
+ public void NullString()
+ {
+ Assert.IsNull(SharpDevelopColorDialog.CustomColorsFromString(null));
+ }
+
+ [Test]
+ public void EmptyString()
+ {
+ Assert.IsNull(SharpDevelopColorDialog.CustomColorsFromString(String.Empty));
+ }
+
+ [Test]
+ public void OneColorInString()
+ {
+ int[] colors = SharpDevelopColorDialog.CustomColorsFromString("34");
+ Assert.AreEqual(1, colors.Length);
+ Assert.AreEqual(34, colors[0]);
+ }
+
+ [Test]
+ public void TwoColorsInString()
+ {
+ int[] colors = SharpDevelopColorDialog.CustomColorsFromString("20|30");
+ Assert.AreEqual(2, colors.Length);
+ Assert.AreEqual(20, colors[0]);
+ Assert.AreEqual(30, colors[1]);
+ }
+
+ [Test]
+ public void SecondColorIsInvalid()
+ {
+ int[] colors = SharpDevelopColorDialog.CustomColorsFromString("20|Test");
+ Assert.AreEqual(1, colors.Length);
+ Assert.AreEqual(20, colors[0]);
+ }
+
+ [Test]
+ public void FirstColorIsInvalid()
+ {
+ int[] colors = SharpDevelopColorDialog.CustomColorsFromString("Test|20");
+ Assert.AreEqual(1, colors.Length);
+ Assert.AreEqual(20, colors[0]);
+ }
+
+ [Test]
+ public void NullIntColorsArray()
+ {
+ Assert.AreEqual(String.Empty, SharpDevelopColorDialog.CustomColorsToString(null));
+ }
+
+ [Test]
+ public void OneCustomColor()
+ {
+ int[] colors = new int[] { 10 };
+ Assert.AreEqual("10", SharpDevelopColorDialog.CustomColorsToString(colors));
+ }
+
+ [Test]
+ public void TwoCustomColors()
+ {
+ int[] colors = new int[] { 10, 20 };
+ Assert.AreEqual("10|20", SharpDevelopColorDialog.CustomColorsToString(colors));
+ }
+ }
+}