From: Ben Soares Date: Thu, 8 Dec 2022 17:29:38 +0000 (+0000) Subject: JAL-629 fix opening files X-Git-Tag: Release_2_11_4_0~507 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=85db53418616e3a36252b9b12fcdee4d0259c431;p=jalview.git JAL-629 fix opening files --- 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);