public void CopyTo(TemplateProject project) { var filterSet = project.PickFilterSet(PageIndex); if (filterSet is null) { throw new Exception("Filter set 'CopyTo' lost reference to filter set"); } if (string.IsNullOrWhiteSpace(FilterKey) || !filterSet.ContainsKey(FilterKey)) { return; } var theFilter = filterSet[FilterKey !];
/// <summary> /// Returns true if the old and new keys are difference, and the the keys is valid as part of a rename. /// If the pageIdx is null, this checks for document-wide filters /// </summary> public static bool IsValidFilterRename(TemplateProject project, int?pageIdx, string oldKey, string?newKey) { var filterSet = project.PickFilterSet(pageIdx); if (filterSet is null) { return(false); } if (string.IsNullOrWhiteSpace(newKey !)) { return(false); // new name is junk } if (filterSet.ContainsKey(newKey)) { return(false); // name is already in use } return(newKey != oldKey); }
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); } }