Пример #1
0
        public void Refresh(ILookup <string, string> definitionNames)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            try
            {
                IsUpdating = true;

                (PlainTextForeground, PlainTextBackground) = FontsAndColorsHelper.GetPlainTextColors();
                var infos = FontsAndColorsHelper.GetTextEditorInfos()
                            .ToImmutableDictionary(
                    kvp => kvp.Key,
                    kvp => kvp.Value
                    .Where(info => definitionNames.Contains(info.bstrName))
                    .ToImmutableDictionary(info => info.bstrName));

                foreach (var item in GridItems.Where(item => definitionNames.Contains(item.DefinitionName)))
                {
                    FontsAndColorsHelper.RefreshClassificationItem(item, infos[item.Category][item.DefinitionName]);
                }
            }
            finally
            {
                IsUpdating = false;
            }
        }
Пример #2
0
        public ClassificationProvider()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            ClassificationNameMap = ClassificationHelpers.GetClassificationNameMap();
            (PlainTextForeground, PlainTextBackground) = FontsAndColorsHelper.GetPlainTextColors();
            var infos = FontsAndColorsHelper.GetTextEditorInfos();

            GridItems = infos.Keys
                        .SelectMany(category => infos[category].Select(info => FontsAndColorsHelper.TryGetClassificationItemForInfo(category, info)))
                        .OfType <ClassificationGridItem>()
                        .ToImmutableArray();
        }
Пример #3
0
        public static void Export(string fileName, IEnumerable <ClassificationGridItem> items)
        {
            var(fontFamily, fontSize) = FontsAndColorsHelper.GetEditorFontInfo(scaleFontSize: false);
            var(defaultForeground, defaultBackground) = FontsAndColorsHelper.GetPlainTextColors();

            var categories = items.GroupBy(item => item.Category);

            var vssettings = new StringBuilder();

            vssettings.AppendLine(
                $@"<UserSettings>
  <ApplicationIdentity version=""16.0""/>
  <ToolsOptions>
    <ToolsOptionsCategory name=""Environment"" RegisteredName=""Environment""/>
  </ToolsOptions>
  <Category name=""Environment_Group"" RegisteredName=""Environment_Group"">
    <Category name=""Environment_FontsAndColors"" Category=""{{1EDA5DD4-927A-43a7-810E-7FD247D0DA1D}}"" Package=""{{DA9FB551-C724-11d0-AE1F-00A0C90FFFC3}}"" RegisteredName=""Environment_FontsAndColors"" PackageName=""Visual Studio Environment Package"">
      <PropertyValue name=""Version"">2</PropertyValue>
      <FontsAndColors Version=""2.0"">
        <Categories>");

            foreach (var categoryItems in categories)
            {
                vssettings.AppendLine(
                    $@"          <Category GUID=""{categoryItems.Key.ToString("B")}"" FontName=""{fontFamily.Source}"" FontSize=""{fontSize}"" CharSet=""1"" FontIsDefault=""No"">
            <Items>");

                foreach (var item in categoryItems)
                {
                    vssettings.Append($@"              <Item Name=""{item.DefinitionName}""");

                    if (item.IsForegroundEditable)
                    {
                        var foreground = ToBGRString(item.Foreground);
                        vssettings.Append($@" Foreground=""{foreground}""");
                    }

                    if (item.IsBackgroundEditable)
                    {
                        var background = item.Background == defaultBackground && item.DefinitionName != "Plain Text"
                            ? "0x01000001"
                            : ToBGRString(item.Background);

                        vssettings.Append($@" Background=""{background}""");
                    }

                    if (item.IsBoldEditable)
                    {
                        vssettings.Append($@" BoldFont=""No""");
                    }

                    vssettings.AppendLine("/>");
                }


                vssettings.AppendLine(
                    $@"            </Items>
          </Category>");
            }

            vssettings.AppendLine(
                $@"        </Categories>
      </FontsAndColors>
    </Category>
  </Category>
</UserSettings>");

            File.WriteAllText(fileName, vssettings.ToString());

            return;
 static ClassificationProvider()
 {
     ThrowIfNotOnUIThread();
     (PlainTextForeground, PlainTextBackground) = FontsAndColorsHelper.GetPlainTextColors();
 }