public PrivateMessageControl CreatePrivateMessageControl(string userName)
 {
     var pmControl = new PrivateMessageControl(userName) { Dock = DockStyle.Fill };
     var isFriend = Program.FriendManager.Friends.Contains(userName);
     User user;
     var isOffline = !Program.TasClient.ExistingUsers.TryGetValue(userName, out user);
     var icon = isOffline ? ZklResources.grayuser : TextImage.GetUserImage(userName);
     var contextMenu = new ContextMenu();
     if (!isFriend)
     {
         var closeButton = new MenuItem();
         closeButton.Click += (s, e) => toolTabs.RemovePrivateTab(userName);
         contextMenu.MenuItems.Add(closeButton);
     }
     toolTabs.AddTab(userName, userName, pmControl, icon, ToolTipHandler.GetUserToolTipString(userName), 0);
     pmControl.ChatLine +=
         (s, e) =>
         {
             if (Program.TasClient.IsLoggedIn)
             {
                 if (Program.TasClient.ExistingUsers.ContainsKey(userName)) Program.TasClient.Say(SayPlace.User, userName, e.Data, false);
                 else Program.TasClient.Say(SayPlace.User, GlobalConst.NightwatchName, e.Data, false, string.Format("!pm {0} ", userName)); // send using PM
             }
         };
     return pmControl;
 }
        public PrivateMessageControl CreatePrivateMessageControl(string userName)
        {
            var pmControl = new PrivateMessageControl(userName)
            {
                Dock = DockStyle.Fill
            };
            var  isFriend = Program.FriendManager.Friends.Contains(userName);
            User user;
            var  isOffline   = !Program.TasClient.ExistingUsers.TryGetValue(userName, out user);
            var  icon        = isOffline ? ZklResources.grayuser : TextImage.GetUserImage(userName);
            var  contextMenu = new ContextMenu();

            if (!isFriend)
            {
                var closeButton = new MenuItem();
                closeButton.Click += (s, e) => toolTabs.RemovePrivateTab(userName);
                contextMenu.MenuItems.Add(closeButton);
            }
            toolTabs.AddTab(userName, userName, pmControl, icon, ToolTipHandler.GetUserToolTipString(userName), 0);
            pmControl.ChatLine +=
                (s, e) =>
            {
                if (Program.TasClient.IsLoggedIn)
                {
                    Program.TasClient.Say(SayPlace.User, userName, e.Data, false);
                }
            };
            return(pmControl);
        }
        // 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) => Program.MainWindow.navigationControl.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) => Program.MainWindow.navigationControl.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;
        }
        // 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 = "http://zero-k.info/Users/LobbyDetail/" + control.UserName;
                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 = "http://zero-k.info/Users/ReportToAdminFromLobby/" + control.UserName;
                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.CloseChannel(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);
        }