/// <summary> /// Adds a user to the tree view list. /// </summary> /// <param name="user">The user to add.</param> /// <returns>The newly created TreeNode.</returns> public TreeNode AddUserToList(IRCUser user) { TreeNode node = new TreeNode(); this.UserTreeView.InvokeAction(() => { TreeNode root = null; node.Name = string.Format("{0}_{1}_node", this.Name, user.NickName); node.Text = user.NickName; node.Tag = user; switch (user.Mode) { case IRCUserMode.Admin: node.ImageKey = "orange"; node.SelectedImageKey = "orange"; node.StateImageKey = "orange"; break; case IRCUserMode.Founder: node.ImageKey = "purple"; node.SelectedImageKey = "purple"; node.StateImageKey = "purple"; break; case IRCUserMode.HalfOperator: node.ImageKey = "blue"; node.SelectedImageKey = "blue"; node.StateImageKey = "blue"; break; case IRCUserMode.Operator: node.ImageKey = "green"; node.SelectedImageKey = "green"; node.StateImageKey = "green"; break; case IRCUserMode.Voice: node.ImageKey = "black"; node.SelectedImageKey = "black"; node.StateImageKey = "black"; break; case IRCUserMode.Normal: node.ImageKey = "white"; node.SelectedImageKey = "white"; node.StateImageKey = "white"; break; } if (this.groupingByMode) { switch (user.Mode) { case IRCUserMode.Admin: if (this.UserTreeView.Nodes.ContainsKey(adminGroupName)) { root = this.UserTreeView.Nodes[adminGroupName]; } else { root = this.UserTreeView.Nodes.Add(adminGroupName, Strings_General.Admin, "group", "group"); root.Tag = UserNodeSorter.AdminGroup; } break; case IRCUserMode.Founder: if (this.UserTreeView.Nodes.ContainsKey(founderGroupName)) { root = this.UserTreeView.Nodes[founderGroupName]; } else { root = this.UserTreeView.Nodes.Add(founderGroupName, Strings_General.Founder, "group", "group"); root.Tag = UserNodeSorter.FounderGroup; } break; case IRCUserMode.HalfOperator: if (this.UserTreeView.Nodes.ContainsKey(halfOperatorGroupName)) { root = this.UserTreeView.Nodes[halfOperatorGroupName]; } else { root = this.UserTreeView.Nodes.Add(halfOperatorGroupName, Strings_General.HalfOperator, "group", "group"); root.Tag = UserNodeSorter.HalfOperator; } break; case IRCUserMode.Operator: if (this.UserTreeView.Nodes.ContainsKey(operatorGroupName)) { root = this.UserTreeView.Nodes[operatorGroupName]; } else { root = this.UserTreeView.Nodes.Add(operatorGroupName, Strings_General.Operator, "group", "group"); root.Tag = UserNodeSorter.Operator; } break; case IRCUserMode.Voice: if (this.UserTreeView.Nodes.ContainsKey(voiceGroupName)) { root = this.UserTreeView.Nodes[voiceGroupName]; } else { root = this.UserTreeView.Nodes.Add(voiceGroupName, Strings_General.Voice, "group", "group"); root.Tag = UserNodeSorter.Voice; } break; case IRCUserMode.Normal: if (this.UserTreeView.Nodes.ContainsKey(normalGroupName)) { root = this.UserTreeView.Nodes[normalGroupName]; } else { root = this.UserTreeView.Nodes.Add(normalGroupName, Strings_General.Normal, "group", "group"); root.Tag = UserNodeSorter.Normal; } break; } } if (root != null) { root.Nodes.Add(node); } else { this.UserTreeView.Nodes.Add(node); } }); return node; }
/// <summary> /// Removes a user from the user tree view. /// </summary> /// <param name="user">The user to remove.</param> public void RemoveUserFromList(IRCUser user) { this.UserTreeView.InvokeAction(() => { if (this.GroupingByMode) { this.RemoveUserFromList(user, this.UserTreeView.Nodes); List<int> emptyGroups = new List<int>(this.UserTreeView.Nodes.Count); for (int i = 0; i < this.UserTreeView.Nodes.Count; i++) { if (this.UserTreeView.Nodes[i].Nodes.Count == 0) { emptyGroups.Add(i); } } for (int i = 0; i < emptyGroups.Count; i++) { this.UserTreeView.Nodes.RemoveAt(emptyGroups[i]); } } else { this.RemoveUserFromTopLevelNodes(user); } }); }
/// <summary> /// Adds a user to the tree view list. /// </summary> /// <param name="user">The user to add.</param> /// <param name="refresh">A value indicating whether or not to refresh the sorting.</param> public void AddUserToList(IRCUser user, bool refresh) { this.UserTreeView.InvokeAction(() => { TreeNode node = this.AddUserToList(user); if (refresh) { this.UserTreeView.Sort(); // If we are in grouping mode and the user's group only has one // node, then it is has been newly created and should be expanded if (this.groupingByMode && node.Parent.Nodes.Count == 1) { node.Parent.Expand(); } } }); }
/// <summary> /// Removes a user from the top level nodes in <see cref="UserTreeView"/>. /// </summary> /// <param name="user">The user to remove.</param> /// <returns>true upon removal, false if not found.</returns> private bool RemoveUserFromTopLevelNodes(IRCUser user) { for (int i = 0; i < this.UserTreeView.Nodes.Count; i++) { if (this.UserTreeView.Nodes[i].Tag == user) { this.UserTreeView.Nodes.RemoveAt(i); break; } } return true; }
/// <summary> /// Removes a user from the user tree view. /// </summary> /// <param name="user">The user to remove.</param> /// <param name="nodes">The nodes to search within.</param> /// <returns>true on removal, false if the node was not found.</returns> private bool RemoveUserFromList(IRCUser user, TreeNodeCollection nodes) { for (int i = 0; i < nodes.Count; i++) { if ((nodes[i].Tag != null) && (nodes[i].Tag == user)) { nodes.RemoveAt(i); return true; } else { if (this.RemoveUserFromList(user, nodes[i].Nodes)) { return true; } } } return false; }
/// <summary> /// Do any channel level processing required for the message. /// </summary> /// <param name="message">The message to process.</param> public void HandleMessage(Message message) { Action namesRequest = () => { if (!this.expectingNamesMessage) { this.users.Clear(); this.expectingNamesMessage = true; this.marshal.Send(this.TabPage, new NamesMessage(this.Name)); } }; if (message is JoinMessage) { namesRequest.Invoke(); } else if (message is PartMessage) { PartMessage partMessage = message as PartMessage; if (partMessage.NickName.Equals(this.marshal.Connection.Nickname, StringComparison.OrdinalIgnoreCase)) { this.Dispose(); return; } else { IRCUser user = this.users.Find(i => i.NickName.Equals(partMessage.NickName, StringComparison.OrdinalIgnoreCase)); this.TabPage.RemoveUserFromList(user); this.users.Remove(user); } } else if (message is KickMessage) { KickMessage kickMessage = message as KickMessage; IRCUser user = this.users.Find(i => i.NickName.Equals(kickMessage.NickName, StringComparison.OrdinalIgnoreCase)); this.TabPage.RemoveUserFromList(user); this.users.Remove(user); } else if (message is NickMessage) { NickMessage nickMessage = message as NickMessage; IRCUser user = this.users.Find(i => i.NickName.Equals(nickMessage.OldNickname, StringComparison.OrdinalIgnoreCase)); if (user != null) { this.TabPage.RemoveUserFromList(user); user.NickName = nickMessage.NewNickname; this.TabPage.AddUserToList(user, true); } else { return; } } else if (message is QuitMessage) { QuitMessage quitMessage = message as QuitMessage; IRCUser user = this.users.Find(i => i.NickName.Equals(quitMessage.NickName, StringComparison.OrdinalIgnoreCase)); if (user != null) { this.TabPage.RemoveUserFromList(user); this.users.Remove(user); } else { return; } } else if (message is ModeMessage) { namesRequest.Invoke(); } GlobalSettings settings = GlobalSettings.Instance; if (settings.DebugMode == GlobalSettings.Boolean.Yes) { this.TabPage.AppendMessage(message.Command, "[RAW]", message.ToString(), MessageType.WarningMessage); } this.TabPage.AppendMessage(message.Command, message.Source, message.Content, message.Type); }
/// <summary> /// Adds a user to the tree view list. /// </summary> /// <param name="user">The user to add.</param> /// <returns>The newly created TreeNode.</returns> public TreeNode AddUserToList(IRCUser user) { TreeNode node = new TreeNode(); this.UserTreeView.InvokeAction(() => { TreeNode root = null; node.Name = string.Format("{0}_{1}_node", this.Name, user.NickName); node.Text = user.NickName; node.Tag = user; switch (user.Mode) { case IRCUserMode.Admin: node.ImageKey = "orange"; node.SelectedImageKey = "orange"; node.StateImageKey = "orange"; break; case IRCUserMode.Founder: node.ImageKey = "purple"; node.SelectedImageKey = "purple"; node.StateImageKey = "purple"; break; case IRCUserMode.HalfOperator: node.ImageKey = "blue"; node.SelectedImageKey = "blue"; node.StateImageKey = "blue"; break; case IRCUserMode.Operator: node.ImageKey = "green"; node.SelectedImageKey = "green"; node.StateImageKey = "green"; break; case IRCUserMode.Voice: node.ImageKey = "black"; node.SelectedImageKey = "black"; node.StateImageKey = "black"; break; case IRCUserMode.Normal: node.ImageKey = "white"; node.SelectedImageKey = "white"; node.StateImageKey = "white"; break; } if (this.groupingByMode) { switch (user.Mode) { case IRCUserMode.Admin: if (this.UserTreeView.Nodes.ContainsKey(adminGroupName)) { root = this.UserTreeView.Nodes[adminGroupName]; } else { root = this.UserTreeView.Nodes.Add(adminGroupName, Strings_General.Admin, "group", "group"); root.Tag = UserNodeSorter.AdminGroup; } break; case IRCUserMode.Founder: if (this.UserTreeView.Nodes.ContainsKey(founderGroupName)) { root = this.UserTreeView.Nodes[founderGroupName]; } else { root = this.UserTreeView.Nodes.Add(founderGroupName, Strings_General.Founder, "group", "group"); root.Tag = UserNodeSorter.FounderGroup; } break; case IRCUserMode.HalfOperator: if (this.UserTreeView.Nodes.ContainsKey(halfOperatorGroupName)) { root = this.UserTreeView.Nodes[halfOperatorGroupName]; } else { root = this.UserTreeView.Nodes.Add(halfOperatorGroupName, Strings_General.HalfOperator, "group", "group"); root.Tag = UserNodeSorter.HalfOperator; } break; case IRCUserMode.Operator: if (this.UserTreeView.Nodes.ContainsKey(operatorGroupName)) { root = this.UserTreeView.Nodes[operatorGroupName]; } else { root = this.UserTreeView.Nodes.Add(operatorGroupName, Strings_General.Operator, "group", "group"); root.Tag = UserNodeSorter.Operator; } break; case IRCUserMode.Voice: if (this.UserTreeView.Nodes.ContainsKey(voiceGroupName)) { root = this.UserTreeView.Nodes[voiceGroupName]; } else { root = this.UserTreeView.Nodes.Add(voiceGroupName, Strings_General.Voice, "group", "group"); root.Tag = UserNodeSorter.Voice; } break; case IRCUserMode.Normal: if (this.UserTreeView.Nodes.ContainsKey(normalGroupName)) { root = this.UserTreeView.Nodes[normalGroupName]; } else { root = this.UserTreeView.Nodes.Add(normalGroupName, Strings_General.Normal, "group", "group"); root.Tag = UserNodeSorter.Normal; } break; } } if (root != null) { root.Nodes.Add(node); } else { this.UserTreeView.Nodes.Add(node); } }); return(node); }