Skip to content

Commit 07a4b37

Browse files
committed
fix: Truncate file names in display with incredibly verbose directory paths
Prevents a stack-overflow with directory structures that are veeery long
1 parent 785dfd0 commit 07a4b37

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

src/main/java/me/coley/recaf/config/ConfDisplay.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public class ConfDisplay extends Config {
7777
*/
7878
@Conf("display.usesystemmenubar")
7979
public boolean useSystemMenubar;
80+
/**
81+
* Maximum depth of a directory structure to display before it gets truncated.
82+
*/
83+
@Conf("display.maxtreedepth")
84+
public int maxTreeDepth = 30;
8085

8186
ConfDisplay() {
8287
super("display");

src/main/java/me/coley/recaf/ui/controls/pane/ConfigPane.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public ConfigPane(GuiController controller, ConfDisplay config) {
5454
editorOverrides.put("display.forceWordWrap", Toggle::new);
5555
editorOverrides.put("display.suggest.classerrors", Toggle::new);
5656
editorOverrides.put("display.maxrecent", v -> new NumberSlider<>(controller, v, 0, 20, 2));
57+
editorOverrides.put("display.maxtreedepth", v -> new NumberSlider<>(controller, v, 10, 100, 10));
5758
if (OSUtil.getOSType() == OSUtil.MAC) {
5859
editorOverrides.put("display.usesystemmenubar", Toggle::new);
5960
} else {

src/main/java/me/coley/recaf/ui/controls/tree/ClassFolderItem.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.coley.recaf.ui.controls.tree;
22

3+
import me.coley.recaf.Recaf;
34
import me.coley.recaf.workspace.JavaResource;
45

56
import java.util.*;
@@ -25,6 +26,15 @@ public ClassFolderItem(JavaResource resource) {
2526
protected void addClass(String name) {
2627
DirectoryItem item = this;
2728
List<String> parts = new ArrayList<>(Arrays.asList(name.split("/")));
29+
// Prune tree directory middle section if it is obnoxiously long
30+
int maxDepth = Recaf.getController().config().display().maxTreeDepth;
31+
if (parts.size() > maxDepth) {
32+
while (parts.size() > maxDepth) {
33+
parts.remove(maxDepth - 1);
34+
}
35+
parts.add(maxDepth - 1, "...");
36+
}
37+
// Build directory structure
2838
StringBuilder sb = new StringBuilder();
2939
while(!parts.isEmpty()) {
3040
String part = parts.remove(0);

src/main/java/me/coley/recaf/ui/controls/tree/FileFolderItem.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.coley.recaf.ui.controls.tree;
22

3+
import me.coley.recaf.Recaf;
34
import me.coley.recaf.workspace.JavaResource;
45

56
import java.util.*;
@@ -25,6 +26,15 @@ public FileFolderItem(JavaResource resource) {
2526
protected void addFile(String name) {
2627
DirectoryItem item = this;
2728
List<String> parts = new ArrayList<>(Arrays.asList(name.split("/")));
29+
// Prune tree directory middle section if it is obnoxiously long
30+
int maxDepth = Recaf.getController().config().display().maxTreeDepth;
31+
if (parts.size() > maxDepth) {
32+
while (parts.size() > maxDepth) {
33+
parts.remove(maxDepth - 1);
34+
}
35+
parts.add(maxDepth - 1, "...");
36+
}
37+
// Build directory structure
2838
while(!parts.isEmpty()) {
2939
String part = parts.remove(0);
3040
boolean isLeaf = parts.isEmpty();

src/main/resources/translations/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@
479479
"display.buttonbar.desc": "Show the easy-access button-bar in the UI. Restart to apply changes.",
480480
"display.maxlength.tree.name": "Max tree name length",
481481
"display.maxlength.tree.desc": "The max length of names in the file tree. Useful for obfuscated assemblies with crazy names.",
482+
"display.maxtreedepth.name": "Max tree directory depth",
483+
"display.maxtreedepth.desc": "The max number of directories to show in the file tree before truncation.",
482484
"display.treesourcename.name": "Show SourceFile names",
483485
"display.treesourcename.desc": "Display classes SourceFile next to their declared names in the file-tree.",
484486
"display.exitwarning.name": "Give save prompt on exit",

0 commit comments

Comments
 (0)