diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index f820caf7dc..f488095429 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/TextEditor/Gui/OptionPanels/GeneralTextEditorPanel.cs b/src/Main/Base/Project/Src/TextEditor/Gui/OptionPanels/GeneralTextEditorPanel.cs index 4ec9db4e5c..2278b7824c 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/OptionPanels/GeneralTextEditorPanel.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/OptionPanels/GeneralTextEditorPanel.cs @@ -8,10 +8,12 @@ using System; using System.IO; using System.Collections; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Text; using System.Text; using System.Windows.Forms; +using System.Threading; using ICSharpCode.SharpDevelop.Internal.ExternalTool; @@ -31,54 +33,42 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.OptionPanels class FontDescriptor { - string name; - bool isMonospaced; + FontFamily fontFamily; + internal string Name; + internal bool IsMonospaced; - public string Name { - get { - return name; - } - set { - name = value; - } - } - - public bool IsMonospaced { - get { - return isMonospaced; - } - set { - isMonospaced = value; - } + public FontDescriptor(FontFamily fontFamily) + { + this.fontFamily = fontFamily; + this.Name = fontFamily.Name; } - public FontDescriptor(string name, bool isMonospaced) + internal void DetectMonospaced(Graphics g) { - this.name = name; - this.isMonospaced = isMonospaced; + this.IsMonospaced = DetectMonospaced(g, fontFamily); } - } - - bool IsMonospaced(FontFamily fontFamily) - { - using (Bitmap newBitmap = new Bitmap(1, 1)) { - using (Graphics g = Graphics.FromImage(newBitmap)) { - using (Font f = new Font(fontFamily, 10)) { - // determine if the length of i == m because I see no other way of - // getting if a font is monospaced or not. - int w1 = (int)g.MeasureString("i.", f).Width; - int w2 = (int)g.MeasureString("mw", f).Width; - return w1 == w2; - } + static bool DetectMonospaced(Graphics g, FontFamily fontFamily) + { + using (Font f = new Font(fontFamily, 10)) { + // determine if the length of i == m because I see no other way of + // getting if a font is monospaced or not. + int w1 = TextRenderer.MeasureText("i.", f).Width; + int w2 = TextRenderer.MeasureText("mw", f).Width; + return w1 == w2; } } } + ComboBox fontListComboBox, fontSizeComboBox; + public override void LoadPanelContents() { SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.GeneralTextEditorPanel.xfrm")); + fontListComboBox = ((ComboBox)ControlDictionary["fontListComboBox"]); + fontSizeComboBox = ((ComboBox)ControlDictionary["fontSizeComboBox"]); + ((CheckBox)ControlDictionary["enableDoublebufferingCheckBox"]).Checked = ((Properties)CustomizationObject).Get("DoubleBuffer", true); //((CheckBox)ControlDictionary["enableCodeCompletionCheckBox"]).Checked = ((Properties)CustomizationObject).Get("EnableCodeCompletion", true); ((CheckBox)ControlDictionary["enableFoldingCheckBox"]).Checked = ((Properties)CustomizationObject).Get("EnableFolding", true); @@ -99,39 +89,65 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.OptionPanels ((ComboBox)ControlDictionary["textEncodingComboBox"]).SelectedIndex = encodingIndex; encoding = CharacterEncodings.GetEncodingByIndex(encodingIndex).CodePage; - Font currentFont = ParseFont(((Properties)CustomizationObject).Get("DefaultFont", ResourceService.DefaultMonospacedFont.ToString()).ToString()); - for (int i = 6; i <= 24; ++i) { - ((ComboBox)ControlDictionary["fontSizeComboBox"]).Items.Add(i); + fontSizeComboBox.Items.Add(i); } - ((ComboBox)ControlDictionary["fontSizeComboBox"]).Text = currentFont.Size.ToString(); - ((ComboBox)ControlDictionary["fontSizeComboBox"]).TextChanged += new EventHandler(UpdateFontPreviewLabel); + fontSizeComboBox.TextChanged += new EventHandler(UpdateFontPreviewLabel); + fontSizeComboBox.Enabled = false; + + fontListComboBox.Enabled = false; + fontListComboBox.TextChanged += new EventHandler(UpdateFontPreviewLabel); + fontListComboBox.SelectedIndexChanged += new EventHandler(UpdateFontPreviewLabel); + fontListComboBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.MeasureComboBoxItem); + fontListComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBoxDrawItem); + + boldComboBoxFont = new Font(ControlDictionary["fontListComboBox"].Font, FontStyle.Bold); +// GeneralTextEditorPanel.selectedFont = ParseFont(ControlDictionary["fontNameDisplayTextBox"].Text); +// +// ControlDictionary["browseButton"].Click += new EventHandler(SelectFontEvent); + UpdateFontPreviewLabel(null, null); + Thread thread = new Thread(DetectMonospacedThread); + thread.IsBackground = true; + thread.Start(); + } + + void DetectMonospacedThread() + { + DebugTimer.Start(); InstalledFontCollection installedFontCollection = new InstalledFontCollection(); + Font currentFont = ParseFont(((Properties)CustomizationObject).Get("DefaultFont", ResourceService.DefaultMonospacedFont.ToString()).ToString()); + List fonts = new List(); int index = 0; foreach (FontFamily fontFamily in installedFontCollection.Families) { if (fontFamily.IsStyleAvailable(FontStyle.Regular) && fontFamily.IsStyleAvailable(FontStyle.Bold) && fontFamily.IsStyleAvailable(FontStyle.Italic)) { if (fontFamily.Name == currentFont.Name) { - index = ((ComboBox)ControlDictionary["fontListComboBox"]).Items.Count; + index = fonts.Count; } - ((ComboBox)ControlDictionary["fontListComboBox"]).Items.Add(new FontDescriptor(fontFamily.Name, IsMonospaced(fontFamily))); + fonts.Add(new FontDescriptor(fontFamily)); } } - - ((ComboBox)ControlDictionary["fontListComboBox"]).SelectedIndex = index; - ((ComboBox)ControlDictionary["fontListComboBox"]).TextChanged += new EventHandler(UpdateFontPreviewLabel); - ((ComboBox)ControlDictionary["fontListComboBox"]).SelectedIndexChanged += new EventHandler(UpdateFontPreviewLabel); - ((ComboBox)ControlDictionary["fontListComboBox"]).MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.MeasureComboBoxItem); - ((ComboBox)ControlDictionary["fontListComboBox"]).DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBoxDrawItem); - - boldComboBoxFont = new Font(ControlDictionary["fontListComboBox"].Font, FontStyle.Bold); - -// GeneralTextEditorPanel.selectedFont = ParseFont(ControlDictionary["fontNameDisplayTextBox"].Text); -// -// ControlDictionary["browseButton"].Click += new EventHandler(SelectFontEvent); - UpdateFontPreviewLabel(this, EventArgs.Empty); + DebugTimer.Stop("Getting installed fonts"); + WorkbenchSingleton.SafeThreadAsyncCall( + delegate { + fontListComboBox.Items.AddRange(fonts.ToArray()); + fontListComboBox.SelectedIndex = index; + fontListComboBox.Enabled = true; + fontSizeComboBox.Text = currentFont.Size.ToString(); + fontSizeComboBox.Enabled = true; + }); + DebugTimer.Start(); + using (Bitmap newBitmap = new Bitmap(1, 1)) { + using (Graphics g = Graphics.FromImage(newBitmap)) { + foreach (FontDescriptor fd in fonts) { + fd.DetectMonospaced(g); + } + } + } + DebugTimer.Stop("Detect Monospaced"); + fontListComboBox.Invalidate(); } void MeasureComboBoxItem(object sender, System.Windows.Forms.MeasureItemEventArgs e) @@ -175,12 +191,14 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.OptionPanels Font CurrentFont { get { + if (!fontListComboBox.Enabled) + return null; int fontSize = 10; try { fontSize = Math.Max(6, Int32.Parse(ControlDictionary["fontSizeComboBox"].Text)); } catch (Exception) {} - FontDescriptor fontDescriptor = (FontDescriptor)((ComboBox)ControlDictionary["fontListComboBox"]).Items[((ComboBox)ControlDictionary["fontListComboBox"]).SelectedIndex]; + FontDescriptor fontDescriptor = (FontDescriptor)fontListComboBox.Items[fontListComboBox.SelectedIndex]; return new Font(fontDescriptor.Name, fontSize); @@ -189,7 +207,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.OptionPanels void UpdateFontPreviewLabel(object sender, EventArgs e) { - ControlDictionary["fontPreviewLabel"].Font = CurrentFont; + Font currentFont = CurrentFont; + ControlDictionary["fontPreviewLabel"].Visible = currentFont != null; + if (currentFont != null) { + ControlDictionary["fontPreviewLabel"].Font = currentFont; + } } public override bool StorePanelContents() @@ -199,7 +221,10 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.OptionPanels ((Properties)CustomizationObject).Set("MouseWheelTextZoom", ((CheckBox)ControlDictionary["mouseWheelZoomCheckBox"]).Checked); //((Properties)CustomizationObject).Set("EnableCodeCompletion", ((CheckBox)ControlDictionary["enableCodeCompletionCheckBox"]).Checked); ((Properties)CustomizationObject).Set("EnableFolding", ((CheckBox)ControlDictionary["enableFoldingCheckBox"]).Checked); - ((Properties)CustomizationObject).Set("DefaultFont", CurrentFont.ToString()); + Font currentFont = CurrentFont; + if (currentFont != null) { + ((Properties)CustomizationObject).Set("DefaultFont", currentFont.ToString()); + } ((Properties)CustomizationObject).Set("Encoding", CharacterEncodings.GetCodePageByIndex(((ComboBox)ControlDictionary["textEncodingComboBox"]).SelectedIndex)); ((Properties)CustomizationObject).Set("ShowQuickClassBrowserPanel", ((CheckBox)ControlDictionary["showQuickClassBrowserCheckBox"]).Checked); diff --git a/src/Main/Base/Project/Src/Util/DebugTimer.cs b/src/Main/Base/Project/Src/Util/DebugTimer.cs new file mode 100644 index 0000000000..ccf5d3e13c --- /dev/null +++ b/src/Main/Base/Project/Src/Util/DebugTimer.cs @@ -0,0 +1,33 @@ +/* + * Created by SharpDevelop. + * User: tfssetup + * Date: 10/27/2006 + * Time: 9:29 AM + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ + +using System; +using System.Diagnostics; +using ICSharpCode.Core; + +namespace ICSharpCode.SharpDevelop +{ + public static class DebugTimer + { + static int startTime; + + [Conditional("DEBUG")] + public static void Start() + { + startTime = Environment.TickCount; + } + + [Conditional("DEBUG")] + public static void Stop(string desc) + { + int stopTime = Environment.TickCount; + LoggingService.Debug('"' + desc + "\" took " + (stopTime - startTime) + " ms"); + } + } +}