From c85bff90a5bea1a106fb5315e0c6315165581209 Mon Sep 17 00:00:00 2001 From: Sebastian Annies Date: Sun, 1 Feb 2015 09:23:48 +0200 Subject: [PATCH] make re-opening of file more robust save current directory for open dialog --- .../sannies/isoviewer/FileOpenEventHandler.java | 17 ++++++++++++++--- .../github/sannies/isoviewer/IsoViewerFx.java | 7 +++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/github/sannies/isoviewer/FileOpenEventHandler.java b/src/main/java/com/github/sannies/isoviewer/FileOpenEventHandler.java index b188260..2e05129 100644 --- a/src/main/java/com/github/sannies/isoviewer/FileOpenEventHandler.java +++ b/src/main/java/com/github/sannies/isoviewer/FileOpenEventHandler.java @@ -25,9 +25,9 @@ import java.io.IOException; public class FileOpenEventHandler implements EventHandler { - FileChooser fileChooser = new FileChooser(); Stage stage; IsoViewerFx isoViewerFx; + File currentDir; public FileOpenEventHandler(Stage stage, IsoViewerFx isoViewerFx) { this.stage = stage; @@ -38,16 +38,27 @@ public FileOpenEventHandler(Stage stage, IsoViewerFx isoViewerFx) { public void handle(ActionEvent event) { -//Set extension filter + FileChooser fileChooser = new FileChooser(); fileChooser.getExtensionFilters().addAll( new FileChooser.ExtensionFilter("MP4 files", "*.mp4", "*.uvu", "*.m4v", "*.m4a", "*.uva", "*.uvv", "*.uvt"), new FileChooser.ExtensionFilter("All files", "*.*")); -//Show open file dialog + //Open directory from existing directory + if(currentDir != null){ + fileChooser.setInitialDirectory(currentDir); + } + + //Set extension filter + FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("AVI files (*.avi)", "*.avi"); + fileChooser.getExtensionFilters().add(extFilter); + + //Show open file dialog File file = fileChooser.showOpenDialog(stage); + if (file != null) { stage.setTitle(file.getPath()); try { + currentDir = file.getParentFile(); isoViewerFx.openFile(file); } catch (IOException e) { diff --git a/src/main/java/com/github/sannies/isoviewer/IsoViewerFx.java b/src/main/java/com/github/sannies/isoviewer/IsoViewerFx.java index 3d9f3ae..40f785a 100644 --- a/src/main/java/com/github/sannies/isoviewer/IsoViewerFx.java +++ b/src/main/java/com/github/sannies/isoviewer/IsoViewerFx.java @@ -63,7 +63,7 @@ public class IsoViewerFx extends Application { public void openFile(File f) throws IOException { IsoFile isoFile = new IsoFile(f.getAbsolutePath()); stage.setTitle(f.getAbsolutePath()); - userPrefs.put("openedFile", f.getAbsolutePath()); + boxesOrTracksTabPane.getTabs().clear(); boxesOrTracksTabPane.getTabs().add(createBoxAndDetailTab(isoFile)); @@ -82,6 +82,7 @@ public void openFile(File f) throws IOException { } } + userPrefs.put("openedFile", f.getAbsolutePath()); } @Override @@ -141,7 +142,7 @@ Tab createTrackTab(Track track) { ListView left = new ListView(FXCollections.observableList(track.getSamples())); - final AvcConfigurationBox avcC = Path.getPath(track.getSampleDescriptionBox(), "avc1[0]/avcC[0]"); + final AvcConfigurationBox avcC = Path.getPath(track.getSampleDescriptionBox(), "avc.[0]/avcC[0]"); if (avcC == null) { left.setCellFactory(new SampleRenderCallback()); } else { @@ -214,6 +215,8 @@ public void loadPosAndSize() { if (new File(openFile).exists()) { try { openFile(new File(openFile)); + } catch (RuntimeException e) { + e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }