diff --git a/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeAction.java b/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeAction.java index d21ec363fd55..740c26c1d9d1 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeAction.java @@ -79,7 +79,7 @@ public class ReformatCodeAction extends AnAction implements DumbAware { final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); PsiFile file = null; - final PsiDirectory dir; + PsiDirectory dir = null; boolean hasSelection = false; if (editor != null){ @@ -110,6 +110,9 @@ public class ReformatCodeAction extends AnAction implements DumbAware { } return; } + else if (files != null && files.length == 1) { + file = PsiManager.getInstance(project).findFile(files[0]); + } else { Project projectContext = PlatformDataKeys.PROJECT_CONTEXT.getData(dataContext); Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext); @@ -144,14 +147,16 @@ public class ReformatCodeAction extends AnAction implements DumbAware { final boolean showDialog = EditorSettingsExternalizable.getInstance().getOptions().SHOW_REFORMAT_DIALOG; - if (file == null && dir != null) { + if (file == null && dir == null) return; + if (file == null) { DirectoryFormattingOptions options = getDirectoryFormattingOptions(project, dir); if (options != null) { reformatDirectory(project, dir, options); } return; } - else if (showDialog) { + + if (showDialog) { LayoutCodeOptions selectedFlags = getLayoutCodeOptions(project, file, dir, hasSelection); if (selectedFlags == null) return; @@ -168,8 +173,6 @@ public class ReformatCodeAction extends AnAction implements DumbAware { } } - if (file == null) return; - if (!showDialog && processChangedTextOnly && isChangeNotTrackedForFile(project, file)) { processChangedTextOnly = false; }