public override void Invoke() { var value = _item.Text; switch (_format) { case ColorFormat.Name: value = GetNamedColor(_colorModel.Color); break; case ColorFormat.Hsl: value = FormatHslColor(_colorModel); //ColorFormatter.FormatColorAs(_colorModel, ColorFormat.Hsl); break; case ColorFormat.Rgb: _colorModel.Format = ColorFormat.Rgb; value = ColorFormatter.FormatColorAs(_colorModel, ColorFormat.Rgb); break; case ColorFormat.RgbHex3: case ColorFormat.RgbHex6: _colorModel.Format = ColorFormat.RgbHex3; value = ColorFormatter.FormatColorAs(_colorModel, ColorFormat.RgbHex3); break; } _span.TextBuffer.Replace(_span.GetSpan(_span.TextBuffer.CurrentSnapshot), value); }
public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view) { HexColorValue hex = (HexColorValue)item; if (!item.IsValid) { yield break; } ColorModel model = ColorParser.TryParseColor(hex.Text, ColorParser.Options.None); if (model != null) { if (ColorConverterSmartTagAction.GetNamedColor(model.Color) != null) { yield return(new ColorConverterSmartTagAction(itemTrackingSpan, hex, model, ColorFormat.Name)); } if (model.Format == ColorFormat.RgbHex6) { string hex3 = ColorFormatter.FormatColorAs(model, ColorFormat.RgbHex3); if (hex3.Length == 4) { yield return(new ColorConverterSmartTagAction(itemTrackingSpan, hex, model, ColorFormat.RgbHex3)); } } yield return(new ColorConverterSmartTagAction(itemTrackingSpan, hex, model, ColorFormat.Rgb)); yield return(new ColorConverterSmartTagAction(itemTrackingSpan, hex, model, ColorFormat.Hsl)); } }
private void SetDisplayText() { string format = "Convert to {0}"; switch (_format) { case ColorFormat.Rgb: _displayText = string.Format(CultureInfo.InvariantCulture, format, ColorFormatter.FormatColorAs(_colorModel, ColorFormat.Rgb)); break; case ColorFormat.Hsl: _displayText = string.Format(CultureInfo.InvariantCulture, format, FormatHslColor(_colorModel)); //string.Format(CultureInfo.InvariantCulture, format, ColorFormatter.FormatColorAs(_colorModel, ColorFormat.Hsl)); break; case ColorFormat.Name: _displayText = string.Format(CultureInfo.InvariantCulture, format, GetNamedColor(_colorModel.Color)); break; case ColorFormat.RgbHex3: case ColorFormat.RgbHex6: _displayText = string.Format(CultureInfo.InvariantCulture, format, ColorFormatter.FormatColorAs(_colorModel, ColorFormat.RgbHex3)); break; } }