Skip to content

Commit

Permalink
Fix diff and latest/reference previews due to API changes in IJ 2021.…
Browse files Browse the repository at this point in the history
…1. Add some additional null checks too. (#54)
  • Loading branch information
Tamás Balog authored May 12, 2021
1 parent 0e21be9 commit f1e2f87
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorLocation;
import com.intellij.openapi.fileEditor.FileEditorProvider;
import com.intellij.openapi.fileEditor.FileEditorState;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
Expand Down Expand Up @@ -72,6 +73,24 @@ public List<ScreenshotDiff> getScreenshotDiffs() {
return screenshotDiffs;
}

/**
* Overriding and implementing this method is required. Since 2021.1
* {@link com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl#createPlaceInfo(FileEditor, FileEditorProvider)}
* has changed how it retrieves the file associated with the editor.
* <p>
* Since then, it is retrieved from {@link FileEditor} instead of {@link com.intellij.openapi.fileEditor.ex.FileEditorManagerEx}.
* <p>
* If this method is not implemented, opening any of the Terra screenshot editors will fail with NPE due the default implementation
* of this method.
* <p>
* See the related <a href="https://youtrack.jetbrains.com/issue/IDEA-264044">YouTrack ticket</a> for details.
*/
@Override
public @Nullable VirtualFile getFile() {
//At this point it is guaranteed that there will be at least one file to associate the editor with.
return screenshotDiffs.get(0).getOriginal();
}

@Override
public @NotNull JComponent getComponent() {
return screenshotDiffs.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public CompareLatestWithReferenceScreenshotsAction(@NotNull Project project) {
* It doesn't matter which latest image is opened because the reference/latest preview will display all of them,
* it is only the name of the image that is required.
* <p>
* If an editor for the file is already open, it focuses that editor.
* If an editor for the file is already open, it puts that editor in focus.
*
* @param tree the wdio tree where this action is invoked on
* @param project the project
*/
@Override
public void performAction(TerraWdioTree tree, @Nullable Project project) {
if (tree != null && isScreenshot(tree.getLastSelectedPathComponent())) {
if (project!= null && tree != null && isScreenshot(tree.getLastSelectedPathComponent())) {
List<VirtualFile> latests = asScreenshot(tree.getLastSelectedPathComponent()).getLatests();
if (!latests.isEmpty()) {
VirtualFile fileToOpen = latests.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public ShowDiffScreenshotsAction(@NotNull Project project) {
* It doesn't matter which diff image is opened because the diff preview will display all of them,
* it is only the name of the image that is required.
* <p>
* If an editor for the file is already open, it focuses that editor.
* If an editor for the file is already open, it puts that editor in focus.
*
* @param tree the wdio tree where this action is invoked on
* @param project the project
*/
@Override
public void performAction(TerraWdioTree tree, @Nullable Project project) {
if (tree != null && isScreenshot(tree.getLastSelectedPathComponent())) {
if (project != null && tree != null && isScreenshot(tree.getLastSelectedPathComponent())) {
VirtualFile fileToOpen = asScreenshot(tree.getLastSelectedPathComponent()).getDiffs().get(0);
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
fileEditorManager.openFile(fileToOpen, true, fileEditorManager.isFileOpen(fileToOpen));
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<idea-plugin require-restart="true">
<name>Terra Support</name>
<id>terra.support</id>
<version>0.6.0-SNAPSHOT</version>
<version>0.5.1</version>
<vendor url="https://github.com/picimako/terra-support">Tamas Balog</vendor>
<resource-bundle>messages.TerraBundle</resource-bundle>

Expand Down

0 comments on commit f1e2f87

Please sign in to comment.