// Get the content string for the selected region. Called by the designer host
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion Region)
        {
            // Get a reference to the designer host
            System.ComponentModel.Design.IDesignerHost host = (System.ComponentModel.Design.IDesignerHost)(Component.Site.GetService(typeof(System.ComponentModel.Design.IDesignerHost)));

            if (host != null)
            {
                ITemplate template = null;
                switch (Region.Name)
                {
                case "FirstPanel":
                    template = Control.FirstPanel;
                    break;

                case "SecondPanel":
                    template = Control.SecondPanel;
                    break;
                }

                // Persist the template in the design host
                if (template != null)
                {
                    return(ControlPersister.PersistTemplate(template, host));
                }
            }

            return(string.Empty);
        }
Beispiel #2
0
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));

            if (host != null && region != null)
            {
                string[] parameters = region.Name.Split('_');

                if (parameters.Length == 2 && parameters[0] == "Body")
                {
                    int activeIndex = int.Parse(parameters[1]);

                    if (activeIndex >= 0)
                    {
                        PanelBase tab = this.tabPanelControl.Items[activeIndex] as PanelBase;

                        if (tab != null && tab is IContent)
                        {
                            ITemplate contentTemplate = ((IContent)tab).Content;

                            if (contentTemplate != null)
                            {
                                return(ControlPersister.PersistTemplate(contentTemplate, host));
                            }
                        }
                    }
                }
            }

            return(String.Empty);
        }
Beispiel #3
0
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost service = (IDesignerHost)CurrentControl.Site.GetService(typeof(IDesignerHost));

            if (service != null)
            {
                if (region.Name == "Items")
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (ControlBase c in CurrentControl.Items)
                    {
                        sb.Append(ControlPersister.PersistControl(c, service));
                    }
                    //sb.Append(ControlPersister.PersistControl(CurrentControl.Items[1], service));
                    //sb.Append("<ext:CheckBox runat=\"server\" Text=\"Click to postback\" Checked=\"True\" AutoPostBack=\"True\" Label=\"CheckBox\" ID=\"CheckBox1\" __designer:mapid=\"4\" OnCheckedChanged=\"CheckBox1_CheckedChanged\"></ext:CheckBox>");
                    //sb.Append("<ext:CheckBox runat=\"server\" Text=\"Click to postback\" Checked=\"True\" AutoPostBack=\"True\" Label=\"CheckBox\" ID=\"CheckBox1\" OnCheckedChanged=\"CheckBox1_CheckedChanged\"></ext:CheckBox>");
                    return(sb.ToString());
                }
                else if (region.Name == "Toolbars")
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (Toolbar c in CurrentControl.Toolbars)
                    {
                        sb.Append(ControlPersister.PersistControl(c, service));
                    }
                    return(sb.ToString());
                }
            }
            return(String.Empty);
        }
Beispiel #4
0
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost service = (IDesignerHost)CurrentControl.Site.GetService(typeof(IDesignerHost));

            if (service != null)
            {
                if (region.Name == "Items")
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (ControlBase c in CurrentControl.Items)
                    {
                        sb.Append(ControlPersister.PersistControl(c, service));
                    }
                    return(sb.ToString());
                }
                else if (region.Name == "Toolbars")
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (Toolbar c in CurrentControl.Toolbars)
                    {
                        sb.Append(ControlPersister.PersistControl(c, service));
                    }
                    return(sb.ToString());
                }
            }
            return(String.Empty);
        }
Beispiel #5
0
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));

            if (host != null && region != null)
            {
                string[] parameters = region.Name.Split('_');

                if (parameters.Length == 2 && parameters[0] == "Body")
                {
                    int activeIndex = int.Parse(parameters[1]);

                    if (activeIndex >= 0)
                    {
                        ContentPanel panel = this.layout.Items[activeIndex] as ContentPanel;
                        if (panel != null)
                        {
                            ITemplate contentTemplate = panel.Body;

                            if (contentTemplate != null)
                            {
                                return(ControlPersister.PersistTemplate(contentTemplate, host));
                            }
                        }
                    }
                }
            }
            return(String.Empty);
        }
Beispiel #6
0
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost service = (IDesignerHost)base.Component.Site.GetService(typeof(IDesignerHost));

            if (service != null)
            {
                int rowIndex = Convert.ToInt32(region.Properties["RowIndex"]);

                StringBuilder sb = new StringBuilder();

                foreach (ControlBase c in CurrentControl.Rows[rowIndex].Items)
                {
                    sb.Append(ControlPersister.PersistControl(c, service));
                }

                return(sb.ToString());

                #region old code

                // table不会自动更新,还不如先不用
                ////int rowIndex = Convert.ToInt32(region.Name.Substring(EDITOR_REGION_PREFIX.Length));

                //int rowIndex = Convert.ToInt32(region.Properties["RowIndex"]);

                //ControlBaseCollection controls = CurrentControl.Rows[rowIndex].Items;

                //StringBuilder sb = new StringBuilder();
                //sb.Append("<table cellpadding='0' cellspacing='0' border='0' style='width:100%;'><tbody><tr>");

                //string columnWidthStr = (1.0 / controls.Count * 100).ToString("F0") + "%";

                //if (controls.Count == 0)
                //{
                //    sb.Append("<td style='width:100%;'></td>");
                //}
                //else
                //{
                //    foreach (ControlBase c in controls)
                //    {
                //        sb.AppendFormat("<td style='width:{0};'>", columnWidthStr);

                //        sb.Append(ControlPersister.PersistControl(c, service));

                //        sb.Append("</td>");
                //    }
                //}

                //sb.Append("</tr></tbody></table>");
                ////sb.Append(ControlPersister.PersistControl(CurrentControl.Rows[rowIndex].Fields[columnIndex], service));

                //return sb.ToString();

                #endregion
            }
            return(String.Empty);
        }
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            ITemplate template = this.GetTemplate(this._changePassword);

            if (template == null)
            {
                return(this.GetEmptyDesignTimeHtml());
            }
            IDesignerHost service = (IDesignerHost)this.GetService(typeof(IDesignerHost));

            return(ControlPersister.PersistTemplate(template, service));
        }
 public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
 {
     if (region is LoginViewDesignerRegion)
     {
         ITemplate template = ((LoginViewDesignerRegion)region).Template;
         if (template != null)
         {
             IDesignerHost service = (IDesignerHost)base.Component.Site.GetService(typeof(IDesignerHost));
             return(ControlPersister.PersistTemplate(template, service));
         }
     }
     return(base.GetEditableDesignerRegionContent(region));
 }
Beispiel #9
0
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));

            if (host != null)
            {
                ITemplate template = this.viewPort.Body;

                if (template != null && this.viewPort.Layout != null)
                {
                    return(ControlPersister.PersistTemplate(template, host));
                }
            }
            return(string.Empty);
        }
Beispiel #10
0
        /// <summary>
        /// 设置设计态的内容
        /// </summary>
        /// <param name="region"></param>
        /// <returns></returns>
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));

            if (host != null)
            {
                ITemplate contentTemplate;
                if (this.currentRegion == 0)
                {
                    contentTemplate = this.deluxeGrid.GridPagerTemplate;
                    return(ControlPersister.PersistTemplate(contentTemplate, host));
                }
            }
            return(String.Empty);
        }
Beispiel #11
0
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            var rldRegion = region as ReorderListDesignerRegion;

            if (rldRegion != null)
            {
                var template = rldRegion.Template;
                if (template != null)
                {
                    var host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));
                    return(ControlPersister.PersistTemplate(template, host));
                }
            }
            return(base.GetEditableDesignerRegionContent(region));
        }
Beispiel #12
0
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost host = (IDesignerHost)this.Component.Site.GetService(typeof(IDesignerHost));

            if (host != null)
            {
                string[] parameters = region.Name.Split('_');

                if (parameters.Length == 3 && parameters[0] == "Body")
                {
                    BorderLayoutRegion layoutRegion = this.GetLayoutRegionByName(parameters[1]);

                    if (layoutRegion != null && layoutRegion.Items.Count > 0)
                    {
                        int      activeIndex  = int.Parse(parameters[2]);
                        IContent contentPanel = null;

                        if (layoutRegion.Items[0] is Panel)
                        {
                            contentPanel = layoutRegion.Items[0] as Panel;
                        }
                        else if (layoutRegion.Items[0] is TabPanel)
                        {
                            TabPanel tabPanel = layoutRegion.Items[0] as TabPanel;

                            if (activeIndex < tabPanel.Items.Count)
                            {
                                contentPanel = tabPanel.Items[activeIndex] as IContent;
                            }
                        }

                        if (contentPanel == null)
                        {
                            return("");
                        }

                        ITemplate contentTemplate = contentPanel.Content;

                        if (contentTemplate != null)
                        {
                            return(ControlPersister.PersistTemplate(contentTemplate, host));
                        }
                    }
                }
            }

            return("");
        }
Beispiel #13
0
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            if (region is EntityRightsViewDesignerRegion)
            {
                var template = ((EntityRightsViewDesignerRegion)region).Template;

                if (template != null)
                {
                    var service = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));

                    return(ControlPersister.PersistTemplate(template, service));
                }
            }

            return(base.GetEditableDesignerRegionContent(region));
        }
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));

            if (host != null)
            {
                ITemplate template = ((Component)this.Control).Content as ITemplate;

                if (template != null)
                {
                    return(ControlPersister.PersistTemplate(template, host));
                }
            }

            return("");
        }
Beispiel #15
0
        public override string GetEditableDesignerRegionContent(System.Web.UI.Design.EditableDesignerRegion Region)
        {
            IDesignerHost host = (IDesignerHost)(Component.Site.GetService(typeof(IDesignerHost)));

            if (host != null)
            {
                ITemplate template = Control.ContentTemplate;
                // Persist the template in the design host
                if (template != null)
                {
                    return(ControlPersister.PersistTemplate(template, host));
                }
            }

            return(string.Empty);
        }
Beispiel #16
0
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost service = (IDesignerHost)base.Component.Site.GetService(typeof(IDesignerHost));

            if (service != null)
            {
                StringBuilder sb = new StringBuilder();

                foreach (ControlBase c in CurrentControl.Items)
                {
                    sb.Append(ControlPersister.PersistControl(c, service));
                }

                return(sb.ToString());
            }
            return(String.Empty);
        }
Beispiel #17
0
        private string GetTemplateContent(ITemplate template, string id)
        {
            DesignerPanel contentPanel = new DesignerPanel();

            contentPanel.ID = id;

            template.InstantiateIn(contentPanel);
            IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));

            Debug.Assert(host != null, "Failed to get IDesignerHost?!?");


            StringBuilder persistedControl = new StringBuilder(1024);

            foreach (System.Web.UI.Control c in contentPanel.Controls)
            {
                persistedControl.Append(ControlPersister.PersistControl(c, host));
            }
            return(persistedControl.ToString());
        }
Beispiel #18
0
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost host = (IDesignerHost)this.Component.Site.GetService(typeof(IDesignerHost));

            if (host != null)
            {
                string[] parameters = region.Name.Split('_');

                if (parameters.Length == 2 && parameters[0] == "Body" && this.fitLayout.Items.Count > 0)
                {
                    int          activeIndex  = int.Parse(parameters[1]);
                    ContentPanel contentPanel = null;

                    if (this.fitLayout.Items[0] is Panel)
                    {
                        contentPanel = this.fitLayout.Items[0] as Panel;
                    }
                    else if (this.fitLayout.Items[0] is TabPanel)
                    {
                        TabPanel tabPanel = this.fitLayout.Items[0] as TabPanel;

                        if (activeIndex < tabPanel.Tabs.Count)
                        {
                            contentPanel = tabPanel.Tabs[activeIndex];
                        }
                    }

                    if (contentPanel == null)
                    {
                        return(string.Empty);
                    }

                    ITemplate contentTemplate = contentPanel.Body;
                    if (contentTemplate != null)
                    {
                        return(ControlPersister.PersistTemplate(contentTemplate, host));
                    }
                }
            }
            return(string.Empty);
        }
Beispiel #19
0
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost service = (IDesignerHost)base.Component.Site.GetService(typeof(IDesignerHost));

            if (service != null)
            {
                if (region.Name == "Content")
                {
                    Tab tab = CurrentControl.Tabs[CurrentControl.ActiveTabIndex];

                    StringBuilder sb = new StringBuilder();
                    foreach (Control c in tab.Items)
                    {
                        sb.Append(ControlPersister.PersistControl(c, service));
                    }
                    return(sb.ToString());

                    // return ControlPersister.PersistControl(CurrentControl.Tabs[CurrentControl.ActiveTabIndex], service);
                }
            }
            return(String.Empty);
        }
Beispiel #20
0
        // Get the content string for the selected region. Called by the designer host?
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            // Get a reference to the designer host
            IDesignerHost host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));

            if (host != null)
            {
                ITemplate template = myControl.View1;
                if (region.Name == "Content1")
                {
                    template = myControl.View2;
                }

                // Persist the template in the design host
                if (template != null)
                {
                    return(ControlPersister.PersistTemplate(template, host));
                }
            }

            return(String.Empty);
        }
Beispiel #21
0
 private void ConvertPersistedControlsToLiteralControls(Control defaultTemplateContents)
 {
     foreach (string str in this.PersistedControlIDs)
     {
         Control control = defaultTemplateContents.FindControl(str);
         if (control != null)
         {
             if (Array.IndexOf <string>(this.PersistedIfNotVisibleControlIDs, str) >= 0)
             {
                 control.Visible               = true;
                 control.Parent.Visible        = true;
                 control.Parent.Parent.Visible = true;
             }
             if (control.Visible)
             {
                 LiteralControl    child    = new LiteralControl(ControlPersister.PersistControl(control, this._designerHost));
                 ControlCollection controls = control.Parent.Controls;
                 int index = controls.IndexOf(control);
                 controls.Remove(control);
                 controls.AddAt(index, child);
             }
         }
     }
 }
Beispiel #22
0
        ///<summary>Converts a designer document fragment to ASP.NET code</summary>
        public string Serialize(string designerDocumentFragment)
        {
            if (host == null)
            {
                throw new Exception("The document cannot be persisted without a host");
            }

            string       serializedDoc = string.Empty;
            StringWriter writer        = new StringWriter();

            //keep method argument meaningfully named, but keep code readable!
            string frag   = designerDocumentFragment;
            int    length = frag.Length;

            int   pos  = 0;
            SMode mode = SMode.Free;

            while (pos < length)
            {
                char c = frag [pos];

                switch (mode)
                {
                //it's freely copying to output, but watching for a directive or control placeholder
                case SMode.Free:
                    if (c == '<')
                    {
                        if ((pos + 10 < length) && frag.Substring(pos + 1, 10) == "aspcontrol")
                        {
                            mode = SMode.ControlId;
                            pos += 10;
                            break;
                        }
                        else if ((pos + 20 < length) && frag.Substring(pos + 1, 20) == "directiveplaceholder")
                        {
                            mode = SMode.DirectiveId;
                            pos += 20;
                            break;
                        }
                    }

                    writer.Write(c);
                    break;

                //it's found a directive placeholder and is scanning for the ID
                case SMode.DirectiveId:
                    if (c == 'i' && (pos + 4 < length) && frag.Substring(pos, 4) == "id=\"")
                    {
                        int idEnd = frag.IndexOf('"', pos + 4 + 1);
                        if (idEnd == -1)
                        {
                            throw new Exception("Identifier was unterminated");
                        }
                        int id = Int32.Parse(frag.Substring(pos + 4, (idEnd - pos - 4)));

                        //TODO: more intelligent removal/copying of directives in case of fragments
                        //works fine with whole document.
                        string directive = RemoveDirective(id);
                        writer.Write(directive);

                        mode = SMode.DirectiveEnd;
                        pos  = idEnd;
                    }
                    break;

                //it's found a control placeholder and is scanning for the ID
                case SMode.ControlId:
                    if (c == 'i' && (pos + 4 < length) && frag.Substring(pos, 4) == "id=\"")
                    {
                        int idEnd = frag.IndexOf("\"", pos + 4);
                        if (idEnd == -1)
                        {
                            throw new Exception("Identifier was unterminated");
                        }
                        string id = frag.Substring(pos + 4, (idEnd - pos - 4));

                        DesignContainer dc      = (DesignContainer)host.Container;
                        Control         control = dc.GetComponent(id) as Control;
                        if (control == null)
                        {
                            throw new Exception("Could not retrieve control " + id);
                        }
                        ControlPersister.PersistControl(writer, control);

                        mode = SMode.ControlEnd;
                        pos  = idEnd;
                    }
                    break;

                //it's found the control's ID and is looking for the end
                case SMode.ControlEnd:
                    if (c == '<' && (pos + 13 < length) && frag.Substring(pos, 13) == "</aspcontrol>")
                    {
                        pos += 12;
                        mode = SMode.Free;
                    }
                    break;

                //it's found the placeholder's ID and is looking for the end
                case SMode.DirectiveEnd:
                    if (c == '/' && (pos + 2 < length) && frag.Substring(pos, 2) == "/>")
                    {
                        pos += 1;
                        mode = SMode.Free;
                    }
                    break;
                }

                pos++;
            }

            serializedDoc = writer.ToString();
            writer.Close();

            return(serializedDoc);
        }
Beispiel #23
0
            // Displays a list of controls in the project, if any,
            // and displays the HTML markup for the selected control.
            private void saveControl()
            {
                // Get the collection of components in the current
                // design mode document.
                ComponentCollection documentComponents =
                    this.Component.Site.Container.Components;

                // Filter the components to those that derive from the
                // System.Web.UI.Control class.

                // Create an IComponent array of the maximum possible length needed.
                IComponent[] filterArray = new IComponent[documentComponents.Count];

                // Count the total qualifying components.
                int total = 0;

                for (int i = 0; i < documentComponents.Count; i++)
                {
                    // If the component derives from System.Web.UI.Control,
                    // copy a reference to the control to the filterArray
                    // array and increment the control count.
                    if (typeof(System.Web.UI.Control).IsAssignableFrom(
                            documentComponents[i].GetType()))
                    {
                        if (((System.Web.UI.Control)documentComponents[i]).UniqueID
                            != null)
                        {
                            filterArray[total] = documentComponents[i];
                            total++;
                        }
                    }
                }

                if (total == 0)
                {
                    throw new Exception(
                              "Document contains no System.Web.UI.Control components.");
                }

                // Move the components that derive from System.Web.UI.Control to a
                // new array of the correct size.
                System.Web.UI.Control[] controlArray =
                    new System.Web.UI.Control[total];
                for (int i = 0; i < total; i++)
                {
                    controlArray[i] = (System.Web.UI.Control)filterArray[i];
                }

                // Create a ControlSelectionForm to select a control.
                ControlSelectionForm selectionForm =
                    new ControlSelectionForm(controlArray);

                // Display the form.
                if (selectionForm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                // Validate the selection.
                if (selectionForm.controlList.SelectedIndex == -1)
                {
                    throw new Exception("You must select a control to persist.");
                }

                //<Snippet3>
                // Parse the selected control into a persistence string.
                string persistedData = ControlPersister.PersistControl(
                    controlArray[selectionForm.controlList.SelectedIndex]);
                //</Snippet3>

                // Display the persistence string in a text box.
                StringDisplayForm displayForm =
                    new StringDisplayForm(persistedData);

                displayForm.ShowDialog();
            }
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost service = (IDesignerHost)this.GetService(typeof(IDesignerHost));

            return(ControlPersister.PersistTemplate(this._login.LayoutTemplate, service));
        }
 public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
 {
     return(ControlPersister.PersistTemplate(this._zone.ZoneTemplate, (IDesignerHost)base.Component.Site.GetService(typeof(IDesignerHost))));
 }
        // Get string value from template
        string PersistTemplate(ITemplate template)
        {
            var host = (IDesignerHost)GetService(typeof(IDesignerHost));

            return(ControlPersister.PersistTemplate(template, host));
        }