Skip to content

Commit

Permalink
Fixed Can't close any tabs once a binary file is opened - 2
Browse files Browse the repository at this point in the history
  • Loading branch information
hajdam committed Apr 11, 2021
1 parent 758778f commit 8d87e3f
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 9 deletions.
4 changes: 2 additions & 2 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
0.2.4
- Added String field in values panel
- Fixed Can't close any tabs once a binary file is opened (issue #35)
- Added String field in values panel (issue #8)
- Fixed 2021.1: Can't close any tabs once a binary file is opened (issue #35)

0.2.3 (2020-07-30)
- Fixed debugger array support for PHP
Expand Down
Binary file modified lib/bined-core-0.2.0-SNAPSHOT.jar
Binary file not shown.
Binary file modified lib/bined-extended-0.2.0-SNAPSHOT.jar
Binary file not shown.
Binary file modified lib/bined-highlight-swing-0.2.0-SNAPSHOT.jar
Binary file not shown.
Binary file modified lib/bined-operation-0.2.0-SNAPSHOT.jar
Binary file not shown.
Binary file modified lib/bined-operation-swing-0.2.0-SNAPSHOT.jar
Binary file not shown.
Binary file modified lib/bined-swing-0.2.0-SNAPSHOT.jar
Binary file not shown.
Binary file modified lib/bined-swing-extended-0.2.0-SNAPSHOT.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions src/org/exbin/bined/intellij/BinEdFileEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@
import javax.swing.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.List;

/**
* File editor using BinEd editor component.
*
* @author ExBin Project (http://exbin.org)
* @version 0.2.2 2020/01/17
* @version 0.2.4 2021/04/10
*/
@ParametersAreNonnullByDefault
public class BinEdFileEditor implements FileEditor, DumbAware {
Expand Down Expand Up @@ -205,6 +204,7 @@ public void setDisplayName(String displayName) {
this.displayName = displayName;
}

@Nonnull
public BinEdVirtualFile getVirtualFile() {
return virtualFile;
}
Expand Down
3 changes: 3 additions & 0 deletions src/org/exbin/bined/intellij/BinEdNativeFileEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public BinEdNativeFile getNativeFile() {
return nativeFile;
}

@Override
public VirtualFile getFile() { return nativeFile.getVirtualFile(); }

public Project getProject() {
return project;
}
Expand Down
15 changes: 13 additions & 2 deletions src/org/exbin/bined/intellij/BinEdVirtualFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileSystem;
import com.intellij.openapi.vfs.VirtualFileWithId;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -32,9 +33,9 @@
* Virtual file for binary editor.
*
* @author ExBin Project (http://exbin.org)
* @version 0.2.1 2019/08/23
* @version 0.2.4 2021/04/11
*/
public class BinEdVirtualFile extends VirtualFile {
public class BinEdVirtualFile extends VirtualFile implements VirtualFileWithId {

public static final String PATH_PREFIX = "bined://";

Expand Down Expand Up @@ -191,4 +192,14 @@ public void setClosed(boolean closed) {
public JComponent getPreferredFocusedComponent() {
return editorFile.getPreferredFocusedComponent();
}

/**
* Seems like some versions of IDE taps into this for some reason.
*
* @return invalid ID
*/
@Override
public int getId() {
return 0;
}
}
21 changes: 18 additions & 3 deletions src/org/exbin/bined/intellij/OpenAsBinaryAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@
*/
package org.exbin.bined.intellij;

import com.intellij.ide.highlighter.ArchiveFileType;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.fileTypes.DirectoryFileType;
import com.intellij.openapi.fileTypes.UnknownFileType;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

Expand All @@ -33,7 +37,7 @@
* Open file in binary editor action.
*
* @author ExBin Project (http://exbin.org)
* @version 0.2.1 2019/08/22
* @version 0.2.4 2021/04/10
*/
public class OpenAsBinaryAction extends AnAction implements DumbAware {

Expand All @@ -44,7 +48,8 @@ public OpenAsBinaryAction() {
@Override
public void update(@NotNull AnActionEvent event) {
super.update(event);
event.getPresentation().setEnabledAndVisible(true);
VirtualFile virtualFile = event.getData(PlatformDataKeys.VIRTUAL_FILE);
event.getPresentation().setEnabledAndVisible(virtualFile != null && virtualFile.isValid() && !(virtualFile.getFileType() instanceof DirectoryFileType || virtualFile.getFileType() instanceof UnknownFileType));
}

@Override
Expand All @@ -55,7 +60,17 @@ public void actionPerformed(@NotNull AnActionEvent event) {
}

VirtualFile virtualFile = event.getData(PlatformDataKeys.VIRTUAL_FILE);
if (virtualFile != null && virtualFile.isValid() && !virtualFile.isDirectory()) {
boolean isValid = virtualFile != null && virtualFile.isValid();
if (isValid && virtualFile.isDirectory()) {
isValid = false;
if (virtualFile.getFileType() instanceof ArchiveFileType) {
if (virtualFile.getFileSystem() instanceof JarFileSystem) {
virtualFile = ((JarFileSystem) virtualFile.getFileSystem()).getVirtualFileForJar(virtualFile);
isValid = virtualFile != null;
}
}
}
if (isValid) {
BinEdVirtualFile binEdVirtualFile = new BinEdVirtualFile(virtualFile);
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, binEdVirtualFile, 0);
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
Expand Down

0 comments on commit 8d87e3f

Please sign in to comment.