# HG changeset patch # User Chris Cannam # Date 1589214557 -3600 # Node ID 83ae68de440101d8cd9c8b24fb571c458cec5281 # Parent 3a63f1f61bd65039660852c98d8b580be00cd4d7 Return a "wrong mode" error (i.e. audio required before annotation) from open() only when looking at a document that is plausibly importable as an annotation in the first place diff -r 3a63f1f61bd6 -r 83ae68de4401 framework/MainWindowBase.cpp --- a/framework/MainWindowBase.cpp Thu Apr 30 14:48:14 2020 +0100 +++ b/framework/MainWindowBase.cpp Mon May 11 17:29:17 2020 +0100 @@ -59,6 +59,7 @@ #include "data/fileio/BZipFileDevice.h" #include "data/fileio/FileSource.h" #include "data/fileio/AudioFileReaderFactory.h" +#include "data/fileio/TextTest.h" #include "rdf/RDFImporter.h" #include "rdf/RDFExporter.h" @@ -1516,7 +1517,20 @@ } else if ((status = openPlaylist(source, mode)) != FileOpenFailed) { return status; } else if (!canImportLayer) { - return FileOpenWrongMode; + // We already checked whether the file is RDF: we know + // it's not. But if it's another format that might be + // supported as a layer, reply that we can't open a layer + // here - otherwise assume it's an unknown file format + if (ImageLayer::isImageFileSupported(source.getLocation())) { + return FileOpenWrongMode; + } + if (extension == "mid" || extension == "midi") { + return FileOpenWrongMode; + } + if (TextTest::isApparentTextDocument(source)) { + return FileOpenWrongMode; + } + return FileOpenFailed; } else if ((status = openImage(source)) != FileOpenFailed) { return status; } else if ((status = openLayer(source)) != FileOpenFailed) { @@ -2057,7 +2071,7 @@ // We don't put the image file in Recent Files - cerr << "openImage: trying location \"" << source.getLocation() << "\" in image layer" << endl; + SVCERR << "openImage: trying location \"" << source.getLocation() << "\" in image layer" << endl; if (!il->addImage(m_viewManager->getGlobalCentreFrame(), source.getLocation())) { if (newLayer) {