Example #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;
            }
        }
        public MainWindowControlViewModel()
        {
            ThrowIfNotOnUIThread();

            var ss = ThreadHelper.JoinableTaskFactory.Run(() => OptionsHelper.GetWritableSettingsStoreAsync());

            if (ss.TryGetBoolean(
                    OptionsHelper.GeneralSettingsCollectionName,
                    nameof(UseExtraContrastSuggestions),
                    out var useExtraContrastSuggestions))
            {
                UseExtraContrastSuggestions = useExtraContrastSuggestions;
            }

            PropertyChanged += OnPropertyChanged;

            EditForegroundCommand     = new RelayCommand <IList>(OnEditForeground);
            EditBackgroundCommand     = new RelayCommand <IList>(OnEditBackground);
            ToggleIsBoldCommand       = new RelayCommand <IList>(OnToggleIsBold);
            ResetToDefaultsCommand    = new RelayCommand <IList>(OnResetToDefaults);
            ResetAllToDefaultsCommand = new RelayCommand(OnResetAllToDefaults);

            foreach (var item in ClassificationProvider.GridItems)
            {
                ClassificationGridItems.Add(item);
            }

            ClassificationGridView        = CollectionViewSource.GetDefaultView(ClassificationGridItems);
            ClassificationGridView.Filter = o => FilterClassification((GridItem)o);
            ClassificationGridView.SortDescriptions.Clear();
            ClassificationGridView.SortDescriptions.Add(new SortDescription(nameof(GridItem.DefinitionLocalizedName), ListSortDirection.Ascending));

            (FontFamily, FontSize) = FontsAndColorsHelper.GetEditorFontInfo();
        }
        public void Refresh(ILookup <string, string> definitionNames)
        {
            ThrowIfNotOnUIThread();

            try
            {
                IsUpdating = true;

                var colorItems = FontsAndColorsHelper.GetColorItems();

                foreach (var classificationItem in GridItems)
                {
                    if (definitionNames.Contains(classificationItem.DefinitionName))
                    {
                        foreach (var colorItem in colorItems)
                        {
                            if (colorItem.AllColorableItemInfo.bstrName == classificationItem.DefinitionName)
                            {
                                FontsAndColorsHelper.RefreshGridItemFromColorItem(classificationItem, colorItem);
                            }
                        }
                    }
                }
            }
            finally
            {
                IsUpdating = false;
            }
        }
Example #4
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();
        }
        public ClassificationProvider()
        {
            ThrowIfNotOnUIThread();
            var builder = ImmutableArray.CreateBuilder <GridItem>();
            var items   = FontsAndColorsHelper.GetColorItems();

            foreach (var item in items)
            {
                var ci = FontsAndColorsHelper.TryGetGridItemForColorItem(item);
                builder.Add(ci);
            }
            GridItems = builder.ToImmutable();
        }
        public MainWindowControlViewModel()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var settingsStore = ThreadHelper.JoinableTaskFactory.Run(() => OptionsHelper.GetWritableSettingsStoreAsync());

            if (settingsStore.TryGetBoolean(OptionsHelper.GeneralSettingsCollectionName, nameof(UseExtraContrastSuggestions), out var useExtraContrastSuggestions))
            {
                UseExtraContrastSuggestions = useExtraContrastSuggestions;
            }
            else
            {
                settingsStore.WriteBoolean(OptionsHelper.GeneralSettingsCollectionName, nameof(UseExtraContrastSuggestions), UseExtraContrastSuggestions);
            }

            ClassificationGridView        = CollectionViewSource.GetDefaultView(ClassificationGridItems);
            ClassificationGridView.Filter = o => FilterClassification((ClassificationGridItem)o);

            PropertyChanged += OnPropertyChanged;

            EditForegroundCommand = new RelayCommand <ClassificationGridItem>(OnEditForeground);
            EditBackgroundCommand = new RelayCommand <ClassificationGridItem>(OnEditBackground);
            ToggleIsBoldCommand   = new RelayCommand <ClassificationGridItem>(OnToggleIsBold);

            ResetToDefaultsCommand         = new RelayCommand <ClassificationGridItem>(OnResetToDefaults);
            UseForegroundSuggestionCommand = new RelayCommand <ClassificationGridItem>(OnUseForegroundSuggestion);

            ResetAllToDefaultsCommand          = new RelayCommand(OnResetAllToDefaults);
            UseAllForegroundSuggestionsCommand = new RelayCommand(OnUseAllForegroundSuggestions);
            ExportThemeCommand    = new RelayCommand(OnExportTheme);
            ImportThemeCommand    = new RelayCommand(OnImportTheme);
            LoadThemeCommand      = new RelayCommand <string>(OnLoadTheme);
            FindMoreThemesCommand = new RelayCommand(OnFindMoreThemes);

            foreach (var classificationItem in ClassificationProvider.GridItems)
            {
                ClassificationGridItems.Add(classificationItem);
            }

            UpdateContrastWarnings();

            ClassificationGridView.SortDescriptions.Clear();
            ClassificationGridView.SortDescriptions.Add(new SortDescription(nameof(ClassificationGridItem.Classification), ListSortDirection.Ascending));

            (FontFamily, FontSize) = FontsAndColorsHelper.GetEditorFontInfo();
        }
Example #7
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();
 }