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