OSDN Git Service

Added RadegastContextMenuStrip this provides the list of actions provides by a contex...
authorDouglas R. Miles <logicmoo@gmail.com>
Wed, 16 Sep 2009 02:49:55 +0000 (02:49 +0000)
committerDouglas R. Miles <logicmoo@gmail.com>
Wed, 16 Sep 2009 02:49:55 +0000 (02:49 +0000)
Fixed context menus for FriendsConsole also Keyboard ContextMenu

git-svn-id: https://radegast.googlecode.com/svn/trunk@245 f7a694da-4d33-11de-9ad6-1127a62b9fcd

Radegast/Core/Types/RadegastContextMenu.cs [new file with mode: 0644]
Radegast/GUI/Consoles/FriendsConsole.Designer.cs
Radegast/GUI/Consoles/FriendsConsole.cs

diff --git a/Radegast/Core/Types/RadegastContextMenu.cs b/Radegast/Core/Types/RadegastContextMenu.cs
new file mode 100644 (file)
index 0000000..47deed7
--- /dev/null
@@ -0,0 +1,79 @@
+// \r
+// Radegast Metaverse Client\r
+// Copyright (c) 2009, Radegast Development Team\r
+// All rights reserved.\r
+// \r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are met:\r
+// \r
+//     * Redistributions of source code must retain the above copyright notice,\r
+//       this list of conditions and the following disclaimer.\r
+//     * Redistributions in binary form must reproduce the above copyright\r
+//       notice, this list of conditions and the following disclaimer in the\r
+//       documentation and/or other materials provided with the distribution.\r
+//     * Neither the name of the application "Radegast", nor the names of its\r
+//       contributors may be used to endorse or promote products derived from\r
+//       this software without specific prior written permission.\r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+// $Id$\r
+//\r
+\r
+using System.Collections.Generic;\r
+using System.ComponentModel;\r
+using System.Windows.Forms;\r
+\r
+namespace Radegast\r
+{\r
+    /// <summary>\r
+    /// A Radegast based ContextMenuStrip\r
+    ///   the Opening/Closing event my be subscribed to be users\r
+    /// </summary>\r
+    public class RadegastContextMenuStrip : ContextMenuStrip\r
+    {       \r
+        /// <summary>\r
+        /// If the context menu has a valid target\r
+        /// </summary>\r
+        public bool HasSelection;\r
+        /// <summary>\r
+        /// The target\r
+        /// </summary>\r
+        public object Selection;\r
+\r
+        // for Control Chartacter we use\r
+        public const Keys ContexMenuKeyCode = Keys.Enter;\r
+        public RadegastContextMenuStrip(IContainer components):base(components)\r
+        {\r
+       \r
+        }\r
+        public RadegastContextMenuStrip()\r
+            : base()\r
+        {\r
+        }\r
+\r
+        public IEnumerable<ToolStripItem> Choices()\r
+        {\r
+            List<ToolStripItem> lst = new List<ToolStripItem>();\r
+            foreach (ToolStripItem item in this.Items)\r
+            {\r
+                lst.Add(item);\r
+            }\r
+            return lst;\r
+        }\r
+    }\r
+\r
+    public interface IContextMenuProvider\r
+    {\r
+        RadegastContextMenuStrip GetContextMenu();\r
+    }\r
+}
\ No newline at end of file
index 3f043e7..7ab1714 100644 (file)
@@ -91,7 +91,9 @@ namespace Radegast
             this.lbxFriends.TabIndex = 0;\r
             this.lbxFriends.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.lbxFriends_DrawItem);\r
             this.lbxFriends.SelectedIndexChanged += new System.EventHandler(this.lbxFriends_SelectedIndexChanged);\r
-            this.lbxFriends.MouseUp += new MouseEventHandler(this.lbxFriends_MouseUp);\r
+            this.lbxFriends.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lbxFriends_MouseDown);\r
+            this.lbxFriends.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lbxFriends_MouseUp);\r
+            this.lbxFriends.KeyUp += new System.Windows.Forms.KeyEventHandler(this.lbxFriends_KeyUp);\r
             // \r
             // lblFriendName\r
             // \r
index bfbc429..e293256 100644 (file)
@@ -37,7 +37,7 @@ using OpenMetaverse;
 \r
 namespace Radegast\r
 {\r
-    public partial class FriendsConsole : UserControl\r
+    public partial class FriendsConsole : UserControl, IContextMenuProvider\r
     {\r
         private RadegastInstance instance;\r
         private GridClient client { get { return instance.Client; } }\r
@@ -305,19 +305,47 @@ namespace Radegast
 \r
         private void lbxFriends_MouseUp(object sender, MouseEventArgs e)\r
         {\r
-            ContextMenuStrip  friendsContextMenuStrip = new ContextMenuStrip {Size = new System.Drawing.Size(61, 4)};\r
+            if (e.Button == MouseButtons.Right) ShowContextMenu();\r
+        }                \r
 \r
-            if (e.Button == MouseButtons.Right)\r
+        private void lbxFriends_KeyUp(object sender, KeyEventArgs e)\r
+        {\r
+            if (e.KeyCode == Keys.Apps) ShowContextMenu();\r
+            if (e.Control && e.KeyCode == RadegastContextMenuStrip.ContexMenuKeyCode) ShowContextMenu();\r
+        }\r
+\r
+        // OnClick and MouseClick etc down not capture a right click event\r
+        private void lbxFriends_MouseDown(object sender, MouseEventArgs e)\r
+        {\r
+            int idx = lbxFriends.IndexFromPoint(lbxFriends.PointToClient(MousePosition));\r
+            if (idx > 0 && idx < lbxFriends.Items.Count)\r
             {\r
-                ListBox box = (ListBox) sender;\r
-                if (box.SelectedIndex >= 0)\r
-                {\r
-                    FriendInfo item = ((FriendsListItem)box.Items[box.SelectedIndex]).Friend;\r
-                    instance.ContextActionManager.AddContributions(\r
-                        friendsContextMenuStrip, typeof (Avatar), item, btnPay.Parent);\r
-                    friendsContextMenuStrip.Show(lbxFriends, new System.Drawing.Point(e.X, e.Y));\r
-                }\r
+                lbxFriends.SetSelected(idx, true);\r
+            }\r
+        }\r
+\r
+        public void ShowContextMenu()\r
+        {\r
+            RadegastContextMenuStrip menu = GetContextMenu();\r
+            if (menu.HasSelection) menu.Show(lbxFriends, lbxFriends.PointToClient(System.Windows.Forms.Control.MousePosition));\r
+        }\r
+\r
+        public RadegastContextMenuStrip GetContextMenu()\r
+        {\r
+            RadegastContextMenuStrip friendsContextMenuStrip = new RadegastContextMenuStrip();\r
+            if (lbxFriends.SelectedIndex >= 0)\r
+            {\r
+                FriendInfo item = ((FriendsListItem)lbxFriends.Items[lbxFriends.SelectedIndex]).Friend;\r
+                instance.ContextActionManager.AddContributions(friendsContextMenuStrip, typeof(Avatar), item, btnPay.Parent);\r
+                friendsContextMenuStrip.Selection = item;\r
+                friendsContextMenuStrip.HasSelection = true;\r
+            }\r
+            else\r
+            {\r
+                friendsContextMenuStrip.Selection = null;\r
+                friendsContextMenuStrip.HasSelection = false;\r
             }\r
+            return friendsContextMenuStrip;\r
         }\r
     }\r
 }\r