示例#1
0
        public static string RenamePageBox(TemplatePage page, string oldKey, string?newKey)
        {
            if (!EditChecks.IsValidBoxRename(page, oldKey, newKey))
            {
                return(oldKey);
            }
            var theBox   = page.Boxes[oldKey];
            var safeName = Strings.CleanKeyName(newKey);

            // Rename the box, fix existing 'depends-on' references
            page.Boxes.Remove(oldKey);
            page.FixReferences(oldKey, safeName !);
            page.Boxes.Add(safeName !, theBox);
            return(safeName !);
        }
示例#2
0
        public static string RenameDataFilter(TemplateProject project, int?pageIdx, string oldKey, string?newKey)
        {
            var filterSet = project.PickFilterSet(pageIdx);

            if (filterSet is null || !filterSet.ContainsKey(oldKey))
            {
                return(oldKey);
            }
            var value = filterSet[oldKey];

            if (!EditChecks.IsValidFilterRename(project, pageIdx, oldKey, newKey))
            {
                return(oldKey);
            }
            var safeName = Strings.CleanKeyName(newKey);

            if (string.IsNullOrWhiteSpace(safeName !))
            {
                return(oldKey);
            }

            // Rename the filter
            filterSet.Add(safeName, value);
            filterSet.Remove(oldKey);

            // Fix any existing data path pairs of {'#',oldKey}
            // These could be in box data paths, or the paths of other filters (including params of IfElse)
            if (pageIdx is null || pageIdx < 0) // rename in document filter set, and every page
            {
                RenameFilterInFilterSet(project.DataFilters, oldKey, safeName);
                foreach (var page in project.Pages)
                {
                    if (page.PageDataFilters.ContainsKey(oldKey))
                    {
                        continue;                                           // over-ridden, so don't rename
                    }
                    RenameFilterInFilterSet(page.PageDataFilters, oldKey, safeName);
                    RenameFilterInBoxes(page.Boxes, oldKey, safeName);
                }
            }