From 3d755416626e021815150276ecb6aaa229b52ed3 Mon Sep 17 00:00:00 2001 From: jwiesemann Date: Fri, 7 Dec 2018 03:34:21 +0100 Subject: [PATCH] Fix bug in template selection in docview framework Don't use the template specified by the filter in the file open dialog if it's incapable of actually handling the current file. This fixes a regression compared to 2.8 in docview code and allows opening a file using the correct template for its extension even if an incorrect (e.g. default) filter is chosen in the file open dialog. Closes #18123. --- docs/changes.txt | 1 + src/common/docview.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 57a5769bcc..4d09c8f13b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -143,6 +143,7 @@ All (GUI): - Add wxToolbook::EnablePage() (Stefan Ziegler). - Adapt AUI colours to system colour changes (Daniel Kulp). - Fix removing and inserting pages in wxToolbook (Stefan Ziegler). +- Fix bug in template selection in docview framework (jwiesemann). wxGTK: diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 54c4f6a5f7..c41b1f60ee 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -1805,7 +1805,18 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, // first choose the template using the extension, if this fails (i.e. // wxFileSelectorEx() didn't fill it), then use the path if ( FilterIndex != -1 ) + { theTemplate = templates[FilterIndex]; + if ( theTemplate ) + { + // But don't use this template if it doesn't match the path as + // can happen if the user specified the extension explicitly + // but didn't bother changing the filter. + if ( !theTemplate->FileMatchesTemplate(path) ) + theTemplate = NULL; + } + } + if ( !theTemplate ) theTemplate = FindTemplateForPath(path); if ( !theTemplate )