コード例 #1
0
        private void OnAfterCheck(object sender, SmartTreeEventHandlerArgs args)
        {
            UiElementInfo elementInfo = args.Node.Tag as UiElementInfo;

            if (args.Action != TreeViewAction.Unknown)
            {
                if (args.Node.Checked)
                {
                    _checkedTestSelector.Add(elementInfo);
                }
                else
                {
                    _checkedTestSelector.Remove(elementInfo);
                }
            }

            if (!_propagating)
            {
                try{
                    _propagating = true;
                    PropagateUp(args.Node.Parent);
                    PropagateDown(args.Node);
                }
                finally {
                    _propagating = false;
                }
            }
            FireSelectionChanged();
        }
コード例 #2
0
ファイル: Command.cs プロジェクト: ManfredLange/csUnit
        /// <summary>
        /// Fills the context menu.
        /// </summary>
        /// <param name="menu">The context menu to be filled.</param>
        /// <param name="type">The type the commands should operate on.</param>
        /// <remarks>The menu items for a context menu have to be created each
        /// time when a context menu is about to be displayed. When the context
        /// menu is destroyed all menu items it it are destroyed with it.
        /// Therefore it's not possible to reuse the menu item that is created
        /// during startup for the main menu. [20Mar2006, ml]</remarks>
        public static void FillContextMenu(ContextMenu menu, UiElementInfo info)
        {
            // Phase 1: collect all commands interested in 'info'
            List <Command> contextCommands = new List <Command>();

            foreach (Command command in _commands)
            {
                command.RegisterForContextMenu(contextCommands, info);
            }

            contextCommands.Sort(delegate(Command cmd1, Command cmd2) {
                return(cmd1.ContextMenuPosition.CompareTo(cmd2.ContextMenuPosition));
            });

            // Phase 2: create menu items for each interested command
            foreach (Command command in contextCommands)
            {
                if (command._insertLeadingSeparator)
                {
                    menu.MenuItems.Add(new MenuItem("-"));
                }
                menu.MenuItems.Add(CreateMenuItemFor(command));
                menu.Popup += new EventHandler(command.OnUiUpdate);
            }
        }
コード例 #3
0
ファイル: Command.cs プロジェクト: ManfredLange/csUnit
        /// <summary>
        /// Fills the context menu.
        /// </summary>
        /// <param name="menu">The context menu to be filled.</param>
        /// <param name="info">The UI element the commands should operate on.</param>
        /// <remarks>The menu items for a context menu have to be created each
        /// time when a context menu is about to be displayed. When the context
        /// menu is destroyed all menu items it it are destroyed with it.
        /// Therefore it's not possible to reuse the menu item that is created
        /// during startup for the main menu. [20Mar2006, ml]</remarks>
        public static void FillContextMenu(ContextMenuStrip menu, UiElementInfo info)
        {
            // Phase 1: collect all commands interested in 'info'
            List <Command> contextCommands = new List <Command>();

            foreach (Command command in Commands)
            {
                command.RegisterForContextMenu(contextCommands, info);
            }

            contextCommands.Sort(delegate(Command cmd1, Command cmd2) {
                return(cmd1.ContextMenuPosition.CompareTo(cmd2.ContextMenuPosition));
            });

            // Phase 2: create menu items for each interested command
            foreach (Command command in contextCommands)
            {
                if (command._insertLeadingSeparator &&
                    menu.Items.Count > 0)
                {
                    menu.Items.Add("-");
                }
                menu.Items.Add(CreateToolStripMenuItem(command));
            }
        }
コード例 #4
0
 protected override void RegisterForContextMenu(List <Command> contextCommands,
                                                UiElementInfo info)
 {
     if (info.IsRecipeItem)
     {
         contextCommands.Add(this);
     }
 }
コード例 #5
0
 protected override void RegisterForContextMenu(List <Command> contextCommands,
                                                UiElementInfo info)
 {
     if (info.IsAssemblyItem ||
         info.IsFixtureItem ||
         info.IsMethodItem)
     {
         contextCommands.Add(this);
     }
 }
コード例 #6
0
 private void FireCheckedStateChanged(UiElementInfo uiElementInfo,
                                      bool isChecked)
 {
     if (ItemCheckedStateChanged != null)
     {
         ItemCheckedStateChanged(this,
                                 new ContentControlEventArgs(uiElementInfo,
                                                             isChecked));
     }
 }
コード例 #7
0
        private void OnMouseUp(object sender, MouseEventArgs args)
        {
            if (args.Button == MouseButtons.Right)
            {
                SmartTreeNode node = _treeTestHierarchy.GetNodeAt(args.X, args.Y);
                if (node != null)
                {
                    _treeTestHierarchy.SelectedNodes.Add(node);
                    UiElementInfo uiElemInfo = node.Tag as UiElementInfo;
                    if (uiElemInfo != null)
                    {
                        // Convert from tree coordinates to screen coordinates, and then back
                        // to form coordinates so that the context menu pops up at the right
                        // position
                        Point spot = PointToClient(_treeTestHierarchy.PointToScreen(new Point(args.X, args.Y)));

                        _contextMenuStrip = new ContextMenuStrip();

                        if (FillContextMenu != null)
                        {
                            FillContextMenu(this, new CsUnitControlEventArgs(_contextMenuStrip, uiElemInfo));
                        }

                        AppendMenuItemsForExpandCollapse();

                        _contextMenuStrip.Show(this, spot);
                        _contextMenuStrip = null;
                    }
                }

                //_treeTestHierarchy.SelectedNode = _treeTestHierarchy.GetNodeAt(args.X, args.Y);
                //if(_treeTestHierarchy.SelectedNode != null
                //   && _treeTestHierarchy.SelectedNode.Tag != null
                //   && _treeTestHierarchy.SelectedNode.Tag.GetType() == typeof(UiElementInfo)) {
                //   UiElementInfo uiElemInfo = (UiElementInfo)_treeTestHierarchy.SelectedNode.Tag;

                //   // Convert from tree coordinates to screen coordinates, and then back
                //   // to form coordinates so that the context menu pops up at the right
                //   // position
                //   Point spot = PointToClient(_treeTestHierarchy.PointToScreen(new Point(args.X, args.Y)));

                //   _contextMenuStrip = new ContextMenuStrip();

                //   if(FillContextMenu != null) {
                //      FillContextMenu(this, new CsUnitControlEventArgs(_contextMenuStrip, uiElemInfo));
                //   }

                //   AppendMenuItemsForExpandCollapse();

                //   _contextMenuStrip.Show(this, spot);
                //   _contextMenuStrip = null;
                //}
            }
        }
コード例 #8
0
 private SmartTreeNode FindAssemblyNode(ITestAssembly ta)
 {
     foreach (SmartTreeNode rootNode in _treeTestHierarchy.Nodes)
     {
         UiElementInfo info = rootNode.Tag as UiElementInfo;
         if (info != null &&
             info.AssemblyPathName == ta.PathName)
         {
             return(rootNode);
         }
     }
     return(null);
 }
コード例 #9
0
        private SmartTreeNode FindNodeFor(UiElementInfo info)
        {
            SmartTreeNode found = null;

            foreach (SmartTreeNode node in _treeTestHierarchy.Nodes)
            {
                found = SearchIn(node, info);
                if (found != null)
                {
                    break;
                }
            }
            return(found);
        }
コード例 #10
0
 private void SetCheckedStatus(SmartTreeNodeCollection nodes)
 {
     foreach (SmartTreeNode node in nodes)
     {
         UiElementInfo elementInfo = node.Tag as UiElementInfo;
         if (elementInfo != null)
         {
             node.Checked = _checkedTestSelector.Contains(elementInfo);
         }
         if (node.Nodes.Count > 0)
         {
             SetCheckedStatus(node.Nodes);
         }
     }
 }
コード例 #11
0
 private void RestoreCheckState(SmartTreeNode root)
 {
     if ((root.Tag as UiElementInfo) != null)
     {
         UiElementInfo element = root.Tag as UiElementInfo;
         root.Checked = _checkedTestSelector.Contains(element);
         if (root.Checked)
         {
             root.EnsureVisible();
         }
     }
     foreach (SmartTreeNode node in root.Nodes)
     {
         RestoreCheckState(node);
     }
 }
コード例 #12
0
 public override void Execute(object sender, EventArgs args)
 {
     if (Recipe.Current != null)
     {
         TestSpec ts = new TestSpec();
         foreach (object item in CommandTarget.SelectedItems)
         {
             UiElementInfo uiElemInfo = item as UiElementInfo;
             if (uiElemInfo != null)
             {
                 ts.AddTest(uiElemInfo.TestSpecName);
             }
         }
         if (ts.FixtureCount > 0)
         {
             Recipe.Current.RunTests(ts);
         }
     }
 }
コード例 #13
0
        private static TreeNode SearchIn(TreeNode node, UiElementInfo info)
        {
            var currentInfo = node.Tag as UiElementInfo;

            if (currentInfo != null &&
                currentInfo == info)
            {
                return(node);
            }
            foreach (TreeNode currentNode in node.Nodes)
            {
                var found = SearchIn(currentNode, info);
                if (found != null)
                {
                    return(found);
                }
            }
            return(null);
        }
コード例 #14
0
ファイル: Command.cs プロジェクト: ManfredLange/csUnit
      /// <summary>
      /// Fills the context menu.
      /// </summary>
      /// <param name="menu">The context menu to be filled.</param>
      /// <param name="info">The UI element the commands should operate on.</param>
      /// <remarks>The menu items for a context menu have to be created each
      /// time when a context menu is about to be displayed. When the context
      /// menu is destroyed all menu items it it are destroyed with it. 
      /// Therefore it's not possible to reuse the menu item that is created
      /// during startup for the main menu. [20Mar2006, ml]</remarks>
      public static void FillContextMenu(ContextMenuStrip menu, UiElementInfo info) {
         // Phase 1: collect all commands interested in 'info'
         List<Command> contextCommands = new List<Command>();
         foreach(Command command in Commands) {
            command.RegisterForContextMenu(contextCommands, info);
         }

         contextCommands.Sort(delegate(Command cmd1, Command cmd2) {
            return cmd1.ContextMenuPosition.CompareTo(cmd2.ContextMenuPosition);
         });

         // Phase 2: create menu items for each interested command
         foreach(Command command in contextCommands) {
            if(   command._insertLeadingSeparator
               && menu.Items.Count > 0 ) {
               menu.Items.Add("-");
            }
            menu.Items.Add(CreateToolStripMenuItem(command));
         }
      }
コード例 #15
0
        private static SmartTreeNode SearchIn(SmartTreeNode node, UiElementInfo info)
        {
            UiElementInfo currentInfo = node.Tag as UiElementInfo;

            if (currentInfo != null &&
                currentInfo == info)
            {
                return(node);
            }
            else
            {
                foreach (SmartTreeNode currentNode in node.Nodes)
                {
                    SmartTreeNode found = SearchIn(currentNode, info);
                    if (found != null)
                    {
                        return(found);
                    }
                }
            }
            return(null);
        }
コード例 #16
0
        private SmartTreeNode CreateOrFindAssemblyNode(ITestAssembly ta, int assemblyNodePosition)
        {
            string[] parts       = ta.FullName.Split(',');
            string   displayName = parts[0] + ", " + parts[1];
            string   toolTipText = "Full Name: " + parts[0] + "\n"
                                   + parts[1].Trim() + "\n"
                                   + parts[2].Trim() + "\n"
                                   + parts[3].Trim() + "\n"
                                   + "Modified: " + ta.ModifiedTimeStamp;

            foreach (SmartTreeNode node in _treeTestHierarchy.Nodes)
            {
                UiElementInfo uieleminfo = node.Tag as UiElementInfo;
                if (uieleminfo != null &&
                    uieleminfo.AssemblyPathName == ta.PathName)
                {
                    node.Text        = displayName;
                    node.ToolTipText = toolTipText;
                    return(node);
                }
            }
            SmartTreeNode assemblyNode = new SmartTreeNode(displayName);

            assemblyNode.Tag         = new UiElementInfo(ta, null, null);
            assemblyNode.ToolTipText = toolTipText;
            assemblyNode.ImageIndex  = 0;
            assemblyNode.HasCheckBox = true;
            if (assemblyNodePosition != PositionAny)
            {
                _treeTestHierarchy.Nodes.Insert(assemblyNodePosition, assemblyNode);
            }
            else
            {
                _treeTestHierarchy.Nodes.Add(assemblyNode);
            }
            return(assemblyNode);
        }
コード例 #17
0
 private static SmartTreeNode FindTestFixtureNode(SmartTreeNodeCollection nodes, string fixtureName)
 {
     foreach (SmartTreeNode node in nodes)
     {
         if (node.Tag is UiElementInfo)
         {
             UiElementInfo info = (UiElementInfo)node.Tag;
             if (info.IsFixtureItem &&
                 info.FixtureName == fixtureName)
             {
                 return(node);
             }
             else
             {
                 SmartTreeNode child = FindTestFixtureNode(node.Nodes, fixtureName);
                 if (child != null)
                 {
                     return(child);
                 }
             }
         }
     }
     return(null);
 }
コード例 #18
0
 private static SmartTreeNode FindTestMethodNode(SmartTreeNodeCollection nodes, string methodFullName)
 {
     foreach (SmartTreeNode node in nodes)
     {
         if (node.Tag is UiElementInfo)
         {
             UiElementInfo info = (UiElementInfo)node.Tag;
             if (info.IsMethodItem &&
                 info.MethodFullName == methodFullName)
             {
                 return(node);
             }
             else
             {
                 SmartTreeNode child = FindTestMethodNode(node.Nodes, methodFullName);
                 if (child != null)
                 {
                     return(child);
                 }
             }
         }
     }
     return(null);
 }
コード例 #19
0
 protected override void RegisterForContextMenu(List<Command> contextCommands,
    UiElementInfo info) {
    contextCommands.Add(this);
 }
コード例 #20
0
 public ContentControlEventArgs(UiElementInfo uiElementInfo, bool isChecked) {
    _uiElementInfo = uiElementInfo;
    _isChecked = isChecked;
 }
コード例 #21
0
ファイル: Program.cs プロジェクト: AllenLius/dtf
        /// <summary>
        /// Add UiElement class and instance
        /// </summary>
        /// <param name="uiInfo"></param>
        private static void AddUiElement(CodeTypeDeclaration targetType, UiElementInfo uiInfo)
        {
            string uiName = uiInfo.Name;
            int    n      = 2;

            while (typeNames.Contains(uiName))
            {
                uiName = uiInfo.Name + n.ToString();
                n++;
            }
            typeNames.Add(uiName);

            // add UiElement type
            CodeTypeDeclaration codeTypeUiElement = new CodeTypeDeclaration()
            {
                Name = uiName
            };

            codeNs.Types.Add(codeTypeUiElement); // add UI to namespace
            CodeConstructor codeCtorUiElement = new CodeConstructor()
            {
                Attributes = MemberAttributes.Final | MemberAttributes.Public
            };

            codeTypeUiElement.Members.Add(new CodeMemberField(typeNameApp, fieldNameApp));
            codeTypeUiElement.Members.Add(codeCtorUiElement);
            codeCtorUiElement.Parameters.Add(new CodeParameterDeclarationExpression(typeof(UiElement), VarNameParent));
            codeCtorUiElement.Parameters.Add(new CodeParameterDeclarationExpression(typeNameApp, varNameApp));
            codeCtorUiElement.BaseConstructorArgs.Add(new CodeSnippetExpression(GetFormattedExpressionString(uiInfo.Condition.ToString())));
            codeCtorUiElement.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(VarNameParent));
            codeCtorUiElement.Statements.Add(
                new CodeAssignStatement(
                    new CodeVariableReferenceExpression(fieldNameApp),
                    new CodeVariableReferenceExpression(varNameApp)));

            // extension class
            CodeTypeDeclaration codeTypeEx = new CodeTypeDeclaration(uiName + "Ex");

            typeNames.Add(codeTypeEx.Name);
            extensionTypeNames.Add(codeTypeEx.Name);
            codeNs.Types.Add(codeTypeEx);

            // inherit UiElement
            codeTypeUiElement.BaseTypes.Add(new CodeTypeReference(typeof(UiElement)));

            // add and implement IUiInspector
            ImplementInterface(uiName, codeTypeEx, typeof(IUiInspectorFactory), typeof(IUiInspector), false);

            // add click
            ImplementInterface(uiName, codeTypeEx, typeof(IPatternFactory), typeof(IMousePattern), true);

            // implement patterns
            foreach (var type in uiInfo.Patterns)
            {
                ImplementInterface(uiName, codeTypeEx, typeof(IPatternFactory), type, true);
            }

            // add app property
            CodeMemberProperty codePropertyApp = new CodeMemberProperty()
            {
                Attributes = MemberAttributes.Public | MemberAttributes.Final, Name = PropertyNameApp, Type = new CodeTypeReference(typeNameApp)
            };

            codeTypeUiElement.Members.Add(codePropertyApp);
            codePropertyApp.GetStatements.Add(
                new CodeMethodReturnStatement(
                    new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(),
                        fieldNameApp)));

            // add UI propety to UiElements
            CodeMemberProperty codePropertyUiElement = new CodeMemberProperty()
            {
                Attributes = MemberAttributes.Final | MemberAttributes.Public, Name = uiInfo.Name, Type = new CodeTypeReference(uiName)
            };

            targetType.Members.Add(codePropertyUiElement);
            CodeExpression uiElementParent = targetType.Name.Equals(TypeNameUiElements) ? new CodePrimitiveExpression(null) as CodeExpression : new CodeThisReferenceExpression() as CodeExpression;

            codePropertyUiElement.GetStatements.Add(
                new CodeMethodReturnStatement(
                    new CodeObjectCreateExpression(codePropertyUiElement.Type, uiElementParent, new CodeVariableReferenceExpression(fieldNameApp))
                    )
                );

            // add children
            foreach (var child in uiInfo.Children)
            {
                AddUiElement(codeTypeUiElement, child);
            }
        }
コード例 #22
0
 public ContentControlEventArgs(UiElementInfo uiElementInfo, bool isChecked)
 {
     _uiElementInfo = uiElementInfo;
     _isChecked     = isChecked;
 }
コード例 #23
0
 protected override void RegisterForContextMenu(List<Command> contextCommands,
    UiElementInfo info) {
    if( info.IsAssemblyItem
       || info.IsFixtureItem
       || info.IsMethodItem ) {
       contextCommands.Add(this);
    }
 }
コード例 #24
0
ファイル: Command.cs プロジェクト: ManfredLange/csUnit
 /// <summary>
 /// When implemented by a command, it can determine whether it wants its
 /// menu item to appear in a context menu depending on the UiElementInfo.
 /// </summary>
 /// <param name="contextCommands">A list to which the command can add itself.</param>
 /// <param name="info">Information about the element the user is pointing to.</param>
 /// <remarks>The default implementation does nothing.</remarks>
 protected virtual void RegisterForContextMenu(List <Command> contextCommands,
                                               UiElementInfo info)
 {
 }
コード例 #25
0
ファイル: Command.cs プロジェクト: ManfredLange/csUnit
 /// <summary>
 /// When implemented by a command, it can determine whether it wants its
 /// menu item to appear in a context menu depending on the UiElementInfo.
 /// </summary>
 /// <param name="contextCommands">A list to which the command can add itself.</param>
 /// <param name="info">Information about the element the user is pointing to.</param>
 /// <remarks>The default implementation does nothing.</remarks>
 protected virtual void RegisterForContextMenu(List<Command> contextCommands,
    UiElementInfo info) {
 }