void InsertActionAt(ActionMenuItem item, bool after, bool separator)
        {
            int pos = menuItems.IndexOf(item);

            if (pos == -1)
            {
                return;
            }

            if (after)
            {
                pos++;
            }

            if (separator)
            {
                ActionTreeNode newNode = new ActionTreeNode(Gtk.UIManagerItemType.Separator, null, null);
                nodes.Insert(pos, newNode);
                Select(newNode);
            }
            else
            {
                InsertAction(pos);
            }
        }
        void Refresh()
        {
            IDesignArea    area    = wrapper.GetDesignArea();
            ActionTreeNode selNode = null;

            foreach (Gtk.Widget w in table.Children)
            {
                ActionMenuItem ami = w as ActionMenuItem;
                if (area.IsSelected(w) && ami != null)
                {
                    selNode = ami.Node;
                    area.ResetSelection(w);
                }
                table.Remove(w);
            }

            Fill();

            ActionMenuItem mi = FindMenuItem(selNode);

            if (mi != null)
            {
                mi.Select();
            }

            GLib.Timeout.Add(50, new GLib.TimeoutHandler(RepositionSubmenu));
        }
        protected override bool OnDragDrop(Gdk.DragContext context, int x, int y, uint time)
        {
            ActionPaletteItem dropped = DND.Drop(context, null, time) as ActionPaletteItem;

            if (dropped == null)
            {
                return(false);
            }

            if (dropped.Node.Type != Gtk.UIManagerItemType.Menuitem &&
                dropped.Node.Type != Gtk.UIManagerItemType.Menu &&
                dropped.Node.Type != Gtk.UIManagerItemType.Toolitem &&
                dropped.Node.Type != Gtk.UIManagerItemType.Separator)
            {
                return(false);
            }

            ActionTreeNode newNode = null;

            // Toolitems are copied, not moved

            using (wrapper.UndoManager.AtomicChange)
            {
                if (dropped.Node.ParentNode != null && dropped.Node.Type != Gtk.UIManagerItemType.Toolitem)
                {
                    if (dropIndex < nodes.Count)
                    {
                        // Do nothing if trying to drop the node over the same node
                        ActionTreeNode dropNode = nodes [dropIndex];
                        if (dropNode == dropped.Node)
                        {
                            return(false);
                        }

                        dropped.Node.ParentNode.Children.Remove(dropped.Node);

                        // The drop position may have changed after removing the dropped node,
                        // so get it again.
                        dropIndex = nodes.IndexOf(dropNode);
                        nodes.Insert(dropIndex, dropped.Node);
                    }
                    else
                    {
                        dropped.Node.ParentNode.Children.Remove(dropped.Node);
                        nodes.Add(dropped.Node);
                        dropIndex = nodes.Count - 1;
                    }
                }
                else
                {
                    newNode = new ActionTreeNode(Gtk.UIManagerItemType.Menuitem, null, dropped.Node.Action);
                    nodes.Insert(dropIndex, newNode);
                }
                // Select the dropped node
                ActionMenuItem mi = (ActionMenuItem)menuItems [dropIndex];
                mi.Select();
            }

            return(base.OnDragDrop(context, x, y, time));
        }
Beispiel #4
0
        public override void Visit(ActionTreeNode node)
        {
            CodeTypeDeclaration type = _typeStack.Peek();
            List <Type>         actionArgumentTypes = new List <Type>();

            CodeMemberMethod method = new CodeMemberMethod();

            method.Name       = node.Name;
            method.ReturnType = _source[typeof(IControllerActionReference)];
            method.Attributes = MemberAttributes.Public;
            method.CustomAttributes.Add(_source.DebuggerAttribute);
            List <CodeExpression> actionArguments = CreateActionArgumentsAndAddParameters(method, node, actionArgumentTypes);

            method.Statements.Add(
                new CodeMethodReturnStatement(CreateNewActionReference(node, actionArguments, actionArgumentTypes)));
            type.Members.Add(method);


            if (actionArguments.Count > 0 && _occurences[node.Name] == 1)
            {
                method = new CodeMemberMethod();
                method.Comments.Add(
                    new CodeCommentStatement("Empty argument Action... Not sure if we want to pass MethodInformation to these..."));
                method.Name       = node.Name;
                method.ReturnType = _source[typeof(IArgumentlessControllerActionReference)];
                method.Attributes = MemberAttributes.Public;
                method.CustomAttributes.Add(_source.DebuggerAttribute);
                method.Statements.Add(
                    new CodeMethodReturnStatement(CreateNewActionReference(node, new List <CodeExpression>(), actionArgumentTypes)));
                type.Members.Add(method);
            }

            base.Visit(node);
        }
Beispiel #5
0
        void Refresh()
        {
            Widget      wrapper = Widget.Lookup(this);
            IDesignArea area    = wrapper.GetDesignArea();

            if (area == null)
            {
                return;
            }

            ActionTreeNode selNode = null;

            foreach (Gtk.Widget w in Children)
            {
                CustomMenuBarItem it = w as CustomMenuBarItem;
                if (it != null && area.IsSelected(it.ActionMenuItem))
                {
                    selNode = it.ActionMenuItem.Node;
                    area.ResetSelection(it.ActionMenuItem);
                }
                Remove(w);
            }

            FillMenu(actionTree);

            if (selNode != null)
            {
                ActionMenuItem mi = FindMenuItem(selNode);
                if (mi != null)
                {
                    mi.Select();
                }
            }
        }
        protected override void OnDestroyed()
        {
            parentNode.ChildNodeAdded   -= OnChildAdded;
            parentNode.ChildNodeRemoved -= OnChildRemoved;
            parentNode = null;

            base.OnDestroyed();
        }
Beispiel #7
0
        public void Select(ActionTreeNode node)
        {
            ActionMenuItem item = FindMenuItem(node);

            if (item != null)
            {
                item.Select();
            }
        }
        /// <summary>
        /// Derive values from a command (e.g. v_pitch - js1_x)
        /// </summary>
        private void DecomposeCommand()
        {
            // populate from input
            // something like "v_pitch - js1_x" OR "v_pitch - xi_thumbl" OR "v_pitch - ximod+xi_thumbl+xi_mod"
            string cmd = ActionTreeNode.CommandFromActionText(NodeText);

            m_action  = ActionTreeNode.ActionFromActionText(NodeText);
            m_cmdCtrl = "";
            if (!string.IsNullOrWhiteSpace(cmd))
            {
                // decomp gamepad entries - could have modifiers so check for contains...
                if (cmd.Contains("xi_thumblx"))
                {
                    // gamepad
                    m_cmdCtrl    = "xi_thumblx";
                    m_deviceName = m_deviceRef.DevName;
                }
                else if (cmd.Contains("xi_thumbly"))
                {
                    // gamepad
                    m_cmdCtrl    = "xi_thumbly";
                    m_deviceName = m_deviceRef.DevName;
                }
                else if (cmd.Contains("xi_thumbrx"))
                {
                    // gamepad
                    m_cmdCtrl    = "xi_thumbrx";
                    m_deviceName = m_deviceRef.DevName;
                }
                else if (cmd.Contains("xi_thumbry"))
                {
                    // gamepad
                    m_cmdCtrl    = "xi_thumbry";
                    m_deviceName = m_deviceRef.DevName;
                }
                else if (cmd.Contains("maxis_x"))
                {
                    // mouse
                    m_cmdCtrl    = "maxis_x";
                    m_deviceName = m_deviceRef.DevName;
                }
                else if (cmd.Contains("maxis_y"))
                {
                    // mouse
                    m_cmdCtrl    = "maxis_y";
                    m_deviceName = m_deviceRef.DevName;
                }
                // assume joystick
                else
                {
                    // get parts
                    m_cmdCtrl    = JoystickCls.ActionFromJsCommand(cmd); //js1_x -> x; js2_rotz -> rotz
                    m_deviceName = m_deviceRef.DevName;
                }
            }
        }
 /// <summary>
 ///     Handles the drop event
 /// </summary>
 /// <param name="sourceNode"></param>
 public override void AcceptDrop(BaseTreeNode sourceNode)
 {
     base.AcceptDrop(sourceNode);
     if (sourceNode is ActionTreeNode)
     {
         ActionTreeNode action = sourceNode as ActionTreeNode;
         action.Delete();
         Item.appendActions(action.Item);
     }
 }
		public void VisitActionNode_NoParameters_CreatesMethod()
		{
			var node = new ActionTreeNode("Index");
			controller.AddChild(node);

			generator.Visit(controller);

			CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
			CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[0], "Index");
		}
Beispiel #11
0
 ActionMenuItem FindMenuItem(ActionTreeNode node)
 {
     foreach (ActionMenuItem mi in menuItems)
     {
         if (mi.Node == node)
         {
             return(mi);
         }
     }
     return(null);
 }
Beispiel #12
0
        public void VisitActionNode_NoParameters_CreatesMethod()
        {
            var node = new ActionTreeNode("Index");

            controller.AddChild(node);

            generator.Visit(controller);

            CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
            CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[0], "Index");
        }
Beispiel #13
0
        public override void Dispose()
        {
            foreach (Gtk.Widget w in table.Children)
            {
                table.Remove(w);
                w.Destroy();
            }

            parentNode.ChildNodeAdded   -= OnChildAdded;
            parentNode.ChildNodeRemoved -= OnChildRemoved;
            parentNode = null;
            base.Dispose();
        }
Beispiel #14
0
        public void VisitActionNode_NoParameters_CreatesMethod()
        {
            ActionTreeNode node = new ActionTreeNode("Index");

            _controller.AddChild(node);

            _mocks.ReplayAll();
            _generator.Visit(_controller);
            _mocks.VerifyAll();

            CodeDomAssert.AssertHasField(_source.Ccu.Namespaces[0].Types[0], "_services");
            CodeDomAssert.AssertHasMethod(_source.Ccu.Namespaces[0].Types[0], "Index");
        }
		public void VisitRouteNode_OneParameters_CreatesMethod()
		{
			var node = new StaticRouteTreeNode("AuthenticateLogIn", "login/authenticate/<userName:string>/<password:string>");
			var actionTreeNode = new ActionTreeNode("action");
			actionTreeNode.AddChild(node);
			controller.AddChild(actionTreeNode);
			node.AddChild(new ParameterTreeNode("userName", "System.String"));

			generator.Visit(controller);

			CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
			CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[2], "AuthenticateLogIn");
		}
Beispiel #16
0
        public void VisitRouteNode_OneParameters_CreatesMethod()
        {
            var node           = new StaticRouteTreeNode("AuthenticateLogIn", "login/authenticate/<userName:string>/<password:string>");
            var actionTreeNode = new ActionTreeNode("action");

            actionTreeNode.AddChild(node);
            controller.AddChild(actionTreeNode);
            node.AddChild(new ParameterTreeNode("userName", "System.String"));

            generator.Visit(controller);

            CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
            CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[2], "AuthenticateLogIn");
        }
Beispiel #17
0
 public ActionItem(ActionTreeNode node, IMenuItemContainer parent, uint itemSpacing)
 {
     DND.SourceSet(this);
     this.parentMenu    = parent;
     this.node          = node;
     this.VisibleWindow = false;
     this.CanFocus      = true;
     this.Events       |= Gdk.EventMask.KeyPressMask;
     this.itemSpacing   = itemSpacing;
     if (node.Action != null)
     {
         node.Action.ObjectChanged += OnActionChanged;
     }
 }
        public override ActionTreeNode AddAction(DataDictionary.Rules.Action action)
        {
            ActionTreeNode retVal = new ActionTreeNode(action);
            Item.appendActions(action);

            Nodes.Add(retVal);
            if (Item.EnclosingRule != null && !Item.EnclosingRule.BelongsToAProcedure())
            {
                SortSubNodes();
            }

            Item.setVerified(false);
            return retVal;
        }
Beispiel #19
0
        static void DumpNode()
        {
            string[]       idElements = _cmdLine.nodeId.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            int            pos        = int.Parse(idElements[0]);
            int            id         = int.Parse(idElements[1]);
            ActionTreeNode node       = FindFirstPreOrder.Find <ActionTree, ActionTreeNode, int>(
                _oppActionTree, _oppActionTree.Positions[pos], n => n.Id == id);

            node.Children.Clear();
            string fileBase = Path.Combine(Path.GetDirectoryName(_cmdLine.oppActionTreeFile),
                                           Path.GetFileNameWithoutExtension(_cmdLine.oppActionTreeFile));
            string fileName = fileBase + "." + _cmdLine.nodeId + ".xml";

            node.XmlSerialize(fileName);
        }
Beispiel #20
0
        public void VisitRouteNode_NoParameters_CreatesMethod()
        {
            RouteTreeNode  node           = new StaticRouteTreeNode("Index", "index");
            ActionTreeNode actionTreeNode = new ActionTreeNode("action");

            actionTreeNode.AddChild(node);
            controller.AddChild(actionTreeNode);

            mocks.ReplayAll();
            generator.Visit(controller);
            mocks.VerifyAll();

            CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
            CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[2], "Index");
        }
Beispiel #21
0
 static void Process(string [] moves, int pocket, ActionTreeNode node, int neyPos, int curPos)
 {
     if (node.ActionKind == Ak.f || node.Children[0].ActionKind == Ak.s)
     {
         // Round 1 reached.
         moves[pocket] += ".";
         return;
     }
     if (node.ActionKind == Ak.f || node.ActionKind == Ak.c || node.ActionKind == Ak.r || (node.ActionKind == Ak.d /*&& neyPos == 0 */ && curPos == 0))
     {
         if (curPos == neyPos)
         {
             int    best    = -1;
             double bestVal = double.MinValue;
             for (int c = 0; c < node.Children.Count; ++c)
             {
                 Debug.Assert(node.Children[c].ActionKind == Ak.f || node.Children[c].ActionKind == Ak.c || node.Children[c].ActionKind == Ak.r);
                 if (node.Children[c].PreflopValues[pocket] > bestVal)
                 {
                     best    = c;
                     bestVal = node.Children[c].PreflopValues[pocket];
                 }
             }
             moves[pocket] += node.Children[best].ActionKind.ToString() + "(";
             Process(moves, pocket, node.Children[best], neyPos, (curPos + 1) % 2);
             moves[pocket] += ")";
         }
         else
         {
             for (int c = 0; c < node.Children.Count; ++c)
             {
                 Debug.Assert(node.Children[c].ActionKind == Ak.f || node.Children[c].ActionKind == Ak.c || node.Children[c].ActionKind == Ak.r);
                 moves[pocket] += node.Children[c].ActionKind.ToString();
                 Process(moves, pocket, node.Children[c], neyPos, (curPos + 1) % 2);
             }
         }
     }
     else
     {
         for (int c = 0; c < node.Children.Count; ++c)
         {
             Process(moves, pocket, node.Children[c], neyPos, (curPos + 1) % 2);
         }
     }
 }
Beispiel #22
0
        public void VisitActionNode_OneParameters_CreatesMethod()
        {
            ActionTreeNode node = new ActionTreeNode("Index");

            _controller.AddChild(node);
            node.AddChild(new ParameterTreeNode("id", typeof(Int32)));

            using (_mocks.Unordered())
            {
            }

            _mocks.ReplayAll();
            _generator.Visit(_controller);
            _mocks.VerifyAll();

            CodeDomAssert.AssertHasField(_source.Ccu.Namespaces[0].Types[0], "_services");
            CodeDomAssert.AssertHasMethod(_source.Ccu.Namespaces[0].Types[0], "Index");
        }
Beispiel #23
0
        protected CodeExpression CreateNewActionReference(ActionTreeNode node, List <CodeExpression> actionArguments,
                                                          List <Type> actionArgumentTypes)
        {
            List <CodeExpression> actionArgumentRuntimeTypes = new List <CodeExpression>();

            foreach (Type type in actionArgumentTypes)
            {
                actionArgumentRuntimeTypes.Add(new CodeTypeOfExpression(_source[type]));
            }

            CodeExpression createMethodSignature = new CodeObjectCreateExpression(
                _source[typeof(MethodSignature)],
                new CodeExpression[]
            {
                new CodeTypeOfExpression(node.Controller.FullName),
                new CodePrimitiveExpression(node.Name),
                new CodeArrayCreateExpression(_source[typeof(Type)], actionArgumentRuntimeTypes.ToArray())
            }
                );

            CodeExpression[] constructionArguments = new CodeExpression[]
            {
                new CodeFieldReferenceExpression(new CodeThisReferenceExpression(),
                                                 _naming.ToMemberVariableName(_serviceIdentifier)),
                new CodeTypeOfExpression(node.Controller.FullName),
                new CodePrimitiveExpression(node.Controller.Area),
                new CodePrimitiveExpression(_naming.ToControllerName(node.Controller.Name)),
                new CodePrimitiveExpression(node.Name),
                createMethodSignature,
                new CodeArrayCreateExpression(_source[typeof(ActionArgument)], actionArguments.ToArray())
            };

            return(new CodeMethodInvokeExpression(
                       new CodeMethodReferenceExpression(
                           new CodePropertyReferenceExpression(
                               new CodeFieldReferenceExpression(new CodeThisReferenceExpression(),
                                                                _naming.ToMemberVariableName(_serviceIdentifier)),
                               "ControllerReferenceFactory"),
                           "CreateActionReference"),
                       constructionArguments
                       ));
        }
        internal ActionMenu(Widget wrapper, IMenuItemContainer parentMenu, ActionTreeNode node)
        {
            DND.DestSet(this, true);
            parentNode          = node;
            this.parentMenu     = parentMenu;
            this.wrapper        = wrapper;
            this.nodes          = node.Children;
            table               = new Gtk.Table(0, 0, false);
            table.ColumnSpacing = 5;
            table.RowSpacing    = 5;
            table.BorderWidth   = 5;
            this.AppPaintable   = true;

            Add(table);

            Fill();

            parentNode.ChildNodeAdded   += OnChildAdded;
            parentNode.ChildNodeRemoved += OnChildRemoved;
        }
		public void VisitActionNode_NullableParameter_CreatesMethod()
		{
			var node = new ActionTreeNode("Index");
			controller.AddChild(node);
			node.AddChild(new ParameterTreeNode("id", "System.Nullable<System.Int32>"));

			generator.Visit(controller);

			var type = source.Ccu.Namespaces[0].Types[0];
			CodeDomAssert.AssertHasField(type, "_services");
			CodeDomAssert.AssertHasMethod(type, "Index");

			var method = type.Members.OfType<CodeMemberMethod>().First(m => m.Name == "Index");
			CodeDomAssert.AssertHasParameter(method, "id");

			var parameter = method.Parameters.OfType<CodeParameterDeclarationExpression>().First(p => p.Name == "id");
			Assert.AreEqual("System.Nullable`1", parameter.Type.BaseType);
			Assert.AreEqual(1, parameter.Type.TypeArguments.Count);
			Assert.AreEqual("System.Int32", parameter.Type.TypeArguments[0].BaseType);
		}
        ActionMenuItem InsertAction(Wrapper.Action action, int n)
        {
            uint row = (uint)n / columns;
            uint col = (uint)(n % columns) * 3;

            IDesignArea    designArea = GetDesignArea();
            ActionTreeNode node       = new ActionTreeNode(Gtk.UIManagerItemType.Menuitem, "", action);
            ActionMenuItem aitem      = new ActionMenuItem(designArea, project, this, node);

            aitem.KeyPressEvent += OnItemKeyPress;
            aitem.MinWidth       = 150;
            aitem.Attach(table, row, col);

            Gtk.Frame fr = new Gtk.Frame();
            fr.Shadow = Gtk.ShadowType.Out;
            aitem.Add(fr);

            items.Add(aitem);
            return(aitem);
        }
Beispiel #27
0
        ActionTreeNode InsertAction(int pos)
        {
            using (wrapper.UndoManager.AtomicChange) {
                Wrapper.Action ac      = (Wrapper.Action)ObjectWrapper.Create(wrapper.Project, new Gtk.Action("", "", null, null));
                ActionTreeNode newNode = new ActionTreeNode(Gtk.UIManagerItemType.Menuitem, null, ac);
                nodes.Insert(pos, newNode);
                ActionMenuItem item = FindMenuItem(newNode);
                item.EditingDone += OnEditingDone;
                item.Select();
                item.StartEditing();
                emptyLabel.Hide();

                if (wrapper.LocalActionGroups.Count == 0)
                {
                    wrapper.LocalActionGroups.Add(new ActionGroup("Default"));
                }
                wrapper.LocalActionGroups [0].Actions.Add(ac);
                return(newNode);
            }
        }
Beispiel #28
0
        public void DropMenu(ActionTreeNode node)
        {
            ActionMenuItem item = FindMenuItem(node);

            if (item != null)
            {
                if (item.HasSubmenu)
                {
                    item.ShowSubmenu();
                    if (openSubmenu != null)
                    {
                        openSubmenu.Select(null);
                    }
                }
                else
                {
                    item.Select();
                }
            }
        }
Beispiel #29
0
        public void VisitRouteNode_OneParameters_CreatesMethod()
        {
            RouteTreeNode  node           = new StaticRouteTreeNode("AuthenticateLogIn", "login/authenticate/<userName:string>/<password:string>");
            ActionTreeNode actionTreeNode = new ActionTreeNode("action");

            actionTreeNode.AddChild(node);
            controller.AddChild(actionTreeNode);
            node.AddChild(new ParameterTreeNode("userName", typeof(string)));

            using (mocks.Unordered())
            {
            }

            mocks.ReplayAll();
            generator.Visit(controller);
            mocks.VerifyAll();

            CodeDomAssert.AssertHasField(source.Ccu.Namespaces[0].Types[0], "_services");
            CodeDomAssert.AssertHasMethod(source.Ccu.Namespaces[0].Types[2], "AuthenticateLogIn");
        }
        /// <summary>
        ///     Handles the drop event
        /// </summary>
        /// <param name="sourceNode"></param>
        public override void AcceptDrop(BaseTreeNode sourceNode)
        {
            base.AcceptDrop(sourceNode);

            ActionTreeNode action = sourceNode as ActionTreeNode;

            if (action != null)
            {
                action.Delete();
                Item.appendActions(action.Item);
            }

            ExpectationTreeNode expectation = sourceNode as ExpectationTreeNode;

            if (expectation != null)
            {
                expectation.Delete();
                Item.appendExpectations(expectation.Item);
            }
        }
Beispiel #31
0
        public void Test_ToStrategicString()
        {
            ChanceTreeNode d0 = new ChanceTreeNode {
                Position = 0, Card = 1
            };
            ChanceTreeNode d1 = new ChanceTreeNode {
                Position = 1, Card = 22
            };
            ActionTreeNode p0 = new ActionTreeNode {
                Position = 0, Amount = 5.3
            };
            ActionTreeNode p1 = new ActionTreeNode {
                Position = 1, Amount = 3.2
            };

            IStrategicAction [] actions = new IStrategicAction [] { d0, d1, p0, p1 };

            string s = StrategicString.ToStrategicString(actions, null);

            Assert.AreEqual("0d1 1d22 0p5.3 1p3.2", s);
        }
Beispiel #32
0
        void InsertAction(int pos)
        {
            Widget wrapper = Widget.Lookup(this);

            using (wrapper.UndoManager.AtomicChange) {
                Wrapper.Action ac   = (Wrapper.Action)ObjectWrapper.Create(wrapper.Project, new Gtk.Action("", "", null, null));
                ActionTreeNode node = new ActionTreeNode(Gtk.UIManagerItemType.Menu, "", ac);
                actionTree.Children.Insert(pos, node);

                ActionMenuItem aitem = FindMenuItem(node);
                aitem.EditingDone += OnEditingDone;
                aitem.Select();
                aitem.StartEditing();

                if (wrapper.LocalActionGroups.Count == 0)
                {
                    wrapper.LocalActionGroups.Add(new ActionGroup("Default"));
                }
                wrapper.LocalActionGroups[0].Actions.Add(ac);
            }
        }
 public void Select(ActionTreeNode node)
 {
     if (node != null)
     {
         ActionMenuItem item = FindMenuItem(node);
         if (item != null)
         {
             item.Select();
         }
     }
     else
     {
         if (menuItems.Count > 0)
         {
             ((ActionMenuItem)menuItems [0]).Select();
         }
         else
         {
             InsertAction(0);
         }
     }
 }
		public override void Visit(ActionTreeNode node)
		{
			var type = typeStack.Peek();
			var actionArgumentTypes = new List<string>();

			var method = new CodeMemberMethod
			{
				Name = node.Name,
				ReturnType = source[typeof (IControllerActionReference)],
				Attributes = MemberAttributes.Public
			};

			method.CustomAttributes.Add(source.DebuggerAttribute);
			
			var actionArguments = CreateActionArgumentsAndAddParameters(method, node, actionArgumentTypes);
			
			method.Statements.Add(new CodeMethodReturnStatement(CreateNewActionReference(node, actionArguments, actionArgumentTypes)));
			type.Members.Add(method);

			if (actionArguments.Count > 0 && occurences[node.Name] == 1)
			{
				method = new CodeMemberMethod
				{
					Name = node.Name,
					ReturnType = source[typeof (IArgumentlessControllerActionReference)],
					Attributes = MemberAttributes.Public
				};

				method.CustomAttributes.Add(source.DebuggerAttribute);
				method.Comments.Add(new CodeCommentStatement("Empty argument Action... Not sure if we want to pass MethodInformation to these..."));
				method.Statements.Add(new CodeMethodReturnStatement(CreateNewActionReference(node, new List<CodeExpression>(), actionArgumentTypes)));
				
				type.Members.Add(method);
			}

			base.Visit(node);
		}
Beispiel #35
0
        public void VisitActionNode_NullableParameter_CreatesMethod()
        {
            var node = new ActionTreeNode("Index");

            controller.AddChild(node);
            node.AddChild(new ParameterTreeNode("id", "System.Nullable<System.Int32>"));

            generator.Visit(controller);

            var type = source.Ccu.Namespaces[0].Types[0];

            CodeDomAssert.AssertHasField(type, "_services");
            CodeDomAssert.AssertHasMethod(type, "Index");

            var method = type.Members.OfType <CodeMemberMethod>().First(m => m.Name == "Index");

            CodeDomAssert.AssertHasParameter(method, "id");

            var parameter = method.Parameters.OfType <CodeParameterDeclarationExpression>().First(p => p.Name == "id");

            Assert.AreEqual("System.Nullable`1", parameter.Type.BaseType);
            Assert.AreEqual(1, parameter.Type.TypeArguments.Count);
            Assert.AreEqual("System.Int32", parameter.Type.TypeArguments[0].BaseType);
        }
		protected CodeExpression CreateNewActionReference(ActionTreeNode node, List<CodeExpression> actionArguments, List<string> actionArgumentTypes)
		{
			var actionArgumentRuntimeTypes = new List<CodeExpression>();
			foreach (var type in actionArgumentTypes)
				actionArgumentRuntimeTypes.Add(new CodeTypeOfExpression(source[type]));
			
			CodeExpression createMethodSignature = new CodeObjectCreateExpression(
				source[typeof (MethodSignature)],
				new CodeExpression[]
				{
					new CodeTypeOfExpression(node.Controller.FullName),
					new CodePrimitiveExpression(node.Name),
					new CodeArrayCreateExpression(source[typeof (Type)], actionArgumentRuntimeTypes.ToArray())
				});

			var constructionArguments = new[]
			{
				new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), naming.ToMemberVariableName(serviceIdentifier)),
				new CodeTypeOfExpression(node.Controller.FullName),
				new CodePrimitiveExpression(node.Controller.Area),
				new CodePrimitiveExpression(naming.ToControllerName(node.Controller.Name)),
				new CodePrimitiveExpression(node.Name),
				createMethodSignature,
				new CodeArrayCreateExpression(source[typeof (ActionArgument)], actionArguments.ToArray())
			};

			return new CodeMethodInvokeExpression(
				new CodeMethodReferenceExpression(
					new CodePropertyReferenceExpression(
						new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), naming.ToMemberVariableName(serviceIdentifier)),
						"ControllerReferenceFactory"),
					"CreateActionReference"),
				constructionArguments);
		}
Beispiel #37
0
		public virtual void Visit(ActionTreeNode node)
		{
			Accept(node.Children);
		}
		public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
		{
			if ((methodDeclaration.Modifier & Modifiers.Public) != Modifiers.Public)
				return null;
			
			var controllerNode = (ControllerTreeNode) treeService.Peek;

			if (controllerNode is WizardControllerTreeNode)
			{
				var wizardControllerInterface = typeof (IWizardController);
				var methodInfos = wizardControllerInterface.GetMethods(BindingFlags.Public | BindingFlags.Instance);

				if ((methodDeclaration.Name == "GetSteps") && (methodDeclaration.Body.Children.Count > 0))
				{
					(controllerNode as WizardControllerTreeNode).WizardStepPages = GetWizardStepPages(methodDeclaration.Body);
					return null;
				}
				
				if (Array.Exists(methodInfos, methodInfo => methodInfo.Name == methodDeclaration.Name))
					return null;
			}

			var action = new ActionTreeNode(methodDeclaration.Name);

			foreach (var parameter in methodDeclaration.Parameters)
			{
				var type = TypeResolver.Resolve(parameter.TypeReference);
				action.AddChild(new ParameterTreeNode(parameter.ParameterName, type));
			}

			foreach (var attributeSection in methodDeclaration.Attributes)
			{
				var attributes = attributeSection.Attributes.FindAll(attribute => attribute.Name == "StaticRoute");

				foreach (var attribute in attributes)
				{
					var name = (PrimitiveExpression) attribute.PositionalArguments[0];
					var pattern = (PrimitiveExpression) attribute.PositionalArguments[1];
					var routeTreeNode = new StaticRouteTreeNode((string) name.Value, (string) pattern.Value);

					action.AddChild(routeTreeNode);
				}

				attributes = attributeSection.Attributes.FindAll(attribute => attribute.Name == "PatternRoute");

				foreach (var attribute in attributes)
				{
					var name = (PrimitiveExpression) attribute.PositionalArguments[0];
					var pattern = (PrimitiveExpression) attribute.PositionalArguments[1];
					var defaults = new string[attribute.PositionalArguments.Count - 2];

					for (var i = 0; i < defaults.Length; i++)
						defaults[i] = (string) ((PrimitiveExpression) attribute.PositionalArguments[2 + i]).Value;

					var routeTreeNode = new PatternRouteTreeNode((string) name.Value, (string) pattern.Value, defaults);
					
					action.AddChild(routeTreeNode);
				}
			}

			if ((controllerNode.RestRoutesDescriptor != null) && (RestActions.Contains(methodDeclaration.Name.ToLower())))
			{
				var name = controllerNode.RestRoutesDescriptor.Name + "_" + methodDeclaration.Name;
				
				if (!action.Children.Any(c => c.Name == name))
				{
					var pattern = CollectionRestActions.Contains(methodDeclaration.Name.ToLower())
						? controllerNode.RestRoutesDescriptor.Collection
						: controllerNode.RestRoutesDescriptor.Collection + controllerNode.RestRoutesDescriptor.Identifier;

					var node = new RestRouteTreeNode(
						name, 
						pattern, 
						RestVerbs[Array.IndexOf(RestActions, methodDeclaration.Name.ToLower())], 
						controllerNode.RestRoutesDescriptor.RestVerbResolverType);

					action.AddChild(node);
				}
			}

			controllerNode.AddChild(action, true);

			return base.VisitMethodDeclaration(methodDeclaration, data);
		}
		protected List<CodeExpression> CreateActionArgumentsAndAddParameters(CodeMemberMethod method, ActionTreeNode node, List<string> actionArgumentTypes)
		{
			var actionArguments = new List<CodeExpression>();
			var index = 0;
			var parameters = node.Children.FindAll(t => t is ParameterTreeNode);

			foreach (ParameterTreeNode parameterInfo in parameters)
			{
				var newParameter = new CodeParameterDeclarationExpression
				{
					Name = parameterInfo.Name,
					Type = source[parameterInfo.Type]
				};

				method.Parameters.Add(newParameter);
				actionArgumentTypes.Add(parameterInfo.Type);

				var argumentCreate =
					new CodeObjectCreateExpression(source[typeof (ActionArgument)], new CodeExpression[]
					{
						new CodePrimitiveExpression(index++),
						new CodePrimitiveExpression(parameterInfo.Name),
						new CodeTypeOfExpression(newParameter.Type),
						new CodeArgumentReferenceExpression(parameterInfo.Name)
					});

				actionArguments.Add(argumentCreate);
			}
			return actionArguments;
		}