Exemplo n.º 1
0
        // 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);
        }