public override bool Equals(object obj) { if (obj == null) { return(false); } if (ReferenceEquals(this, obj)) { return(true); } if (obj.GetType() != typeof(AmbientColor)) { return(false); } AmbientColor other = (AmbientColor)obj; return(Colors.Equals(other.Colors) && Name == other.Name); }
public static AmbientColor Import(Dictionary <string, ColorScheme.VSSettingColor> colors, string vsSetting) { var result = new AmbientColor(); var attrs = vsSetting.Split(','); foreach (var attr in attrs) { var info = attr.Split('='); if (info.Length != 2) { continue; } var idx = info [1].LastIndexOf('/'); var source = info [1].Substring(0, idx); var dest = info [1].Substring(idx + 1); ColorScheme.VSSettingColor color; if (!colors.TryGetValue(source, out color)) { continue; } result.Name = color.Name; string colorString; switch (dest) { case "Foreground": colorString = color.Foreground; break; case "Background": colorString = color.Background; break; default: throw new InvalidDataException("Invalid attribute source: " + dest); } result.Colors.Add(Tuple.Create(info [0], ColorScheme.ImportVsColor(colorString))); } if (result.Colors.Count == 0) { return(null); } return(result); }
public static AmbientColor Create (XElement element, Dictionary<string, Cairo.Color> palette) { var result = new AmbientColor (); foreach (var node in element.DescendantNodes ()) { if (node.NodeType == System.Xml.XmlNodeType.Element) { var el = (XElement)node; switch (el.Name.LocalName) { case "name": result.Name = el.Value; break; default: result.Colors.Add (Tuple.Create (el.Name.LocalName, ColorScheme.ParsePaletteColor (palette, el.Value))); break; } } } return result; }
public static AmbientColor Create(XElement element, Dictionary <string, Color> palette) { var result = new AmbientColor(); foreach (var node in element.DescendantNodes()) { if (node.NodeType == System.Xml.XmlNodeType.Element) { var el = (XElement)node; switch (el.Name.LocalName) { case "name": result.Name = el.Value; break; default: result.Colors.Add(Tuple.Create(el.Name.LocalName, ColorScheme.ParsePaletteColor(palette, el.Value))); break; } } } return(result); }
public static AmbientColor Import (Dictionary<string, ColorScheme.VSSettingColor> colors, string vsSetting) { var result = new AmbientColor (); var attrs = vsSetting.Split (','); foreach (var attr in attrs) { var info = attr.Split ('='); if (info.Length != 2) continue; var idx = info [1].LastIndexOf ('/'); var source = info [1].Substring (0, idx); var dest = info [1].Substring (idx + 1); ColorScheme.VSSettingColor color; if (!colors.TryGetValue (source, out color)) continue; result.Name = color.Name; string colorString; switch (dest) { case "Foreground": colorString = color.Foreground; break; case "Background": colorString = color.Background; break; default: throw new InvalidDataException ("Invalid attribute source: " + dest); } result.Colors.Add (Tuple.Create (info [0], ColorScheme.ImportVsColor (colorString))); } if (result.Colors.Count == 0) return null; return result; }
public static ColorScheme LoadFrom(Stream stream) { var result = new ColorScheme(); var reader = System.Runtime.Serialization.Json.JsonReaderWriterFactory.CreateJsonReader(stream, new System.Xml.XmlDictionaryReaderQuotas()); var root = XElement.Load(reader); // The fields we'd like to extract result.Name = root.XPathSelectElement("name").Value; if (result.Name != "Default") { result.CopyValues(SyntaxModeService.DefaultColorStyle); } var version = Version.Parse(root.XPathSelectElement("version").Value); if (version.Major != 1) { return(null); } var el = root.XPathSelectElement("description"); if (el != null) { result.Description = el.Value; } el = root.XPathSelectElement("originator"); if (el != null) { result.Originator = el.Value; } el = root.XPathSelectElement("baseScheme"); if (el != null) { result.BaseScheme = el.Value; } if (result.BaseScheme != null) { var baseScheme = SyntaxModeService.GetColorStyle(result.BaseScheme); if (baseScheme != null) { result.CopyValues(baseScheme); } } var palette = new Dictionary <string, Cairo.Color> (); foreach (var color in root.XPathSelectElements("palette/*")) { var name = color.XPathSelectElement("name").Value; if (palette.ContainsKey(name)) { throw new InvalidDataException("Duplicate palette color definition for: " + name); } palette.Add( name, ParseColor(color.XPathSelectElement("value").Value) ); } foreach (var colorElement in root.XPathSelectElements("//colors/*")) { var color = AmbientColor.Create(colorElement, palette); PropertyDecsription info; if (!ambientColors.TryGetValue(color.Name, out info)) { Console.WriteLine("Ambient color:" + color.Name + " not found."); continue; } info.Info.SetValue(result, color, null); } foreach (var textColorElement in root.XPathSelectElements("//text/*")) { var color = ChunkStyle.Create(textColorElement, palette); PropertyDecsription info; if (!textColors.TryGetValue(color.Name, out info)) { Console.WriteLine("Text color:" + color.Name + " not found."); continue; } info.Info.SetValue(result, color, null); } // Check scheme bool valid = true; foreach (var color in textColors.Values) { if (color.Info.GetValue(result, null) == null) { Console.WriteLine(color.Attribute.Name + " == null"); valid = false; } } foreach (var color in ambientColors.Values) { if (color.Info.GetValue(result, null) == null) { Console.WriteLine(color.Attribute.Name + " == null"); valid = false; } } if (!valid) { throw new InvalidDataException("Scheme " + result.Name + " is not valid."); } return(result); }
public static ColorScheme Import(string fileName, Stream stream) { var result = new ColorScheme(); result.Name = Path.GetFileNameWithoutExtension(fileName); result.Description = "Imported color scheme"; result.Originator = "Imported from " + fileName; var colors = new Dictionary <string, VSSettingColor> (); using (var reader = XmlReader.Create(stream)) { while (reader.Read()) { if (reader.LocalName == "Item") { var color = VSSettingColor.Create(reader); if (colors.ContainsKey(color.Name)) { Console.WriteLine("Warning: {0} is defined twice in vssettings.", color.Name); continue; } colors[color.Name] = color; } } } HashSet <string> importedAmbientColors = new HashSet <string> (); // convert ambient colors foreach (var ambient in ambientColors.Values) { if (!string.IsNullOrEmpty(ambient.Attribute.VSSetting)) { var import = AmbientColor.Import(colors, ambient.Attribute.VSSetting); if (import != null) { importedAmbientColors.Add(import.Name); ambient.Info.SetValue(result, import, null); continue; } } } // convert text colors foreach (var vsc in colors.Values) { bool found = false; foreach (var color in textColors) { if (color.Value.Attribute.VSSetting == null) { continue; } var split = color.Value.Attribute.VSSetting.Split('?'); foreach (var s in split) { if (s == vsc.Name) { /* if (vsc.Foreground == "0x02000000" && vsc.Background == "0x02000000") { * color.Value.Info.SetValue (result, result.PlainText, null); * found = true; * continue; * }*/ var textColor = ChunkStyle.Import(color.Value.Attribute.Name, vsc); if (textColor != null) { color.Value.Info.SetValue(result, textColor, null); found = true; } } } } if (!found && !importedAmbientColors.Contains(vsc.Name)) { Console.WriteLine(vsc.Name + " not imported!"); } } result.IndentationGuide = new AmbientColor(); result.IndentationGuide.Colors.Add(Tuple.Create("color", AlphaBlend(result.PlainText.Foreground, result.PlainText.Background, 0.3))); result.TooltipText = result.PlainText.Clone(); var h = (HslColor)result.TooltipText.Background; h.L += 0.01; result.TooltipText.Background = h; result.TooltipPagerTop = new AmbientColor(); result.TooltipPagerTop.Colors.Add(Tuple.Create("color", result.TooltipText.Background)); result.TooltipPagerBottom = new AmbientColor(); result.TooltipPagerBottom.Colors.Add(Tuple.Create("color", result.TooltipText.Background)); result.TooltipPagerTriangle = new AmbientColor(); result.TooltipPagerTriangle.Colors.Add(Tuple.Create("color", AlphaBlend(result.PlainText.Foreground, result.PlainText.Background, 0.8))); result.TooltipBorder = new AmbientColor(); result.TooltipBorder.Colors.Add(Tuple.Create("color", AlphaBlend(result.PlainText.Foreground, result.PlainText.Background, 0.5))); var defaultStyle = SyntaxModeService.GetColorStyle(HslColor.Brightness(result.PlainText.Background) < 0.5 ? "Monokai" : "Default"); foreach (var color in textColors.Values) { if (color.Info.GetValue(result, null) == null) { color.Info.SetValue(result, color.Info.GetValue(defaultStyle, null), null); } } foreach (var color in ambientColors.Values) { if (color.Info.GetValue(result, null) == null) { color.Info.SetValue(result, color.Info.GetValue(defaultStyle, null), null); } } if (result.PlainText.TransparentForeground) { result.PlainText.Foreground = new Cairo.Color(0, 0, 0); } return(result); }
void SelectAmbientColor (TreeIter iter, AmbientColor ambientColor) { notebookColorChooser.Page = 1; SetColorToButton (colorbuttonPrimary, ambientColor.Color); SetColorToButton (colorbuttonSecondary, ambientColor.SecondColor); colorbuttonSecondary.Sensitive = ambientColor.HasSecondColor; SetColorToButton (colorbuttonBorder, ambientColor.BorderColor); colorbuttonBorder.Sensitive = ambientColor.HasBorderColor; }
void SetAmbientColor (Gtk.TreeIter iter, AmbientColor oldStyle) { var newStyle = new AmbientColor (); newStyle.Color = GetColorFromButton (colorbuttonPrimary); newStyle.SecondColor = GetColorFromButton (colorbuttonSecondary); colorStore.SetValue (iter, 2, newStyle); var newscheme = colorSheme.Clone (); ApplyStyle (newscheme); this.textEditor.TextViewMargin.PurgeLayoutCache (); this.textEditor.Document.MimeType = "text/x-csharp"; this.textEditor.GetTextEditorData ().ColorStyle = newscheme; this.textEditor.QueueDraw (); }
void SelectAmbientColor (AmbientColor ambientColor) { SetColorToButton (colorbuttonPrimary, ambientColor.Color); SetColorToButton (colorbuttonSecondary, ambientColor.SecondColor); SetColorToButton (colorbuttonBorder, ambientColor.BorderColor); this.colorbuttonPrimary.Sensitive = true; this.colorbuttonSecondary.Sensitive = ambientColor.HasSecondColor; this.colorbuttonBorder.Sensitive = ambientColor.HasBorderColor; this.colorbuttonBorder.Visible = true; this.togglebuttonBold.Visible = false; this.togglebuttonItalic.Visible = false; this.colorbuttonPrimary.LabelText = "Primary color:"; this.colorbuttonSecondary.LabelText = "Secondary color:"; }
public DebugTextMarker (int offset, int length, AmbientColor background, ChunkStyle forground = null) : base (offset, length) { this.forground = forground; this.background = background; }
protected Cairo.Color GetBorderColor (AmbientColor color) { if (color.HasBorderColor) return color.BorderColor; return color.Color; }