Skip to content

Commit c3bf7a5

Browse files
committed
added additional fallback for example files loading
- when creating a .exe with gradle it could not access the example files - created an example.txt file, that references all example files - should work for all instances now
1 parent 0765730 commit c3bf7a5

2 files changed

Lines changed: 1674 additions & 1 deletion

File tree

src/main/java/wprover/GExpert.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
import java.nio.file.Path;
3535
import java.nio.file.Paths;
3636
import java.util.*;
37+
import java.util.List;
3738
import java.util.jar.JarEntry;
3839
import java.util.jar.JarFile;
3940
import java.util.jar.JarInputStream;
41+
import java.util.stream.Collectors;
4042

4143
import org.apache.commons.cli.*;
4244

@@ -807,9 +809,50 @@ public void setLocation(int x, int y) {
807809
* @param menu the menu to which the example files will be added
808810
*/
809811
void addAllExamples(JMenu menu) {
810-
addDirectory(menu, "docs/examples");
812+
try (InputStream in = getClass().getClassLoader().getResourceAsStream("examples.txt")) {
813+
if (in == null) {
814+
return;
815+
}
816+
817+
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
818+
List<String> paths = reader.lines().collect(Collectors.toList());
819+
Map<String, JMenu> menuMap = new HashMap<>();
820+
menuMap.put("", menu); // root
821+
822+
for (String path : paths) {
823+
if (!path.endsWith(".gex")) continue;
824+
825+
String[] parts = path.split("/");
826+
String filename = parts[parts.length - 1];
827+
String label = filename.substring(0, filename.length() - 4);
828+
829+
// Create submenus if needed
830+
String currentPath = "";
831+
JMenu parent = menu;
832+
for (int i = 0; i < parts.length - 1; i++) {
833+
currentPath = currentPath.isEmpty() ? parts[i] : currentPath + "/" + parts[i];
834+
if (!menuMap.containsKey(currentPath)) {
835+
JMenu submenu = new JMenu(parts[i]);
836+
menuMap.put(currentPath, submenu);
837+
parent.add(submenu);
838+
}
839+
parent = menuMap.get(currentPath);
840+
}
841+
842+
JMenuItem item = new JMenuItem(label);
843+
item.setActionCommand("example");
844+
item.setName("docs/examples/" + path); // used for loading
845+
item.setToolTipText(path);
846+
item.addActionListener(this);
847+
parent.add(item);
848+
}
849+
850+
} catch (IOException e) {
851+
e.printStackTrace();
852+
}
811853
}
812854

855+
813856
/**
814857
* Populate a JMenu by scanning a folder on the classpath.
815858
* @param menu the menu to fill

0 commit comments

Comments
 (0)