/// <summary> /// Configure the specified tree node using the fields in 'Description'. /// Recursively descends through all child nodes as well. /// </summary> /// <remarks> /// If any models have been deleted, calls to this function will not /// cause those models to be removed from the tree. When child models are /// updated, this function will attempt to update any existing tree nodes /// representing the children - if none exist, they will be added. /// </remarks> /// <param name="node">The node.</param> /// <param name="description">The description.</param> /// <param name="checkForExisting"> /// If set to true, will attempt to update existing nodes instead of creating /// new ones, where possible. This should only be set to false when populating /// the tree control for the first time, and when set to false it will improve /// performance considerably, especially for large tree structures. /// </param> private void RefreshNode(TreeIter node, TreeViewNode description, bool checkForExisting = true) { Gdk.Pixbuf pixbuf = null; if (MasterView != null && MasterView.HasResource(description.ResourceNameForImage)) { pixbuf = new Gdk.Pixbuf(null, description.ResourceNameForImage); } string tick = description.Checked ? "✓" : ""; treemodel.SetValues(node, description.Name, pixbuf, description.ToolTip, tick, description.Colour, description.Strikethrough); foreach (TreeViewNode child in description.Children) { string path = GetFullPath(treemodel.GetPath(node)); TreeIter iter; if (checkForExisting) { if (FindChild(node, child.Name, out TreeIter matchingChild)) { iter = matchingChild; } else { iter = treemodel.AppendNode(node); } } else { iter = treemodel.AppendNode(node); } RefreshNode(iter, child); } }
/// <summary> /// Configure the specified tree node using the fields in 'Description'. /// Recursively descends through all child nodes as well. /// </summary> /// <param name="node">The node.</param> /// <param name="description">The description.</param> private void RefreshNode(TreeIter node, TreeViewNode description) { Gdk.Pixbuf pixbuf = null; if (MasterView.HasResource(description.ResourceNameForImage)) { pixbuf = new Gdk.Pixbuf(null, description.ResourceNameForImage); } string tick = description.Checked ? "✔" : ""; treemodel.SetValues(node, description.Name, pixbuf, description.ToolTip, tick, description.Colour, description.Strikethrough); for (int i = 0; i < description.Children.Count; i++) { TreeIter iter = treemodel.AppendNode(node); RefreshNode(iter, description.Children[i]); } }
/// <summary> /// Configure the specified tree node using the fields in 'Description'. /// Recursively descends through all child nodes as well. /// </summary> /// <remarks> /// If any models have been deleted, calls to this function will not /// cause those models to be removed from the tree. When child models are /// updated, this function will attempt to update any existing tree nodes /// representing the children - if none exist, they will be added. /// </remarks> /// <param name="node">The node.</param> /// <param name="description">The description.</param> private void RefreshNode(TreeIter node, TreeViewNode description) { Gdk.Pixbuf pixbuf = null; if (MasterView != null && MasterView.HasResource(description.ResourceNameForImage)) { pixbuf = new Gdk.Pixbuf(null, description.ResourceNameForImage); } string tick = description.Checked ? "✓" : ""; treemodel.SetValues(node, description.Name, pixbuf, description.ToolTip, tick, description.Colour, description.Strikethrough); foreach (TreeViewNode child in description.Children) { string path = GetFullPath(treemodel.GetPath(node)); TreeIter iter = FindNode($"{path}.{child.Name}"); if (iter.Equals(TreeIter.Zero)) { iter = treemodel.AppendNode(node); } RefreshNode(iter, child); } }
public void PopulateContextMenu(List <MenuDescriptionArgs> menuDescriptions) { ClearPopup(); foreach (MenuDescriptionArgs description in menuDescriptions) { MenuItem item; if (description.ShowCheckbox) { CheckMenuItem checkItem = new CheckMenuItem(description.Name); checkItem.Active = description.Checked; item = checkItem; } else if (!String.IsNullOrEmpty(description.ResourceNameForImage) && MasterView.HasResource(description.ResourceNameForImage)) { item = WidgetExtensions.CreateImageMenuItem(description.Name, new Image(null, description.ResourceNameForImage)); } else { item = new MenuItem(description.Name); } if (!String.IsNullOrEmpty(description.ShortcutKey)) { string keyName = String.Empty; Gdk.ModifierType modifier = Gdk.ModifierType.None; string[] keyNames = description.ShortcutKey.Split(new Char[] { '+' }); foreach (string name in keyNames) { if (name == "Ctrl") { modifier |= Gdk.ModifierType.ControlMask; } else if (name == "Shift") { modifier |= Gdk.ModifierType.ShiftMask; } else if (name == "Alt") { modifier |= Gdk.ModifierType.Mod1Mask; } else if (name == "Del") { keyName = "Delete"; } else { keyName = name; } } try { Gdk.Key accelKey = (Gdk.Key)Enum.Parse(typeof(Gdk.Key), keyName, false); item.AddAccelerator("activate", accel, (uint)accelKey, modifier, AccelFlags.Visible); } catch { } } item.Activated += description.OnClick; popup.Append(item); } if (popup.AttachWidget == null) { popup.AttachToWidget(Listview, null); } popup.ShowAll(); }