public static void Add(this TreeView treView, LimitModifier input, ContextMenuStrip strip) { if (treView == null) { return; } TreeNode nodeToAddTo = treView.Nodes[(int)Enum.Parse(typeof(LimitType), input.Limit)]; if (!nodeToAddTo.Nodes.ContainsKey(input.DisplayName)) { nodeToAddTo.Nodes.Add(input.CreateTreeNode(strip)); nodeToAddTo.Expand(); } }
/// <summary> /// Edit and update a Limit Modifier. /// </summary> /// <param name="treLimit"></param> /// <param name="cmsLimitModifier"></param> protected void UpdateLimitModifier(TreeView treLimit, ContextMenuStrip cmsLimitModifier) { TreeNode objSelectedNode = treLimit.SelectedNode; string strGuid = objSelectedNode.Tag.ToString(); LimitModifier objLimitModifier = _objCharacter.LimitModifiers.FindById(strGuid); //If the LimitModifier couldn't be found (Ie it comes from an Improvement or the user hasn't properly selected a treenode, fail out early. if (objLimitModifier == null) { MessageBox.Show(LanguageManager.GetString("Warning_NoLimitFound", GlobalOptions.Language)); return; } frmSelectLimitModifier frmPickLimitModifier = new frmSelectLimitModifier(objLimitModifier); frmPickLimitModifier.ShowDialog(this); if (frmPickLimitModifier.DialogResult == DialogResult.Cancel) { return; } //Remove the old LimitModifier to ensure we don't double up. _objCharacter.LimitModifiers.Remove(objLimitModifier); // Create the new limit modifier. objLimitModifier = new LimitModifier(_objCharacter); string strLimit = treLimit.SelectedNode.Parent.Text; string strCondition = frmPickLimitModifier.SelectedCondition; objLimitModifier.Create(frmPickLimitModifier.SelectedName, frmPickLimitModifier.SelectedBonus, strLimit, strCondition); objLimitModifier.Guid = new Guid(strGuid); if (objLimitModifier.InternalId == Guid.Empty.ToString()) { return; } _objCharacter.LimitModifiers.Add(objLimitModifier); //Add the new treeview node for the LimitModifier. objSelectedNode.Parent.Nodes.Add(objLimitModifier.CreateTreeNode(cmsLimitModifier)); objSelectedNode.Remove(); }