Exemplo n.º 1
0
 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);
             }
         }
     }
 }
Exemplo n.º 2
0
        void FormatUpdated(object sender, EventArgs e)
        {
            Debug.WriteLine("ClassificationFormatMapping changed.");
            var defaultProperties = _ClassificationFormatMap.DefaultTextProperties;

            if (_DefaultFontFamily == defaultProperties.Typeface.FontFamily && _DefaultFontSize == defaultProperties.FontRenderingEmSize)
            {
                return;
            }
            Debug.WriteLine("Default text properties changed.");
            _DefaultFontFamily = defaultProperties.Typeface.FontFamily;
            _DefaultFontSize   = defaultProperties.FontRenderingEmSize;
            // hack: it is weird that this property is not in sync with the Text editor format, we have to force that
            _EditorFormatMap.GetProperties(Constants.EditorProperties.PlainText)
            .SetTypeface(defaultProperties.Typeface);
            if (_IsDecorating != 0)
            {
                Debug.WriteLine("Cancelled formatMap update.");
                return;
            }
            var updated = new Dictionary <IClassificationType, TextFormattingRunProperties>();

            foreach (var item in FormatStore.GetStyles())
            {
                // explicitly update formats when font name or font size is changed in font options
                if (item.Value.Stretch.HasValue && String.IsNullOrWhiteSpace(item.Value.Font) ||
                    item.Value.FontSize != 0)
                {
                    var key = _RegService.GetClassificationType(item.Key);
                    if (key == null)
                    {
                        continue;
                    }
                    updated[key] = SetProperties(_ClassificationFormatMap.GetTextProperties(key), item.Value, _DefaultFontSize);
                }
            }
            if (updated.Count > 0)
            {
                Debug.WriteLine("Decorate updated format: " + updated.Count);
                Decorate(updated.Keys, true);
            }
        }
Exemplo n.º 3
0
        void DecorateClassificationTypes()
        {
            if (_ClassificationFormatMap.IsInBatchUpdate)
            {
                return;
            }
            _ClassificationFormatMap.BeginBatchUpdate();
            var defaultSize = _ClassificationFormatMap.DefaultTextProperties.FontRenderingEmSize;

            foreach (var item in _ClassificationFormatMap.CurrentPriorityOrder)
            {
                StyleBase style;
                TextFormattingRunProperties textFormatting;
                if (item == null ||
                    (style = FormatStore.GetStyle(item.Classification)) == null ||
                    (textFormatting = FormatStore.GetBackupFormatting(item.Classification)) == null)
                {
                    continue;
                }
                _ClassificationFormatMap.SetTextProperties(item, SetProperties(textFormatting, style, defaultSize));
            }
            _ClassificationFormatMap.EndBatchUpdate();
            Debug.WriteLine("Decorated");
        }
Exemplo n.º 4
0
        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");
            }
        }