Exemple #1
0
        protected virtual void SortFields([NotNull] TemplateSectionWriter templateSectionWriter)
        {
            var lastSortorder = 0;

            var fields = templateSectionWriter.Fields.ToList();

            for (var index = 0; index < fields.Count; index++)
            {
                var fieldWriter = fields.ElementAt(index);
                if (fieldWriter.Item == null)
                {
                    continue;
                }

                var sortorder = fieldWriter.Item.Appearance.Sortorder;

                if (sortorder <= lastSortorder)
                {
                    var nextSortorder = lastSortorder + 200;

                    if (index < fields.Count - 1)
                    {
                        var nextField = fields.ElementAt(index + 1);
                        if (nextField.Item != null)
                        {
                            nextSortorder = nextField.Item.Appearance.Sortorder;
                            if (nextSortorder < lastSortorder + 2)
                            {
                                nextSortorder = lastSortorder + 200;
                            }
                        }
                    }

                    sortorder = lastSortorder + (nextSortorder - lastSortorder) / 2;

                    using (new EditContext(fieldWriter.Item))
                    {
                        fieldWriter.Item.Appearance.Sortorder = sortorder;
                    }
                }

                lastSortorder = sortorder;
            }
        }
Exemple #2
0
        protected virtual void WriteSection([NotNull] TemplateSectionWriter templateSectionWriter, [NotNull] IEnumerable <Data.Templates.TemplateField> inheritedFields)
        {
            if (Item == null)
            {
                return;
            }

            var isNew = templateSectionWriter.Item == null;

            if (isNew)
            {
                var id = new ID(templateSectionWriter.TemplateSection.Id);
                templateSectionWriter.Item = Item.Database.AddFromTemplateSynchronized(templateSectionWriter.TemplateSection.Name, new TemplateID(TemplateIDs.TemplateSection), Item, id);
                if (templateSectionWriter.Item == null)
                {
                    throw new EmitException("Could not create section item");
                }
            }

            if (Item != null && templateSectionWriter.Item.ParentID != Item.ID)
            {
                templateSectionWriter.Item.MoveTo(Item);
            }

            using (new EditContext(templateSectionWriter.Item))
            {
                if (templateSectionWriter.Item.Name != templateSectionWriter.TemplateSection.Name)
                {
                    templateSectionWriter.Item.Name = templateSectionWriter.TemplateSection.Name;
                }

                if (!string.IsNullOrEmpty(templateSectionWriter.TemplateSection.Icon))
                {
                    templateSectionWriter.Item.Appearance.Icon = templateSectionWriter.TemplateSection.Icon;
                }
            }

            foreach (var fieldWriter in templateSectionWriter.Fields)
            {
                WriteField(templateSectionWriter, fieldWriter, inheritedFields);
            }
        }
Exemple #3
0
        protected virtual void DeleteFields([NotNull] TemplateSectionWriter templateSectionWriter)
        {
            if (templateSectionWriter.Item == null)
            {
                return;
            }

            foreach (Data.Items.Item child in templateSectionWriter.Item.Children)
            {
                if (child.TemplateID != TemplateIDs.TemplateField)
                {
                    continue;
                }

                var found = false;

                foreach (var field in templateSectionWriter.Fields)
                {
                    if (field.Item == null)
                    {
                        continue;
                    }

                    if (field.Item.ID == child.ID)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    child.Recycle();
                }
            }
        }
Exemple #4
0
        protected virtual void WriteField([NotNull] TemplateSectionWriter templateSectionWriter, [NotNull] TemplateFieldWriter templateFieldWriter, [NotNull] IEnumerable <Data.Templates.TemplateField> inheritedFields)
        {
            if (inheritedFields.Any(f => string.Equals(f.Name, templateFieldWriter.TemplateField.Name, StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }

            var item = templateFieldWriter.Item;

            var isNew = item == null;

            if (isNew)
            {
                var id = new ID(templateFieldWriter.TemplateField.Id);
                item = templateSectionWriter.Item.Database.AddFromTemplateSynchronized(templateFieldWriter.TemplateField.Name, new TemplateID(TemplateIDs.TemplateField), templateSectionWriter.Item, id);
                if (item == null)
                {
                    throw new EmitException("Could not create template field", templateFieldWriter.TemplateField.Name);
                }

                templateFieldWriter.Item = item;
            }

            if (templateSectionWriter.Item != null && item.ParentID != templateSectionWriter.Item.ID)
            {
                item.MoveTo(templateSectionWriter.Item);
            }

            using (new EditContext(item))
            {
                if (!string.IsNullOrEmpty(templateFieldWriter.TemplateField.Name))
                {
                    item.Name = templateFieldWriter.TemplateField.Name;
                }

                if (!string.IsNullOrEmpty(templateFieldWriter.TemplateField.Type))
                {
                    item["Type"] = templateFieldWriter.TemplateField.Type;
                }

                item["Shared"]      = templateFieldWriter.TemplateField.IsShared ? "1" : string.Empty;
                item["Unversioned"] = templateFieldWriter.TemplateField.IsUnversioned ? "1" : string.Empty;

                if (!string.IsNullOrEmpty(templateFieldWriter.TemplateField.Source))
                {
                    item["Source"] = templateFieldWriter.TemplateField.Source;
                }

                if (!string.IsNullOrEmpty(templateFieldWriter.TemplateField.ShortHelp))
                {
                    item.Help.ToolTip = templateFieldWriter.TemplateField.ShortHelp;
                }

                if (!string.IsNullOrEmpty(templateFieldWriter.TemplateField.LongHelp))
                {
                    item.Help.Text = templateFieldWriter.TemplateField.LongHelp;
                }

                item.Appearance.Sortorder = templateFieldWriter.TemplateField.Sortorder;
            }
        }