private void SaveStyle() { string styleName = StyleList.SelectedValue; if (styleName == "AdditionalStyles") { StyleSheet additionalStyles = new StyleSheet(); additionalStyles.Process(AdditionalCSSStyles.Text); // remove all existing non mapped custom styles from the style sheet List <string> nonMappedStyleNames = GetNonMappedStyleNames(); foreach (string key in nonMappedStyleNames) { _styleSheet.Styles.Remove(key); } foreach (string key in additionalStyles.Styles.Keys) { if (_styleSheet.Styles.Keys.Contains(key)) { _styleSheet.Styles[key] = additionalStyles.Styles[key]; } else { _styleSheet.Styles.Add(key, additionalStyles.Styles[key]); } } } else { if (_styleSheet.Styles.ContainsKey(styleName)) { StyleSheet.Style style = _styleSheet.Styles[styleName]; style.Attributes = GetStyleAttributes(); if (!string.IsNullOrEmpty(this.InnerWrapper) && _styleSheet.Styles.ContainsKey(this.InnerWrapper)) { StyleSheet.Style innerWrapper = _styleSheet.Styles[this.InnerWrapper]; innerWrapper.Attributes = GetInnerWrapperAttributes(); } } else { StyleSheet.Style style = new StyleSheet.Style(); style.Name = styleName; style.Attributes = GetStyleAttributes(); _styleSheet.Styles.Add(styleName, style); if (!string.IsNullOrEmpty(this.InnerWrapper)) { StyleSheet.Style innerWraper = new StyleSheet.Style(); innerWraper.Name = this.InnerWrapper; innerWraper.Attributes = GetInnerWrapperAttributes(); _styleSheet.Styles.Add(this.InnerWrapper, innerWraper); } } } File.WriteAllText(this.FullCurrentFileName, _styleSheet.ToString()); }
protected void BindCssEditor() { // CLEAR STYLE ATTRIBUTES UI ClearAttributesUI(); string styleName = StyleList.SelectedValue; if (styleName == "AdditionalStyles") { ToggleCssEditor(false); AdditionalCSSStyles.Text = string.Empty; foreach (StyleSheet.Style style in _styleSheet.Styles.Values) { XmlNode node = null; try { node = _stylesDocument.DocumentElement.SelectSingleNode("/Styles/Style[@StyleName=\'" + style.Name + "\']"); if (node == null) { node = _stylesDocument.DocumentElement.SelectSingleNode("/Styles/Style[@InnerWrapper=\'" + style.Name + "\']"); } if (node != null) { continue; } } catch (Exception exp) { Logger.Error(exp.Message, exp); } AdditionalCSSStyles.Text += style.ToString(); } } else { ToggleCssEditor(true); if (_styleSheet.Styles.ContainsKey(styleName)) { StyleSheet.Style style = _styleSheet.Styles[styleName]; StyleSheet.Style innerWrapper = null; if (!string.IsNullOrEmpty(this.InnerWrapper) && _styleSheet.Styles.ContainsKey(this.InnerWrapper)) { innerWrapper = _styleSheet.Styles[this.InnerWrapper]; } Initialize(style, innerWrapper); } } }
public void Initialize(StyleSheet.Style style, StyleSheet.Style innerWrapperStyle) { foreach (string attribute in style.Attributes.Keys) { switch (attribute.ToLower()) { case "background-color": BackgroundColor_Style.Text = style.Attributes[attribute].Trim(); break; case "background-image": string backgroundImage = style.Attributes[attribute]; if (!String.IsNullOrEmpty(backgroundImage)) { backgroundImage = backgroundImage.Replace("url(/", "~/").Replace(")", string.Empty).Trim(); } BackgroundImage_Style.Text = backgroundImage; break; case "background-repeat": SelectItem(BackgroundRepeat_Style, style.Attributes[attribute]); break; case "background-attachment": SelectItem(BackgroundAttachment_Style, style.Attributes[attribute]); break; case "color": Color_Style.Text = style.Attributes[attribute].Trim(); break; case "font-style": SelectItem(FontStyle_Style, style.Attributes[attribute]); break; case "font-size": FontSize_Style.Text = style.Attributes[attribute]; break; case "font-family": FontFamily_Style.Text = style.Attributes[attribute]; break; case "font-weight": SelectItem(FontWeight_Style, style.Attributes[attribute]); break; case "border": AllCSSBorder.Value = style.Attributes[attribute]; break; case "border-top": TopCSSBorder.Value = style.Attributes[attribute]; break; case "border-bottom": BottomCSSBorder.Value = style.Attributes[attribute]; break; case "border-left": LeftCSSBorder.Value = style.Attributes[attribute]; break; case "border-right": RightCSSBorder.Value = style.Attributes[attribute]; break; case "margin": case "margin-top": case "margin-bottom": case "margin-left": case "margin-right": case "padding": case "padding-top": case "padding-bottom": case "padding-left": case "padding-right": case "height": case "width": ; // DO NOTHING, THIS WILL BE HANDLED AFTERWARDS break; default: ExtraCssAttributes.Text += string.Format("{0}:{1};\n", attribute, style.Attributes[attribute]); break; } } // STRIP EMPTY LINE BREAK AT THE END ExtraCssAttributes.Text = ExtraCssAttributes.Text.Trim(); if (innerWrapperStyle == null && string.IsNullOrEmpty(InnerWrapper)) { innerWrapperStyle = style; } if (innerWrapperStyle != null) { if (innerWrapperStyle.Attributes.ContainsKey("margin")) { MarginAll_Style.Text = innerWrapperStyle.Attributes["margin"]; } if (innerWrapperStyle.Attributes.ContainsKey("margin-top")) { MarginTop_Style.Text = innerWrapperStyle.Attributes["margin-top"]; } if (innerWrapperStyle.Attributes.ContainsKey("margin-bottom")) { MarginBottom_Style.Text = innerWrapperStyle.Attributes["margin-bottom"]; } if (innerWrapperStyle.Attributes.ContainsKey("margin-left")) { MarginLeft_Style.Text = innerWrapperStyle.Attributes["margin-left"]; } if (innerWrapperStyle.Attributes.ContainsKey("margin-right")) { MarginRight_Style.Text = innerWrapperStyle.Attributes["margin-right"]; } if (innerWrapperStyle.Attributes.ContainsKey("padding")) { PaddingAll_Style.Text = innerWrapperStyle.Attributes["padding"]; } if (innerWrapperStyle.Attributes.ContainsKey("padding-top")) { PaddingTop_Style.Text = innerWrapperStyle.Attributes["padding-top"]; } if (innerWrapperStyle.Attributes.ContainsKey("padding-bottom")) { PaddingBottom_Style.Text = innerWrapperStyle.Attributes["padding-bottom"]; } if (innerWrapperStyle.Attributes.ContainsKey("padding-left")) { PaddingLeft_Style.Text = innerWrapperStyle.Attributes["padding-left"]; } if (innerWrapperStyle.Attributes.ContainsKey("padding-right")) { PaddingRight_Style.Text = innerWrapperStyle.Attributes["padding-right"]; } if (innerWrapperStyle.Attributes.ContainsKey("height")) { Height_Style.Text = innerWrapperStyle.Attributes["height"]; } if (innerWrapperStyle.Attributes.ContainsKey("width")) { Width_Style.Text = innerWrapperStyle.Attributes["width"]; } } }