当前位置: 首页>>代码示例>>Java>>正文


Java DocumentEvent.getDocument方法代码示例

本文整理汇总了Java中com.intellij.openapi.editor.event.DocumentEvent.getDocument方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentEvent.getDocument方法的具体用法?Java DocumentEvent.getDocument怎么用?Java DocumentEvent.getDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.editor.event.DocumentEvent的用法示例。


在下文中一共展示了DocumentEvent.getDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: documentChanged

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void documentChanged(DocumentEvent event) {
  Document document = event.getDocument();
  FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
  VirtualFile file = fileDocumentManager.getFile(document);
  if (file == null) {
    return;
  }

  String path = ExternalSystemApiUtil.getLocalFileSystemPath(file);
  for (MyEntry entry : myAutoImportAware) {
    if (entry.aware.getAffectedExternalProjectPath(path, myProject) != null) {
      // Document save triggers VFS event but FileDocumentManager might be registered after the current listener, that's why
      // call to 'saveDocument()' might not produce the desired effect. That's why we reschedule document save if necessary.
      scheduleDocumentSave(document);
      return;
    }
  } 
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:ExternalSystemAutoImporter.java

示例2: documentChanged

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void documentChanged(DocumentEvent e) {
  synchronized (this) {
    final Document document = e.getDocument();
    Lexer l = getLexer();
    // if the document been changed before "from __future__ import unicode_literals"
    // we should update the whole document
    if (l instanceof LayeredLexer) {
      Lexer delegate = ((LayeredLexer)l).getDelegate();
      int offset = e.getOffset();
      int lineNumber = document.getLineNumber(offset);
      TextRange tr = new TextRange(document.getLineStartOffset(lineNumber), document.getLineEndOffset(lineNumber));
      document.putUserData(KEY, document.getText(tr).indexOf(PyNames.UNICODE_LITERALS) == -1);
      Boolean hasUnicodeImport = document.getUserData(KEY);
      if (delegate instanceof PythonHighlightingLexer &&
          (((PythonHighlightingLexer)delegate).getImportOffset() > e.getOffset()
           || hasUnicodeImport != hadUnicodeImport)) {
        ((PythonHighlightingLexer)delegate).clearState(e.getDocument().getTextLength());
        setText(document.getCharsSequence());
      }
      else super.documentChanged(e);
    }
    else super.documentChanged(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:PythonEditorHighlighter.java

示例3: documentChanged

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void documentChanged(DocumentEvent e) {
  if (!myTaskFile.isTrackChanges()) {
    return;
  }
  if (myAnswerPlaceholders.isEmpty()) return;
  if (e instanceof DocumentEventImpl) {
    DocumentEventImpl event = (DocumentEventImpl)e;
    Document document = e.getDocument();
    int offset = e.getOffset();
    int change = event.getNewLength() - event.getOldLength();
    for (AnswerPlaceholderWrapper answerPlaceholderWrapper : myAnswerPlaceholders) {
      int twStart = answerPlaceholderWrapper.getTwStart();
      if (twStart > offset) {
        twStart += change;
      }
      int twEnd = answerPlaceholderWrapper.getTwEnd();
      if (twEnd >= offset) {
        twEnd += change;
      }
      AnswerPlaceholder answerPlaceholder = answerPlaceholderWrapper.getAnswerPlaceholder();
      int length = twEnd - twStart;
      answerPlaceholder.setOffset(twStart);
      if (myTrackLength) {
        if (answerPlaceholder.getUseLength()) {
          answerPlaceholder.setLength(length);
        } else {
          if (answerPlaceholder.isActive() && myTaskFile.isTrackLengths()) {
            answerPlaceholder.setPossibleAnswer(document.getText(TextRange.create(twStart, twStart + length)));
          }
        }
      }
    }
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:36,代码来源:EduDocumentListener.java

示例4: onBeforeDocumentChange

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
@CalledInAwt
protected void onBeforeDocumentChange(@NotNull DocumentEvent e) {
  super.onBeforeDocumentChange(e);
  if (myDiffChanges.isEmpty()) return;

  Side side = null;
  if (e.getDocument() == getEditor(Side.LEFT).getDocument()) side = Side.LEFT;
  if (e.getDocument() == getEditor(Side.RIGHT).getDocument()) side = Side.RIGHT;
  if (side == null) {
    LOG.warn("Unknown document changed");
    return;
  }

  int line1 = e.getDocument().getLineNumber(e.getOffset());
  int line2 = e.getDocument().getLineNumber(e.getOffset() + e.getOldLength()) + 1;
  int shift = DiffUtil.countLinesShift(e);

  List<SimpleDiffChange> invalid = new ArrayList<SimpleDiffChange>();
  for (SimpleDiffChange change : myDiffChanges) {
    if (change.processChange(line1, line2, shift, side)) {
      invalid.add(change);
    }
  }

  if (!invalid.isEmpty()) {
    myDiffChanges.removeAll(invalid);
    myInvalidDiffChanges.addAll(invalid);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:SimpleDiffViewer.java

示例5: onBeforeDocumentChange

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
@CalledInAwt
protected void onBeforeDocumentChange(@NotNull DocumentEvent e) {
  super.onBeforeDocumentChange(e);
  if (myDiffChanges.isEmpty()) return;

  ThreeSide side = null;
  if (e.getDocument() == getEditor(ThreeSide.LEFT).getDocument()) side = ThreeSide.LEFT;
  if (e.getDocument() == getEditor(ThreeSide.RIGHT).getDocument()) side = ThreeSide.RIGHT;
  if (e.getDocument() == getEditor(ThreeSide.BASE).getDocument()) side = ThreeSide.BASE;
  if (side == null) {
    LOG.warn("Unknown document changed");
    return;
  }

  int line1 = e.getDocument().getLineNumber(e.getOffset());
  int line2 = e.getDocument().getLineNumber(e.getOffset() + e.getOldLength()) + 1;
  int shift = DiffUtil.countLinesShift(e);

  List<SimpleThreesideDiffChange> invalid = new ArrayList<SimpleThreesideDiffChange>();
  for (SimpleThreesideDiffChange change : myDiffChanges) {
    if (change.processChange(line1, line2, shift, side)) {
      invalid.add(change);
    }
  }

  if (!invalid.isEmpty()) {
    myDiffChanges.removeAll(invalid);
    myInvalidDiffChanges.addAll(invalid);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:SimpleThreesideDiffViewer.java

示例6: onDocumentChanged

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
public void onDocumentChanged(@NotNull DocumentEvent e) {
  if (StringUtil.indexOf(e.getOldFragment(), '\n') != -1 ||
      StringUtil.indexOf(e.getNewFragment(), '\n') != -1) {
    for (int i = 0; i < myCount; i++) {
      if (myEditors[i].getDocument() == e.getDocument()) {
        myShouldUpdateLineNumbers[i] = true;
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:FoldingModelSupport.java

示例7: beforeDocumentChange

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void beforeDocumentChange(DocumentEvent e) {
  Document document = e.getDocument();
  if (shouldBeIgnored(document)) return;

  UndoManagerImpl undoManager = getUndoManager();
  if (undoManager.isActive() && isUndoable(document) && (undoManager.isUndoInProgress() || undoManager.isRedoInProgress()) && 
      document.getUserData(UNDOING_EDITOR_CHANGE) != Boolean.TRUE) {
    throw new IllegalStateException("Do not change documents during undo as it will break undo sequence.");
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:DocumentUndoProvider.java

示例8: documentChanged

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void documentChanged(final DocumentEvent e) {
  Document document = e.getDocument();
  if (shouldBeIgnored(document)) return;

  UndoManagerImpl undoManager = getUndoManager();
  if (undoManager.isActive() && isUndoable(document)) {
    registerUndoableAction(e);
  }
  else {
    registerNonUndoableAction(document);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:DocumentUndoProvider.java

示例9: documentChanged

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void documentChanged(DocumentEvent event) {
  if (myDocumentSavingInProgress) {
    /** When {@link FileDocumentManager#saveAllDocuments} is called,
     *  {@link com.intellij.openapi.editor.impl.TrailingSpacesStripper} can change a document.
     *  These needless 'documentChanged' events should be filtered out.
     */
    return;
  }
  final Document document = event.getDocument();
  final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
  if (file == null) {
    return;
  }
  if (!myChangedFiles.contains(file)) {
    if (ProjectCoreUtil.isProjectOrWorkspaceFile(file)) {
      return;
    }
    if (myChangedFileFilter != null && !myChangedFileFilter.value(file)) {
      return;
    }

    myChangedFiles.add(file);
  }

  myAlarm.cancelRequest(myAlarmRunnable);
  myAlarm.addRequest(myAlarmRunnable, myDelayMillis);
  myModificationStamp++;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:DelayedDocumentWatcher.java

示例10: beforeDocumentChange

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void beforeDocumentChange(@NotNull DocumentEvent event) {
  if (myStopTrackingDocuments || myProject.isDisposed()) return;

  final Document document = event.getDocument();
  VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
  boolean isRelevant = virtualFile != null && isRelevant(virtualFile);

  if (document instanceof DocumentImpl && !myUncommittedInfos.containsKey(document)) {
    myUncommittedInfos.put(document, new UncommittedInfo((DocumentImpl)document));
  }

  final FileViewProvider viewProvider = getCachedViewProvider(document);
  boolean inMyProject = viewProvider != null && viewProvider.getManager() == myPsiManager;
  if (!isRelevant || !inMyProject) {
    return;
  }

  final List<PsiFile> files = viewProvider.getAllFiles();
  PsiFile psiCause = null;
  for (PsiFile file : files) {
    if (file == null) {
      throw new AssertionError("View provider "+viewProvider+" ("+viewProvider.getClass()+") returned null in its files array: "+files+" for file "+viewProvider.getVirtualFile());
    }

    if (mySynchronizer.isInsideAtomicChange(file)) {
      psiCause = file;
    }
  }

  if (psiCause == null) {
    beforeDocumentChangeOnUnlockedDocument(viewProvider);
  }

  ((SingleRootFileViewProvider)viewProvider).beforeDocumentChanged(psiCause);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:PsiDocumentManagerBase.java

示例11: documentChanged

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void documentChanged(DocumentEvent e) {
  UndoManager undoManager = UndoManager.getInstance(myProject);
  boolean undoOrRedo = undoManager.isUndoInProgress() || undoManager.isRedoInProgress();
  if (undoOrRedo) {
    // allow undo/redo up until 'creation stamp' back in time
    // and check it after action is completed
    if (e.getDocument() == myOrigDocument) {
      //noinspection SSBasedInspection
      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
          if (myOrigCreationStamp > myOrigDocument.getModificationStamp()) {
            closeEditor();
          }
        }
      });
    }
  }
  else if (e.getDocument() == myNewDocument) {
    commitToOriginal(e);
    if (!isValid()) {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          closeEditor();
        }
      }, myProject.getDisposed());
    }
  }
  else if (e.getDocument() == myOrigDocument) {
    if (myCommittingToOriginal || myAltFullRange != null && myAltFullRange.isValid()) return;
    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        closeEditor();
      }
    }, myProject.getDisposed());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:41,代码来源:QuickEditHandler.java

示例12: beforeDocumentChange

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void beforeDocumentChange(DocumentEvent e) {
  if (myDeaf) return;
  if (DumbService.isDumb(myProject)) return;
  if (myInitialText == null) {
    final Document document = e.getDocument();
    final PsiDocumentManager documentManager = myPsiDocumentManager;

    if (!documentManager.isUncommited(document)) {
      final CommandProcessor processor = CommandProcessor.getInstance();
      final String currentCommandName = processor.getCurrentCommandName();

      if (!Comparing.strEqual(TYPING_COMMAND_NAME, currentCommandName) &&
          !Comparing.strEqual(PASTE_COMMAND_NAME, currentCommandName) &&
          !Comparing.strEqual("Cut", currentCommandName) &&
          !Comparing.strEqual(LanguageChangeSignatureDetector.MOVE_PARAMETER, currentCommandName) &&
          !Comparing.equal(EditorActionUtil.DELETE_COMMAND_GROUP, processor.getCurrentCommandGroupId())) {
        return;
      }
      final PsiFile file = documentManager.getPsiFile(document);
      if (file != null) {
        final PsiElement element = file.findElementAt(e.getOffset());
        if (element != null) {
          final ChangeInfo info = createInitialChangeInfo(element);
          if (info != null) {
            final PsiElement method = info.getMethod();
            final TextRange textRange = method.getTextRange();
            if (document.getTextLength() <= textRange.getEndOffset()) return;
            if (method instanceof PsiNameIdentifierOwner) {
              myInitialName = ((PsiNameIdentifierOwner)method).getName();
            }
            myInitialText =  document.getText(textRange);
            myInitialChangeInfo = info;
          }
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:ChangeSignatureGestureDetector.java

示例13: beforeDocumentChange

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void beforeDocumentChange(DocumentEvent e) {
  if (!myTaskFile.isTrackChanges()) {
    return;
  }
  myTaskFile.setHighlightErrors(true);
  Document document = e.getDocument();
  myAnswerPlaceholders.clear();
  for (AnswerPlaceholder answerPlaceholder : myTaskFile.getAnswerPlaceholders()) {
    int twStart = answerPlaceholder.getRealStartOffset(document);
    int length = usePossibleAnswerLength ? answerPlaceholder.getPossibleAnswerLength() : answerPlaceholder.getLength();
    int twEnd = twStart + length;
    myAnswerPlaceholders.add(new AnswerPlaceholderWrapper(answerPlaceholder, twStart, twEnd));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:EduDocumentListener.java

示例14: documentChanged

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void documentChanged(DocumentEvent e) {
  if (!myTaskFile.isTrackChanges()) {
    return;
  }
  if (myAnswerPlaceholders.isEmpty()) return;
  if (e instanceof DocumentEventImpl) {
    DocumentEventImpl event = (DocumentEventImpl)e;
    Document document = e.getDocument();
    int offset = e.getOffset();
    int change = event.getNewLength() - event.getOldLength();
    for (AnswerPlaceholderWrapper answerPlaceholderWrapper : myAnswerPlaceholders) {
      int twStart = answerPlaceholderWrapper.getTwStart();
      if (twStart > offset) {
        twStart += change;
      }
      int twEnd = answerPlaceholderWrapper.getTwEnd();
      if (twEnd >= offset) {
        twEnd += change;
      }
      AnswerPlaceholder answerPlaceholder = answerPlaceholderWrapper.getAnswerPlaceholder();
      int line = document.getLineNumber(twStart);
      int start = twStart - document.getLineStartOffset(line);
      int length = twEnd - twStart;
      answerPlaceholder.setLine(line);
      answerPlaceholder.setStart(start);
      if (usePossibleAnswerLength) {
        answerPlaceholder.setPossibleAnswer(document.getText(TextRange.create(twStart, twStart + length)));
      }
      else if (myTrackLength) {
        answerPlaceholder.setLength(length);
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:EduDocumentListener.java

示例15: onBeforeDocumentChange

import com.intellij.openapi.editor.event.DocumentEvent; //导入方法依赖的package包/类
@Override
@CalledInAwt
protected void onBeforeDocumentChange(@NotNull DocumentEvent e) {
  super.onBeforeDocumentChange(e);
  enterBulkChangeUpdateBlock();
  if (myAllMergeChanges.isEmpty()) return;

  ThreeSide side = null;
  if (e.getDocument() == getEditor(ThreeSide.LEFT).getDocument()) side = ThreeSide.LEFT;
  if (e.getDocument() == getEditor(ThreeSide.RIGHT).getDocument()) side = ThreeSide.RIGHT;
  if (e.getDocument() == getEditor(ThreeSide.BASE).getDocument()) side = ThreeSide.BASE;
  if (side == null) {
    LOG.warn("Unknown document changed");
    return;
  }

  if (side != ThreeSide.BASE) {
    LOG.error("Non-base side was changed"); // unsupported operation
    return;
  }

  if (myInitialRediffFinished) myContentModified = true;

  int line1 = e.getDocument().getLineNumber(e.getOffset());
  int line2 = e.getDocument().getLineNumber(e.getOffset() + e.getOldLength()) + 1;
  int shift = DiffUtil.countLinesShift(e);

  final List<Pair<TextMergeChange, TextMergeChange.State>> corruptedStates = ContainerUtil.newArrayList();
  for (TextMergeChange change : myAllMergeChanges) {
    TextMergeChange.State oldState = change.processBaseChange(line1, line2, shift);
    if (oldState != null) {
      if (myCurrentMergeCommand == null) {
        corruptedStates.add(Pair.create(change, oldState));
      }
      reinstallHighlighter(change); // document state is not updated yet - can't reinstall range here
    }
  }

  if (!corruptedStates.isEmpty() && myUndoManager != null) {
    // document undo is registered inside onDocumentChange, so our undo() will be called after its undo().
    // thus thus we can avoid checks for isUndoInProgress() (to avoid modification of the same TextMergeChange by this listener)
    myUndoManager.undoableActionPerformed(new BasicUndoableAction(getEditor(ThreeSide.BASE).getDocument()) {
      @Override
      public void undo() throws UnexpectedUndoException {
        enterBulkChangeUpdateBlock();
        for (Pair<TextMergeChange, TextMergeChange.State> pair : corruptedStates) {
          restoreChangeState(pair.first, pair.second);
        }
        exitBulkChangeUpdateBlock();
      }

      @Override
      public void redo() throws UnexpectedUndoException {
      }
    });
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:58,代码来源:TextMergeTool.java


注:本文中的com.intellij.openapi.editor.event.DocumentEvent.getDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。