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"
35 #include "wx/cocoa/autorelease.h"
36 #include "wx/cocoa/string.h"
38 #import <AppKit/NSOpenPanel.h>
39 #import <AppKit/NSSavePanel.h>
41 #import <Foundation/NSArray.h>
42 // ============================================================================
44 // ============================================================================
46 IMPLEMENT_CLASS(wxCocoaDirDialog, wxDialog)
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
53 const wxString& defaultPath, long style, const wxPoint& pos,
54 const wxSize& size, const wxString& name)
56 wxTopLevelWindows.Append(this);
59 m_dialogStyle = style;
63 wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr));
66 parent->AddChild(this);
68 m_cocoaNSWindow = nil;
71 //If the user requests to save - use a NSSavePanel
72 //else use a NSOpenPanel
73 if (m_dialogStyle & wxFD_SAVE)
75 SetNSPanel([NSSavePanel savePanel]);
77 [GetNSSavePanel() setTitle:wxNSStringWithWxString(message)];
79 [GetNSSavePanel() setPrompt:@"Save"];
80 [GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES];
81 [GetNSSavePanel() setCanSelectHiddenExtension:YES];
83 else //m_dialogStyle & wxFD_OPEN
85 SetNSPanel([NSOpenPanel openPanel]);
86 [m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)];
88 [(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES];
89 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:NO];
90 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:YES];
91 [GetNSSavePanel() setPrompt:@"Open"];
94 if (m_dialogStyle & wxDD_NEW_DIR_BUTTON) //m_dialogStyle & wxDD_NEW_DIR_BUTTON
96 [(NSOpenPanel*)m_cocoaNSWindow setCanCreateDirectories:YES];
100 wxDirDialog::~wxDirDialog()
104 int wxDirDialog::ShowModal()
106 wxAutoNSAutoreleasePool thePool;
112 if (m_dialogStyle & wxFD_SAVE)
114 nResult = [GetNSSavePanel()
115 runModalForDirectory:wxNSStringWithWxString(m_dir)
116 file:wxNSStringWithWxString(m_fileName)];
118 if (nResult == NSOKButton)
120 m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename]));
121 m_path = m_fileNames[0];
124 else //m_dialogStyle & wxFD_OPEN
126 nResult = [(NSOpenPanel*)m_cocoaNSWindow
127 runModalForDirectory:wxNSStringWithWxString(m_dir)
128 file:wxNSStringWithWxString(m_fileName)
131 if (nResult == NSOKButton)
133 for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i)
135 m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)]));
138 m_path = m_fileNames[0];
142 return nResult == NSOKButton ? wxID_OK : wxID_CANCEL;
145 #endif // wxUSE_DIRDLG