]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/dirdlg.mm
minor cleanup 2 - reformatting
[wxWidgets.git] / src / cocoa / dirdlg.mm
CommitLineData
937f314d
VZ
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#include "wx/filename.h"
32
33#include "wx/cocoa/autorelease.h"
34#include "wx/cocoa/string.h"
35
36#import <AppKit/NSOpenPanel.h>
37#import <AppKit/NSSavePanel.h>
38
39#import <Foundation/NSArray.h>
40// ============================================================================
41// implementation
42// ============================================================================
43
44IMPLEMENT_CLASS(wxCocoaDirDialog, wxDialog)
45
46// ----------------------------------------------------------------------------
47// wxDirDialog
48// ----------------------------------------------------------------------------
49
50wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
51 const wxString& defaultPath, long style, const wxPoint& pos,
52 const wxSize& size, const wxString& name)
53{
54 wxTopLevelWindows.Append(this);
55
56 m_message = message;
57 m_dialogStyle = style;
58 m_parent = parent;
59 m_path = defaultPath;
60
61 wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr));
62
63 if ( parent )
64 parent->AddChild(this);
65
66 m_cocoaNSWindow = nil;
67 m_cocoaNSView = nil;
68
69 //If the user requests to save - use a NSSavePanel
70 //else use a NSOpenPanel
71 if (m_dialogStyle & wxSAVE)
72 {
73 SetNSPanel([NSSavePanel savePanel]);
74
75 [GetNSSavePanel() setTitle:wxNSStringWithWxString(message)];
76
77 [GetNSSavePanel() setPrompt:@"Save"];
78 [GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES];
79 [GetNSSavePanel() setCanSelectHiddenExtension:YES];
80 }
81 else //m_dialogStyle & wxOPEN
82 {
83 SetNSPanel([NSOpenPanel openPanel]);
84 [m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)];
85
86 [(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES];
87 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:NO];
88 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:YES];
89 [GetNSSavePanel() setPrompt:@"Open"];
90 }
91
92 if (m_dialogStyle & wxDD_NEW_DIR_BUTTON) //m_dialogStyle & wxDD_NEW_DIR_BUTTON
93 {
94 [(NSOpenPanel*)m_cocoaNSWindow setCanCreateDirectories:YES];
95 }
96}
97
98wxDirDialog::~wxDirDialog()
99{
100}
101
102int wxDirDialog::ShowModal()
103{
104 wxAutoNSAutoreleasePool thePool;
105
106 m_fileNames.Empty();
107
108 int nResult;
109
110 if (m_dialogStyle & wxSAVE)
111 {
112 nResult = [GetNSSavePanel()
113 runModalForDirectory:wxNSStringWithWxString(m_dir)
114 file:wxNSStringWithWxString(m_fileName)];
115
116 if (nResult == NSOKButton)
117 {
118 m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename]));
119 m_path = m_fileNames[0];
120 }
121 }
122 else //m_dialogStyle & wxOPEN
123 {
124 nResult = [(NSOpenPanel*)m_cocoaNSWindow
125 runModalForDirectory:wxNSStringWithWxString(m_dir)
126 file:wxNSStringWithWxString(m_fileName)
127 types:NULL];
128
129 if (nResult == NSOKButton)
130 {
131 for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i)
132 {
133 m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)]));
134 }
135
136 m_path = m_fileNames[0];
137 }
138 }
139
140 return nResult == NSOKButton ? wxID_OK : wxID_CANCEL;
141}
142
143#endif // wxUSE_DIRDLG
144