www.pudn.com > wxwinter2.rar > wxdWFMenu.cs


using System; 
using System.IO; 
using System.Text; 
using System.CodeDom; 
using System.CodeDom.Compiler; 
using System.Collections; 
using System.ComponentModel; 
using System.Collections.Generic; 
using System.ComponentModel.Design; 
using System.ComponentModel.Design.Serialization; 
using System.Workflow.ComponentModel.Compiler; 
using System.Workflow.ComponentModel; 
using System.Workflow.ComponentModel.Design; 
using System.Windows.Forms; 
using System.Drawing; 
 
namespace wxwinter.wf.Design 
{ 
    //ÏÔʾÓÒ¼ü²Ëµ¥ 
    public sealed class wxdWFMenu : MenuCommandService 
    { 
        public wxdWFMenu(IServiceProvider serviceProvider) 
            : base(serviceProvider) 
        { 
        } 
 
        public override void ShowContextMenu(CommandID menuID, int x, int y) 
        { 
            if (menuID == WorkflowMenuCommands.SelectionMenu) 
            { 
                ContextMenu contextMenu = new ContextMenu(); 
 
                foreach (DesignerVerb verb in Verbs) 
                { 
                    MenuItem menuItem = new MenuItem(verb.Text, new EventHandler(OnMenuClicked)); 
                    menuItem.Tag = verb; 
                    contextMenu.MenuItems.Add(menuItem); 
                } 
 
                MenuItem[] items = GetSelectionMenuItems(); 
                if (items.Length > 0) 
                { 
                    contextMenu.MenuItems.Add(new MenuItem("-")); 
                    foreach (MenuItem item in items) 
                        contextMenu.MenuItems.Add(item); 
                } 
 
                WorkflowView workflowView = GetService(typeof(WorkflowView)) as WorkflowView; 
                if (workflowView != null) 
                    contextMenu.Show(workflowView, workflowView.PointToClient(new Point(x, y))); 
            } 
        } 
 
        private void OnMenuClicked(object sender, EventArgs e) 
        { 
            MenuItem menuItem = sender as MenuItem; 
            if (menuItem != null && menuItem.Tag is MenuCommand) 
            { 
                MenuCommand command = menuItem.Tag as MenuCommand; 
                command.Invoke(); 
            } 
        } 
 
        private MenuItem[] GetSelectionMenuItems() 
        { 
            List menuItems = new List(); 
 
            bool addMenuItems = true; 
            ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService; 
            if (selectionService != null) 
            { 
                foreach (object obj in selectionService.GetSelectedComponents()) 
                { 
                    if (!(obj is Activity)) 
                    { 
                        addMenuItems = false; 
                        break; 
                    } 
                } 
            } 
 
            if (addMenuItems) 
            { 
                Dictionary selectionCommands = new Dictionary(); 
                selectionCommands.Add(WorkflowMenuCommands.Cut, "¼ôÇÐ"); 
                selectionCommands.Add(WorkflowMenuCommands.Copy, "¸´ÖÆ"); 
                selectionCommands.Add(WorkflowMenuCommands.Paste, "Õ³Ìù"); 
                selectionCommands.Add(WorkflowMenuCommands.Delete, "ɾ³ý"); 
 
 
 
                foreach (CommandID id in selectionCommands.Keys) 
                { 
                    MenuCommand command = FindCommand(id); 
                    if (command != null) 
                    { 
                        MenuItem menuItem = new MenuItem(selectionCommands[id], new EventHandler(OnMenuClicked)); 
                        menuItem.Tag = command; 
                        menuItems.Add(menuItem); 
                    } 
                } 
            } 
 
            return menuItems.ToArray(); 
        } 
    } 
}