private void miTrace_Click(object sender, RoutedEventArgs e) { DTopic t; var mi = sender as MenuItem; if (mi == null || (t = mi.Tag as DTopic) == null) { return; } bool ic = JsLib.ofBool(JsLib.GetField(t.Manifest, "Logram.trace"), false); t.SetField("Logram.trace", !ic); }
public ObservableCollection <Control> MenuItems(DTopic t, loItem ctrl) { var l = new ObservableCollection <Control>(); JSC.JSValue v1; MenuItem mi; mi = new MenuItem() { Header = "Open in new tab", Tag = t }; mi.Click += miOpen_Click; l.Add(mi); mi = new MenuItem() { Header = "Show in Workspace", Tag = t }; mi.Click += miShow_Click; l.Add(mi); l.Add(new Separator()); if (ctrl is loPin) { bool ic = JsLib.ofBool(JsLib.GetField(t.Manifest, "Logram.trace"), false); mi = new MenuItem() { Header = "Trace", Tag = t, IsCheckable = true, IsChecked = ic }; mi.Click += miTrace_Click; l.Add(mi); l.Add(new Separator()); } if (t.Manifest != null && (v1 = t.Manifest["Children"]).ValueType == JSC.JSValueType.Object) { var ad = new Dictionary <string, JSC.JSValue>(); Jso2Acts(v1, ad); FillContextMenu(t, l, ad); } else if (t.Manifest != null && (v1 = t.Manifest["Children"]).ValueType == JSC.JSValueType.String) { t.GetAsync(v1.Value as string).ContinueWith(tt => FillContextMenuFromChildren(t, l, tt), TaskScheduler.FromCurrentSynchronizationContext()); } else { t.Connection.CoreTypes.GetAsync(null).ContinueWith(tt => FillContextMenuFromChildren(t, l, tt), TaskScheduler.FromCurrentSynchronizationContext()); } return(l); }
public override void Render(int chLevel) { if (model == null || model.State == null || model.Manifest == null) { return; } if (_mode != 0 && chLevel == 3) { var src_s = JsLib.OfString(JsLib.GetField(model.Manifest, "cctor.LoBind"), null); if (src_s == null) { _mode = 1; } else if (_source == null || _source.path != src_s || (_mode == 2 && _srcBinding == null && lv._dataIsLoaded)) { model.GetAsync(src_s).ContinueWith(SourceLoaded, TaskScheduler.FromCurrentSynchronizationContext()); return; } if (_mode != 2 && _srcBinding != null) { _source = null; _srcBinding.Dispose(); _srcBinding = null; } } this.Offset = _owner.Offset + _ownerOffset; if (chLevel == 3) { lv.MapRemove(this); lv.MapSet(_mode == 0 ? 3 : 0, (int)(Offset.X / CELL_SIZE + 0.5), (int)(Offset.Y / CELL_SIZE + 0.5), this); } var tc = model.State.ValueType; Brush br; switch (tc) { case JSC.JSValueType.Object: if (model.State is ByteArray || model.State.Value is ByteArray) { br = brByteArray; } else { br = Brushes.MediumOrchid; } break; case JSC.JSValueType.String: br = Brushes.Gold; break; case JSC.JSValueType.Double: case JSC.JSValueType.Integer: { double val = (double)model.State; br = val > 0 ? (val == 1 ? Brushes.LawnGreen : Brushes.LightSeaGreen) : (val == 0 ? brValueFalse : Brushes.DodgerBlue); //-V3024 } break; case JSC.JSValueType.Boolean: br = (bool)model.State.Value ? Brushes.LawnGreen : brValueFalse; //-V3095 break; default: br = Brushes.Black; break; } bool ic = (!(_owner is loVariable) || _mode == 0) && JsLib.ofBool(JsLib.GetField(model.Manifest, "Logram.trace"), false); if (!ic && chLevel == 1 && this.brush == br) { return; } this.brush = br; string val_s = string.Empty; if (ic) { var v = model.State; if (v != null) { switch (v.ValueType) { case JSC.JSValueType.Boolean: case JSC.JSValueType.Integer: case JSC.JSValueType.String: val_s = v.Value.ToString(); break; case JSC.JSValueType.Double: { double d = (double)v; int p = (int)Math.Log10(Math.Abs(d)); switch (p) { case -2: val_s = d.ToString("0.000##"); break; case -1: val_s = d.ToString("0.00##"); break; case 0: val_s = d.ToString("0.0##"); break; case 1: val_s = d.ToString("0.##"); break; case 2: val_s = d.ToString("0.#"); break; case 3: val_s = d.ToString("0.#"); break; case 4: val_s = d.ToString("0"); break; default: val_s = d.ToString("G4"); break; } } break; case JSC.JSValueType.Date: { var dt = (v.Value as JSL.Date).ToDateTime(); val_s = dt.ToString("yyMMdd HH:mm:ss"); break; } } } } using (DrawingContext dc = this.RenderOpen()) { if (_mode == 3) { dc.DrawRectangle(_selected ? brItemSelected : this.brush, null, new Rect(-2, -5, 4, 10)); } else { dc.DrawEllipse(_selected ? brItemSelected : this.brush, null, new Point(0, 0), 3, 3); } if (ic) { var ft = new FormattedText(val_s, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, LogramView.LFont, CELL_SIZE * 0.7, Brushes.Black); Point p; if (_mode == 0) { p = new Point(2, 2 - CELL_SIZE); } else { p = new Point(-2 - ft.WidthIncludingTrailingWhitespace, 2 - CELL_SIZE); } dc.DrawText(ft, p); } } if (_mode != 0 && _srcBinding != null && chLevel > 1) { _srcBinding.Render(chLevel); } if (_mode == 0 && chLevel > 0) { foreach (loBinding w in _connections.ToArray()) { w.Render(chLevel); } } }