private void shortcutKey_Down(object sender, KeyEventArgs e) { MyNode temp = FocusManager.GetFocusedElement(this) as MyNode; MyNode temp1; //使用自带的FOUCS属性 if (e.Key == Key.A) { //为什么enter键不行有问题?【创建兄弟】 myNode.removeNode(); temp1 = new MyNode("创建了一个新节点", grid, myNode); temp.Child.Add(temp1); myNode.SetNumber_Numberother(0); RecoverWantEdit(myNode); myNode.ShowChildren(0); myNode.CreateRelation(); temp1.Click += myNode_Click; temp1.KeyDown += shortcutKey_Down; } else if (e.Key == Key.Tab) { //创建兄弟节点 if (temp.father != null) { myNode.removeNode(); temp1 = new MyNode("创建了一个兄弟节点", grid, temp.father); temp.father.Child.Add(temp1); myNode.SetNumber_Numberother(0); RecoverWantEdit(myNode); myNode.ShowChildren(0); myNode.CreateRelation(); temp1.Click += myNode_Click; temp1.KeyDown += shortcutKey_Down; } } else if (e.Key == Key.Delete) { if (temp.father != null) { myNode.removeNode(); //删除对应的线 temp.father.lines.Remove(temp.father.lines[temp.father.Child.IndexOf(temp)]); temp.father.Child.Remove(temp); myNode.SetNumber_Numberother(0); RecoverWantEdit(myNode); myNode.ShowChildren(0); myNode.CreateRelation(); temp = null; } } else if (e.Key == Key.E) { //edit键 myNode.removeNode(); myNode.SetNumber_Numberother(0); RecoverWantEdit(myNode); temp.wantEdit = true; myNode.ShowChildren(0); myNode.CreateRelation(); } }
public bool generateNode(String name, int type) { if (currentNode == null) { return(false); } MyNode tempNode; if (n >= paraLength) { return(false); } int current = n; if (name == null) { if (!IsNumberic(section1.Paragraphs[current].StyleName)) { //不是数字,是个文本 tempNode = new MyNode(section1.Paragraphs[current].Text, currentNode.grid, this.currentNode); this.currentNode.Child.Add(tempNode); n++; return(true); } tempNode = new MyNode(section1.Paragraphs[current].Text, currentNode.grid, this.currentNode); this.currentNode.Child.Add(tempNode); currentNode = tempNode; n++; while (generateNode(section1.Paragraphs[current].Text, int.Parse(section1.Paragraphs[current].StyleName))) { } return(false); } else { if (!IsNumberic(section1.Paragraphs[current].StyleName)) { //文本 tempNode = new MyNode(section1.Paragraphs[current].Text, currentNode.grid, this.currentNode); this.currentNode.Child.Add(tempNode); n++; return(true); } if (int.Parse(section1.Paragraphs[current].StyleName) > type) { //比上一个节点更小【子节点】 tempNode = new MyNode(section1.Paragraphs[current].Text, currentNode.grid, this.currentNode); this.currentNode.Child.Add(tempNode); currentNode = tempNode; n++; while (generateNode(section1.Paragraphs[current].Text, int.Parse(section1.Paragraphs[current].StyleName))) { } return(true); } else { //比上一个节点大 currentNode = currentNode.father; return(false); } } }