} else if (file != null) {
if (editor != null) {
// ApplicationManager.getApplication().runWriteAction(new Runnable() {
// @Override
// public void run() {
Document document = editor.getDocument();
String text = document.getText();
int fixedStartOffset = startOffset;
//if there is selected text
if (startOffset != 0) {
//start offset must be on the start of line
fixedStartOffset = text.substring(0, startOffset).lastIndexOf(LINE_SEPARATOR) + 1;
}
document.setText(codeFormatterFacade.format(text, fixedStartOffset, endOffset, LINE_SEPARATOR));
// }
// });
} else {
FileDocumentManager instance = FileDocumentManager.getInstance();
String iDocument = codeFormatterFacade.format(ioFile(file), LINE_SEPARATOR);
Document writeTo = instance.getDocument(file);
writeTo.setText(iDocument);
instance.saveDocument(writeTo);
}
} else {
notifyNothingWasFormatted();
return;