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"
32 #include "wx/filename.h"
34 #include "wx/cocoa/autorelease.h"
35 #include "wx/cocoa/string.h"
37 #import <AppKit/NSOpenPanel.h>
38 #import <AppKit/NSSavePanel.h>
40 #import <Foundation/NSArray.h>
41 // ============================================================================
43 // ============================================================================
45 IMPLEMENT_CLASS(wxCocoaDirDialog, wxDialog)
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
52 const wxString& defaultPath, long style, const wxPoint& pos,
53 const wxSize& size, const wxString& name)
55 wxTopLevelWindows.Append(this);
58 m_dialogStyle = style;
62 wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr));
65 parent->AddChild(this);
67 m_cocoaNSWindow = nil;
70 //If the user requests to save - use a NSSavePanel
71 //else use a NSOpenPanel
72 if (m_dialogStyle & wxFD_SAVE)
74 SetNSPanel([NSSavePanel savePanel]);
76 [GetNSSavePanel() setTitle:wxNSStringWithWxString(message)];
78 [GetNSSavePanel() setPrompt:@"Save"];
79 [GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES];
80 [GetNSSavePanel() setCanSelectHiddenExtension:YES];
82 else //m_dialogStyle & wxFD_OPEN
84 SetNSPanel([NSOpenPanel openPanel]);
85 [m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)];
87 [(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES];
88 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:NO];
89 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:YES];
90 [GetNSSavePanel() setPrompt:@"Open"];
93 if (m_dialogStyle & wxDD_NEW_DIR_BUTTON) //m_dialogStyle & wxDD_NEW_DIR_BUTTON
95 [(NSOpenPanel*)m_cocoaNSWindow setCanCreateDirectories:YES];
99 wxDirDialog::~wxDirDialog()
103 int wxDirDialog::ShowModal()
105 wxAutoNSAutoreleasePool thePool;
111 if (m_dialogStyle & wxFD_SAVE)
113 nResult = [GetNSSavePanel()
114 runModalForDirectory:wxNSStringWithWxString(m_dir)
115 file:wxNSStringWithWxString(m_fileName)];
117 if (nResult == NSOKButton)
119 m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename]));
120 m_path = m_fileNames[0];
123 else //m_dialogStyle & wxFD_OPEN
125 nResult = [(NSOpenPanel*)m_cocoaNSWindow
126 runModalForDirectory:wxNSStringWithWxString(m_dir)
127 file:wxNSStringWithWxString(m_fileName)
130 if (nResult == NSOKButton)
132 for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i)
134 m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)]));
137 m_path = m_fileNames[0];
141 return nResult == NSOKButton ? wxID_OK : wxID_CANCEL;
144 #endif // wxUSE_DIRDLG