Skip to content

Commit

Permalink
Try to use the development sources folder as the initial folder for o…
Browse files Browse the repository at this point in the history
…pen/save operations in the structure command.
  • Loading branch information
shartte committed Jan 29, 2025
1 parent c829839 commit 80202bf
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/guideme/internal/command/StructureCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import guideme.internal.GuidebookText;
import guideme.internal.MutableGuide;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -391,6 +392,8 @@ private static void exportStructure(ServerLevel level, BlockPos origin, Vec3i si
}

private static String pickFileForOpen() {
setDefaultFolder();

try (var stack = MemoryStack.stackPush()) {

return TinyFileDialogs.tinyfd_openFileDialog(
Expand All @@ -403,6 +406,8 @@ private static String pickFileForOpen() {
}

private static String pickFileForSave() {
setDefaultFolder();

try (var stack = MemoryStack.stackPush()) {

return TinyFileDialogs.tinyfd_saveFileDialog(
Expand All @@ -421,4 +426,19 @@ private static PointerBuffer createFilterPatterns(MemoryStack stack) {
filterPatternsBuffer.flip();
return filterPatternsBuffer;
}

private static void setDefaultFolder() {
// If any guide has development sources, default to that folder
if (lastOpenedOrSavedPath == null) {
for (var guide : GuideRegistry.getAll()) {
if (guide.getDevelopmentSourceFolder() != null) {
lastOpenedOrSavedPath = guide.getDevelopmentSourceFolder().toString();
if (!lastOpenedOrSavedPath.endsWith("/") && !lastOpenedOrSavedPath.endsWith("\\")) {
lastOpenedOrSavedPath += File.separator;
}
break;
}
}
}
}
}

0 comments on commit 80202bf

Please sign in to comment.