Package org.eclipse.jface.text

Examples of org.eclipse.jface.text.IRewriteTarget


   */
  public void run() {
    ITextEditor editor= getTextEditor();
    if (editor == null || !validateEditorInputState())
      return;
    IRewriteTarget target= (IRewriteTarget)editor.getAdapter(IRewriteTarget.class);
    if (target != null)
      target.beginCompoundChange();
    runCompoundChange();
    if (target != null)
      target.endCompoundChange();

  }
View Full Code Here


   * @since 2.1
   */
  private void insertProposal(ICompletionProposal p, char trigger, int stateMask, final int offset) {

    fInserting= true;
    IRewriteTarget target= null;
    IEditingSupport helper= new IEditingSupport() {

      public boolean isOriginator(DocumentEvent event, IRegion focus) {
        return focus.getOffset() <= offset && focus.getOffset() + focus.getLength() >= offset;
      }

      public boolean ownsFocusShell() {
        return false;
      }

    };

    try {

      IDocument document= fContentAssistSubjectControlAdapter.getDocument();

      if (fViewer instanceof ITextViewerExtension) {
        ITextViewerExtension extension= (ITextViewerExtension) fViewer;
        target= extension.getRewriteTarget();
      }

      if (target != null)
        target.beginCompoundChange();

      if (fViewer instanceof IEditingSupportRegistry) {
        IEditingSupportRegistry registry= (IEditingSupportRegistry) fViewer;
        registry.register(helper);
      }


      if (p instanceof ICompletionProposalExtension2 && fViewer != null) {
        ICompletionProposalExtension2 e= (ICompletionProposalExtension2) p;
        e.apply(fViewer, trigger, stateMask, offset);
      } else if (p instanceof ICompletionProposalExtension) {
        ICompletionProposalExtension e= (ICompletionProposalExtension) p;
        e.apply(document, trigger, offset);
      } else {
        p.apply(document);
      }
      fireAppliedEvent(p);

      Point selection= p.getSelection(document);
      if (selection != null) {
        fContentAssistSubjectControlAdapter.setSelectedRange(selection.x, selection.y);
        fContentAssistSubjectControlAdapter.revealRange(selection.x, selection.y);
      }

      IContextInformation info= p.getContextInformation();
      if (info != null) {

        int contextInformationOffset;
        if (p instanceof ICompletionProposalExtension) {
          ICompletionProposalExtension e= (ICompletionProposalExtension) p;
          contextInformationOffset= e.getContextInformationPosition();
        } else {
          if (selection == null)
            selection= fContentAssistSubjectControlAdapter.getSelectedRange();
          contextInformationOffset= selection.x + selection.y;
        }

        fContentAssistant.showContextInformation(info, contextInformationOffset);
      } else
        fContentAssistant.showContextInformation(null, -1);


    } finally {
      if (target != null)
        target.endCompoundChange();

      if (fViewer instanceof IEditingSupportRegistry) {
        IEditingSupportRegistry registry= (IEditingSupportRegistry) fViewer;
        registry.unregister(helper);
      }
View Full Code Here

    fLastCompletion= null;

    ITextEditor editor= getTextEditor();

    if (editor != null) {
      IRewriteTarget target= (IRewriteTarget) editor.getAdapter(IRewriteTarget.class);
      if (target != null) {
        fExitStrategy.disarm();
        target.endCompoundChange();
      }
    }

    fDocument= null;
  }
View Full Code Here

      if (completionState.hasOnly1EmptySuggestion) {
        notifyUser();
        return;
      }

      IRewriteTarget target= (IRewriteTarget)getTextEditor().getAdapter(IRewriteTarget.class);
      if (target != null)
        target.beginCompoundChange();

      fLastCompletion= completionState;
    }
  }
View Full Code Here

        return;

      Object adapter= editor.getAdapter(IRewriteTarget.class);
      if (adapter instanceof IRewriteTarget) {

        IRewriteTarget target= (IRewriteTarget) adapter;
        IDocument document= target.getDocument();
        if (document != null) {
          Shell shell= getTextEditor().getSite().getShell();
          ConvertRunnable runnable= new ConvertRunnable(target, fLineDelimiter);

          if (document.getNumberOfLines() < 40) {
View Full Code Here

        fInformationPresenter.showInformation();
        return;
      case FORMAT:
        {
          final Point selection= rememberSelection();
          final IRewriteTarget target= getRewriteTarget();
          final IDocument document= getDocument();
          IFormattingContext context= null;
          DocumentRewriteSession rewriteSession= null;

          if (document instanceof IDocumentExtension4) {
            IDocumentExtension4 extension= (IDocumentExtension4) document;
            DocumentRewriteSessionType type= (selection.y == 0 && document.getLength() > 1000) || selection.y > 1000
              ? DocumentRewriteSessionType.SEQUENTIAL
              : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
            rewriteSession= extension.startRewriteSession(type);
          } else {
            setRedraw(false);
            target.beginCompoundChange();
          }

          try {

            final String rememberedContents= document.get();

            try {

              if (fContentFormatter instanceof IContentFormatterExtension) {
                final IContentFormatterExtension extension= (IContentFormatterExtension) fContentFormatter;
                context= createFormattingContext();
                if (selection.y == 0) {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
                } else {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE);
                  context.setProperty(FormattingContextProperties.CONTEXT_REGION, new Region(selection.x, selection.y));
                }
                extension.format(document, context);
              } else {
                IRegion r;
                if (selection.y == 0) {
                  IRegion coverage= getModelCoverage();
                  r= coverage == null ? new Region(0, 0) : coverage;
                } else {
                  r= new Region(selection.x, selection.y);
                }
                fContentFormatter.format(document, r);
              }

              updateSlaveDocuments(document);

            } catch (RuntimeException x) {
              // fire wall for https://bugs.eclipse.org/bugs/show_bug.cgi?id=47472
              // if something went wrong we undo the changes we just did
              // TODO to be removed after 3.0 M8
              document.set(rememberedContents);
              throw x;
            }

          } finally {

            if (document instanceof IDocumentExtension4) {
              IDocumentExtension4 extension= (IDocumentExtension4) document;
              extension.stopRewriteSession(rewriteSession);
            } else {
              target.endCompoundChange();
              setRedraw(true);
            }

            restoreSelection();
            if (context != null)
View Full Code Here

  }

  private void endCompoundChangeIfNeeded() {
    if (fHasOpenCompoundChange) {
      ITextViewerExtension extension= (ITextViewerExtension) fCurrentTarget.getViewer();
      IRewriteTarget target= extension.getRewriteTarget();
      target.endCompoundChange();
      fHasOpenCompoundChange= false;
    }
  }
View Full Code Here

  }

  private void beginCompoundChangeIfNeeded() {
    if (!fHasOpenCompoundChange) {
      ITextViewerExtension extension= (ITextViewerExtension) fCurrentTarget.getViewer();
      IRewriteTarget target= extension.getRewriteTarget();
      target.beginCompoundChange();
      fHasOpenCompoundChange= true;
    }
  }
View Full Code Here

              delta= length;
            st.replaceTextRange(fSelection.x + delta, length, ""); //$NON-NLS-1$

            if (fTextDragAndDropToken == null) {
              // Move in same editor - end compound change
              IRewriteTarget target= (IRewriteTarget)getAdapter(IRewriteTarget.class);
              if (target != null)
                target.endCompoundChange();
            }

          }
        } finally {
          fTextDragAndDropToken= null;
        }
      }
    });

    // Install drag target
    DropTargetListener dropTargetListener= new DropTargetAdapter() {

      private Point fSelection;

      public void dragEnter(DropTargetEvent event) {
        fTextDragAndDropToken= null;
        fSelection= st.getSelection();
        if (event.detail == DND.DROP_DEFAULT) {
          if ((event.operations & DND.DROP_MOVE) != 0) {
            event.detail= DND.DROP_MOVE;
          } else if ((event.operations & DND.DROP_COPY) != 0) {
            event.detail= DND.DROP_COPY;
          } else {
            event.detail= DND.DROP_NONE;
          }
        }
      }

      public void dragOperationChanged(DropTargetEvent event) {
        if (event.detail == DND.DROP_DEFAULT) {
          if ((event.operations & DND.DROP_MOVE) != 0) {
            event.detail= DND.DROP_MOVE;
          } else if ((event.operations & DND.DROP_COPY) != 0) {
            event.detail= DND.DROP_COPY;
          } else {
            event.detail= DND.DROP_NONE;
          }
        }
      }

      public void dragOver(DropTargetEvent event) {
        event.feedback |= DND.FEEDBACK_SCROLL;
      }

      public void drop(DropTargetEvent event) {
        try {
          if (fTextDragAndDropToken != null && event.detail == DND.DROP_MOVE) {
            // Move in same editor
            int caretOffset= st.getCaretOffset();
            if (fSelection.x <= caretOffset && caretOffset <= fSelection.y) {
              event.detail= DND.DROP_NONE;
              return;
            }

            // Start compound change
            IRewriteTarget target= (IRewriteTarget)getAdapter(IRewriteTarget.class);
            if (target != null)
              target.beginCompoundChange();
          }

          if (!validateEditorInputState()) {
            event.detail= DND.DROP_NONE;
            return;
View Full Code Here

            String delim;
            String insertion;
            int offset;
            int length;
            ILineRange selectionBefore = getLineRange(document, movingArea);
            IRewriteTarget target = null;
            if (pyEdit != null) {
                target = (IRewriteTarget) pyEdit.getAdapter(IRewriteTarget.class);
                if (target != null) {
                    target.beginCompoundChange();
                    if (!getMoveUp()) {
                        //When going up we'll just do a single document change, so, there's
                        //no need to set the redraw.
                        target.setRedraw(false);
                    }
                }
            }
            ILineRange selectionAfter;
            boolean isStringPartition;
            try {
                if (getMoveUp()) {
                    //check partition in the start of the skipped line
                    isStringPartition = ParsingUtils.isStringPartition(document, skippedLine.getOffset());
                    delim = document.getLineDelimiter(skippedLine.getEndLine());
                    Assert.isNotNull(delim);
                    offset = skippedLine.getOffset();
                    length = moving.length() + delim.length() + skipped.length();
                } else {
                    //check partition in the start of the line after the skipped line
                    int offsetToCheckPartition;
                    if (skippedLine.getEndLine() == document.getNumberOfLines() - 1) {
                        offsetToCheckPartition = document.getLength() - 1; //check the last document char
                    } else {
                        offsetToCheckPartition = skippedLine.getOffset() + skippedLine.getLength(); //that's always the '\n' of the line
                    }

                    isStringPartition = ParsingUtils.isStringPartition(document, offsetToCheckPartition);

                    delim = document.getLineDelimiter(movingArea.getEndLine());
                    Assert.isNotNull(delim);
                    offset = movingArea.getOffset();

                    //When going down, we need to remove the movingArea to compute the new indentation
                    //properly (otherwise we'd use that text being moved on the compute algorithm)
                    document.replace(movingArea.getOffset(), movingArea.getLength() + delim.length(), "");
                    length = skipped.length();
                    int pos = skippedPs.getAbsoluteCursorOffset() - (movingArea.getLength() + delim.length());
                    skippedPs.setSelection(pos, pos);
                }

                PyAutoIndentStrategy indentStrategy = null;
                if (pyEdit != null) {
                    indentStrategy = pyEdit.getAutoEditStrategy();
                }
                if (indentStrategy == null) {
                    indentStrategy = new PyAutoIndentStrategy();
                }

                if (!isStringPartition) {
                    if (indentStrategy.getIndentPrefs().getSmartLineMove()) {
                        String prevExpectedIndent = calculateNewIndentationString(document, skippedPs, indentStrategy);
                        if (prevExpectedIndent != null) {
                            moving = StringUtils.removeWhitespaceColumnsToLeftAndApplyIndent(moving,
                                    prevExpectedIndent, false);
                        }
                    }
                }
                if (getMoveUp()) {
                    insertion = moving + delim + skipped;

                } else {
                    insertion = skipped + delim + moving;
                }

                // modify the document
                document.replace(offset, length, insertion);

                if (getMoveUp()) {
                    selectionAfter = new LineRange(selectionBefore.getStartLine() - 1,
                            selectionBefore.getNumberOfLines());
                } else {
                    selectionAfter = new LineRange(selectionBefore.getStartLine() + 1,
                            selectionBefore.getNumberOfLines());
                }
            } finally {
                if (target != null) {
                    target.endCompoundChange();
                    if (!getMoveUp()) {
                        target.setRedraw(true);
                    }
                }
            }

            // move the selection along
View Full Code Here

TOP

Related Classes of org.eclipse.jface.text.IRewriteTarget

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.