LAB-31 support non-interactive template workflow for CreateClassQuickFix
authorSergey Stupin <sergey.stupin@jetbrains.com>
Thu, 13 Aug 2020 14:49:35 +0000 (16:49 +0200)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Thu, 13 Aug 2020 14:56:39 +0000 (14:56 +0000)
GitOrigin-RevId: 32e53f623f7baef08720d8057d7a94d2279ff78f

python/python-psi-impl/src/com/jetbrains/python/PythonUiService.java
python/python-psi-impl/src/com/jetbrains/python/inspections/quickfix/CreateClassQuickFix.java
python/src/com/jetbrains/python/PythonUiServiceImpl.java

index 61bc9d591ae7ea74105a3cd65ec845484785f0c9..10bec4a60aad69e423f84bfe6547ef17f7afb68a 100644 (file)
@@ -4,6 +4,7 @@ import com.intellij.codeInspection.InspectionProfileEntry;
 import com.intellij.codeInspection.LocalQuickFix;
 import com.intellij.openapi.components.ServiceManager;
 import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.fileEditor.FileEditor;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.InputValidator;
 import com.intellij.openapi.util.JDOMExternalizableStringList;
@@ -35,6 +36,10 @@ public class PythonUiService {
 
   public void showBalloonError(Project project, @PopupContent String message) {}
 
+  public FileEditor getSelectedEditor(@NotNull Project project, VirtualFile virtualFile) {
+    return null;
+  }
+
   public Editor openTextEditor(@NotNull Project project, PsiElement anchor) {
     return null;
   }
index f9886d68a034c4d8ed300f036b6c3d3bbedd7a05..cda33a53ac3b19b68b86342181f5bddef62466f2 100644 (file)
@@ -8,7 +8,6 @@ import com.intellij.codeInspection.LocalQuickFix;
 import com.intellij.codeInspection.ProblemDescriptor;
 import com.intellij.lang.injection.InjectedLanguageManager;
 import com.intellij.openapi.fileEditor.FileEditor;
-import com.intellij.openapi.fileEditor.FileEditorManager;
 import com.intellij.openapi.fileEditor.TextEditor;
 import com.intellij.openapi.project.Project;
 import com.intellij.psi.PsiElement;
@@ -17,6 +16,7 @@ import com.intellij.psi.SmartPointerManager;
 import com.intellij.psi.SmartPsiElementPointer;
 import com.jetbrains.python.PyNames;
 import com.jetbrains.python.PyPsiBundle;
+import com.jetbrains.python.PythonUiService;
 import com.jetbrains.python.psi.LanguageLevel;
 import com.jetbrains.python.psi.PyClass;
 import com.jetbrains.python.psi.PyElementGenerator;
@@ -82,12 +82,12 @@ public class CreateClassQuickFix implements LocalQuickFix {
     builder.replaceElement(pyClass.getStatementList(), PyNames.PASS);
 
 
-    final FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(anchor.getContainingFile().getVirtualFile());
-    if (!(editor instanceof TextEditor)) {
-      return;
+    final FileEditor editor = PythonUiService.getInstance().getSelectedEditor(project, anchor.getContainingFile().getVirtualFile());
+    if (editor instanceof TextEditor) {
+      builder.run(((TextEditor)editor).getEditor(), false);
+    }else {
+      builder.runNonInteractively(false);
     }
-
-    builder.run(((TextEditor)editor).getEditor(), false);
   }
 
 }
index ae114142b32e9a00f519d2faa4b37f9fe697e94f..5faeba826fc5989286598ac94cce947489ae7432 100644 (file)
@@ -14,6 +14,7 @@ import com.intellij.openapi.actionSystem.DataContext;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.markup.TextAttributes;
+import com.intellij.openapi.fileEditor.FileEditor;
 import com.intellij.openapi.fileEditor.FileEditorLocation;
 import com.intellij.openapi.fileEditor.FileEditorManager;
 import com.intellij.openapi.fileEditor.OpenFileDescriptor;
@@ -72,6 +73,11 @@ public final class PythonUiServiceImpl extends PythonUiService {
   }
 
   @Override
+  public FileEditor getSelectedEditor(@NotNull Project project, VirtualFile virtualFile) {
+    return FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
+  }
+
+  @Override
   public Editor openTextEditor(@NotNull Project project, PsiElement anchor) {
     PsiFile file = InjectedLanguageManager.getInstance(project).getTopLevelFile(anchor);
     return openTextEditor(project, file.getVirtualFile());