public void AddTab(string name, string title, Control control, Image icon, string tooltip, int sortImportance) { bool isPrivateTab = control is PrivateMessageControl; name = isPrivateTab ? (name + "_pm") : (name + "_chan"); var button = new ToolStripButton(name, icon) { Name = name, Alignment = ToolStripItemAlignment.Left, TextAlign = ContentAlignment.MiddleLeft, ImageAlign = ContentAlignment.MiddleLeft, AutoToolTip = false, ToolTipText = tooltip, Tag = sortImportance, Text = title, }; if (control is BattleChatControl) { button.Height = button.Height * 2; } button.MouseEnter += button_MouseEnter; button.MouseLeave += button_MouseLeave; button.MouseDown += (s, e) => { if (e.Button == MouseButtons.Right) { var point = new Point(button.Bounds.Location.X + e.X, button.Bounds.Location.Y + e.Y); try { Program.ToolTip.Visible = false; if (control is ChatControl) { ContextMenus.GetChannelContextMenu((ChatControl)control).Show(toolStrip, point); } else if (control is PrivateMessageControl) { ContextMenus.GetPrivateMessageContextMenu((PrivateMessageControl)control).Show(toolStrip, point); } } catch (Exception ex) { Trace.TraceError("Error displaying tooltip:{0}", ex); } finally { Program.ToolTip.Visible = true; } } else if (e.Button == MouseButtons.Middle) { if (control is ChatControl) { var chatControl = (ChatControl)control; if (chatControl.CanLeave) { Program.TasClient.LeaveChannel(chatControl.ChannelName); } } else if (control is PrivateMessageControl) { var chatControl = (PrivateMessageControl)control; ActionHandler.ClosePrivateChat(chatControl.UserName); } } }; var added = false; var insertItemText = sortImportance + Name; for (var i = 0; i < toolStrip.Items.Count; i++) { var existingItemText = (int)toolStrip.Items[i].Tag + toolStrip.Items[i].Text; if (String.Compare(existingItemText, insertItemText) < 0) { toolStrip.Items.Insert(i, button); added = true; break; } } if (!added) { toolStrip.Items.Add(button); } button.Click += (s, e) => { try { if (control is BattleChatControl) { NavigationControl.Instance.Path = "chat/battle"; } else if (control is PrivateMessageControl) { var pmControl = (PrivateMessageControl)control; var userName = pmControl.UserName; NavigationControl.Instance.Path = "chat/user/" + userName; } else if (control is ChatControl) { var chatControl = (ChatControl)control; var channelName = chatControl.ChannelName; NavigationControl.Instance.Path = "chat/channel/" + channelName; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }; control.Dock = DockStyle.Fill; control.Visible = false; controls.Add(name, control); panel.Controls.Add(control); }
// warning: a lot of duplication in GetPrivateMessageContextMenuWpf! change both at once! (temporary solution) // warning: a lot of duplication in GetPrivateMessageContextMenuWpf! change both at once! (temporary solution) public static ContextMenu GetPrivateMessageContextMenu(PrivateMessageControl control) { var contextMenu = new ContextMenu(); try { var headerItem = new System.Windows.Forms.MenuItem("Private Channel - " + control.UserName); headerItem.Enabled = false; headerItem.DefaultItem = true; //This is to make it appear bold contextMenu.MenuItems.Add(headerItem); contextMenu.MenuItems.Add("-"); var details = new System.Windows.Forms.MenuItem("Details"); details.Click += (s, e) => NavigationControl.Instance.Path = string.Format("{1}/Users/LobbyDetail/{0}", control.UserName, GlobalConst.BaseSiteUrl); contextMenu.MenuItems.Add(details); if (Program.FriendManager.Friends.Contains(control.UserName)) { var pinItem = new System.Windows.Forms.MenuItem("Unfriend"); pinItem.Click += (s, e) => Program.FriendManager.RemoveFriend(control.UserName); contextMenu.MenuItems.Add(pinItem); } else { var pinItem = new System.Windows.Forms.MenuItem("Friend"); pinItem.Click += (s, e) => Program.FriendManager.AddFriend(control.UserName); contextMenu.MenuItems.Add(pinItem); } var isUserOnline = Program.TasClient.ExistingUsers.ContainsKey(control.UserName); var joinItem = new System.Windows.Forms.MenuItem("Join Same Battle"); joinItem.Enabled = isUserOnline && Program.TasClient.ExistingUsers[control.UserName].IsInBattleRoom; joinItem.Click += (s, e) => ActionHandler.JoinPlayer(control.UserName); contextMenu.MenuItems.Add(joinItem); var reportUser = new System.Windows.Forms.MenuItem("Report User"); reportUser.Click += (s, e) => NavigationControl.Instance.Path = string.Format("{1}/Users/ReportToAdminFromLobby/{0}", control.UserName, GlobalConst.BaseSiteUrl); contextMenu.MenuItems.Add(reportUser); contextMenu.MenuItems.Add("-"); var showJoinLeaveLines = new System.Windows.Forms.MenuItem("Show Join/Leave Lines") { Checked = control.ChatBox.ShowJoinLeave }; showJoinLeaveLines.Click += (s, e) => control.ChatBox.ShowJoinLeave = !control.ChatBox.ShowJoinLeave; contextMenu.MenuItems.Add(showJoinLeaveLines); var showHistoryLines = new System.Windows.Forms.MenuItem("Show Recent History") { Checked = control.ChatBox.ShowHistory }; showHistoryLines.Click += (s, e) => control.ChatBox.ShowHistory = !control.ChatBox.ShowHistory; contextMenu.MenuItems.Add(showHistoryLines); var historyItem = new System.Windows.Forms.MenuItem("Open History"); historyItem.Click += (s, e) => HistoryManager.OpenHistory(control.UserName); contextMenu.MenuItems.Add(historyItem); if (control.CanClose) { var closeItem = new System.Windows.Forms.MenuItem("Close"); closeItem.Click += (s, e) => ActionHandler.ClosePrivateChat(control.UserName); contextMenu.MenuItems.Add(closeItem); } contextMenu.MenuItems.Add("-"); MenuItem textColoringMenu = new System.Windows.Forms.MenuItem("Compose a colored text"); textColoringMenu.Click += (s, e) => { ActionHandler.ShowColoringPanel(control.sendBox); }; contextMenu.MenuItems.Add(textColoringMenu); MenuItem unicodeTranslator = new System.Windows.Forms.MenuItem("Get Unicode symbols"); unicodeTranslator.Click += (s, e) => { ActionHandler.ShowUnicodeTranslator(); }; contextMenu.MenuItems.Add(unicodeTranslator); } catch (Exception e) { Trace.WriteLine("Error generating channel context menu: " + e); } return(contextMenu); }