internal static string WriteObject(IScriptable scriptable, Indent indent = null) { if (scriptable == null) { return(null); } IIgnorable ignorable = scriptable as IIgnorable; if (ignorable != null && ignorable.Ignored) { return(null); } if (scriptable is ICustomScriptable) { ICustomScriptable s = scriptable as ICustomScriptable; string r = s.Write(); if (indent != null) { r = indent.GetIndent(s.Indent()) + r; if (s.Indent() == "#") { r += " `[" + scriptable.GetType().Name + "]`"; } } return(r); } if (scriptable is IReadOnlyScriptable) { string r = scriptable.ToString(); if (indent != null) { indent.Push(null); r = "`" + r + "`"; } return(r); } foreach (Accessor accessor in FieldAccessor.GetForObject(scriptable)) { foreach (FieldTag tag in accessor.GetTags()) { if (tag.flag == FieldTags.Title) { string r = "" + accessor.Get(); if (indent != null) { r = indent.GetIndent(tag.arg) + r; if (tag.arg == "#") { r += " `[" + scriptable.GetType().Name + "]`"; } } return(r); } } } return(null); }
private static string Write(IScriptable scriptable, Indent indent, int depth) { if (scriptable == null) { return(""); } StringBuilder sb = new StringBuilder(); string text = WriteObject(scriptable, indent); if (text != null) { if (!(scriptable is IReadOnlyScriptable)) { sb.Append("<!-- [" + depth + "](" + scriptable.GetGuid() + ") "); //if (indent.Peek() == null) sb.Append("\n-->"); //else sb.AppendLine("-->"); sb.AppendLine("-->"); } sb.AppendLine(text); } foreach (Accessor accessor in FieldAccessor.GetForObject(scriptable)) { IList list = accessor.Get() as IList; if (list == null) { continue; } for (int i = 0; i < list.Count; i++) { IScriptable child = list[i] as IScriptable; if (child == null) { continue; } IIgnorable ignorable = child as IIgnorable; if (ignorable != null && ignorable.Ignored) { continue; } sb.AppendLine(); sb.Append(Write(child, indent, depth + 1)); } } if (text != null) { indent.Pop(); } return(sb.ToString()); }
private void ToggleIgnoredItems() { if (CurrentList == null) { return; } bool check = !UpdateIgnoredMenuItem(); foreach (int i in this.listBoxList.SelectedIndices) { IIgnorable ignoreable = CurrentList[i] as IIgnorable; if (ignoreable == null) { continue; } ignoreable.Ignored = check; } }
protected override void OnDrawItem(DrawItemEventArgs e) { if (e.Index > -1 && e.Index < Items.Count) { string s = Items[e.Index].ToString(); bool ignored = false; if (e.Index < parentEditor.CurrentList.Count) { IIgnorable ignorable = parentEditor.CurrentList[e.Index] as IIgnorable; ignored = ignorable != null && ignorable.Ignored; } bool selected = e.State.HasFlag(DrawItemState.Selected); Color fillColor = selected ? SystemColors.Highlight: SystemColors.Window; Color textColor = selected ? SystemColors.HighlightText : (ignored ? SystemColors.GrayText : SystemColors.WindowText); e.Graphics.FillRectangle( new SolidBrush(fillColor), e.Bounds); int firstNewline = s.IndexOf("\n"); if (firstNewline >= 0 && !selected) { string firstLine = s.Substring(0, firstNewline); string restOfLine = s.Substring(firstNewline + 1); e.Graphics.DrawString(firstLine, Font, new SolidBrush(textColor), new PointF(e.Bounds.X, e.Bounds.Y)); e.Graphics.DrawString(restOfLine, Font, new SolidBrush(SystemColors.GrayText), new PointF(e.Bounds.X, e.Bounds.Y + e.Graphics.MeasureString(firstLine, Font).Height)); } else { e.Graphics.DrawString(s, Font, new SolidBrush(textColor), new PointF(e.Bounds.X, e.Bounds.Y)); } } }
private bool UpdateIgnoredMenuItem() { if (CurrentList == null) { return(false); } bool check = true; foreach (int i in this.listBoxList.SelectedIndices) { IIgnorable ignoreable = CurrentList[i] as IIgnorable; if (ignoreable == null) { this.ignoredToolStripMenuItem.Enabled = false; } else if (!ignoreable.Ignored) { check = false; } } this.ignoredToolStripMenuItem.Checked = check; return(check); }