1
/////////////////////////////////////////////////////////////////////////////
2
// Name: src/cocoa/dirdlg.mm
3
// Purpose: wxDirDialog for wxCocoa
5
// Modified by: Hiroyuki Nakamura(maloninc)
7
// RCS-ID: $Id: dirdlg.mm 40007 2006-07-05 13:10:46Z SC $
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);
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
wxAutoNSAutoreleasePool thePool;
113
if (HasFlag(wxFD_SAVE))
115
nResult = [GetNSSavePanel()
116
runModalForDirectory:wxNSStringWithWxString(m_dir)
117
file:wxNSStringWithWxString(m_fileName)];
119
if (nResult == NSOKButton)
121
m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename]));
122
m_path = m_fileNames[0];
125
else //m_dialogStyle & wxFD_OPEN
127
nResult = [(NSOpenPanel*)m_cocoaNSWindow
128
runModalForDirectory:wxNSStringWithWxString(m_dir)
129
file:wxNSStringWithWxString(m_fileName)
132
if (nResult == NSOKButton)
134
for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i)
136
m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)]));
139
m_path = m_fileNames[0];
143
return nResult == NSOKButton ? wxID_OK : wxID_CANCEL;
146
#endif // wxUSE_DIRDLG