Amoeba.Windows.AvalonEditHelper_MulticastMessage.CustomElementGenerator.ConstructElement C# (CSharp) Метод

ConstructElement() публичный Метод

public ConstructElement ( int offset ) : ICSharpCode.AvalonEdit.Rendering.VisualLineElement
offset int
Результат ICSharpCode.AvalonEdit.Rendering.VisualLineElement
            public override VisualLineElement ConstructElement(int offset)
            {
                var result = this.FindMatch(offset);

                if (result != null)
                {
                    if (result.Type == "State")
                    {
                        var size = (double)new FontSizeConverter().ConvertFromString(Settings.Instance.Global_Fonts_Message_FontSize + "pt");

                        var image = new Image() { Height = (size - 3), Width = (size - 3), Margin = new Thickness(1.5, 1.5, 0, 0) };
                        if (result.Value == "#") image.Source = StatesIconManager.Instance.Green;
                        else if (result.Value == "!") image.Source = StatesIconManager.Instance.Red;
                        else if (result.Value == "@") image.Source = StatesIconManager.Instance.Yello;

                        var element = new CustomObjectElement(result.Value, image);

                        element.ClickEvent += (string text) =>
                        {
                            this.OnSelectEvent(new CustomElementRange(offset, offset + result.Value.Length));
                        };

                        return element;
                    }
                    else if (result.Type == "Signature")
                    {
                        Brush brush;

                        if (Inspect.ContainTrustSignature(result.Value)) brush = new SolidColorBrush(_serviceManager.Config.Colors.Message_Trust);
                        else brush = new SolidColorBrush(_serviceManager.Config.Colors.Message_Untrust);

                        var element = new CustomTextElement(result.Value);
                        element.Foreground = brush;

                        element.ClickEvent += (string text) =>
                        {
                            this.OnSelectEvent(new CustomElementRange(offset, offset + result.Value.Length));
                        };

                        return element;
                    }
                    else if (result.Type == "Uri")
                    {
                        var uri = result.Value;

                        CustomObjectElement element = null;

                        if (uri.StartsWith("http:") | uri.StartsWith("https:"))
                        {
                            var textBlock = new TextBlock();
                            textBlock.Text = uri.Substring(0, Math.Min(64, uri.Length)) + ((uri.Length > 64) ? "..." : "");
                            textBlock.ToolTip = HttpUtility.UrlDecode(uri);

                            if (Settings.Instance.Global_UrlHistorys.Contains(uri)) textBlock.Foreground = new SolidColorBrush(_serviceManager.Config.Colors.Link);
                            else textBlock.Foreground = new SolidColorBrush(_serviceManager.Config.Colors.Link_New);

                            element = new CustomObjectElement(uri, textBlock);
                        }
                        else if (uri.StartsWith("Tag:"))
                        {
                            var tag = AmoebaConverter.FromTagString(uri);

                            var textBlock = new TextBlock();
                            textBlock.Text = uri.Substring(0, Math.Min(64, uri.Length)) + ((uri.Length > 64) ? "..." : "");
                            textBlock.ToolTip = MessageConverter.ToInfoMessage(tag);

                            if (Settings.Instance.Global_TagHistorys.Contains(tag)) textBlock.Foreground = new SolidColorBrush(_serviceManager.Config.Colors.Link);
                            else textBlock.Foreground = new SolidColorBrush(_serviceManager.Config.Colors.Link_New);

                            element = new CustomObjectElement(uri, textBlock);
                        }
                        else if (uri.StartsWith("Seed:"))
                        {
                            var seed = AmoebaConverter.FromSeedString(uri);

                            var textBlock = new TextBlock();
                            textBlock.Text = uri.Substring(0, Math.Min(64, uri.Length)) + ((uri.Length > 64) ? "..." : "");
                            textBlock.ToolTip = MessageConverter.ToInfoMessage(seed);

                            if (Settings.Instance.Global_SeedHistorys.Contains(seed)) textBlock.Foreground = new SolidColorBrush(_serviceManager.Config.Colors.Link);
                            else textBlock.Foreground = new SolidColorBrush(_serviceManager.Config.Colors.Link_New);

                            element = new CustomObjectElement(uri, textBlock);
                        }

                        if (element != null)
                        {
                            element.ClickEvent += (string text) =>
                            {
                                this.OnSelectEvent(new CustomElementRange(offset, offset + result.Value.Length));
                                this.OnClickEvent(text);
                            };

                            return element;
                        }
                    }
                }

                return null;
            }
AvalonEditHelper_MulticastMessage.CustomElementGenerator