1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/dirdlg.mm
3 // Purpose: wxDirDialog for wxCocoa
5 // Modified by: Hiroyuki Nakamura(maloninc)
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
25 #include "wx/dirdlg.h"
28 #include "wx/msgdlg.h"
29 #include "wx/filedlg.h"
33 #include "wx/filename.h"
34 #include "wx/testing.h"
36 #include "wx/cocoa/autorelease.h"
37 #include "wx/cocoa/string.h"
39 #import <AppKit/NSOpenPanel.h>
40 #import <AppKit/NSSavePanel.h>
42 #import <Foundation/NSArray.h>
43 // ============================================================================
45 // ============================================================================
47 IMPLEMENT_CLASS(wxCocoaDirDialog, wxDialog)
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
54 const wxString& defaultPath, long style, const wxPoint& pos,
55 const wxSize& size, const wxString& name)
57 wxTopLevelWindows.Append(this);
61 SetWindowStyle(style);
65 wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr));
68 parent->AddChild(this);
70 m_cocoaNSWindow = nil;
73 //If the user requests to save - use a NSSavePanel
74 //else use a NSOpenPanel
75 if (HasFlag(wxFD_SAVE))
77 SetNSPanel([NSSavePanel savePanel]);
79 [GetNSSavePanel() setTitle:wxNSStringWithWxString(message)];
81 [GetNSSavePanel() setPrompt:@"Save"];
82 [GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES];
83 [GetNSSavePanel() setCanSelectHiddenExtension:YES];
85 else //m_dialogStyle & wxFD_OPEN
87 SetNSPanel([NSOpenPanel openPanel]);
88 [m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)];
90 [(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES];
91 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:NO];
92 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:YES];
93 [GetNSSavePanel() setPrompt:@"Open"];
96 if (HasFlag(wxDD_NEW_DIR_BUTTON)) //m_dialogStyle & wxDD_NEW_DIR_BUTTON
98 [(NSOpenPanel*)m_cocoaNSWindow setCanCreateDirectories:YES];
102 wxDirDialog::~wxDirDialog()
106 int wxDirDialog::ShowModal()
108 WX_TESTING_SHOW_MODAL_HOOK();
110 wxAutoNSAutoreleasePool thePool;
116 if (HasFlag(wxFD_SAVE))
118 nResult = [GetNSSavePanel()
119 runModalForDirectory:wxNSStringWithWxString(m_dir)
120 file:wxNSStringWithWxString(m_fileName)];
122 if (nResult == NSOKButton)
124 m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename]));
125 m_path = m_fileNames[0];
128 else //m_dialogStyle & wxFD_OPEN
130 nResult = [(NSOpenPanel*)m_cocoaNSWindow
131 runModalForDirectory:wxNSStringWithWxString(m_dir)
132 file:wxNSStringWithWxString(m_fileName)
135 if (nResult == NSOKButton)
137 for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i)
139 m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)]));
142 m_path = m_fileNames[0];
146 return nResult == NSOKButton ? wxID_OK : wxID_CANCEL;
149 #endif // wxUSE_DIRDLG