void BackupFormat(object sender, FormatItemsEventArgs e) { if (e.ChangedItems.Count > 0) { foreach (var item in e.ChangedItems) { var t = _RegService.GetClassificationType(item); if (t != null) { FormatStore.GetOrSaveBackupFormatting(t, true); } } } }
void DecorateClassificationTypes(IEnumerable <IClassificationType> classifications, bool fullUpdate) { if (_ClassificationFormatMap.IsInBatchUpdate) { return; } var defaultSize = _ClassificationFormatMap.DefaultTextProperties.FontRenderingEmSize; var updated = new Dictionary <IClassificationType, TextFormattingRunProperties>(); StyleBase style; TextFormattingRunProperties textFormatting; foreach (var item in classifications) { if (item == null || (style = FormatStore.GetOrCreateStyle(item)) == null || (textFormatting = FormatStore.GetOrSaveBackupFormatting(item, _Initialized == false)) == null) { continue; } var p = SetProperties(textFormatting, style, defaultSize); if (p != textFormatting || fullUpdate) { updated[item] = p; } } var refreshList = new List <(IClassificationType type, TextFormattingRunProperties property)>(); foreach (var item in updated) { foreach (var subType in item.Key.GetSubTypes()) { if (updated.ContainsKey(subType) == false) { if ((style = FormatStore.GetOrCreateStyle(subType)) == null || (textFormatting = FormatStore.GetBackupFormatting(subType)) == null) { continue; } refreshList.Add((subType, SetProperties(textFormatting, style, defaultSize))); } } } if (refreshList.Count > 0) { foreach (var item in refreshList) { updated[item.type] = item.property; } } if (updated.Count > 0) { _ClassificationFormatMap.BeginBatchUpdate(); foreach (var item in updated) { _ClassificationFormatMap.SetTextProperties(item.Key, item.Value); Debug.WriteLine("Update format: " + item.Key.Classification); } _ClassificationFormatMap.EndBatchUpdate(); Debug.WriteLine($"Decorated {updated.Count} formats"); } }