EDU-397 "Show Preview" action doesn't work
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Mon, 24 Aug 2015 09:44:39 +0000 (12:44 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Mon, 24 Aug 2015 09:44:39 +0000 (12:44 +0300)
python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCShowPreview.java

index 8f24ed50a13ce9c8ed09b03321e7aa4de9c95d94..7f2a252d85d40a7c9698bf181d7fa502fe5c28c9 100644 (file)
@@ -27,6 +27,8 @@ import com.intellij.openapi.editor.EditorFactory;
 import com.intellij.openapi.editor.ex.EditorEx;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.project.DumbAwareAction;
+import com.intellij.openapi.project.DumbModePermission;
+import com.intellij.openapi.project.DumbService;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.FrameWrapper;
 import com.intellij.openapi.util.Disposer;
@@ -44,6 +46,7 @@ import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
 import javax.swing.border.EmptyBorder;
+import java.awt.*;
 import java.text.SimpleDateFormat;
 import java.util.AbstractMap;
 import java.util.Calendar;
@@ -117,7 +120,7 @@ public class CCShowPreview extends DumbAwareAction {
       LOG.info("Generated file " + userFileName + "was not found");
       return;
     }
-    FrameWrapper showPreviewFrame = new FrameWrapper(project);
+    final FrameWrapper showPreviewFrame = new FrameWrapper(project);
     showPreviewFrame.setTitle(userFileName);
     LabeledEditor labeledEditor = new LabeledEditor(null);
     final EditorFactory factory = EditorFactory.getInstance();
@@ -140,10 +143,17 @@ public class CCShowPreview extends DumbAwareAction {
     header.add(new JLabel("Read-only preview."));
     String timeStamp = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime());
     header.add(new JLabel(String.format("Created %s.", timeStamp)));
-    labeledEditor.setComponent(createdEditor.getComponent(), header);
+    JComponent editorComponent = createdEditor.getComponent();
+    labeledEditor.setComponent(editorComponent, header);
     createdEditor.setCaretVisible(false);
     createdEditor.setCaretEnabled(false);
     showPreviewFrame.setComponent(labeledEditor);
-    showPreviewFrame.show();
+    showPreviewFrame.setSize(new Dimension(500, 500));
+    DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() {
+      @Override
+      public void run() {
+        showPreviewFrame.show();
+      }
+    });
   }
 }
\ No newline at end of file