/// <summary> /// Update the view to display the current state. /// </summary> private void UpdateView() { if (SettingFontFamily != null) { buttonFont.Content = String.Format("{0}, {1:0}pt", SettingFontFamily, SettingFontSize); } else { buttonFont.Content = String.Format("none, {0:0}pt", SettingFontSize); } borderSymbolForeground.Background = null; textBlockSymbolForeground.Text = null; borderSymbolBackground.Background = null; textBlockSymbolBackground.Text = null; checkBoxSymbolBold.IsChecked = false; checkBoxSymbolItalic.IsChecked = false; EditorSymbolSettings ess = SelectedSettingSymbol; if (ess != null) { if (ess.Foreground.HasValue) { borderSymbolForeground.Background = new SolidColorBrush(ess.Foreground.Value); } textBlockSymbolForeground.Text = ess.ForegroundAsString; if (ess.Background.HasValue) { borderSymbolBackground.Background = new SolidColorBrush(ess.Background.Value); } textBlockSymbolBackground.Text = ess.BackgroundAsString; checkBoxSymbolBold.IsChecked = ess.IsBold; checkBoxSymbolItalic.IsChecked = ess.IsItalic; textBlockSymbolForegroundTitle.Visibility = Visibility.Visible; buttonSymbolForeground.Visibility = Visibility.Visible; textBlockSymbolBackgroundTitle.Visibility = Visibility.Visible; buttonSymbolBackground.Visibility = Visibility.Visible; stackPanelSymbolBold.Visibility = Visibility.Visible; stackPanelSymbolItalic.Visibility = Visibility.Visible; } else { textBlockSymbolForegroundTitle.Visibility = Visibility.Hidden; buttonSymbolForeground.Visibility = Visibility.Hidden; textBlockSymbolBackgroundTitle.Visibility = Visibility.Hidden; buttonSymbolBackground.Visibility = Visibility.Hidden; stackPanelSymbolBold.Visibility = Visibility.Hidden; stackPanelSymbolItalic.Visibility = Visibility.Hidden; } }
/// <summary> /// Add a symbol to the Symbols collection. /// </summary> /// <param name="name">EditorSymbolSettings.Name</param> /// <param name="foreground">EditorSymbolSettings.Foreground</param> /// <param name="background">EditorSymbolSettings.Background</param> /// <param name="isBold">EditorSymbolSettings.IsBold</param> /// <param name="isItalic">EditorSymbolSettings.IsItalic</param> public void AddSymbol(string name, Color?foreground, Color?background, bool isBold, bool isItalic) { EditorSymbolSettings ess = new EditorSymbolSettings(name); ess.Foreground = foreground; ess.Background = background; ess.IsBold = isBold; ess.IsItalic = isItalic; _symbols.Add(ess); }
/// <summary> /// Update the symbol. /// </summary> /// <param name="sender">Object that raised the event.</param> /// <param name="e">Event arguments.</param> private void checkBoxSymbolItalic_Changed(object sender, RoutedEventArgs e) { try { EditorSymbolSettings ess = SelectedSettingSymbol; if (ess != null) { ess.IsItalic = checkBoxSymbolItalic.IsChecked.HasValue && checkBoxSymbolItalic.IsChecked.Value; } } catch (Exception err) { App.HandleException(err); } }
/// <summary> /// Constructor. /// </summary> /// <param name="highlight">A stream that contains xshd formatted highlight instructions.</param> public EditorSettings(string settingName, Stream highlight) { if (String.IsNullOrWhiteSpace(settingName)) { throw new ArgumentException("settingName is null or whitespace.", "settingName"); } if (highlight == null) { throw new ArgumentNullException("highlight"); } _settingName = settingName; using (System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(highlight)) HighlightDefinition = HighlightingLoader.Load(reader, HighlightingManager.Instance); Symbols = new List <EditorSymbolSettings>(); FontFamily = new FontFamily("Consolas"); FontSizeInPoints = 10; Foreground = Colors.Black; Background = Colors.White; SelectionForeground = null; SelectionBackground = Colors.LightBlue; FindResultBackground = Colors.DarkOrange; if (!Load()) { List <EditorSymbolSettings> symbols = new List <EditorSymbolSettings>(); foreach (HighlightingColor hc in HighlightDefinition.NamedHighlightingColors) { EditorSymbolSettings ess = new EditorSymbolSettings(hc.Name); ess.Foreground = (hc.Foreground != null) ? hc.Foreground.GetColor(null) : null; ess.Background = (hc.Background != null) ? hc.Background.GetColor(null) : null; ess.Weight = hc.FontWeight; ess.Style = hc.FontStyle; ess.Commit(); symbols.Add(ess); } Symbols = symbols; } else { ApplySymbolUpdates(); } Themes = new List <EditorSettingsTheme>(); }
/// <summary> /// Add a symbol to the Symbols collection. /// </summary> /// <param name="name">EditorSymbolSettings.Name</param> /// <param name="foreground">EditorSymbolSettings.Foreground</param> /// <param name="background">EditorSymbolSettings.Background</param> /// <param name="isBold">EditorSymbolSettings.IsBold</param> /// <param name="isItalic">EditorSymbolSettings.IsItalic</param> public void AddSymbol(string name, string foreground, string background, bool isBold, bool isItalic) { EditorSymbolSettings ess = new EditorSymbolSettings(name); if (foreground != null) { ess.Foreground = (Color)ColorConverter.ConvertFromString(foreground); } if (background != null) { ess.Background = (Color)ColorConverter.ConvertFromString(background); } ess.IsBold = isBold; ess.IsItalic = isItalic; _symbols.Add(ess); }
/// <summary> /// Show the color selection dialog. /// </summary> /// <param name="sender">Object that raised the event.</param> /// <param name="e">Event arguments.</param> private void buttonSymbolBackground_Click(object sender, RoutedEventArgs e) { try { EditorSymbolSettings ess = SelectedSettingSymbol; if (ess != null) { ColorSelectWindow dlg = new ColorSelectWindow(); dlg.AllowNoColor = true; dlg.SelectedColor = ess.Background; if (App.ShowDialog(dlg)) { ess.Background = dlg.SelectedColor; UpdateView(); } } } catch (Exception err) { App.HandleException(err); } }
/// <summary> /// Load settings from file. /// </summary> /// <returns>true if settings were loaded, false if they were not.</returns> private bool Load() { string text = Properties.Settings.Default[_settingName] as string; if (String.IsNullOrWhiteSpace(text)) { return(false); } else { try { using (StringReader reader = new StringReader(text)) { using (XmlReader xml = XmlReader.Create(reader)) { if (!xml.ReadToDescendant("settings")) { throw new Exception("settings element is missing."); } xml.Read(); while (xml.NodeType == XmlNodeType.Element) { switch (xml.LocalName) { case "header": Header = xml.ReadElementContentAsString(); break; case "font": if (xml["family"] != null) { FontFamily = new FontFamily(xml["family"]); } if (xml["size"] != null) { FontSizeInPoints = double.Parse(xml["size"]); } if (xml["foreground"] != null) { Foreground = (Color)ColorConverter.ConvertFromString(xml["foreground"]); } if (xml["background"] != null) { Background = (Color)ColorConverter.ConvertFromString(xml["background"]); } if (xml["selectionForeground"] != null) { SelectionForeground = (Color)ColorConverter.ConvertFromString(xml["selectionForeground"]); } else { SelectionForeground = null; } if (xml["selectionBackground"] != null) { SelectionBackground = (Color)ColorConverter.ConvertFromString(xml["selectionBackground"]); } else { SelectionBackground = null; } if (xml["findResultBackground"] != null) { FindResultBackground = (Color)ColorConverter.ConvertFromString(xml["findResultBackground"]); } xml.Read(); break; case "symbols": List <EditorSymbolSettings> symbols = new List <EditorSymbolSettings>(); xml.Read(); while (xml.NodeType == XmlNodeType.Element) { EditorSymbolSettings ess = new EditorSymbolSettings(); ess.ReadXml(xml); symbols.Add(ess); } Symbols = symbols; xml.Read(); break; default: break; } } } } if (Symbols.Count() == 0) { return(false); } } catch { return(false); } return(true); } }