Пример #1
0
        public Command Copy()
        {
            Type            type        = GetType();
            ConstructorInfo constructor = type.GetConstructor(new Type[0]);

            if (constructor == null)
            {
                return(null);
            }
            object result = constructor.Invoke(new object[0]);

            if (result == null)
            {
                return(null);
            }

            PropertyInfo[] properties = type.GetProperties();
            foreach (PropertyInfo property in properties)
            {
                GinArgumentAttribute attr = property.GetCustomAttributes(true).OfType <GinArgumentAttribute>().FirstOrDefault();
                if (attr != null)
                {
                    object propertyValue = property.GetValue(this, null);
                    property.SetValue(result, propertyValue, null);
                }
            }

            return((Command)result);
        }
Пример #2
0
        public static void CreateNodeEditor(CommandTreeNode node, object editedObject, Control container, PackageBody body, PropertyHelpCallback helpCallback)
        {
            container.Controls.Clear();
            FlowLayoutPanel flowPanel;

            if (container is FlowLayoutPanel)
            {
                flowPanel = (FlowLayoutPanel)container;
            }
            else
            {
                flowPanel = new FlowLayoutPanel();
                container.Controls.Add(flowPanel);
                flowPanel.FlowDirection = FlowDirection.TopDown;
                flowPanel.Dock          = DockStyle.Fill;
            }
            Type type       = editedObject.GetType();
            var  properties = type.GetProperties();

            foreach (var currentProperty in properties)
            {
                GinArgumentAttribute argumentAttr = (GinArgumentAttribute)currentProperty.GetCustomAttributes(typeof(GinArgumentAttribute), false).FirstOrDefault();
                bool isArgument = argumentAttr != null;
                if (isArgument)
                {
                    object  value   = currentProperty.GetValue(editedObject, null);
                    Control control = null;
                    control = argumentAttr.GetEditor(value, currentProperty.Name, body, new PropertyChangedDelegate(
                                                         (propertyName, propertyValue) =>
                    {
                        PropertyInfo changedProperty = type.GetProperty(propertyName);
                        if (changedProperty != null)
                        {
                            changedProperty.SetValue(editedObject, propertyValue, null);
                            if (editedObject is Command)
                            {
                                string name = ((Command)editedObject).GetHumanReadableName();
                                if (name != node.NodeName)
                                {
                                    node.NodeName = name;
                                }
                            }
                        }
                    }),
                                                     new PropertyActivatedDelegate(propertyName =>
                    {
                        if (helpCallback != null)
                        {
                            helpCallback(propertyName, argumentAttr.Name, argumentAttr.Description, argumentAttr.AllowTemplates, control as ITemplatedEditor);
                        }
                    }));
                    if (control != null)
                    {
                        control.Tag = currentProperty;
                        flowPanel.Controls.Add(control);
                    }
                }
            }
        }
Пример #3
0
 public abstract CommandTreeNode AppendChild(Command command, GinNameAttribute commandAttribute, PropertyInfo property, GinArgumentAttribute propertyAttribute);
Пример #4
0
        public override CommandTreeNode AppendChild(Command command, GinNameAttribute commandAttribute, PropertyInfo property, GinArgumentAttribute propertyAttribute)
        {
            var         acceptNot        = property.GetCustomAttributes(typeof(GinArgumentCommandAcceptNotAttribute), false);
            List <Type> notAcceptedTypes = null;

            if (acceptNot != null)
            {
                notAcceptedTypes = new List <Type>();
                foreach (var item in acceptNot)
                {
                    notAcceptedTypes.Add(((GinArgumentCommandAcceptNotAttribute)item).NotAcceptedType);
                }
            }
            var         acceptOnly    = property.GetCustomAttributes(typeof(GinArgumentCommandAcceptOnlyAttribute), false);
            List <Type> acceptedTypes = null;

            if (acceptOnly != null)
            {
                acceptedTypes = new List <Type>();
                foreach (var item in acceptOnly)
                {
                    acceptedTypes.Add(((GinArgumentCommandAcceptOnlyAttribute)item).AcceptedType);
                }
            }
            TreeNode node = new TreeNode()
            {
                Text               = propertyAttribute.Name,
                ToolTipText        = propertyAttribute.Description,
                ImageIndex         = 1,
                SelectedImageIndex = 1,
                Tag = new TreeNodeData()
                {
                    Command           = command,
                    CommandAttribute  = commandAttribute,
                    Property          = property,
                    PropertyAttribute = propertyAttribute,
                    AcceptedTypes     = acceptedTypes.ToArray(),
                    NotAcceptedTypes  = notAcceptedTypes.ToArray()
                }
            };

            _node.Nodes.Add(node);
            TreeViewTreeNode treeNode = new TreeViewTreeNode(node);

            ((TreeNodeData)node.Tag).Node = treeNode;
            return(treeNode);
        }