void PasteUSS(string copyBuffer) { // Paste does nothing if document has no stylesheets. var mainStyleSheet = m_PaneWindow.document.activeStyleSheet; if (mainStyleSheet == null) { return; } var pasteStyleSheet = StyleSheetUtilities.CreateInstance(); var importer = new BuilderStyleSheetImporter(); // Cannot be cached because the StyleBuilder never gets reset. importer.Import(pasteStyleSheet, copyBuffer); // Select all pasted selectors. m_Selection.ClearSelection(null); foreach (var selector in pasteStyleSheet.complexSelectors) { BuilderAssetUtilities.AddStyleComplexSelectorToSelection(pasteStyleSheet, selector); } BuilderAssetUtilities.TransferAssetToAsset(m_PaneWindow.document, mainStyleSheet, pasteStyleSheet); ScriptableObject.DestroyImmediate(pasteStyleSheet); }
static void SwallowStyleRule(VisualTreeAsset vta, VisualTreeAsset other, VisualElementAsset vea) { if (vea.ruleIndex < 0) return; if (vta.inlineSheet == null) vta.inlineSheet = StyleSheetUtilities.CreateInstance(); var toStyleSheet = vta.inlineSheet; var fromStyleSheet = other.inlineSheet; var rule = fromStyleSheet.rules[vea.ruleIndex]; // Add rule to StyleSheet. var rulesList = toStyleSheet.rules.ToList(); var index = rulesList.Count; rulesList.Add(rule); toStyleSheet.rules = rulesList.ToArray(); // Add property values to sheet. foreach (var property in rule.properties) { for (int i = 0; i < property.values.Length; ++i) { var valueHandle = property.values[i]; valueHandle.valueIndex = toStyleSheet.SwallowStyleValue(fromStyleSheet, valueHandle); property.values[i] = valueHandle; } } vea.ruleIndex = index; }
public static StyleSheet GetOrCreateInlineStyleSheet(this VisualTreeAsset vta) { if (vta.inlineSheet == null) { vta.inlineSheet = StyleSheetUtilities.CreateInstance(); } return(vta.inlineSheet); }
void PasteUSS(string copyBuffer) { var pasteStyleSheet = StyleSheetUtilities.CreateInstance(); var importer = new BuilderStyleSheetImporter(); // Cannot be cached because the StyleBuilder never gets reset. importer.Import(pasteStyleSheet, copyBuffer); BuilderAssetUtilities.TransferAssetToAsset(m_PaneWindow.document, pasteStyleSheet); ScriptableObject.DestroyImmediate(pasteStyleSheet); }
public static StyleSheet DeepCopy(this StyleSheet styleSheet) { if (styleSheet == null) { return(null); } var newStyleSheet = StyleSheetUtilities.CreateInstance(); styleSheet.DeepOverwrite(newStyleSheet); return(newStyleSheet); }
void PasteUSS(string copyBuffer) { var pasteStyleSheet = StyleSheetUtilities.CreateInstance(); var importer = new BuilderStyleSheetImporter(); // Cannot be cached because the StyleBuilder never gets reset. importer.Import(pasteStyleSheet, copyBuffer); BuilderAssetUtilities.TransferAssetToAsset(m_PaneWindow.document, pasteStyleSheet); m_Selection.ClearSelection(null); var scs = m_PaneWindow.document.mainStyleSheet.complexSelectors.Last(); BuilderAssetUtilities.AddStyleComplexSelectorToSelection(m_PaneWindow.document, scs); ScriptableObject.DestroyImmediate(pasteStyleSheet); }
public static StyleRule GetOrCreateInlineStyleRule(this VisualTreeAsset vta, VisualElementAsset vea, out bool wasCreated) { wasCreated = vea.ruleIndex < 0; if (wasCreated) { if (vta.inlineSheet == null) { var newSheet = StyleSheetUtilities.CreateInstance(); vta.inlineSheet = newSheet; } vea.ruleIndex = vta.inlineSheet.AddRule(); } return(vta.inlineSheet.GetRule(vea.ruleIndex)); }