/// <summary> /// Handles Context->Create Label MenuClick /// </summary> /// <param name="sender">The Sender</param> /// <param name="e">The Event Arguments</param> private void HandleCreateLabelContextMenuClick(object sender, EventArgs e) { try { //Just exit if the selected node is null if (TreeView.SelectedNode == null) { return; } using (var editLabelForm = new Forms.EditLabelForm()) { //Make sure to set the parent id of the new label, to the id of the selected node. //If we arent on a label, we can assume this is a top-level label if (TreeView.SelectedNode.GetType() == typeof(NavigationTreeNodes.LabelTreeNode)) { editLabelForm.BoundLabel.ParentID = (TreeView.SelectedNode as NavigationTreeNodes.LabelTreeNode).BoundLabel.ID; } if (editLabelForm.ShowDialog() == DialogResult.OK) { var label = _labelManagementService.CreateLabel(editLabelForm.BoundLabel); AttachChildLabelToNode(TreeView.SelectedNode, label); } } } catch (Exception caught) { logger.Error("Unexpected Error Handlign Create Label ContextMenu Click", caught); throw; } }
/// <summary> /// Handles Context->Modify Label MenuClick /// </summary> /// <param name="sender">The Sender</param> /// <param name="e">The Event Arguments</param> private void HandleModifyLabelContextMenuClick(object sender, EventArgs e) { try { /* * I think if anything, we might have to be careful that the label is removed from here, * and then re-attached to the parent label, and if the Parent Label ID is null, it should be attached * to the rood node for that */ //Just exit if the selected node is null if (TreeView.SelectedNode == null) { return; } // We are only interested in editing Labels if (TreeView.SelectedNode.GetType() == typeof(NavigationTreeNodes.LabelTreeNode)) { var labelToEdit = (TreeView.SelectedNode as NavigationTreeNodes.LabelTreeNode).BoundLabel; long?originalParent = labelToEdit.ParentID == null ? null as long? : labelToEdit.ParentID.Value; using (var editLabelForm = new Forms.EditLabelForm(labelToEdit)) { if (editLabelForm.ShowDialog() == DialogResult.OK) { _labelManagementService.UpdateLabel(editLabelForm.BoundLabel); if (originalParent != editLabelForm.BoundLabel.ParentID) { // Remove the Label from it's current position if the parent changed TreeView.Nodes.RemoveByKey(labelToEdit.Name); //Add it to the correct parent if (editLabelForm.BoundLabel.ParentID == null) { _rootLabelsTreeNode.Nodes.Add(new NavigationTreeNodes.LabelTreeNode(editLabelForm.BoundLabel)); } else { var newParentNode = TreeView.Nodes[editLabelForm.BoundLabel.ParentID.ToString()]; newParentNode.Nodes.Add(new NavigationTreeNodes.LabelTreeNode(editLabelForm.BoundLabel)); } } } } } } catch (Exception caught) { logger.Error("Unexpected Error handling Modify Label ContextMenu Click", caught); throw; } }