Skip to content

Commit

Permalink
feat: Support loading directories in UI
Browse files Browse the repository at this point in the history
File > Load prompt only takes files though. Drag drop is the only supported way for directories atm.
  • Loading branch information
Col-E committed May 20, 2021
1 parent b0fa2d7 commit ad21bf6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -3,7 +3,7 @@
<groupId>me.coley</groupId>
<artifactId>recaf</artifactId>
<url>https://github.com/Col-E/Recaf/</url>
<version>2.19.6</version>
<version>2.20.0</version>
<name>Recaf</name>
<description>A modern java bytecode editor</description>
<!-- Variables -->
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/coley/recaf/Recaf.java
Expand Up @@ -31,7 +31,7 @@
* @author Matt
*/
public class Recaf {
public static final String VERSION = "2.19.6";
public static final String VERSION = "2.20.0";
public static final String DOC_URL = "https://col-e.github.io/Recaf-documentation/";
public static final int ASM_VERSION = Opcodes.ASM9;
private static Controller currentController;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/me/coley/recaf/command/impl/LoadWorkspace.java
Expand Up @@ -42,6 +42,9 @@ public Workspace call() throws Exception {
status = LangUtil.translate("ui.load.resolve");
String name = input.getFileName().toString().toLowerCase();
String ext = IOUtil.getExtension(input);
if (Files.isDirectory(input)){
ext = "dir";
}
// Handle symbolic links
int symLevel = 0;
if (ShortcutUtil.isPotentialValidLink(input)) {
Expand All @@ -67,6 +70,10 @@ public Workspace call() throws Exception {
status = LangUtil.translate("ui.load.initialize.resource");
resource = new WarResource(input);
break;
case "dir":
status = LangUtil.translate("ui.load.initialize.resource");
resource = new DirectoryResource(input);
break;
case "json":
status = LangUtil.translate("ui.load.initialize.workspace");
// Represents an already existing workspace, so we can parse and return that here
Expand Down
42 changes: 21 additions & 21 deletions src/main/java/me/coley/recaf/config/ConfKeybinding.java
Expand Up @@ -23,49 +23,49 @@ public class ConfKeybinding extends Config {
* Save current application to file.
*/
@Conf("binding.saveapp")
public Binding saveApp = KeybindingCreator.from(
public Binding saveApp = BindingCreator.from(
Binding.from(KeyCode.CONTROL, KeyCode.E),
KeybindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.E))
BindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.E))
).buildKeyBindingForCurrentOS();
/**
* Save current work.
*/
@Conf("binding.save")
public Binding save = KeybindingCreator.from(
public Binding save = BindingCreator.from(
Binding.from(KeyCode.CONTROL, KeyCode.S),
KeybindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.S))
BindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.S))
).buildKeyBindingForCurrentOS();
/**
* Undo last change.
*/
@Conf("binding.undo")
public Binding undo = KeybindingCreator.from(
public Binding undo = BindingCreator.from(
Binding.from(KeyCode.CONTROL, KeyCode.U),
KeybindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.U))
BindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.U))
).buildKeyBindingForCurrentOS();
/**
* Open find search.
*/
@Conf("binding.find")
public Binding find = KeybindingCreator.from(
public Binding find = BindingCreator.from(
Binding.from(KeyCode.CONTROL, KeyCode.F),
KeybindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.F))
BindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.F))
).buildKeyBindingForCurrentOS();
/**
* Close top-most window <i>(Except the main window)</i>
*/
@Conf("binding.close.window")
public Binding closeWindow = KeybindingCreator.from(
public Binding closeWindow = BindingCreator.from(
Binding.from(KeyCode.CONTROL, KeyCode.ESCAPE),
KeybindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.ESCAPE))
BindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.ESCAPE))
).buildKeyBindingForCurrentOS();
/**
* Close current file/class tab.
*/
@Conf("binding.close.tab")
public Binding closeTab = KeybindingCreator.from(
public Binding closeTab = BindingCreator.from(
Binding.from(KeyCode.CONTROL, KeyCode.W),
KeybindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.W))
BindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.W))
).buildKeyBindingForCurrentOS();
/**
* Goto the selected item's definition.
Expand All @@ -76,17 +76,17 @@ public class ConfKeybinding extends Config {
* Goto the selected item's definition.
*/
@Conf("binding.rename")
public Binding rename = KeybindingCreator.from(
public Binding rename = BindingCreator.from(
Binding.from(KeyCode.CONTROL, KeyCode.R),
KeybindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.R))
BindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.R))
).buildKeyBindingForCurrentOS();
/**
* Swap to the next view mode for the class viewport
*/
@Conf("binding.swapview")
public Binding swapview = KeybindingCreator.from(
public Binding swapview = BindingCreator.from(
Binding.from(KeyCode.CONTROL, KeyCode.Q), // META + Q on Mac closes the window so probably not a great idea
KeybindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.A))
BindingCreator.OSBinding.from(OSUtil.MAC, Binding.from(KeyCode.META, KeyCode.A))
).buildKeyBindingForCurrentOS();

/**
Expand Down Expand Up @@ -164,7 +164,7 @@ private void handleWindowKeyEvents(KeyEvent e, GuiController controller, Stage s
/**
* Wrapper to act as bind utility.
*
* @author Matt
* @author Matt Coley
*/
public static class Binding extends ArrayList<String> {
/**
Expand Down Expand Up @@ -263,11 +263,11 @@ else if (event.isMetaDown())
*
* @author TimmyOVO
*/
public static final class KeybindingCreator {
public static final class BindingCreator {
private final Binding defaultBinding;
private final Map<OSUtil, Binding> bindings;

private KeybindingCreator(Binding defaultBinding, OSBinding... osBindings) {
private BindingCreator(Binding defaultBinding, OSBinding... osBindings) {
this.defaultBinding = defaultBinding;
this.bindings = Arrays.stream(OSUtil.values())
.collect(Collectors.toMap(os -> os, os -> defaultBinding));
Expand All @@ -288,8 +288,8 @@ private KeybindingCreator(Binding defaultBinding, OSBinding... osBindings) {
* @param osBindings os specified keybinding.
* @return A KeybindingCreator instance.
*/
public static KeybindingCreator from(Binding defaultBinding, OSBinding... osBindings) {
return new KeybindingCreator(defaultBinding, osBindings);
public static BindingCreator from(Binding defaultBinding, OSBinding... osBindings) {
return new BindingCreator(defaultBinding, osBindings);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/coley/recaf/ui/MainMenu.java
Expand Up @@ -574,6 +574,8 @@ private void addRecentItem(String path) {
Path fspath = Paths.get(path);
if(Files.exists(fspath)) {
String name = fspath.getFileName().toString();
if (Files.isDirectory(fspath))
name += "/";
Node graphic = new IconView(getFileIcon(name));
mFileRecent.getItems().add(new ActionMenuItem(name, graphic, () -> controller.loadWorkspace(fspath, null)));
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/coley/recaf/util/UiUtil.java
Expand Up @@ -51,6 +51,8 @@ else if(Arrays.asList("png", "gif", "jpeg", "jpg", "bmp").contains(ext))
path = "icons/image.png";
else if(Arrays.asList("jar", "war").contains(ext))
path = "icons/jar.png";
} else if (ext.endsWith("/")) {
path = "icons/folder-source.png";
}
if(path == null)
path = "icons/binary.png";
Expand Down

0 comments on commit ad21bf6

Please sign in to comment.