1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/dirdlg.mm
3 // Purpose: wxDirDialog for wxCocoa
5 // Modified by: Hiroyuki Nakamura(maloninc)
7 // Copyright: (c) Ryan Norton
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
24 #include "wx/dirdlg.h"
27 #include "wx/msgdlg.h"
28 #include "wx/filedlg.h"
32 #include "wx/filename.h"
33 #include "wx/modalhook.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);
60 SetWindowStyle(style);
64 wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr));
67 parent->AddChild(this);
69 m_cocoaNSWindow = nil;
72 //If the user requests to save - use a NSSavePanel
73 //else use a NSOpenPanel
74 if (HasFlag(wxFD_SAVE))
76 SetNSPanel([NSSavePanel savePanel]);
78 [GetNSSavePanel() setTitle:wxNSStringWithWxString(message)];
80 [GetNSSavePanel() setPrompt:@"Save"];
81 [GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES];
82 [GetNSSavePanel() setCanSelectHiddenExtension:YES];
84 else //m_dialogStyle & wxFD_OPEN
86 SetNSPanel([NSOpenPanel openPanel]);
87 [m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)];
89 [(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES];
90 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:NO];
91 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:YES];
92 [GetNSSavePanel() setPrompt:@"Open"];
95 if (HasFlag(wxDD_NEW_DIR_BUTTON)) //m_dialogStyle & wxDD_NEW_DIR_BUTTON
97 [(NSOpenPanel*)m_cocoaNSWindow setCanCreateDirectories:YES];
101 wxDirDialog::~wxDirDialog()
105 int wxDirDialog::ShowModal()
107 WX_HOOK_MODAL_DIALOG();
109 wxAutoNSAutoreleasePool thePool;
115 if (HasFlag(wxFD_SAVE))
117 nResult = [GetNSSavePanel()
118 runModalForDirectory:wxNSStringWithWxString(m_dir)
119 file:wxNSStringWithWxString(m_fileName)];
121 if (nResult == NSOKButton)
123 m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename]));
124 m_path = m_fileNames[0];
127 else //m_dialogStyle & wxFD_OPEN
129 nResult = [(NSOpenPanel*)m_cocoaNSWindow
130 runModalForDirectory:wxNSStringWithWxString(m_dir)
131 file:wxNSStringWithWxString(m_fileName)
134 if (nResult == NSOKButton)
136 for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i)
138 m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)]));
141 m_path = m_fileNames[0];
145 return nResult == NSOKButton ? wxID_OK : wxID_CANCEL;
148 #endif // wxUSE_DIRDLG