Esempio n. 1
0
 @Override
 protected void connectPartitioningToElement(IEditorInput input, IDocument document) {
   if (document instanceof IDocumentExtension3) {
     IDocumentExtension3 extension = (IDocumentExtension3) document;
     if (extension.getDocumentPartitioner(IXQueryPartitions.XQUERY_PARTITIONING) == null) {
       XQueryDocumentSetupParticipant participant = new XQueryDocumentSetupParticipant();
       participant.setup(document);
     }
   }
   if (!(input instanceof IFileEditorInput)) {
     // disable folding
     IPreferenceStore store = XQueryUI.getDefault().getPreferenceStore();
     store.setDefault(PreferenceConstants.EDITOR_FOLDING_ENABLED, false);
     store.setDefault(PreferenceConstants.EDITOR_COMMENTS_FOLDING_ENABLED, false);
   }
 }
  /**
   * Adds two spaces to the indentation of the previous line.
   *
   * @param d the document to work on
   * @param c the command to deal with
   */
  private void autoIndentAfterNewLine(IDocument d, DocumentCommand c) {

    if (c.offset == -1 || d.getLength() == 0) return;

    try {
      String lastPartitionType = null;
      if (d instanceof IDocumentExtension3) {
        IDocumentExtension3 id3 = (IDocumentExtension3) d;
        lastPartitionType =
            id3.getDocumentPartitioner(SassEditor.SASS_PARTITIONING).getContentType(c.offset - 1);
      }

      // find start of line
      int p = (c.offset == d.getLength() ? c.offset - 1 : c.offset);
      IRegion info = d.getLineInformationOfOffset(p);
      int start = info.getOffset();

      // find white spaces
      int end = findEndOfWhiteSpace(d, start, c.offset);

      // indent if we just finished an element
      StringBuffer buf = new StringBuffer(c.text);
      if (lastPartitionType != null
          && (lastPartitionType.equalsIgnoreCase(SassPartitionScanner.SASS_CLASS)
              || lastPartitionType.equalsIgnoreCase(SassPartitionScanner.SASS_ID))) {
        buf.append("  ");
      }

      if (end > start) {
        // append to input
        buf.append(d.get(start, end - start));
      }

      c.text = buf.toString();

    } catch (BadLocationException excp) {
      // stop work
    }
  }