public void AddAttributes(IRichTextAttributes styleClass, StringRange range) { if (range.Length == 0) { return; } var starts = spans [range.Location]; // // If there already an identical span // Span span = null; if (starts != null) { foreach (var s in starts) { if (s.Range.Length == range.Length) { span = s; break; } } if (span != null) { span.AddClass(styleClass.ClassName); return; } } // // If not, we need to insert it // span = new Span(range, styleClass.ClassName); span.Url = styleClass.Link; if (starts == null) { starts = new List <Span> (); spans [range.Location] = starts; starts.Add(span); return; } // // Insert it before shorter spans // var i = 0; while (i < starts.Count && starts [i].Range.Length >= range.Length) { i++; } starts.Insert(i, span); }
public MenuButton( object label, Action <Div> onClick = null, string svgIcon = null, string tooltip = null, object pill = null, AnyTask pillTask = null, Theme?pillTheme = Theme.Empty, IconButton[] actions = null) { this.SetClass("menu-button"); var button = new InternalButton(onClick, label, svgIcon, tooltip); this.VisualTree.Add(button); Control pillContainer = null; if (pillTask != null || pill != null) { var _pillContainer = new DumpContainer(); pillContainer = _pillContainer.ToControl(); this.VisualTree.Add(pillContainer); var formatter = new DefaultContentFormatter(); Control Format(object content) { return(formatter.Format(content, (c, e) => { if (e) { return c; } var span = new Span(c); span.AddClass("menu-button--pill"); if (pillTheme != null) { span.AddClass($"theme-{Utils.SplitCamelCase(pillTheme.ToString()).Replace(" ", "-").ToLower()}"); } return span; })); } if (pillTask != null) { pillTask.OnResult(result => { _pillContainer.Content = Format(result); }); } else { _pillContainer.Content = Format(pill); } } Div divActions = null; if (actions != null) { divActions = new Div( actions.Cast <Control>() ); divActions.SetClass("menu-button--actions"); this.VisualTree.Add(divActions); } if (actions != null) { JavascriptHelpers.ShowOnMouseOver(this, divActions, pillContainer); } }