|
|
|
@ -8,10 +8,12 @@ |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.IO; |
|
|
|
using System.IO; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections; |
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Drawing; |
|
|
|
using System.Drawing; |
|
|
|
using System.Drawing.Text; |
|
|
|
using System.Drawing.Text; |
|
|
|
using System.Text; |
|
|
|
using System.Text; |
|
|
|
using System.Windows.Forms; |
|
|
|
using System.Windows.Forms; |
|
|
|
|
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
|
|
|
|
using ICSharpCode.SharpDevelop.Internal.ExternalTool; |
|
|
|
using ICSharpCode.SharpDevelop.Internal.ExternalTool; |
|
|
|
|
|
|
|
|
|
|
|
@ -31,54 +33,42 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.OptionPanels |
|
|
|
|
|
|
|
|
|
|
|
class FontDescriptor |
|
|
|
class FontDescriptor |
|
|
|
{ |
|
|
|
{ |
|
|
|
string name; |
|
|
|
FontFamily fontFamily; |
|
|
|
bool isMonospaced; |
|
|
|
internal string Name; |
|
|
|
|
|
|
|
internal bool IsMonospaced; |
|
|
|
|
|
|
|
|
|
|
|
public string Name { |
|
|
|
public FontDescriptor(FontFamily fontFamily) |
|
|
|
get { |
|
|
|
{ |
|
|
|
return name; |
|
|
|
this.fontFamily = fontFamily; |
|
|
|
} |
|
|
|
this.Name = fontFamily.Name; |
|
|
|
set { |
|
|
|
|
|
|
|
name = value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsMonospaced { |
|
|
|
|
|
|
|
get { |
|
|
|
|
|
|
|
return isMonospaced; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
set { |
|
|
|
|
|
|
|
isMonospaced = value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public FontDescriptor(string name, bool isMonospaced) |
|
|
|
internal void DetectMonospaced(Graphics g) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.name = name; |
|
|
|
this.IsMonospaced = DetectMonospaced(g, fontFamily); |
|
|
|
this.isMonospaced = isMonospaced; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
static bool DetectMonospaced(Graphics g, FontFamily fontFamily) |
|
|
|
|
|
|
|
{ |
|
|
|
bool IsMonospaced(FontFamily fontFamily) |
|
|
|
using (Font f = new Font(fontFamily, 10)) { |
|
|
|
{ |
|
|
|
// determine if the length of i == m because I see no other way of
|
|
|
|
using (Bitmap newBitmap = new Bitmap(1, 1)) { |
|
|
|
// getting if a font is monospaced or not.
|
|
|
|
using (Graphics g = Graphics.FromImage(newBitmap)) { |
|
|
|
int w1 = TextRenderer.MeasureText("i.", f).Width; |
|
|
|
using (Font f = new Font(fontFamily, 10)) { |
|
|
|
int w2 = TextRenderer.MeasureText("mw", f).Width; |
|
|
|
// determine if the length of i == m because I see no other way of
|
|
|
|
return w1 == w2; |
|
|
|
// 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; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ComboBox fontListComboBox, fontSizeComboBox; |
|
|
|
|
|
|
|
|
|
|
|
public override void LoadPanelContents() |
|
|
|
public override void LoadPanelContents() |
|
|
|
{ |
|
|
|
{ |
|
|
|
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.GeneralTextEditorPanel.xfrm")); |
|
|
|
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["enableDoublebufferingCheckBox"]).Checked = ((Properties)CustomizationObject).Get("DoubleBuffer", true); |
|
|
|
//((CheckBox)ControlDictionary["enableCodeCompletionCheckBox"]).Checked = ((Properties)CustomizationObject).Get("EnableCodeCompletion", true);
|
|
|
|
//((CheckBox)ControlDictionary["enableCodeCompletionCheckBox"]).Checked = ((Properties)CustomizationObject).Get("EnableCodeCompletion", true);
|
|
|
|
((CheckBox)ControlDictionary["enableFoldingCheckBox"]).Checked = ((Properties)CustomizationObject).Get("EnableFolding", 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; |
|
|
|
((ComboBox)ControlDictionary["textEncodingComboBox"]).SelectedIndex = encodingIndex; |
|
|
|
encoding = CharacterEncodings.GetEncodingByIndex(encodingIndex).CodePage; |
|
|
|
encoding = CharacterEncodings.GetEncodingByIndex(encodingIndex).CodePage; |
|
|
|
|
|
|
|
|
|
|
|
Font currentFont = ParseFont(((Properties)CustomizationObject).Get("DefaultFont", ResourceService.DefaultMonospacedFont.ToString()).ToString()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 6; i <= 24; ++i) { |
|
|
|
for (int i = 6; i <= 24; ++i) { |
|
|
|
((ComboBox)ControlDictionary["fontSizeComboBox"]).Items.Add(i); |
|
|
|
fontSizeComboBox.Items.Add(i); |
|
|
|
} |
|
|
|
} |
|
|
|
((ComboBox)ControlDictionary["fontSizeComboBox"]).Text = currentFont.Size.ToString(); |
|
|
|
fontSizeComboBox.TextChanged += new EventHandler(UpdateFontPreviewLabel); |
|
|
|
((ComboBox)ControlDictionary["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(); |
|
|
|
InstalledFontCollection installedFontCollection = new InstalledFontCollection(); |
|
|
|
|
|
|
|
Font currentFont = ParseFont(((Properties)CustomizationObject).Get("DefaultFont", ResourceService.DefaultMonospacedFont.ToString()).ToString()); |
|
|
|
|
|
|
|
List<FontDescriptor> fonts = new List<FontDescriptor>(); |
|
|
|
|
|
|
|
|
|
|
|
int index = 0; |
|
|
|
int index = 0; |
|
|
|
foreach (FontFamily fontFamily in installedFontCollection.Families) { |
|
|
|
foreach (FontFamily fontFamily in installedFontCollection.Families) { |
|
|
|
if (fontFamily.IsStyleAvailable(FontStyle.Regular) && fontFamily.IsStyleAvailable(FontStyle.Bold) && fontFamily.IsStyleAvailable(FontStyle.Italic)) { |
|
|
|
if (fontFamily.IsStyleAvailable(FontStyle.Regular) && fontFamily.IsStyleAvailable(FontStyle.Bold) && fontFamily.IsStyleAvailable(FontStyle.Italic)) { |
|
|
|
if (fontFamily.Name == currentFont.Name) { |
|
|
|
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)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
DebugTimer.Stop("Getting installed fonts"); |
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).SelectedIndex = index; |
|
|
|
WorkbenchSingleton.SafeThreadAsyncCall( |
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).TextChanged += new EventHandler(UpdateFontPreviewLabel); |
|
|
|
delegate { |
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).SelectedIndexChanged += new EventHandler(UpdateFontPreviewLabel); |
|
|
|
fontListComboBox.Items.AddRange(fonts.ToArray()); |
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.MeasureComboBoxItem); |
|
|
|
fontListComboBox.SelectedIndex = index; |
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBoxDrawItem); |
|
|
|
fontListComboBox.Enabled = true; |
|
|
|
|
|
|
|
fontSizeComboBox.Text = currentFont.Size.ToString(); |
|
|
|
boldComboBoxFont = new Font(ControlDictionary["fontListComboBox"].Font, FontStyle.Bold); |
|
|
|
fontSizeComboBox.Enabled = true; |
|
|
|
|
|
|
|
}); |
|
|
|
// GeneralTextEditorPanel.selectedFont = ParseFont(ControlDictionary["fontNameDisplayTextBox"].Text);
|
|
|
|
DebugTimer.Start(); |
|
|
|
//
|
|
|
|
using (Bitmap newBitmap = new Bitmap(1, 1)) { |
|
|
|
// ControlDictionary["browseButton"].Click += new EventHandler(SelectFontEvent);
|
|
|
|
using (Graphics g = Graphics.FromImage(newBitmap)) { |
|
|
|
UpdateFontPreviewLabel(this, EventArgs.Empty); |
|
|
|
foreach (FontDescriptor fd in fonts) { |
|
|
|
|
|
|
|
fd.DetectMonospaced(g); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
DebugTimer.Stop("Detect Monospaced"); |
|
|
|
|
|
|
|
fontListComboBox.Invalidate(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void MeasureComboBoxItem(object sender, System.Windows.Forms.MeasureItemEventArgs e) |
|
|
|
void MeasureComboBoxItem(object sender, System.Windows.Forms.MeasureItemEventArgs e) |
|
|
|
@ -175,12 +191,14 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.OptionPanels |
|
|
|
|
|
|
|
|
|
|
|
Font CurrentFont { |
|
|
|
Font CurrentFont { |
|
|
|
get { |
|
|
|
get { |
|
|
|
|
|
|
|
if (!fontListComboBox.Enabled) |
|
|
|
|
|
|
|
return null; |
|
|
|
int fontSize = 10; |
|
|
|
int fontSize = 10; |
|
|
|
try { |
|
|
|
try { |
|
|
|
fontSize = Math.Max(6, Int32.Parse(ControlDictionary["fontSizeComboBox"].Text)); |
|
|
|
fontSize = Math.Max(6, Int32.Parse(ControlDictionary["fontSizeComboBox"].Text)); |
|
|
|
} catch (Exception) {} |
|
|
|
} 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, |
|
|
|
return new Font(fontDescriptor.Name, |
|
|
|
fontSize); |
|
|
|
fontSize); |
|
|
|
@ -189,7 +207,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.OptionPanels |
|
|
|
|
|
|
|
|
|
|
|
void UpdateFontPreviewLabel(object sender, EventArgs e) |
|
|
|
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() |
|
|
|
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("MouseWheelTextZoom", ((CheckBox)ControlDictionary["mouseWheelZoomCheckBox"]).Checked); |
|
|
|
//((Properties)CustomizationObject).Set("EnableCodeCompletion", ((CheckBox)ControlDictionary["enableCodeCompletionCheckBox"]).Checked);
|
|
|
|
//((Properties)CustomizationObject).Set("EnableCodeCompletion", ((CheckBox)ControlDictionary["enableCodeCompletionCheckBox"]).Checked);
|
|
|
|
((Properties)CustomizationObject).Set("EnableFolding", ((CheckBox)ControlDictionary["enableFoldingCheckBox"]).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("Encoding", CharacterEncodings.GetCodePageByIndex(((ComboBox)ControlDictionary["textEncodingComboBox"]).SelectedIndex)); |
|
|
|
((Properties)CustomizationObject).Set("ShowQuickClassBrowserPanel", ((CheckBox)ControlDictionary["showQuickClassBrowserCheckBox"]).Checked); |
|
|
|
((Properties)CustomizationObject).Set("ShowQuickClassBrowserPanel", ((CheckBox)ControlDictionary["showQuickClassBrowserCheckBox"]).Checked); |
|
|
|
|
|
|
|
|
|
|
|
|