Skip to content

Commit

Permalink
make re-opening of file more robust
Browse files Browse the repository at this point in the history
save current directory for open dialog
  • Loading branch information
sannies committed Feb 1, 2015
1 parent 929182b commit c85bff9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import java.io.IOException;

public class FileOpenEventHandler implements EventHandler<ActionEvent> {
FileChooser fileChooser = new FileChooser();
Stage stage;
IsoViewerFx isoViewerFx;
File currentDir;

public FileOpenEventHandler(Stage stage, IsoViewerFx isoViewerFx) {
this.stage = stage;
Expand All @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/github/sannies/isoviewer/IsoViewerFx.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -82,6 +82,7 @@ public void openFile(File f) throws IOException {
}

}
userPrefs.put("openedFile", f.getAbsolutePath());
}

@Override
Expand Down Expand Up @@ -141,7 +142,7 @@ Tab createTrackTab(Track track) {


ListView<Sample> left = new ListView<Sample>(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 {
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit c85bff9

Please sign in to comment.