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(); }
/// <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); } }
/// <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)); } }
protected override void RegisterForContextMenu(List <Command> contextCommands, UiElementInfo info) { if (info.IsRecipeItem) { contextCommands.Add(this); } }
protected override void RegisterForContextMenu(List <Command> contextCommands, UiElementInfo info) { if (info.IsAssemblyItem || info.IsFixtureItem || info.IsMethodItem) { contextCommands.Add(this); } }
private void FireCheckedStateChanged(UiElementInfo uiElementInfo, bool isChecked) { if (ItemCheckedStateChanged != null) { ItemCheckedStateChanged(this, new ContentControlEventArgs(uiElementInfo, isChecked)); } }
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; //} } }
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); }
private SmartTreeNode FindNodeFor(UiElementInfo info) { SmartTreeNode found = null; foreach (SmartTreeNode node in _treeTestHierarchy.Nodes) { found = SearchIn(node, info); if (found != null) { break; } } return(found); }
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); } } }
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); } }
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); } } }
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); }
/// <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)); } }
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); }
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); }
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); }
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); }
protected override void RegisterForContextMenu(List<Command> contextCommands, UiElementInfo info) { contextCommands.Add(this); }
public ContentControlEventArgs(UiElementInfo uiElementInfo, bool isChecked) { _uiElementInfo = uiElementInfo; _isChecked = isChecked; }
/// <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); } }
protected override void RegisterForContextMenu(List<Command> contextCommands, UiElementInfo info) { if( info.IsAssemblyItem || info.IsFixtureItem || info.IsMethodItem ) { contextCommands.Add(this); } }
/// <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) { }
/// <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) { }