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