From 85db53418616e3a36252b9b12fcdee4d0259c431 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 8 Dec 2022 17:29:38 +0000 Subject: [PATCH] JAL-629 fix opening files --- src/jalview/gui/Desktop.java | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index f2af0c0..16603df 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -107,6 +107,7 @@ import jalview.io.DataSourceType; import jalview.io.FileFormat; import jalview.io.FileFormatException; import jalview.io.FileFormatI; +import jalview.io.FileFormats; import jalview.io.FileLoader; import jalview.io.FormatAdapter; import jalview.io.IdentifyFile; @@ -1185,9 +1186,29 @@ public class Desktop extends jalview.jbgui.GDesktop public void run() { File selectedFile = chooser.getSelectedFile(); - FileFormatI format = chooser.getSelectedFormat(); Cache.setProperty("LAST_DIRECTORY", selectedFile.getParent()); - viewport.addFile(selectedFile, format); + + FileFormatI format = chooser.getSelectedFormat(); + + /* + * Call IdentifyFile to verify the file contains what its extension implies. + * Skip this step for dynamically added file formats, because IdentifyFile does + * not know how to recognise them. + */ + if (FileFormats.getInstance().isIdentifiable(format)) + { + try + { + format = new IdentifyFile().identify(selectedFile, + DataSourceType.FILE); + } catch (FileFormatException e) + { + // format = null; //?? + } + } + + new FileLoader().LoadFile(viewport, selectedFile, + DataSourceType.FILE, format); } }); chooser.showOpenDialog(this); -- 1.7.10.2