]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/dirdlg.mm
wxArrayString::Sort() wasn't MT-safe even though it tried to
[wxWidgets.git] / src / cocoa / dirdlg.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/dirdlg.mm
3 // Purpose: wxDirDialog for wxCocoa
4 // Author: Ryan Norton
5 // Modified by: Hiroyuki Nakamura(maloninc)
6 // Created: 2006-01-10
7 // RCS-ID: $Id$
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #if wxUSE_DIRDLG
24
25 #ifndef WX_PRECOMP
26 #include "wx/msgdlg.h"
27 #include "wx/filedlg.h"
28 #include "wx/dirdlg.h"
29 #include "wx/app.h"
30 #endif
31
32 #include "wx/filename.h"
33
34 #include "wx/cocoa/autorelease.h"
35 #include "wx/cocoa/string.h"
36
37 #import <AppKit/NSOpenPanel.h>
38 #import <AppKit/NSSavePanel.h>
39
40 #import <Foundation/NSArray.h>
41 // ============================================================================
42 // implementation
43 // ============================================================================
44
45 IMPLEMENT_CLASS(wxCocoaDirDialog, wxDialog)
46
47 // ----------------------------------------------------------------------------
48 // wxDirDialog
49 // ----------------------------------------------------------------------------
50
51 wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
52 const wxString& defaultPath, long style, const wxPoint& pos,
53 const wxSize& size, const wxString& name)
54 {
55 wxTopLevelWindows.Append(this);
56
57 m_message = message;
58 m_dialogStyle = style;
59 m_parent = parent;
60 m_path = defaultPath;
61
62 wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr));
63
64 if ( parent )
65 parent->AddChild(this);
66
67 m_cocoaNSWindow = nil;
68 m_cocoaNSView = nil;
69
70 //If the user requests to save - use a NSSavePanel
71 //else use a NSOpenPanel
72 if (m_dialogStyle & wxFD_SAVE)
73 {
74 SetNSPanel([NSSavePanel savePanel]);
75
76 [GetNSSavePanel() setTitle:wxNSStringWithWxString(message)];
77
78 [GetNSSavePanel() setPrompt:@"Save"];
79 [GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES];
80 [GetNSSavePanel() setCanSelectHiddenExtension:YES];
81 }
82 else //m_dialogStyle & wxFD_OPEN
83 {
84 SetNSPanel([NSOpenPanel openPanel]);
85 [m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)];
86
87 [(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES];
88 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:NO];
89 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:YES];
90 [GetNSSavePanel() setPrompt:@"Open"];
91 }
92
93 if (m_dialogStyle & wxDD_NEW_DIR_BUTTON) //m_dialogStyle & wxDD_NEW_DIR_BUTTON
94 {
95 [(NSOpenPanel*)m_cocoaNSWindow setCanCreateDirectories:YES];
96 }
97 }
98
99 wxDirDialog::~wxDirDialog()
100 {
101 }
102
103 int wxDirDialog::ShowModal()
104 {
105 wxAutoNSAutoreleasePool thePool;
106
107 m_fileNames.Empty();
108
109 int nResult;
110
111 if (m_dialogStyle & wxFD_SAVE)
112 {
113 nResult = [GetNSSavePanel()
114 runModalForDirectory:wxNSStringWithWxString(m_dir)
115 file:wxNSStringWithWxString(m_fileName)];
116
117 if (nResult == NSOKButton)
118 {
119 m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename]));
120 m_path = m_fileNames[0];
121 }
122 }
123 else //m_dialogStyle & wxFD_OPEN
124 {
125 nResult = [(NSOpenPanel*)m_cocoaNSWindow
126 runModalForDirectory:wxNSStringWithWxString(m_dir)
127 file:wxNSStringWithWxString(m_fileName)
128 types:NULL];
129
130 if (nResult == NSOKButton)
131 {
132 for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i)
133 {
134 m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)]));
135 }
136
137 m_path = m_fileNames[0];
138 }
139 }
140
141 return nResult == NSOKButton ? wxID_OK : wxID_CANCEL;
142 }
143
144 #endif // wxUSE_DIRDLG