示例#1
0
            public CommandToolStripMenuItem Clone()
            {
                var ret = new CommandToolStripMenuItem(Preset);

                ret.Text = ret.ToolTipText = Path.GetFileNameWithoutExtension(Preset.FilePath);
                return(ret);
            }
示例#2
0
        private void LoadPresets(string dir, ToolStripMenuItem menuItem)
        {
            foreach (var childDir in Directory.GetDirectories(dir))
            {
                var childMenu = new ToolStripMenuItem();
                menuItem.DropDownItems.Add(childMenu);
                childMenu.Text = childMenu.ToolTipText = Path.GetFileName(childDir);
                LoadPresets(childDir, childMenu);
            }

            foreach (var childFile in Directory.GetFiles(dir))
            {
                try
                {
                    var name      = Path.Combine(Path.GetDirectoryName(childFile), Path.GetFileNameWithoutExtension(childFile)).Substring(dir.Length).TrimStart(Path.DirectorySeparatorChar);
                    var preset    = new ParameterPreset(childFile, name);
                    var childMenu = new CommandToolStripMenuItem(preset);
                    menuItem.DropDownItems.Add(childMenu);
                    childMenu.Text   = childMenu.ToolTipText = Path.GetFileNameWithoutExtension(childFile);
                    childMenu.Click += childMenu_Click;
                }
                catch
                {
                    MessageBox.Show(Utility.Language["ErrorInLoadingParameterPreset"]);
                }
            }
        }
        public void Menu_item_should_be_enabled_if_command_can_execute()
        {
            var menuCommand = new MenuCommand {
                CanExecute = new Observable <bool>(true)
            };

            var menuItem = new CommandToolStripMenuItem(menuCommand);

            Assert.IsTrue(menuItem.Enabled);
        }
        public void Menu_item_text_should_match_command()
        {
            var menuCommand = new MenuCommand {
                Text = "someText"
            };

            var menuItem = new CommandToolStripMenuItem(menuCommand);

            Assert.AreEqual(menuItem.Text, menuCommand.Text);
        }
        public void Menu_item_should_run_command_when_clicked()
        {
            var command     = MockRepository.GenerateStub <ICommand>();
            var menuCommand = new MenuCommand {
                Command = command
            };
            var menuItem = new CommandToolStripMenuItem(menuCommand);

            menuItem.PerformClick();

            command.AssertWasCalled(c => c.Execute(Arg <IProgressMonitor> .Is.Anything));
        }
        public void Menu_item_should_run_command_with_task_manager_if_provided_when_clicked()
        {
            var command     = MockRepository.GenerateStub <ICommand>();
            var menuCommand = new MenuCommand {
                Command = command
            };
            var taskManager = MockRepository.GenerateStub <ITaskManager>();
            var menuItem    = new CommandToolStripMenuItem(menuCommand, taskManager);

            menuItem.PerformClick();

            taskManager.AssertWasCalled(tm => tm.QueueTask(command));
        }
        private CommandToolStripMenuItem GetItemWithCommand <TCommand>()
        {
            foreach (ToolStripItem item in new MainWindowWrapper(Item).VMMenuItems.StartShutdownMenu.DropDownItems)
            {
                CommandToolStripMenuItem commandItem = item as CommandToolStripMenuItem;

                if (commandItem != null && commandItem.Command is TCommand)
                {
                    return(commandItem);
                }
            }
            return(null);
        }
        public void Menu_item_image_should_come_from_command()
        {
            var menuCommand = new MenuCommand();
            var menuItem    = new CommandToolStripMenuItem(menuCommand);

            Assert.IsNull(menuItem.Image);

            var image = new Bitmap(1, 1);

            menuCommand.Image = image;
            menuItem          = new CommandToolStripMenuItem(menuCommand);

            Assert.AreEqual(image, menuItem.Image);
        }
        public void Menu_item_should_become_enabled_if_command_can_execute()
        {
            var canExecute  = new Observable <bool>();
            var menuCommand = new MenuCommand {
                CanExecute = canExecute
            };
            var menuItem = new CommandToolStripMenuItem(menuCommand);

            Assert.IsFalse(menuItem.Enabled);

            canExecute.Value = true;

            Assert.IsTrue(menuItem.Enabled);
        }
示例#10
0
        private void HandleNodeRightClick(VirtualTreeNodeMouseClickEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }

            if (treeView.SelectedNodes.Count == 0)
            {
                treeView.SelectedNode = e.Node;

                if (treeView.SelectedNode != e.Node)  // if node is unselectable in TreeView_BeforeSelect: CA-26615
                {
                    return;
                }
            }

            if (TreeNodeRightClicked != null)
            {
                TreeNodeRightClicked();
            }

            TreeContextMenu.Items.Clear();

            if (e.Node == treeView.Nodes[0] && treeView.SelectedNodes.Count == 1)
            {
                if (e.Node.Tag == null)// XenCenter (top most)
                {
                    TreeContextMenu.Items.Add(new CommandToolStripMenuItem(new AddHostCommand(Program.MainWindow), true));
                    TreeContextMenu.Items.Add(new CommandToolStripMenuItem(new NewPoolCommand(Program.MainWindow, new SelectedItem[0]), true));
                    TreeContextMenu.Items.Add(new CommandToolStripMenuItem(new ConnectAllHostsCommand(Program.MainWindow), true));
                    TreeContextMenu.Items.Add(new CommandToolStripMenuItem(new DisconnectAllHostsCommand(Program.MainWindow), true));
                }
                else
                {
                    var groupingTag = e.Node.Tag as GroupingTag;
                    if (groupingTag != null && groupingTag.Grouping as OrganizationViewFolders != null)
                    {
                        TreeContextMenu.Items.Add(new CommandToolStripMenuItem(
                                                      new NewFolderCommand(Program.MainWindow, new[] { new SelectedItem(groupingTag, e.Node) }),
                                                      true));
                    }
                }
            }
            else
            {
                TreeContextMenu.Items.AddRange(Program.MainWindow.ContextMenuBuilder.Build(Program.MainWindow.SelectionManager.Selection));
            }

            int insertIndex = TreeContextMenu.Items.Count;

            if (TreeContextMenu.Items.Count > 0)
            {
                CommandToolStripMenuItem lastItem = TreeContextMenu.Items[TreeContextMenu.Items.Count - 1] as CommandToolStripMenuItem;

                if (lastItem != null && lastItem.Command is PropertiesCommand)
                {
                    insertIndex--;
                }
            }

            AddExpandCollapseItems(insertIndex, treeView.SelectedNodes);
            AddOrgViewItems(insertIndex, treeView.SelectedNodes);

            if (TreeContextMenu.Items.Count > 0)
            {
                TreeContextMenu.Show(treeView.PointToScreen(Point.Empty) + (Size)treeView.LastMouseDownEventPosition);
            }
        }
示例#11
0
        public void Add(MenuCommand menuCommand)
        {
            var menuItem = new CommandToolStripMenuItem(menuCommand);

            item.DropDownItems.Add(menuItem);
        }