Ticket #11541 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Fix for opening of multiple document templates not working on OSX

Reported by: SnowLeopard Owned by:
Priority: normal Milestone: 2.9.1
Component: wxOSX-Cocoa Version: 2.9-svn
Keywords: OSX document templates Cc:
Blocked By: Patch: yes
Blocking:

Description

Say that you have a program with more than one document template (e.g., files with the DOC1 and DOC2 extensions). When a wxID_OPEN event is fired, the OSX file open dialog will appear and you will be able to select any file that matches the extensions for your templates (i.e., you can select either DOC1 or DOC2). Note how this is different from Windows where you have a file filter and you need to change that filter to select different document types--this is because the OSX file open doesn't have a file filter combobox like Windows. It just clumps all allowable file types into one filter.

Here is the problem--if you select any document type other than the first one (e.g., select DOC2), then the program will always load it as a DOC1 file. The culprit is "wxDocManager::SelectDocumentPath" in docview.cpp:

if ( FilterIndex != -1 )
            theTemplate = templates[FilterIndex];

On OSX, no matter what doc type you select, "FilterIndex" will always be zero. If you wrap this logic in a "#ifndef WXMAC" block, then that fixes it because then FindTemplateForPath is called and selects the proper template (see attached patch).

Attachments

update.diff download (0.7 KB) - added by SnowLeopard 3 years ago.
Fix

Change History

Changed 3 years ago by SnowLeopard

Fix

Changed 3 years ago by vadz

  • status changed from new to confirmed
  • milestone set to 2.9.1

Thanks for finding and reporting the problem! Unfortunately I don't think the patch provides the correct solution for it. The code in docview.cpp already has provision for not using the filter index if the current platform doesn't support it, it's just supposed to remain -1 then. It's wrong that it is set to 0 by default by wxFileSelectorEx().

Could you please test if the following patch (also) fixes the problem:

  • src/common/fldlgcmn.cpp

    diff --git a/src/common/fldlgcmn.cpp b/src/common/fldlgcmn.cpp
    index f4b4e0a..adab661 100644
    a b  
    3636 
    3737void wxFileDialogBase::Init() 
    3838{ 
    39     m_filterIndex = 0; 
     39    m_filterIndex = -1; // unknown 
    4040    m_windowStyle = 0; 
    4141    m_extraControl = NULL; 
    4242    m_extraControlCreator = NULL; 
     
    5959 
    6060    m_parent = parent; 
    6161    m_windowStyle = style; 
    62     m_filterIndex = 0; 
    6362 
    6463    if (!HasFdFlag(wxFD_OPEN) && !HasFdFlag(wxFD_SAVE)) 
    6564        m_windowStyle |= wxFD_OPEN;     // wxFD_OPEN is the default 

TIA!

Changed 3 years ago by vadz

Oops, a further grep showed that maybe changing this is not as simple as I thought... Carbon and generic implementation might be not happy with filter index being -1 by default. So maybe the best would be to just make wxFileDialog::GetFilterIndex() always return -1 in wxOSX/Cocoa? At least until Stefan ports Carbon code (which, IIUC, implements filters on its own) to Cocoa if this is possible at all?

Changed 3 years ago by csomor

  • status changed from confirmed to closed
  • resolution set to fixed

was fixed in r63178, closing manually

Note: See TracTickets for help on using tickets.