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"
26 #include "wx/msgdlg.h"
27 #include "wx/filedlg.h"
28 #include "wx/dirdlg.h"
31 #include "wx/filename.h"
33 #include "wx/cocoa/autorelease.h"
34 #include "wx/cocoa/string.h"
36 #import <AppKit/NSOpenPanel.h>
37 #import <AppKit/NSSavePanel.h>
39 #import <Foundation/NSArray.h>
40 // ============================================================================
42 // ============================================================================
44 IMPLEMENT_CLASS(wxCocoaDirDialog, wxDialog)
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
51 const wxString& defaultPath, long style, const wxPoint& pos,
52 const wxSize& size, const wxString& name)
54 wxTopLevelWindows.Append(this);
57 m_dialogStyle = style;
61 wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr));
64 parent->AddChild(this);
66 m_cocoaNSWindow = nil;
69 //If the user requests to save - use a NSSavePanel
70 //else use a NSOpenPanel
71 if (m_dialogStyle & wxSAVE)
73 SetNSPanel([NSSavePanel savePanel]);
75 [GetNSSavePanel() setTitle:wxNSStringWithWxString(message)];
77 [GetNSSavePanel() setPrompt:@"Save"];
78 [GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES];
79 [GetNSSavePanel() setCanSelectHiddenExtension:YES];
81 else //m_dialogStyle & wxOPEN
83 SetNSPanel([NSOpenPanel openPanel]);
84 [m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)];
86 [(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES];
87 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:NO];
88 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:YES];
89 [GetNSSavePanel() setPrompt:@"Open"];
92 if (m_dialogStyle & wxDD_NEW_DIR_BUTTON) //m_dialogStyle & wxDD_NEW_DIR_BUTTON
94 [(NSOpenPanel*)m_cocoaNSWindow setCanCreateDirectories:YES];
98 wxDirDialog::~wxDirDialog()
102 int wxDirDialog::ShowModal()
104 wxAutoNSAutoreleasePool thePool;
110 if (m_dialogStyle & wxSAVE)
112 nResult = [GetNSSavePanel()
113 runModalForDirectory:wxNSStringWithWxString(m_dir)
114 file:wxNSStringWithWxString(m_fileName)];
116 if (nResult == NSOKButton)
118 m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename]));
119 m_path = m_fileNames[0];
122 else //m_dialogStyle & wxOPEN
124 nResult = [(NSOpenPanel*)m_cocoaNSWindow
125 runModalForDirectory:wxNSStringWithWxString(m_dir)
126 file:wxNSStringWithWxString(m_fileName)
129 if (nResult == NSOKButton)
131 for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i)
133 m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)]));
136 m_path = m_fileNames[0];
140 return nResult == NSOKButton ? wxID_OK : wxID_CANCEL;
143 #endif // wxUSE_DIRDLG