EDU-409 Show Preview action does nothing for non-text files (e.g.pictures)
authorliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 3 Sep 2015 12:31:51 +0000 (15:31 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 3 Sep 2015 12:31:51 +0000 (15:31 +0300)
python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCShowPreview.java

index 9d461e54c1af29a16dc97dc9bc01557033fa0683..ac02e7648b07bb33ccf2fa3218bf789cd693abd9 100644 (file)
@@ -31,6 +31,7 @@ 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.project.DumbService;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.FrameWrapper;
+import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiDirectory;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiDirectory;
@@ -54,7 +55,7 @@ public class CCShowPreview extends DumbAwareAction {
   private static final Logger LOG = Logger.getInstance(CCShowPreview.class.getName());
 
   public CCShowPreview() {
   private static final Logger LOG = Logger.getInstance(CCShowPreview.class.getName());
 
   public CCShowPreview() {
-    super("Show Preview","Show preview", null);
+    super("Show Preview","Show Preview", null);
   }
 
   @Override
   }
 
   @Override
@@ -63,12 +64,10 @@ public class CCShowPreview extends DumbAwareAction {
       return;
     }
     Presentation presentation = e.getPresentation();
       return;
     }
     Presentation presentation = e.getPresentation();
-    presentation.setEnabled(false);
-    presentation.setVisible(false);
+    presentation.setEnabledAndVisible(false);
     final PsiFile file = CommonDataKeys.PSI_FILE.getData(e.getDataContext());
     if (file != null && file.getName().contains(".answer")) {
     final PsiFile file = CommonDataKeys.PSI_FILE.getData(e.getDataContext());
     if (file != null && file.getName().contains(".answer")) {
-      presentation.setEnabled(true);
-      presentation.setVisible(true);
+      presentation.setEnabledAndVisible(true);
     }
   }
 
     }
   }
 
@@ -99,6 +98,9 @@ public class CCShowPreview extends DumbAwareAction {
     if (taskFile == null) {
       return;
     }
     if (taskFile == null) {
       return;
     }
+    if (taskFile.getAnswerPlaceholders().isEmpty()) {
+      Messages.showInfoMessage("Preview is available for task files with answer placeholders only", "No Preview for This File");
+    }
     final TaskFile taskFileCopy = new TaskFile();
     TaskFile.copy(taskFile, taskFileCopy);
     final String taskFileName = CCProjectService.getRealTaskFileName(file.getVirtualFile().getName());
     final TaskFile taskFileCopy = new TaskFile();
     TaskFile.copy(taskFile, taskFileCopy);
     final String taskFileName = CCProjectService.getRealTaskFileName(file.getVirtualFile().getName());