Пример #1
0
 public void AddFieldContainer(IFieldControlContainer controlContainer)
 {
     if (FieldPanel != null)
     {
         FieldPanel.AddFieldContainer(controlContainer);
     }
 }
Пример #2
0
 public void AddFieldContainer(IFieldControlContainer controlContainer)
 {
     Controls.Add(controlContainer as Control);
     if (controlContainer is IDynamicContainer)
     {
         if (GetParent() != null)
         {
             (controlContainer as IDynamicContainer).Parent = GetParent();
         }
     }
 }
Пример #3
0
        private void LoadTab(TabArguments tabArgs)
        {
            this.tagData       = tabArgs.TagData;
            this.tagDefinition = tabArgs.TagDefinition;
            //XmlNode nameNode = tabArgs.NameNode;
            XmlNode mainNode = tabArgs.MainNode;
            int     maxDepth = tabArgs.MaxDepth;

            //tagDefinition = tabArgs.TagDefinition;
            containers.Push(tabArgs.Container);

            className = tagDefinition.SelectSingleNode("//xml/name").InnerText;

            buildDepth.Push(0);

            tabArgs.MainBlockGlobals = new ContainerGlobals(null, mainNode, maxDepth);
            tabArgs.MainBlockGlobals.DepthDifference = maxDepth;
            tabArgs.MainBlockGlobals.TagDefinition   = tabArgs.TagDefinition;

            // This is the top-most block container and is placed directly into the tab, because CreateTab pushes itself onto the stack.
            BlockContainerPanel container = BuildStruct(tabArgs.MainBlockGlobals);

            container.Location        = new Point((containers.Peek() as Control).Margin.Left, (containers.Peek() as Control).Margin.Top);
            container.DepthDifference = maxDepth;
            container.DatabindChildrenToBlock(tagData);
            container.AutoSizeMode = Prometheus.Controls.TagEditor.AutoSizeType.GrowAndShrink | Prometheus.Controls.TagEditor.AutoSizeType.WidthAndHeight;
            container.DrawBorder   = true;

            IFieldControlContainer cont = containers.Peek();

            cont.AddFieldContainer(container);

            buildDepth.Pop();

            ConnectBlocks(container);
            tabArgs.IsLoaded = true;

            //AttachedControl_SizeChanged(tabControl.Tabs[tabControl.TabIndex].AttachedControl, null);
        }
Пример #4
0
        public void DatabindChildrenToBlock(IBlock block, IFieldControlContainer container)
        {
            #region Old Method

            /*linkedBlock = block;
             *
             * if (block != null)
             * {
             * int index = -1;
             * IFieldControl[] childFields = GetChildFields();
             * foreach (FieldControlBase field in childFields)
             * {
             *  index++;
             *  field.Enabled = true;
             *
             *  try
             *  {
             *    // If the field is not a block, we will need to databind it.
             *    if (!(field is IBlockControl))
             *    {
             *      IField binding = (LocateFieldByName(linkedBlock, field.BoundPropertyName) as IField);
             *      if (binding != null)
             *      {
             *        field.DataBind(binding);
             *        Binding[] bindings = field.GetDataBindings();
             *        foreach (Binding bind in bindings)
             *        {
             *          bind.Parse += bind_Parse;
             *        }
             *      }
             *    }
             *    // If it is a block, we need to recurse on the block so that its children get databound.
             *    else
             *    {
             *      IBlockCollection binding = LocateFieldByName(linkedBlock, field.BoundPropertyName) as IBlockCollection;
             *      if (binding != null)
             *      {
             *        (field as IBlockControl).DataBindCollection(binding);
             *        (field as IBlockControl).Initialize();
             *      }
             *      else
             *        field.Enabled = false;
             *    }
             *  }
             *  catch (Exception ex)
             *  {
             *    Interfaces.Output.Write(Interfaces.OutputTypes.Warning, "There was an error databinding to " + field.BoundPropertyName + ":" + ex.Message, ex);
             *    //MessageBox.Show("There was an error binding \"" + field.BoundPropertyName + ":\" " + ex.Message);
             *  }
             * }
             * }
             * else
             * {
             * foreach (FieldControlBase field in GetChildFields())
             *  field.Enabled = false;
             * }*/
            #endregion

            #region New Method
            if (container is FieldContainerBase)
            {
                container = (container as FieldContainerBase).FieldPanel;
            }
            if (container == null)
            {
                return;
            }
            //(container as Control).Enabled = (block != null);
            if (block == null)
            {
                IFieldControl[] children = container.GetChildFields();
                foreach (FieldControlBase field in children)
                {
                    field.Enabled = false;
                }
                return;
            }

            Control control = container as Control;
            // This is a bug-fix. At some point along the line, databinding was attached to an FieldContainerBase... so to fix it, we relink to the FieldPanel property.
            if (container is FieldContainerBase)
            {
                control = (container as FieldContainerBase).FieldPanel;
            }

            for (int x = 0; x < control.Controls.Count; x++)
            {
                Control curControl = control.Controls[x];
                curControl.Visible = true;

                // Determine whether or not the field is a FieldControlBase or not.
                FieldControlBase field = (curControl is FieldControlBase) ? curControl as FieldControlBase : null;

                #region the current control is a field
                if (field != null)
                {
                    field.Enabled = true;
                    #region If the field is not a block, we will need to databind it.
                    if (!(field is IBlockControl))
                    {
                        IField binding = (LocateFieldByName(block, field.BoundPropertyName) as IField);
                        if (binding != null)
                        {
                            field.DataBind(binding);
                            Binding[] bindings = field.GetDataBindings();
                            foreach (Binding bind in bindings)
                            {
                                bind.Parse += bind_Parse;
                            }
                        }
                        else
                        {
                            field.Enabled = false;
                        }
                    }
                    #endregion
                    else // This shouldn't happen, EVER!
                    {
                        Interfaces.Output.Write(Interfaces.OutputTypes.Information, "DatabindChildrenToBlock came across an IBlockControl.");
                    }
                }
                #endregion
                #region the current control is a block container.
                else if (curControl is Prometheus.Controls.BlockContainer)
                {
                    Prometheus.Controls.BlockContainer blockContainer = curControl as Prometheus.Controls.BlockContainer;
                    blockContainer.Enabled = true;
                    IBlock nextBlock = null;
                    BlockContainerPanel nextContainer = null;

                    #region get the next container
                    // We're getting all of the controls of type FieldContainerPanel, though there should only be one.

                    /*Control[] fieldContainerPanels = GetChildControlsByType(blockContainer, typeof(BlockContainerPanel));
                     * if (fieldContainerPanels.Length > 0)
                     * {
                     * nextContainer = fieldContainerPanels[0] as BlockContainerPanel;
                     * }
                     * else
                     * {
                     * // This is a warning because the rest of the tag will work properly and execution can continue as normal.
                     * Interfaces.Output.Write(Interfaces.OutputTypes.Warning, "During databinding, the block \"" + blockContainer.BoundPropertyName + "\" did not have a field container panel!");
                     * continue;
                     * }*/
                    if (blockContainer.FieldPanel != null)
                    {
                        nextContainer = blockContainer.FieldPanel;
                    }

                    #endregion

                    #region get the next block

                    /*Control[] blocks = GetChildControlsByType(blockContainer, typeof(IBlockControl));
                     * if (blocks.Length > 0)
                     * {
                     * IBlockControl blockControl = blocks[0] as IBlockControl;
                     * blockControl.Container = nextContainer as IFieldControlContainer;
                     * IBlockCollection binding = LocateFieldByName(block, (blockControl as IBoundPropertyCapable).BoundPropertyName) as IBlockCollection;
                     * if (binding != null)
                     * {
                     *  blockControl.DataBindCollection(binding);
                     *  blockControl.Initialize();
                     * }
                     * }
                     * else
                     * {
                     * Interfaces.Output.Write(Interfaces.OutputTypes.Warning, "During databinding, the block \"" + blockContainer.BoundPropertyName + "\" did not have an IBlockControl!");
                     * continue;
                     * }*/
                    if (blockContainer.Block != null)
                    {
                        IBlockControl blockControl = blockContainer.Block;
                        if (blockContainer.FieldPanel == null)
                        {
                            blockControl.Container = blockContainer;
                        }
                        else
                        {
                            blockControl.Container = blockContainer.FieldPanel;
                        }
                        IBlockCollection binding = LocateFieldByName(block, (blockControl as IBoundPropertyCapable).BoundPropertyName) as IBlockCollection;
                        if (binding != null)
                        {
                            blockControl.DataBindCollection(binding);
                            blockControl.Initialize();
                        }
                        if (blockControl.SelectedBlockIndex > -1)
                        {
                            nextBlock = blockControl.BlockCollection.GetBlock(blockControl.SelectedBlockIndex);
                        }
                    }
                    #endregion

                    if ((nextBlock != null) && (nextContainer != null))
                    {
                        DatabindChildrenToBlock(nextBlock, nextContainer);
                    }
                }
                else if (curControl is FieldContainerBase)
                {
                    FieldContainerBase fieldContainer = curControl as FieldContainerBase;
                    fieldContainer.Enabled = true;

                    DatabindChildrenToBlock(block, fieldContainer.FieldPanel);
                }
                #endregion
            }
            #endregion
        }
Пример #5
0
        /// <summary>
        /// Builds a BlockContainer control, populating it with the appropriate controls
        /// based on the supplied XML TDF data.
        /// </summary>
        protected BlockContainerPanel BuildStruct(ContainerGlobals globals)
        {
            XmlNode node      = globals.BlockNode;
            bool    mainBlock = globals.MainBlock;
            int     maxDepth  = globals.MaxDepth;

            //int depth = (int)buildDepth.Peek();

            // Setup the block container.
            BlockContainerPanel container = new BlockContainerPanel();

            container.Name = node.Attributes["name"].Value;
            container.SuspendLayout();
            container.Location          = new Point(0, 0);
            container.LinkedUndoManager = undoManager;
            container.LinkedUndoManager.StateChanged += new StateChangedHandler(LinkedUndoManager_StateChanged);
            containers.Push(container);

            XmlNodeList valueNodes = node.SelectNodes("*");

            foreach (XmlNode valueNode in valueNodes)
            {
                if (valueNode.Name.ToLower() == "group")
                {
                    ProcessGroup(container, valueNode, mainBlock, maxDepth);
                }
                else if (valueNode.Name.ToLower() == "section")
                {
                    ProcessSection(globals, valueNode, mainBlock, maxDepth);
                }
                else if (valueNode.Name.ToLower() == "region")
                {
                    ProcessRegion(globals, valueNode, mainBlock, maxDepth);
                }
                else if (valueNode.Name.ToLower() == "value")
                {
                    string        valueName = valueNode.Attributes["name"].InnerText;
                    IFieldControl fieldControl;
                    string        valueText        = valueNode.Attributes["type"].InnerText;
                    string        fullPropertyName = (mainBlock ? className + "Values." : "") + GlobalMethods.MakePublicName(valueName);

                    // Create the proper control based on the name that we got from the XML.
                    if (gameDefinition.FieldControlTable.ContainsKey(valueText))
                    {
                        Type     fieldControlType = gameDefinition.FieldControlTable[valueText];
                        Assembly targetAssembly   = Assembly.GetAssembly(fieldControlType);
                        fieldControl = (targetAssembly.CreateInstance(fieldControlType.FullName) as IFieldControl);

                        fieldControl.Configure(valueNode);
                        //((Control)fieldControl).Font = new Font("Verdana", 6.75f); // Set in Interfaces\TagEditor\FieldControl.cs
                        if (valueText != "Block")
                        {
                            // If this is a tag reference control, hook up its events.
                            if (fieldControl is ITagReferenceControl)
                            {
                                (fieldControl as ITagReferenceControl).OpenTag += new OpenTagEventHandler(TagEditorControl_OpenTag);
                            }

                            IFieldControlContainer c = containers.Peek();
                            c.AddField(fieldControl);
                            (fieldControl as Control).Visible = true;
                        }
                        else
                        {
                            ProcessBlock(globals, valueNode, fieldControl, fullPropertyName);
                        }
                    }
                    else
                    {
                        continue;
                    }
                    fieldControl.BoundPropertyName = fullPropertyName;
                }
            }
//      depth = (int)(buildDepth.Pop());
//    buildDepth.Push(depth - 1);
            containers.Pop();
            container.ResumeLayout(false);
            container.Width = container.Width;
            return(container);
        }