com.intellij.openapi.editor.DocumentRunnable Java Examples

The following examples show how to use com.intellij.openapi.editor.DocumentRunnable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocumentUtil.java    From codehelper.generator with Apache License 2.0 6 votes vote down vote up
public static void insertString(Document document, String insertLine, int offset, Project project) {

        ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(document, null) {
            @Override
            public void run() {
                CommandProcessor.getInstance().executeCommand(project, new Runnable() {
                    @Override
                    public void run() {
                        try {
                            document.insertString(offset, insertLine);
                        } catch (Exception ignored) {
                        }
                    }
                }, insertLine, document);
            }
        });

    }
 
Example #2
Source File: DocumentUtil.java    From codehelper.generator with Apache License 2.0 6 votes vote down vote up
public static void replaceString(Project project, Document document, String newString, int offset,int length) {
    ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(document, null) {
        @Override
        public void run() {
            CommandProcessor.getInstance().executeCommand(project, new Runnable() {
                @Override
                public void run() {
                    try {
                        document.replaceString(offset, offset + length, newString);
                    } catch (Exception ignored) {
                    }
                }
            }, "", document);
        }
    });
}
 
Example #3
Source File: KillRingSaveAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(final Editor editor, final DataContext dataContext) {
  SelectionModel selectionModel = editor.getSelectionModel();
  if (!selectionModel.hasSelection()) {
    return;
  }

  final int start = selectionModel.getSelectionStart();
  final int end = selectionModel.getSelectionEnd();
  if (start >= end) {
    return;
  }
  KillRingUtil.copyToKillRing(editor, start, end, false);
  if (myRemove) {
    ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(editor.getDocument(),editor.getProject()) {
      @Override
      public void run() {
        editor.getDocument().deleteString(start, end);
      }
    });
  } 
}