Ejemplo n.º 1
0
 public void insertStyle(String styleName, String value) {
   if (currentEditor.getValue().getMediaType().equals(MediaType.XHTML)) {
     XHTMLCodeEditor xhtmlCodeEditor = (XHTMLCodeEditor) currentEditor.getValue();
     XMLTagPair pair =
         xhtmlCodeEditor.findSurroundingTags(new XHTMLCodeEditor.BlockTagInspector());
     if (pair != null) {
       logger.info("found xml block tag " + pair.getTagName());
       String tagAtttributes =
           xhtmlCodeEditor.getRange(pair.getOpenTagEnd(), pair.getTagAttributesEnd());
       if (tagAtttributes.contains(
           "style=")) // wenn bereits styles vorhanden, dann diese modifizieren
       {
         tagAtttributes =
             tagAtttributes.replaceAll(
                 "style\\s*=\\s*\"(.*)" + styleName + ":([^;]*)(;?)(.*)\\s*\"",
                 "style=\"$1" + styleName + ":" + value + "$3$4\"");
         xhtmlCodeEditor.replaceRange(
             tagAtttributes, pair.getOpenTagEnd(), pair.getTagAttributesEnd());
       } else {
         EditorPosition pos =
             new EditorPosition(
                 pair.getOpenTagBegin().getLine(),
                 pair.getOpenTagBegin().getColumn() + pair.getTagName().length());
         xhtmlCodeEditor.insertAt(" style=\"" + styleName + ":" + value + "\"", pos);
       }
       refreshPreview();
       xhtmlCodeEditor.requestFocus();
     }
   }
 }
Ejemplo n.º 2
0
  public void decreaseIndent() {
    if (currentEditor.getValue().getMediaType().equals(MediaType.XHTML)) {
      XHTMLCodeEditor xhtmlCodeEditor = (XHTMLCodeEditor) currentEditor.getValue();
      XMLTagPair pair =
          xhtmlCodeEditor.findSurroundingTags(new XHTMLCodeEditor.BlockTagInspector());
      if (pair != null) {
        logger.info("found xml block tag " + pair.getTagName());
        String tagAtttributes =
            xhtmlCodeEditor.getRange(pair.getOpenTagEnd(), pair.getTagAttributesEnd());

        Matcher regexMatcher = indentRegex.matcher(tagAtttributes);
        if (regexMatcher.find()) {
          String currentIndentStr = regexMatcher.group(2);
          int currentIndent = NumberUtils.toInt(currentIndentStr, 0);
          String currentUnit = regexMatcher.group(3);
          switch (currentUnit) {
            case "%":
            case "rem":
            case "em":
              currentIndent--;
              break;
            case "px":
              currentIndent = currentIndent - 10;
              break;
          }
          insertStyle("text-indent", currentIndent + currentUnit);
        } else {
          insertStyle("text-indent", "-1em");
        }
      }
    }
  }