com.intellij.psi.search.EverythingGlobalScope#com.intellij.openapi.editor.actionSystem.DocCommandGroupId源码实例Demo

下面列出了com.intellij.psi.search.EverythingGlobalScope#com.intellij.openapi.editor.actionSystem.DocCommandGroupId 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public void actionPerformed(AnActionEvent e) {
  final Project project = e.getProject();
  final BaseRefactorHandler handler = initHandler(project, e.getDataContext());

  boolean processChooser = handler.processChooser();

  if (processChooser) {
    final Editor editor = getEditor(e);

    CommandProcessor.getInstance().executeCommand(project, new Runnable() {
      @Override
      public void run() {
        ApplicationManager.getApplication().runWriteAction(handler);
      }
    }, getClass().getName() + "-Commandname", DocCommandGroupId.noneGroupId(editor.getDocument()));
  }
}
 
源代码2 项目: consulo   文件: CodeInsightAction.java
@RequiredUIAccess
public void actionPerformedImpl(@Nonnull final Project project, final Editor editor) {
  if (editor == null) return;
  //final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
  if (psiFile == null) return;
  final CodeInsightActionHandler handler = getHandler();
  PsiElement elementToMakeWritable = handler.getElementToMakeWritable(psiFile);
  if (elementToMakeWritable != null && !(EditorModificationUtil.checkModificationAllowed(editor) && FileModificationService.getInstance().preparePsiElementsForWrite(elementToMakeWritable))) {
    return;
  }

  CommandProcessor.getInstance().executeCommand(project, () -> {
    final Runnable action = () -> {
      if (!ApplicationManager.getApplication().isHeadlessEnvironment() && !editor.getContentComponent().isShowing()) return;
      handler.invoke(project, editor, psiFile);
    };
    if (handler.startInWriteAction()) {
      ApplicationManager.getApplication().runWriteAction(action);
    }
    else {
      action.run();
    }
  }, getCommandName(), DocCommandGroupId.noneGroupId(editor.getDocument()), editor.getDocument());
}
 
源代码3 项目: consulo   文件: DesktopEditorErrorPanel.java
@RequiredUIAccess
public void mouseClicked(final MouseEvent e) {
  CommandProcessor.getInstance().executeCommand(myEditor.getProject(), new Runnable() {
    @Override
    @RequiredUIAccess
    public void run() {
      doMouseClicked(e);
    }
  }, EditorBundle.message("move.caret.command.name"), DocCommandGroupId.noneGroupId(myEditor.getDocument()), UndoConfirmationPolicy.DEFAULT, myEditor.getDocument());
}
 
源代码4 项目: consulo   文件: DocumentImpl.java
@Override
public void setText(@Nonnull final CharSequence text) {
  Runnable runnable = () -> replaceString(0, getTextLength(), text, LocalTimeCounter.currentTime(), true);
  if (CommandProcessor.getInstance().isUndoTransparentActionInProgress()) {
    runnable.run();
  }
  else {
    CommandProcessor.getInstance().executeCommand(null, runnable, "", DocCommandGroupId.noneGroupId(this));
  }

  clearLineModificationFlags();
}
 
源代码5 项目: consulo   文件: MultiCaretCodeInsightAction.java
public void actionPerformedImpl(final Project project, final Editor hostEditor) {
  CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> {
    MultiCaretCodeInsightActionHandler handler = getHandler();
    try {
      iterateOverCarets(project, hostEditor, handler);
    }
    finally {
      handler.postInvoke();
    }
  }), getCommandName(), DocCommandGroupId.noneGroupId(hostEditor.getDocument()));

  hostEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
}
 
源代码6 项目: nopol   文件: ApplyPatchAction.java
@Override
public void actionPerformed(ActionEvent e) {
	final Project project = this.parent.getProject();
	PsiElement buggyElement = this.parent.getBuggyElement();
	final Patch selectedPatch = this.parent.getSelectedPatch();

	PsiClass classToBeFix = JavaPsiFacade.getInstance(project).findClass(selectedPatch.getRootClassName(), new EverythingGlobalScope(project));
	OpenFileDescriptor descriptor = new OpenFileDescriptor(project, classToBeFix.getContainingFile().getVirtualFile(), buggyElement.getTextOffset());
	Editor editor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
	Document modifiedDocument = editor.getDocument();

	final String patch;

	if (selectedPatch.getType() == RepairType.CONDITIONAL) {
		buggyElement = ((PsiIfStatement) buggyElement).getCondition();
		patch = selectedPatch.asString();
	} else {
		String newline = FileDocumentManager.getInstance().getFile(modifiedDocument).getDetectedLineSeparator();
		StringBuilder sb = new StringBuilder();
		sb.append("if( ");
		sb.append(selectedPatch.asString());
		sb.append(" ) {" + newline);
		sb.append(buggyElement.getText() + newline);
		sb.append("}");
		patch = sb.toString();
	}

	final PsiElement finalBuggyElement = buggyElement;

	CommandProcessor.getInstance().executeCommand(project, () -> WriteCommandAction.runWriteCommandAction(project, () -> {
		//Apply the patch
		modifiedDocument.replaceString(finalBuggyElement.getTextOffset(), finalBuggyElement.getTextOffset() + finalBuggyElement.getTextLength(), patch);
		//Move caret to modification
		editor.getCaretModel().moveToOffset(finalBuggyElement.getTextOffset());
		//Select patch
		editor.getSelectionModel().setSelection(finalBuggyElement.getTextOffset(), finalBuggyElement.getTextOffset() +
				(selectedPatch.getType() == RepairType.CONDITIONAL ? finalBuggyElement.getTextLength() : patch.length()));
		PsiDocumentManager.getInstance(project).commitDocument(modifiedDocument);
		CodeStyleManager.getInstance(project).reformat(PsiDocumentManager.getInstance(project).getPsiFile(modifiedDocument), false);
	}), "Apply Patch", DocCommandGroupId.noneGroupId(modifiedDocument));

	PsiDocumentManager.getInstance(project).commitDocument(modifiedDocument);

	parent.close(0);
}
 
源代码7 项目: consulo   文件: CodeInsightTestFixtureImpl.java
@Override
public void type(final char c) {
  assertInitialized();
  UIUtil.invokeAndWaitIfNeeded(new Runnable() {
    @Override
    public void run() {
      final EditorActionManager actionManager = EditorActionManager.getInstance();
      if (c == '\b') {
        performEditorAction(IdeActions.ACTION_EDITOR_BACKSPACE);
        return;
      }
      if (c == '\n') {
        if (_performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM)) {
          return;
        }

        performEditorAction(IdeActions.ACTION_EDITOR_ENTER);
        return;
      }
      if (c == '\t') {
        if (_performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_REPLACE)) {
          return;
        }
        if (_performEditorAction(IdeActions.ACTION_EXPAND_LIVE_TEMPLATE_BY_TAB)) {
          return;
        }
        if (_performEditorAction(IdeActions.ACTION_EDITOR_NEXT_TEMPLATE_VARIABLE)) {
          return;
        }
        if (_performEditorAction(IdeActions.ACTION_EDITOR_TAB)) {
          return;
        }
      }
      if (c == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
        if (_performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_COMPLETE_STATEMENT)) {
          return;
        }
      }

      CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
        @Override
        public void run() {
          CommandProcessor.getInstance().setCurrentCommandGroupId(myEditor.getDocument());
          ActionManagerEx.getInstanceEx().fireBeforeEditorTyping(c, getEditorDataContext());
          actionManager.getTypedAction().actionPerformed(getEditor(), c, getEditorDataContext());
        }
      }, null, DocCommandGroupId.noneGroupId(myEditor.getDocument()));
    }
  });
}
 
源代码8 项目: consulo   文件: BaseEnterHandler.java
@Override
public DocCommandGroupId getCommandGroupId(Editor editor) {
  return DocCommandGroupId.withGroupId(editor.getDocument(), GROUP_ID);
}