Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 784 #790

Merged
merged 19 commits into from
May 5, 2024
Merged
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class PuzzleEditorPanel extends LegupPanel implements IHistoryListener {
private JMenuItem helpLegup, aboutLegup;
private JMenuBar menuBar;
private JToolBar toolBar;
private JFileChooser folderBrowser;
private JFrame frame;
private JButton[] buttons;
JSplitPane splitPanel;
Expand Down Expand Up @@ -380,25 +381,37 @@ public void loadPuzzleFromHome(String game, String[] statements) {
public Object[] promptPuzzle() {
GameBoardFacade facade = GameBoardFacade.getInstance();
if (facade.getBoard() != null) {
if (noQuit("Opening a new puzzle to edit?")) {
if (noQuit("Opening a new puzzle?")) {
return new Object[0];
}
}
if (fileDialog == null) {
fileDialog = new FileDialog(this.frame);
}

LegupPreferences preferences = LegupPreferences.getInstance();
String preferredDirectory = preferences.getUserPref(LegupPreferences.WORK_DIRECTORY);
if (preferences.getSavedPath() != "") {
preferredDirectory = preferences.getSavedPath();
}

fileDialog.setMode(FileDialog.LOAD);
fileDialog.setTitle("Select Puzzle");
fileDialog.setDirectory(preferredDirectory);
fileDialog.setVisible(true);
File preferredDirectoryFile = new File(preferredDirectory);
JFileChooser fileBrowser = new JFileChooser(preferredDirectoryFile);
String fileName = null;
File puzzleFile = null;
if (fileDialog.getDirectory() != null && fileDialog.getFile() != null) {
fileName = fileDialog.getDirectory() + File.separator + fileDialog.getFile();
puzzleFile = new File(fileName);

fileBrowser.showOpenDialog(this);
fileBrowser.setVisible(true);
fileBrowser.setCurrentDirectory(new File(preferredDirectory));
fileBrowser.setDialogTitle("Select Proof File");
fileBrowser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileBrowser.setAcceptAllFileFilterUsed(false);

File puzzlePath = fileBrowser.getSelectedFile();
System.out.println(puzzlePath.getAbsolutePath());

if (puzzlePath != null) {
fileName = puzzlePath.getAbsolutePath();
String lastDirectoryPath = fileName.substring(0, fileName.lastIndexOf(File.separator));
preferences.setSavedPath(lastDirectoryPath);
puzzleFile = puzzlePath;
} else {
// The attempt to prompt a puzzle ended gracefully (cancel)
return null;
Expand Down
Loading