void MakeNewPacket(String groupName) { CPacketStruct cp = new CPacketStruct(); InputForm input = new InputForm(); DialogResult result = input.ShowDialog("New Packet Name"); if (result == DialogResult.Abort || result == DialogResult.Cancel || input.InputText.Trim().Length == 0) { return; } String newPacketPath = _groupsDir + "\\" + groupName + "\\" + input.InputText; if (Directory.Exists(newPacketPath)) { MessageBox.Show("중복되는 이름이 있습니다."); return; } String msgFile = newPacketPath + "\\Msg.text"; DlgMsgMaker msgMaker = new DlgMsgMaker(cp, msgFile, getActivatedPeer().Endian == Endians.Big); msgMaker.Location = this.Location; msgMaker.ShowDialog(); TR_Groups.AddChild(_groupsRoot.Nodes[groupName], input.InputText); getActivatedPeer().InitList(); //if (_activatedPeerNode != null) _activatedPeerNode.InitList(); //_activatedMsgList.initList(); }
void RootNodeContextClicked(TriStateTreeNode node, String text, int index) { if (node.Equals(_peersRoot)) { switch (text) { case "새 Peer 생성": InputForm input = new InputForm(); DialogResult result = input.ShowDialog("New Packet Name"); if (result == DialogResult.Abort || result == DialogResult.Cancel || input.InputText.Trim().Length == 0) { return; } String newPacketPath = _peersDir + "\\" + input.InputText + ".xml"; if (File.Exists(newPacketPath)) { MessageBox.Show("중복되는 이름이 있습니다."); return; } Con_Peer peer = new Con_Peer(newPacketPath); TriStateTreeNode peerNode = TR_Groups.AddChild(_peersRoot, input.InputText); peerNode.RelativeObject["peer"] = peer; if (_groupsRoot.Nodes.Count > 0) { String groupName = _groupsRoot.Nodes[0].Text; peer.SetMsgList(groupName); } break; } } else if (node.Equals(_groupsRoot)) { switch (text) { case "새 그룹 생성": FormAdders.InputForm input = new InputForm(); DialogResult result = input.ShowDialog("Report 사용자이름 입력"); if (result == System.Windows.Forms.DialogResult.Cancel || result == System.Windows.Forms.DialogResult.Cancel) { return; } if (input.InputText.Trim().Length == 0) { return; } string newDir = _groupsDir + "\\" + input.InputText; if (Directory.Exists(newDir)) { MessageBox.Show("이름이 중복됩니다."); return; } TriStateTreeNode child = TR_Groups.AddChild(_groupsRoot, input.InputText); TR_Groups.AddContextMenuItemParentNode(child, "새 패킷 생성"); Directory.CreateDirectory(newDir); _groupPaths = Directory.GetDirectories(_groupsDir); break; } } }
public void loadGroups() { TR_Groups.ClearAllItems(); _peersRoot = TR_Groups.AddRoot("Peers"); //TR_Groups.AddContextMenuItemEndNode(_peersRoot, "새 Peer 생성"); TR_Groups.AddContextMenuItemParentNode(_peersRoot, "새 Peer 생성"); String[] peerPaths = Directory.GetFiles(_peersDir); for (int i = 0; i < peerPaths.Length; i++) { Con_Peer peer = new Con_Peer(peerPaths[i]); String name = peerPaths[i].Substring(peerPaths[i].LastIndexOf("\\") + 1); name = name.Substring(0, name.LastIndexOf("."));// .xml을 떼어줌.. TriStateTreeNode node = TR_Groups.AddChild(_peersRoot, name); node.RelativeObject["peer"] = peer; peer.SetName(name); _activatedPeerNode = node; //_peersGroup[peer] = name;//마지막 읽은 group을 _activatedPeer에 배정한다. //peer.SetMsgList(name, new ConMsgList(name)); } String[] grpPaths = Directory.GetDirectories(_groupsDir); _groupsRoot = TR_Groups.AddRoot("Groups"); //TR_Groups.AddContextMenuItemEndNode(_groupsRoot, "새 그룹 생성"); TR_Groups.AddContextMenuItemParentNode(_groupsRoot, "새 그룹 생성"); for (int i = 0; i < grpPaths.Length; i++) { String name = grpPaths[i].Substring(grpPaths[i].LastIndexOf("\\") + 1); TriStateTreeNode grp = TR_Groups.AddChild(_groupsRoot, name); TR_Groups.AddContextMenuItemParentNode(grp, "새 패킷 생성"); grp.RelativeObject["dir"] = grpPaths[i]; String[] packets = Directory.GetDirectories(grpPaths[i]); for (int p = 0; p < packets.Length; p++) { String childName = packets[p].Substring(packets[p].LastIndexOf("\\") + 1); TriStateTreeNode childNode = TR_Groups.AddChild(grp, childName); childNode.RelativeObject["dir"] = packets[p]; TR_Groups.AddContextMenuItemEndNode(childNode, "편집"); TR_Groups.AddContextMenuItemEndNode(childNode, "삭제"); TR_Groups.AddContextMenuItemEndNode(childNode, "복사본만들기"); } } for (int i = 0; i < _peersRoot.Nodes.Count; i++) { if (_groupsRoot.Nodes.Count > 0) { TriStateTreeNode node = _peersRoot.Nodes[i]; Con_Peer peer = node.RelativeObject["peer"] as Con_Peer; XmlDocument xDoc; XmlNode root = XmlHandlers.XmlGetter.RootNode(out xDoc, peerPaths[i]); XmlNode Envs = XmlHandlers.XmlGetter.Child(root, "Envs"); String groupName = _groupsRoot.Nodes[0].Text; bool isFound = false; foreach (XmlNode anEnv in Envs.ChildNodes) { string name = XmlHandlers.XmlGetter.Attribute(anEnv, "Name"); if (name.ToLower().Equals("groupname")) { for (int g = 0; g < _groupsRoot.Nodes.Count; g++) { if (_groupsRoot.Nodes[g].Text.Equals(anEnv.InnerText)) { groupName = anEnv.InnerText; isFound = true; break; } } if (isFound) { break; } } } _peersGroup[peer] = groupName; node.Text = peer.Name + "[" + groupName + "]"; } } TR_Groups.Refresh(); _groupsRoot.Expand(); _peersRoot.Expand(); TR_Groups.Refresh(); }