/// <summary> /// Executes the command action. /// </summary> /// <param name="target"></param> /// <param name="parameter"></param> public override void Execute(NNode target, object parameter) { INRichTextView richTextView = GetRichTextView(target); NMessageBox.Show("Rich Text Custom Command executed!", "Custom Command", ENMessageBoxButtons.OK, ENMessageBoxIcon.Information); }
/// <summary> /// Executes the command action. /// </summary> /// <param name="target"></param> /// <param name="parameter"></param> public override void Execute(NNode target, object parameter) { NScheduleView scheduleView = GetScheduleView(target); NMessageBox.Show("Schedule Custom Command executed!", "Custom Command", ENMessageBoxButtons.OK, ENMessageBoxIcon.Information); }
public static void AddChildren(this NNode root, int parent, int[] children, int level) { int currentLevel = 1; var parentNode = FindNode(root, parent, currentLevel, level); parentNode.Add(children); }
// 1. Boring level order traversal // 2. OR recursion static NNode FindNode(NNode node, int x, int currentLevel, int level) { if (node == null) { return(null); } if (currentLevel > level) { return(null); } if (node.Value == x) { return(node); } foreach (var child in node.ChildNodes) { var n = FindNode(child, x, currentLevel + 1, level); if (n != null) { return(n); } } return(null); }
public int Count(NNode node, int x) { if (node == null) { return(-1); } var q = new Queue <NNode>(); q.Enqueue(node); while (q.Any()) { int size = q.Count; while (size > 0) { var next = q.Dequeue(); if (next == null) { continue; } if (next.Value == x) { return(next.ChildNodes.Count()); } foreach (var nn in next.ChildNodes) { q.Enqueue(nn); } } } return(-1); }
public void Test2() { int level = 1; // root var root = new NNode(20); root.AddChildren(20, new int[] { 2, 34, 50, 60, 70 }, level); // level 2 level++; root.AddChildren(2, new int[] { 15, 20 }, level); root.AddChildren(34, new int[] { 30 }, level); root.AddChildren(50, new int[] { 40, 100, 20 }, level); root.AddChildren(60, new int[] { }, level); root.AddChildren(70, new int[] { }, level); // level 3 level++; root.AddChildren(20, new int[] { 25, 50 }, level); var sut = new NumberOfChildrenOfGivenNodeInNaryTree(); var count = sut.Count(root, 50); Assert.That(count, Is.EqualTo(3)); }
/// <summary> /// Executes the command action. /// </summary> /// <param name="target"></param> /// <param name="parameter"></param> public override void Execute(NNode target, object parameter) { NDrawingView drawingView = GetDrawingView(target); NMessageBox.Show("Drawing Custom Command executed!", "Custom Command", ENMessageBoxButtons.OK, ENMessageBoxIcon.Information); }
public int MaxDepth(NNode root) { if (root == null) { return(0); } return(GetDepth(root, 1)); }
private NButton CreateShowDesignerButton(NNode node) { NButton button = new NButton(NDesigner.GetDesigner(node).ToString()); button.Tag = node; button.Click += new Function <NEventArgs>(OnShowDesignerClick); return(button); }
public void CheckClick(NNode node, object sender) { var button = sender as NSButton; if (button != null) { node.IsChecked = button.State == NSCellStateValue.Mixed ? NSCellStateValue.On : button.State; RaiseCheckChange(); } }
public NNode MakeNewNode(NNodeDefinition nodeDefinition) { var nNode = new NNode { Guid = new ShortGuid("NODE_" + (_nextNodeId++).ToSymbolString()), NodeDefinition = nodeDefinition }; Nodes.Add(nNode.Guid, nNode); return(nNode); }
public int GetDepth(NNode root, int h) { if (root == null) { return(h); } int maxh = h; foreach (var r in root.children) { maxh = Math.Max(maxh, GetDepth(r, h + 1)); } return(maxh); }
public override void Reset() { if (ListOfView.Count > 0) { ListOfView.Clear(); } if (_ds != null) { _ds = null; _node = null; _backgrundLayer = null; } }
public int GetDepth(NNode node) { if (node == null) { return(0); } int maxDepth = 0; foreach (var c in node.ChildNodes) { maxDepth = Math.Max(maxDepth, GetDepth(c)); } return(maxDepth + 1); }
public void Test1() { var root = new NNode(1); root.Add(7, 8); var three = new NNode(3); three.Add(5, 4); root.Add(three); var depth = new DepthOfNaryTree().GetDepth(root); Assert.That(depth, Is.EqualTo(3)); }
protected override LabelControl CreateLabelDescription(NNode node, NSOutlineView outlineView, NSView view, NSTableColumn tableColumn) { var label = new LabelControl(new RectangleF(InfoSwitcherFloats.NameLabelX.AsResourceFloat(), RowHeight / 2 - InfoSwitcherFloats.NameLabelY.AsResourceFloat(), tableColumn.Width - InfoSwitcherFloats.NameLabelX.AsResourceFloat(), InfoSwitcherFloats.NameLabelY.AsResourceFloat())) { StringValue = node.ItemDescription, TextColor = InfoSwitcherColors.AdditionalText.AsResourceNsColor(), Font = InfoSwitcherFonts.AdditionalText.AsResourceNsFont() }; label.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; view.AddSubview(new LabelControl(new RectangleF(InfoSwitcherFloats.NameLabelX.AsResourceFloat(), RowHeight / 2 - InfoSwitcherFloats.AdditionalTextY.AsResourceFloat(), tableColumn.Width - InfoSwitcherFloats.NameLabelX.AsResourceFloat(), InfoSwitcherFloats.NameLabelY.AsResourceFloat())) { StringValue = node.Name, ToolTip = node.ItemDescription, Font = InfoSwitcherFonts.NameTextFont.AsResourceNsFont() }); return(label); }
public void Test1() { // root var root = new NNode(20); var twentyFive = new NNode(25); var fifty = new NNode(50); var twenty = new NNode(20); twenty.Add(twentyFive, fifty); var fifteen = new NNode(15); var two = new NNode(2); two.Add(fifteen, twenty); root.Add(two); var thirty = new NNode(30); var thirtyFour = new NNode(34); thirtyFour.Add(thirty); root.Add(thirtyFour); // 50 -> 40, 100, 20 var fifty2 = new NNode(50); fifty2.Add(40, 100, 20); root.Add(fifty2); root.Add(new NNode(60)); root.Add(new NNode(70)); var sut = new NumberOfChildrenOfGivenNodeInNaryTree(); var count = sut.Count(root, 50); Assert.That(count, Is.EqualTo(3)); }
private void OnShowDesignerClick(NEventArgs args) { try { NNode node = (NNode)args.TargetNode.Tag; NEditorWindow editorWindow = NEditorWindow.CreateForInstance( node, null, OwnerWindow, null); if (node is NStyleNodeCollectionTree) { editorWindow.PreferredSize = new NSize(500, 360); } editorWindow.Open(); } catch (Exception ex) { NTrace.WriteException("OnShowDesignerClick failed.", ex); } }
public IList <IList <int> > LevelOrder(NNode root) { IList <IList <int> > list = new List <IList <int> >(); Queue <NNode> q = new Queue <NNode>(); q.Enqueue(root); while (q.Count > 0) { int n = q.Count; IList <int> l = new List <int>(); for (int i = 0; i < n; i++) { var node = q.Dequeue(); l.Add(node.val); foreach (var child in node.children) { q.Enqueue(child); } } list.Add(l); } return(list); }
public override bool IsChecked(NNode target) { MyCommandableWidget w = this.OwnerInputElement as MyCommandableWidget; return(false); }
public override void Execute(NNode target, object parameter) { throw new System.NotImplementedException(); }
private static void WatchFile(string path, NNode <PathInfo> node, NTree <PathInfo> tree) { FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = path; /* Watch for changes in LastAccess and LastWrite times, and * the renaming of files or directories. */ watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Size | NotifyFilters.CreationTime; // Watch all files. watcher.Filter = ""; watcher.IncludeSubdirectories = false; // Add event handlers. watcher.Changed += (o, e) => { Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); }; ///TODO: Invalidate the size with a tag watcher.Created += (o, e) => { node.AddChild(new NNode <PathInfo> { Value = new PathInfo { Path = e.FullPath, IsFile = FastFileOperations.IsFile(e.FullPath), Size = 0 } }); Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); }; watcher.Deleted += (o, e) => { var effectedNode = node.Children.FirstOrDefault(p => p.Value.Path == e.FullPath); if (effectedNode == null) { Console.Error.WriteLine("Unexpected error: Cannot find {0} in file tree.", e.FullPath); } else { Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); tree.RemoveNode(effectedNode); } }; watcher.Renamed += (o, e) => { // Specify what is done when a file is renamed. Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath); var effectedNode = node.Children.FirstOrDefault(p => p.Value.Path == e.OldFullPath); if (effectedNode == null) { Console.Error.WriteLine("Unexpected error: Cannot find {0} in file tree.", e.FullPath); } else { effectedNode.Value.Path = e.FullPath; } }; watcher.Error += watcher_Error; // Begin watching. watcher.EnableRaisingEvents = true; }
public override bool IsEnabled(NNode target) { throw new System.NotImplementedException(); }
private void OnTestSerializationButtonClick(NEventArgs arg) { ENPersistencyFormat persistencyFormat = (ENPersistencyFormat)arg.TargetNode.Tag; NStopwatch stopwatch; try { Type nodeType = typeof(NNode); Type[] types = nodeType.Assembly.GetTypes(); int nodeCount = 0, successfullySerialized = 0; stopwatch = NStopwatch.StartNew(); StringBuilder output = new StringBuilder(); for (int i = 0, count = types.Length; i < count; i++) { Type type = types[i]; // not a NNode type, abstract or generic => skip if (!nodeType.IsAssignableFrom(type) || type.IsAbstract || type.IsGenericType) { continue; } NNode node; try { nodeCount++; NNode typeInstance = (NNode)Activator.CreateInstance(type); // Serialize MemoryStream memoryStream = new MemoryStream(); NDomNodeSerializer serializer = new NDomNodeSerializer(); serializer.SerializeDefaultValues = true; serializer.SaveToStream(new NNode[] { typeInstance }, memoryStream, persistencyFormat); // Deserialize to check if the serialization has succeeded NDomNodeDeserializer deserializer = new NDomNodeDeserializer(); memoryStream = new MemoryStream(memoryStream.ToArray()); node = deserializer.LoadFromStream(memoryStream, persistencyFormat)[0]; output.AppendLine("Sucessfully serialized node type [" + type.Name + "]."); successfullySerialized++; } catch (Exception ex) { output.AppendLine("Failed to serialize node type [" + type.Name + "]. Exception was [" + ex.Message + "]"); } } stopwatch.Stop(); output.AppendLine("=================================================="); output.AppendLine("Nodes serialized: " + successfullySerialized.ToString() + " of " + nodeCount.ToString()); output.AppendLine("Time elapsed: " + stopwatch.ElapsedMilliseconds.ToString() + " ms"); m_TextBox.Text = output.ToString(); m_TextBox.SetCaretPos(new NTextPosition(m_TextBox.Text.Length, false)); m_TextBox.EnsureCaretVisible(); } catch (Exception ex) { NTrace.WriteLine(ex.Message); } // Restore the default cursor this.OwnerWindow.Cursor = null; }