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);
}