]>
Commit | Line | Data |
---|---|---|
81169710 | 1 | ////////////////////////////////////////////////////////////////////////////// |
8b17ba72 | 2 | // Name: filedlgg.cpp |
23254b13 | 3 | // Purpose: wxGenericFileDialog |
8b17ba72 RR |
4 | // Author: Robert Roebling |
5 | // Modified by: | |
6 | // Created: 12/12/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Robert Roebling | |
65571936 | 9 | // Licence: wxWindows licence |
8b17ba72 RR |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8b17ba72 RR |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
4e1901b7 | 19 | #if wxUSE_FILEDLG |
1e6feb95 | 20 | |
06cc1fb9 | 21 | // NOTE : it probably also supports MAC, untested |
144cf6da | 22 | #if !defined(__UNIX__) && !defined(__DOS__) && !defined(__WIN32__) && !defined(__OS2__) |
23254b13 | 23 | #error wxGenericFileDialog currently only supports Unix, win32 and DOS |
8b17ba72 RR |
24 | #endif |
25 | ||
04dbb646 VZ |
26 | #include "wx/checkbox.h" |
27 | #include "wx/textctrl.h" | |
28 | #include "wx/choice.h" | |
29 | #include "wx/checkbox.h" | |
30 | #include "wx/stattext.h" | |
8b17ba72 RR |
31 | #include "wx/debug.h" |
32 | #include "wx/log.h" | |
33 | #include "wx/intl.h" | |
34 | #include "wx/msgdlg.h" | |
35 | #include "wx/sizer.h" | |
0b855868 | 36 | #include "wx/bmpbuttn.h" |
cae5359f | 37 | #include "wx/tokenzr.h" |
eaf40b23 | 38 | #include "wx/config.h" |
48fe8374 | 39 | #include "wx/imaglist.h" |
5e673a6a | 40 | #include "wx/dir.h" |
60d2cc25 | 41 | #include "wx/artprov.h" |
1142c837 | 42 | #include "wx/settings.h" |
1265e13d | 43 | #include "wx/file.h" // for wxS_IXXX constants only |
23254b13 JS |
44 | #include "wx/filedlg.h" // wxOPEN, wxSAVE... |
45 | #include "wx/generic/filedlgg.h" | |
06cc1fb9 | 46 | #include "wx/generic/dirctrlg.h" // for wxFileIconsTable |
8b17ba72 | 47 | |
e6daf794 RR |
48 | #if wxUSE_TOOLTIPS |
49 | #include "wx/tooltip.h" | |
50 | #endif | |
51 | ||
ac2def68 RR |
52 | #include <sys/types.h> |
53 | #include <sys/stat.h> | |
4894ae18 VS |
54 | |
55 | #ifdef __UNIX__ | |
56 | #include <dirent.h> | |
57 | #include <pwd.h> | |
58 | #ifndef __VMS | |
59 | # include <grp.h> | |
60 | #endif | |
61 | #endif | |
62 | ||
6a8c7c70 VS |
63 | #ifdef __WINDOWS__ |
64 | #include "wx/msw/wrapwin.h" | |
65 | #include "wx/msw/mslu.h" | |
66 | #endif | |
67 | ||
4894ae18 VS |
68 | #ifdef __WATCOMC__ |
69 | #include <direct.h> | |
27df579a | 70 | #endif |
4894ae18 | 71 | |
7a82dabc | 72 | #include <time.h> |
099d4217 | 73 | #if defined(__UNIX__) || defined(__DOS__) |
ac2def68 | 74 | #include <unistd.h> |
099d4217 | 75 | #endif |
8b17ba72 | 76 | |
655cf310 | 77 | // ---------------------------------------------------------------------------- |
06cc1fb9 | 78 | // private functions |
655cf310 VS |
79 | // ---------------------------------------------------------------------------- |
80 | ||
06cc1fb9 | 81 | static |
7a1e00a1 | 82 | int wxCALLBACK wxFileDataNameCompare( long data1, long data2, long data) |
655cf310 | 83 | { |
06cc1fb9 JS |
84 | wxFileData *fd1 = (wxFileData*)data1; |
85 | wxFileData *fd2 = (wxFileData*)data2; | |
86 | if (fd1->GetFileName() == wxT("..")) return -data; | |
87 | if (fd2->GetFileName() == wxT("..")) return data; | |
88 | if (fd1->IsDir() && !fd2->IsDir()) return -data; | |
89 | if (fd2->IsDir() && !fd1->IsDir()) return data; | |
90 | return data*wxStrcmp( fd1->GetFileName(), fd2->GetFileName() ); | |
655cf310 VS |
91 | } |
92 | ||
c8c0e54c | 93 | static |
7a1e00a1 | 94 | int wxCALLBACK wxFileDataSizeCompare( long data1, long data2, long data) |
23254b13 JS |
95 | { |
96 | wxFileData *fd1 = (wxFileData*)data1; | |
97 | wxFileData *fd2 = (wxFileData*)data2; | |
06cc1fb9 JS |
98 | if (fd1->GetFileName() == wxT("..")) return -data; |
99 | if (fd2->GetFileName() == wxT("..")) return data; | |
23254b13 JS |
100 | if (fd1->IsDir() && !fd2->IsDir()) return -data; |
101 | if (fd2->IsDir() && !fd1->IsDir()) return data; | |
06cc1fb9 JS |
102 | if (fd1->IsLink() && !fd2->IsLink()) return -data; |
103 | if (fd2->IsLink() && !fd1->IsLink()) return data; | |
104 | return data*(fd1->GetSize() - fd2->GetSize()); | |
23254b13 JS |
105 | } |
106 | ||
107 | static | |
7a1e00a1 | 108 | int wxCALLBACK wxFileDataTypeCompare( long data1, long data2, long data) |
23254b13 JS |
109 | { |
110 | wxFileData *fd1 = (wxFileData*)data1; | |
111 | wxFileData *fd2 = (wxFileData*)data2; | |
06cc1fb9 JS |
112 | if (fd1->GetFileName() == wxT("..")) return -data; |
113 | if (fd2->GetFileName() == wxT("..")) return data; | |
23254b13 JS |
114 | if (fd1->IsDir() && !fd2->IsDir()) return -data; |
115 | if (fd2->IsDir() && !fd1->IsDir()) return data; | |
116 | if (fd1->IsLink() && !fd2->IsLink()) return -data; | |
117 | if (fd2->IsLink() && !fd1->IsLink()) return data; | |
b600ed13 | 118 | return data*wxStrcmp( fd1->GetFileType(), fd2->GetFileType() ); |
23254b13 JS |
119 | } |
120 | ||
121 | static | |
7a1e00a1 | 122 | int wxCALLBACK wxFileDataTimeCompare( long data1, long data2, long data) |
23254b13 JS |
123 | { |
124 | wxFileData *fd1 = (wxFileData*)data1; | |
125 | wxFileData *fd2 = (wxFileData*)data2; | |
06cc1fb9 JS |
126 | if (fd1->GetFileName() == wxT("..")) return -data; |
127 | if (fd2->GetFileName() == wxT("..")) return data; | |
23254b13 JS |
128 | if (fd1->IsDir() && !fd2->IsDir()) return -data; |
129 | if (fd2->IsDir() && !fd1->IsDir()) return data; | |
130 | ||
b600ed13 | 131 | return fd1->GetDateTime().IsLaterThan(fd2->GetDateTime()) ? int(data) : -int(data); |
c8c0e54c VZ |
132 | } |
133 | ||
144cf6da | 134 | #if defined(__DOS__) || defined(__WINDOWS__) || defined (__OS2__) |
abc2a4cc | 135 | #define IsTopMostDir(dir) (dir.empty()) |
70a7eb07 MW |
136 | #else |
137 | #define IsTopMostDir(dir) (dir == wxT("/")) | |
5e673a6a VS |
138 | #endif |
139 | ||
06cc1fb9 JS |
140 | // defined in src/generic/dirctrlg.cpp |
141 | extern size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayInt &icon_ids); | |
142 | ||
8b17ba72 RR |
143 | //----------------------------------------------------------------------------- |
144 | // wxFileData | |
145 | //----------------------------------------------------------------------------- | |
146 | ||
06cc1fb9 | 147 | wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, fileType type, int image_id ) |
8b17ba72 | 148 | { |
ca9fb418 | 149 | Init(); |
06cc1fb9 JS |
150 | m_fileName = fileName; |
151 | m_filePath = filePath; | |
23254b13 | 152 | m_type = type; |
06cc1fb9 | 153 | m_image = image_id; |
7a82dabc | 154 | |
b600ed13 VZ |
155 | ReadData(); |
156 | } | |
157 | ||
ca9fb418 VZ |
158 | void wxFileData::Init() |
159 | { | |
160 | m_size = 0; | |
161 | m_type = wxFileData::is_file; | |
162 | m_image = wxFileIconsTable::file; | |
163 | } | |
164 | ||
81169710 VZ |
165 | void wxFileData::Copy( const wxFileData& fileData ) |
166 | { | |
167 | m_fileName = fileData.GetFileName(); | |
168 | m_filePath = fileData.GetFilePath(); | |
169 | m_size = fileData.GetSize(); | |
170 | m_dateTime = fileData.GetDateTime(); | |
171 | m_permissions = fileData.GetPermissions(); | |
172 | m_type = fileData.GetType(); | |
ca9fb418 | 173 | m_image = fileData.GetImageId(); |
81169710 VZ |
174 | } |
175 | ||
b600ed13 VZ |
176 | void wxFileData::ReadData() |
177 | { | |
06cc1fb9 | 178 | if (IsDrive()) |
37fd1c97 | 179 | { |
23254b13 JS |
180 | m_size = 0; |
181 | return; | |
182 | } | |
183 | ||
144cf6da | 184 | #if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) |
06cc1fb9 | 185 | // c:\.. is a drive don't stat it |
567be187 | 186 | if ((m_fileName == wxT("..")) && (m_filePath.length() <= 5)) |
23254b13 JS |
187 | { |
188 | m_type = is_drive; | |
37fd1c97 VS |
189 | m_size = 0; |
190 | return; | |
191 | } | |
7f04165e | 192 | #endif // __DOS__ || __WINDOWS__ |
c8c0e54c | 193 | |
8115f9e7 | 194 | wxStructStat buff; |
479cd5de | 195 | |
144cf6da | 196 | #if defined(__UNIX__) && (!defined( __OS2__ ) && !defined(__VMS)) |
06cc1fb9 | 197 | lstat( m_filePath.fn_str(), &buff ); |
23254b13 | 198 | m_type |= S_ISLNK( buff.st_mode ) != 0 ? is_link : 0; |
7f04165e | 199 | #else // no lstat() |
f3660dcb SC |
200 | // only translate to file charset if we don't go by our |
201 | // wxStat implementation | |
202 | #ifndef wxNEED_WX_UNISTD_H | |
203 | wxStat( m_filePath.fn_str() , &buff ); | |
204 | #else | |
06cc1fb9 | 205 | wxStat( m_filePath, &buff ); |
f3660dcb | 206 | #endif |
9f2d09aa RR |
207 | #endif |
208 | ||
23254b13 JS |
209 | m_type |= (buff.st_mode & S_IFDIR) != 0 ? is_dir : 0; |
210 | m_type |= (buff.st_mode & wxS_IXUSR) != 0 ? is_exe : 0; | |
8b17ba72 | 211 | |
06cc1fb9 JS |
212 | // try to get a better icon |
213 | if (m_image == wxFileIconsTable::file) | |
214 | { | |
ca65c044 WS |
215 | if (m_fileName.Find(wxT('.'), true) != wxNOT_FOUND) |
216 | { | |
1d529ef7 | 217 | m_image = wxTheFileIconsTable->GetIconID( m_fileName.AfterLast(wxT('.'))); |
ca65c044 WS |
218 | } else if (IsExe()) |
219 | { | |
06cc1fb9 | 220 | m_image = wxFileIconsTable::executable; |
ca65c044 | 221 | } |
06cc1fb9 JS |
222 | } |
223 | ||
254a2129 | 224 | m_size = (long)buff.st_size; |
8b17ba72 | 225 | |
06cc1fb9 | 226 | m_dateTime = buff.st_mtime; |
8b17ba72 | 227 | |
06cc1fb9 JS |
228 | #if defined(__UNIX__) |
229 | m_permissions.Printf(_T("%c%c%c%c%c%c%c%c%c"), | |
7f04165e VZ |
230 | buff.st_mode & wxS_IRUSR ? _T('r') : _T('-'), |
231 | buff.st_mode & wxS_IWUSR ? _T('w') : _T('-'), | |
06cc1fb9 JS |
232 | buff.st_mode & wxS_IXUSR ? _T('x') : _T('-'), |
233 | buff.st_mode & wxS_IRGRP ? _T('r') : _T('-'), | |
234 | buff.st_mode & wxS_IWGRP ? _T('w') : _T('-'), | |
235 | buff.st_mode & wxS_IXGRP ? _T('x') : _T('-'), | |
236 | buff.st_mode & wxS_IROTH ? _T('r') : _T('-'), | |
237 | buff.st_mode & wxS_IWOTH ? _T('w') : _T('-'), | |
238 | buff.st_mode & wxS_IXOTH ? _T('x') : _T('-')); | |
239 | #elif defined(__WIN32__) | |
567be187 | 240 | DWORD attribs = GetFileAttributes(m_filePath); |
06cc1fb9 JS |
241 | if (attribs != (DWORD)-1) |
242 | { | |
243 | m_permissions.Printf(_T("%c%c%c%c"), | |
244 | attribs & FILE_ATTRIBUTE_ARCHIVE ? _T('A') : _T(' '), | |
245 | attribs & FILE_ATTRIBUTE_READONLY ? _T('R') : _T(' '), | |
246 | attribs & FILE_ATTRIBUTE_HIDDEN ? _T('H') : _T(' '), | |
247 | attribs & FILE_ATTRIBUTE_SYSTEM ? _T('S') : _T(' ')); | |
248 | } | |
249 | #endif | |
8b17ba72 RR |
250 | } |
251 | ||
b600ed13 | 252 | wxString wxFileData::GetFileType() const |
8b17ba72 | 253 | { |
06cc1fb9 JS |
254 | if (IsDir()) |
255 | return _("<DIR>"); | |
256 | else if (IsLink()) | |
257 | return _("<LINK>"); | |
258 | else if (IsDrive()) | |
259 | return _("<DRIVE>"); | |
7448de8d | 260 | else if (m_fileName.Find(wxT('.'), true) != wxNOT_FOUND) |
06cc1fb9 | 261 | return m_fileName.AfterLast(wxT('.')); |
8b17ba72 | 262 | |
06cc1fb9 | 263 | return wxEmptyString; |
8b17ba72 RR |
264 | } |
265 | ||
06cc1fb9 | 266 | wxString wxFileData::GetModificationTime() const |
23254b13 | 267 | { |
06cc1fb9 JS |
268 | // want time as 01:02 so they line up nicely, no %r in WIN32 |
269 | return m_dateTime.FormatDate() + wxT(" ") + m_dateTime.Format(wxT("%I:%M:%S %p")); | |
23254b13 JS |
270 | } |
271 | ||
8b17ba72 RR |
272 | wxString wxFileData::GetHint() const |
273 | { | |
06cc1fb9 | 274 | wxString s = m_filePath; |
2b5f62a0 | 275 | s += wxT(" "); |
b8985048 | 276 | |
23254b13 | 277 | if (IsDir()) |
b8985048 | 278 | s += _("<DIR>"); |
23254b13 | 279 | else if (IsLink()) |
b8985048 | 280 | s += _("<LINK>"); |
23254b13 | 281 | else if (IsDrive()) |
b8985048 VZ |
282 | s += _("<DRIVE>"); |
283 | else // plain file | |
284 | s += wxString::Format( _("%ld bytes"), m_size ); | |
285 | ||
286 | s += wxT(' '); | |
287 | ||
288 | if ( !IsDrive() ) | |
23254b13 | 289 | { |
b8985048 VZ |
290 | s << GetModificationTime() |
291 | << wxT(" ") | |
292 | << m_permissions; | |
8b17ba72 | 293 | } |
23254b13 | 294 | |
8b17ba72 RR |
295 | return s; |
296 | }; | |
297 | ||
23254b13 | 298 | wxString wxFileData::GetEntry( fileListFieldType num ) const |
8b17ba72 RR |
299 | { |
300 | wxString s; | |
9cedab37 | 301 | switch ( num ) |
8b17ba72 | 302 | { |
9cedab37 | 303 | case FileList_Name: |
06cc1fb9 | 304 | s = m_fileName; |
8b17ba72 | 305 | break; |
9cedab37 | 306 | |
06cc1fb9 JS |
307 | case FileList_Size: |
308 | if (!IsDir() && !IsLink() && !IsDrive()) | |
9cedab37 | 309 | s.Printf(_T("%ld"), m_size); |
8b17ba72 | 310 | break; |
9cedab37 | 311 | |
06cc1fb9 | 312 | case FileList_Type: |
b600ed13 | 313 | s = GetFileType(); |
8b17ba72 | 314 | break; |
8b17ba72 | 315 | |
9cedab37 | 316 | case FileList_Time: |
7448de8d | 317 | if (!IsDrive()) |
06cc1fb9 | 318 | s = GetModificationTime(); |
9cedab37 | 319 | break; |
8b17ba72 | 320 | |
06cc1fb9 | 321 | #if defined(__UNIX__) || defined(__WIN32__) |
9cedab37 VZ |
322 | case FileList_Perm: |
323 | s = m_permissions; | |
324 | break; | |
06cc1fb9 | 325 | #endif // defined(__UNIX__) || defined(__WIN32__) |
8b17ba72 | 326 | |
9cedab37 VZ |
327 | default: |
328 | wxFAIL_MSG( _T("unexpected field in wxFileData::GetEntry()") ); | |
329 | } | |
8b17ba72 | 330 | |
9cedab37 | 331 | return s; |
8b17ba72 RR |
332 | } |
333 | ||
06cc1fb9 | 334 | void wxFileData::SetNewName( const wxString &filePath, const wxString &fileName ) |
8b17ba72 | 335 | { |
06cc1fb9 JS |
336 | m_fileName = fileName; |
337 | m_filePath = filePath; | |
8b17ba72 RR |
338 | } |
339 | ||
340 | void wxFileData::MakeItem( wxListItem &item ) | |
341 | { | |
06cc1fb9 | 342 | item.m_text = m_fileName; |
9b00bb16 | 343 | item.ClearAttributes(); |
9cedab37 VZ |
344 | if (IsExe()) |
345 | item.SetTextColour(*wxRED); | |
346 | if (IsDir()) | |
347 | item.SetTextColour(*wxBLUE); | |
48fe8374 | 348 | |
06cc1fb9 | 349 | item.m_image = m_image; |
655cf310 | 350 | |
8b17ba72 RR |
351 | if (IsLink()) |
352 | { | |
564a150b VZ |
353 | wxColour dg = wxTheColourDatabase->Find( _T("MEDIUM GREY") ); |
354 | if ( dg.Ok() ) | |
355 | item.SetTextColour(dg); | |
8b17ba72 RR |
356 | } |
357 | item.m_data = (long)this; | |
358 | } | |
c8c0e54c | 359 | |
8b17ba72 RR |
360 | //----------------------------------------------------------------------------- |
361 | // wxFileCtrl | |
362 | //----------------------------------------------------------------------------- | |
363 | ||
d84afea9 | 364 | IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl,wxListCtrl) |
8b17ba72 RR |
365 | |
366 | BEGIN_EVENT_TABLE(wxFileCtrl,wxListCtrl) | |
ca65c044 WS |
367 | EVT_LIST_DELETE_ITEM(wxID_ANY, wxFileCtrl::OnListDeleteItem) |
368 | EVT_LIST_DELETE_ALL_ITEMS(wxID_ANY, wxFileCtrl::OnListDeleteAllItems) | |
369 | EVT_LIST_END_LABEL_EDIT(wxID_ANY, wxFileCtrl::OnListEndLabelEdit) | |
370 | EVT_LIST_COL_CLICK(wxID_ANY, wxFileCtrl::OnListColClick) | |
8b17ba72 RR |
371 | END_EVENT_TABLE() |
372 | ||
655cf310 | 373 | |
8b17ba72 RR |
374 | wxFileCtrl::wxFileCtrl() |
375 | { | |
ca65c044 | 376 | m_showHidden = false; |
23254b13 JS |
377 | m_sort_foward = 1; |
378 | m_sort_field = wxFileData::FileList_Name; | |
8b17ba72 RR |
379 | } |
380 | ||
9cedab37 VZ |
381 | wxFileCtrl::wxFileCtrl(wxWindow *win, |
382 | wxWindowID id, | |
383 | const wxString& wild, | |
384 | bool showHidden, | |
385 | const wxPoint& pos, | |
386 | const wxSize& size, | |
387 | long style, | |
388 | const wxValidator &validator, | |
5e673a6a | 389 | const wxString &name) |
9cedab37 VZ |
390 | : wxListCtrl(win, id, pos, size, style, validator, name), |
391 | m_wild(wild) | |
8b17ba72 | 392 | { |
06cc1fb9 | 393 | wxImageList *imageList = wxTheFileIconsTable->GetSmallImageList(); |
655cf310 | 394 | |
0b855868 | 395 | SetImageList( imageList, wxIMAGE_LIST_SMALL ); |
c8c0e54c | 396 | |
9cedab37 | 397 | m_showHidden = showHidden; |
23254b13 JS |
398 | |
399 | m_sort_foward = 1; | |
400 | m_sort_field = wxFileData::FileList_Name; | |
401 | ||
402 | m_dirName = wxT("*"); | |
403 | ||
404 | if (style & wxLC_REPORT) | |
405 | ChangeToReportMode(); | |
8b17ba72 RR |
406 | } |
407 | ||
408 | void wxFileCtrl::ChangeToListMode() | |
409 | { | |
23254b13 | 410 | ClearAll(); |
8b17ba72 | 411 | SetSingleStyle( wxLC_LIST ); |
8f4fcc4e | 412 | UpdateFiles(); |
8b17ba72 RR |
413 | } |
414 | ||
415 | void wxFileCtrl::ChangeToReportMode() | |
416 | { | |
23254b13 | 417 | ClearAll(); |
8b17ba72 | 418 | SetSingleStyle( wxLC_REPORT ); |
23254b13 | 419 | |
06cc1fb9 JS |
420 | // do this since WIN32 does mm/dd/yy UNIX does mm/dd/yyyy |
421 | // don't hardcode since mm/dd is dd/mm elsewhere | |
23254b13 | 422 | int w, h; |
06cc1fb9 JS |
423 | wxDateTime dt(22, wxDateTime::Dec, 2002, 22, 22, 22); |
424 | wxString txt = dt.FormatDate() + wxT("22") + dt.Format(wxT("%I:%M:%S %p")); | |
425 | GetTextExtent(txt, &w, &h); | |
426 | ||
427 | InsertColumn( 0, _("Name"), wxLIST_FORMAT_LEFT, w ); | |
428 | InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT, w/2 ); | |
429 | InsertColumn( 2, _("Type"), wxLIST_FORMAT_LEFT, w/2 ); | |
430 | InsertColumn( 3, _("Modified"), wxLIST_FORMAT_LEFT, w ); | |
431 | #if defined(__UNIX__) | |
432 | GetTextExtent(wxT("Permissions 2"), &w, &h); | |
433 | InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT, w ); | |
434 | #elif defined(__WIN32__) | |
435 | GetTextExtent(wxT("Attributes 2"), &w, &h); | |
436 | InsertColumn( 4, _("Attributes"), wxLIST_FORMAT_LEFT, w ); | |
23254b13 JS |
437 | #endif |
438 | ||
8f4fcc4e | 439 | UpdateFiles(); |
8b17ba72 RR |
440 | } |
441 | ||
06cc1fb9 | 442 | void wxFileCtrl::ChangeToSmallIconMode() |
8b17ba72 | 443 | { |
23254b13 | 444 | ClearAll(); |
06cc1fb9 | 445 | SetSingleStyle( wxLC_SMALL_ICON ); |
8f4fcc4e | 446 | UpdateFiles(); |
8b17ba72 RR |
447 | } |
448 | ||
449 | void wxFileCtrl::ShowHidden( bool show ) | |
450 | { | |
451 | m_showHidden = show; | |
8f4fcc4e | 452 | UpdateFiles(); |
8b17ba72 RR |
453 | } |
454 | ||
0b855868 RR |
455 | long wxFileCtrl::Add( wxFileData *fd, wxListItem &item ) |
456 | { | |
457 | long ret = -1; | |
458 | item.m_mask = wxLIST_MASK_TEXT + wxLIST_MASK_DATA + wxLIST_MASK_IMAGE; | |
459 | fd->MakeItem( item ); | |
460 | long my_style = GetWindowStyleFlag(); | |
461 | if (my_style & wxLC_REPORT) | |
462 | { | |
463 | ret = InsertItem( item ); | |
23254b13 JS |
464 | for (int i = 1; i < wxFileData::FileList_Max; i++) |
465 | SetItem( item.m_itemId, i, fd->GetEntry((wxFileData::fileListFieldType)i) ); | |
0b855868 | 466 | } |
06cc1fb9 | 467 | else if ((my_style & wxLC_LIST) || (my_style & wxLC_SMALL_ICON)) |
0b855868 RR |
468 | { |
469 | ret = InsertItem( item ); | |
c8c0e54c | 470 | } |
0b855868 RR |
471 | return ret; |
472 | } | |
473 | ||
b600ed13 VZ |
474 | void wxFileCtrl::UpdateItem(const wxListItem &item) |
475 | { | |
476 | wxFileData *fd = (wxFileData*)GetItemData(item); | |
477 | wxCHECK_RET(fd, wxT("invalid filedata")); | |
478 | ||
479 | fd->ReadData(); | |
480 | ||
481 | SetItemText(item, fd->GetFileName()); | |
c3627a00 | 482 | SetItemImage(item, fd->GetImageId()); |
b600ed13 VZ |
483 | |
484 | if (GetWindowStyleFlag() & wxLC_REPORT) | |
485 | { | |
486 | for (int i = 1; i < wxFileData::FileList_Max; i++) | |
487 | SetItem( item.m_itemId, i, fd->GetEntry((wxFileData::fileListFieldType)i) ); | |
488 | } | |
489 | } | |
490 | ||
8f4fcc4e | 491 | void wxFileCtrl::UpdateFiles() |
c8c0e54c | 492 | { |
2b5f62a0 | 493 | // don't do anything before ShowModal() call which sets m_dirName |
23254b13 | 494 | if ( m_dirName == wxT("*") ) |
2b5f62a0 VZ |
495 | return; |
496 | ||
37fd1c97 | 497 | wxBusyCursor bcur; // this may take a while... |
7a82dabc | 498 | |
23254b13 | 499 | DeleteAllItems(); |
7a82dabc | 500 | |
8b17ba72 | 501 | wxListItem item; |
8b17ba72 RR |
502 | item.m_itemId = 0; |
503 | item.m_col = 0; | |
0b855868 | 504 | |
144cf6da | 505 | #if defined(__WINDOWS__) || defined(__DOS__) || defined(__WXMAC__) || defined(__OS2__) |
37fd1c97 | 506 | if ( IsTopMostDir(m_dirName) ) |
abc2a4cc | 507 | { |
06cc1fb9 JS |
508 | wxArrayString names, paths; |
509 | wxArrayInt icons; | |
510 | size_t n, count = wxGetAvailableDrives(paths, names, icons); | |
511 | ||
512 | for (n=0; n<count; n++) | |
abc2a4cc | 513 | { |
999836aa | 514 | wxFileData *fd = new wxFileData(paths[n], names[n], wxFileData::is_drive, icons[n]); |
81169710 | 515 | if (Add(fd, item) != -1) |
37fd1c97 | 516 | item.m_itemId++; |
81169710 VZ |
517 | else |
518 | delete fd; | |
37fd1c97 | 519 | } |
abc2a4cc | 520 | } |
5e673a6a | 521 | else |
06cc1fb9 | 522 | #endif // defined(__DOS__) || defined(__WINDOWS__) |
8b17ba72 | 523 | { |
5e673a6a VS |
524 | // Real directory... |
525 | if ( !IsTopMostDir(m_dirName) ) | |
8b17ba72 | 526 | { |
5e673a6a | 527 | wxString p(wxPathOnly(m_dirName)); |
144cf6da | 528 | #if defined(__UNIX__) && !defined(__OS2__) |
abc2a4cc | 529 | if (p.empty()) p = wxT("/"); |
06cc1fb9 | 530 | #endif // __UNIX__ |
999836aa | 531 | wxFileData *fd = new wxFileData(p, wxT(".."), wxFileData::is_dir, wxFileIconsTable::folder); |
81169710 | 532 | if (Add(fd, item) != -1) |
7448de8d | 533 | item.m_itemId++; |
81169710 VZ |
534 | else |
535 | delete fd; | |
8b17ba72 | 536 | } |
c8c0e54c | 537 | |
5e673a6a | 538 | wxString dirname(m_dirName); |
144cf6da | 539 | #if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) |
5e673a6a VS |
540 | if (dirname.length() == 2 && dirname[1u] == wxT(':')) |
541 | dirname << wxT('\\'); | |
144cf6da | 542 | #endif // defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) |
5e673a6a VS |
543 | wxDir dir(dirname); |
544 | ||
545 | if ( dir.IsOpened() ) | |
cae5359f | 546 | { |
23254b13 JS |
547 | wxString dirPrefix(dirname); |
548 | if (dirPrefix.Last() != wxFILE_SEP_PATH) | |
549 | dirPrefix += wxFILE_SEP_PATH; | |
550 | ||
5e673a6a | 551 | int hiddenFlag = m_showHidden ? wxDIR_HIDDEN : 0; |
7a82dabc | 552 | |
5e673a6a VS |
553 | bool cont; |
554 | wxString f; | |
555 | ||
556 | // Get the directories first (not matched against wildcards): | |
557 | cont = dir.GetFirst(&f, wxEmptyString, wxDIR_DIRS | hiddenFlag); | |
558 | while (cont) | |
551adc4b | 559 | { |
999836aa | 560 | wxFileData *fd = new wxFileData(dirPrefix + f, f, wxFileData::is_dir, wxFileIconsTable::folder); |
81169710 | 561 | if (Add(fd, item) != -1) |
7448de8d | 562 | item.m_itemId++; |
81169710 VZ |
563 | else |
564 | delete fd; | |
565 | ||
5e673a6a VS |
566 | cont = dir.GetNext(&f); |
567 | } | |
568 | ||
7a82dabc | 569 | // Tokenize the wildcard string, so we can handle more than 1 |
5e673a6a VS |
570 | // search pattern in a wildcard. |
571 | wxStringTokenizer tokenWild(m_wild, wxT(";")); | |
572 | while ( tokenWild.HasMoreTokens() ) | |
573 | { | |
7a82dabc | 574 | cont = dir.GetFirst(&f, tokenWild.GetNextToken(), |
5e673a6a VS |
575 | wxDIR_FILES | hiddenFlag); |
576 | while (cont) | |
577 | { | |
999836aa | 578 | wxFileData *fd = new wxFileData(dirPrefix + f, f, wxFileData::is_file, wxFileIconsTable::file); |
81169710 | 579 | if (Add(fd, item) != -1) |
7448de8d | 580 | item.m_itemId++; |
81169710 VZ |
581 | else |
582 | delete fd; | |
583 | ||
5e673a6a VS |
584 | cont = dir.GetNext(&f); |
585 | } | |
551adc4b | 586 | } |
cae5359f | 587 | } |
cae5359f | 588 | } |
c8c0e54c | 589 | |
06cc1fb9 | 590 | SortItems(m_sort_field, m_sort_foward); |
8b17ba72 RR |
591 | } |
592 | ||
0b855868 | 593 | void wxFileCtrl::SetWild( const wxString &wild ) |
8b17ba72 | 594 | { |
06cc1fb9 JS |
595 | if (wild.Find(wxT('|')) != wxNOT_FOUND) |
596 | return; | |
597 | ||
0b855868 | 598 | m_wild = wild; |
8f4fcc4e | 599 | UpdateFiles(); |
0b855868 RR |
600 | } |
601 | ||
602 | void wxFileCtrl::MakeDir() | |
603 | { | |
5e673a6a | 604 | wxString new_name( _("NewName") ); |
0b855868 | 605 | wxString path( m_dirName ); |
75ec8bd4 | 606 | path += wxFILE_SEP_PATH; |
0b855868 RR |
607 | path += new_name; |
608 | if (wxFileExists(path)) | |
8b17ba72 | 609 | { |
0b855868 RR |
610 | // try NewName0, NewName1 etc. |
611 | int i = 0; | |
c8c0e54c | 612 | do { |
0b855868 | 613 | new_name = _("NewName"); |
c8c0e54c | 614 | wxString num; |
223d09f6 | 615 | num.Printf( wxT("%d"), i ); |
c8c0e54c VZ |
616 | new_name += num; |
617 | ||
0b855868 | 618 | path = m_dirName; |
75ec8bd4 | 619 | path += wxFILE_SEP_PATH; |
0b855868 | 620 | path += new_name; |
c8c0e54c VZ |
621 | i++; |
622 | } while (wxFileExists(path)); | |
8b17ba72 | 623 | } |
c8c0e54c | 624 | |
0b855868 | 625 | wxLogNull log; |
c8c0e54c | 626 | if (!wxMkdir(path)) |
8b17ba72 | 627 | { |
0b855868 | 628 | wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR ); |
c8c0e54c | 629 | dialog.ShowModal(); |
0b855868 | 630 | return; |
8b17ba72 | 631 | } |
8b17ba72 | 632 | |
06cc1fb9 | 633 | wxFileData *fd = new wxFileData( path, new_name, wxFileData::is_dir, wxFileIconsTable::folder ); |
0b855868 RR |
634 | wxListItem item; |
635 | item.m_itemId = 0; | |
636 | item.m_col = 0; | |
13111b2a | 637 | long id = Add( fd, item ); |
c8c0e54c | 638 | |
0b855868 RR |
639 | if (id != -1) |
640 | { | |
06cc1fb9 | 641 | SortItems(m_sort_field, m_sort_foward); |
c8c0e54c | 642 | id = FindItem( 0, (long)fd ); |
0b855868 RR |
643 | EnsureVisible( id ); |
644 | EditLabel( id ); | |
645 | } | |
81169710 VZ |
646 | else |
647 | delete fd; | |
8b17ba72 RR |
648 | } |
649 | ||
650 | void wxFileCtrl::GoToParentDir() | |
651 | { | |
5e673a6a | 652 | if (!IsTopMostDir(m_dirName)) |
8b17ba72 | 653 | { |
353f41cb | 654 | size_t len = m_dirName.Len(); |
083f7497 | 655 | if (wxEndsWithPathSeparator(m_dirName)) |
353f41cb | 656 | m_dirName.Remove( len-1, 1 ); |
c8c0e54c | 657 | wxString fname( wxFileNameFromPath(m_dirName) ); |
0b855868 | 658 | m_dirName = wxPathOnly( m_dirName ); |
144cf6da | 659 | #if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) |
abc2a4cc | 660 | if (!m_dirName.empty()) |
23254b13 JS |
661 | { |
662 | if (m_dirName.Last() == wxT('.')) | |
ca65c044 | 663 | m_dirName = wxEmptyString; |
23254b13 JS |
664 | } |
665 | #elif defined(__UNIX__) | |
abc2a4cc | 666 | if (m_dirName.empty()) |
5e673a6a VS |
667 | m_dirName = wxT("/"); |
668 | #endif | |
8f4fcc4e | 669 | UpdateFiles(); |
13111b2a | 670 | long id = FindItem( 0, fname ); |
abc2a4cc | 671 | if (id != wxNOT_FOUND) |
c8c0e54c VZ |
672 | { |
673 | SetItemState( id, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); | |
674 | EnsureVisible( id ); | |
675 | } | |
8b17ba72 RR |
676 | } |
677 | } | |
678 | ||
679 | void wxFileCtrl::GoToHomeDir() | |
680 | { | |
681 | wxString s = wxGetUserHome( wxString() ); | |
5e673a6a | 682 | GoToDir(s); |
8b17ba72 RR |
683 | } |
684 | ||
685 | void wxFileCtrl::GoToDir( const wxString &dir ) | |
686 | { | |
da865fdd | 687 | if (!wxDirExists(dir)) return; |
06cc1fb9 | 688 | |
8b17ba72 | 689 | m_dirName = dir; |
8f4fcc4e | 690 | UpdateFiles(); |
e6daf794 RR |
691 | SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); |
692 | EnsureVisible( 0 ); | |
8b17ba72 RR |
693 | } |
694 | ||
81169710 | 695 | void wxFileCtrl::FreeItemData(wxListItem& item) |
8b17ba72 | 696 | { |
81169710 VZ |
697 | if ( item.m_data ) |
698 | { | |
699 | wxFileData *fd = (wxFileData*)item.m_data; | |
700 | delete fd; | |
701 | ||
702 | item.m_data = 0; | |
703 | } | |
8b17ba72 RR |
704 | } |
705 | ||
7a82dabc VZ |
706 | void wxFileCtrl::OnListDeleteItem( wxListEvent &event ) |
707 | { | |
708 | FreeItemData(event.m_item); | |
709 | } | |
710 | ||
a3a363f6 | 711 | void wxFileCtrl::OnListDeleteAllItems( wxListEvent & WXUNUSED(event) ) |
81169710 VZ |
712 | { |
713 | FreeAllItemsData(); | |
714 | } | |
715 | ||
7a82dabc | 716 | void wxFileCtrl::FreeAllItemsData() |
12c1b46a RR |
717 | { |
718 | wxListItem item; | |
719 | item.m_mask = wxLIST_MASK_DATA; | |
720 | ||
721 | item.m_itemId = GetNextItem( -1, wxLIST_NEXT_ALL ); | |
92da8bde | 722 | while ( item.m_itemId != -1 ) |
12c1b46a RR |
723 | { |
724 | GetItem( item ); | |
7a82dabc | 725 | FreeItemData(item); |
12c1b46a RR |
726 | item.m_itemId = GetNextItem( item.m_itemId, wxLIST_NEXT_ALL ); |
727 | } | |
728 | } | |
729 | ||
0b855868 | 730 | void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event ) |
8b17ba72 RR |
731 | { |
732 | wxFileData *fd = (wxFileData*)event.m_item.m_data; | |
0b855868 | 733 | wxASSERT( fd ); |
c8c0e54c | 734 | |
abc2a4cc | 735 | if ((event.GetLabel().empty()) || |
0b855868 RR |
736 | (event.GetLabel() == _(".")) || |
737 | (event.GetLabel() == _("..")) || | |
75ec8bd4 | 738 | (event.GetLabel().First( wxFILE_SEP_PATH ) != wxNOT_FOUND)) |
8b17ba72 | 739 | { |
0b855868 | 740 | wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR ); |
c8c0e54c | 741 | dialog.ShowModal(); |
0b855868 | 742 | event.Veto(); |
c8c0e54c | 743 | return; |
8b17ba72 | 744 | } |
c8c0e54c | 745 | |
06cc1fb9 | 746 | wxString new_name( wxPathOnly( fd->GetFilePath() ) ); |
75ec8bd4 | 747 | new_name += wxFILE_SEP_PATH; |
0b855868 | 748 | new_name += event.GetLabel(); |
c8c0e54c | 749 | |
0b855868 | 750 | wxLogNull log; |
c8c0e54c | 751 | |
0b855868 | 752 | if (wxFileExists(new_name)) |
8b17ba72 | 753 | { |
0b855868 | 754 | wxMessageDialog dialog(this, _("File name exists already."), _("Error"), wxOK | wxICON_ERROR ); |
c8c0e54c | 755 | dialog.ShowModal(); |
0b855868 | 756 | event.Veto(); |
8b17ba72 | 757 | } |
c8c0e54c | 758 | |
06cc1fb9 | 759 | if (wxRenameFile(fd->GetFilePath(),new_name)) |
8b17ba72 | 760 | { |
0b855868 | 761 | fd->SetNewName( new_name, event.GetLabel() ); |
c8c0e54c | 762 | SetItemState( event.GetItem(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); |
b600ed13 | 763 | UpdateItem( event.GetItem() ); |
0b855868 | 764 | EnsureVisible( event.GetItem() ); |
8b17ba72 RR |
765 | } |
766 | else | |
767 | { | |
0b855868 | 768 | wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR ); |
c8c0e54c | 769 | dialog.ShowModal(); |
0b855868 | 770 | event.Veto(); |
8b17ba72 | 771 | } |
8b17ba72 RR |
772 | } |
773 | ||
23254b13 JS |
774 | void wxFileCtrl::OnListColClick( wxListEvent &event ) |
775 | { | |
776 | int col = event.GetColumn(); | |
777 | ||
778 | switch (col) | |
779 | { | |
780 | case wxFileData::FileList_Name : | |
06cc1fb9 | 781 | case wxFileData::FileList_Size : |
23254b13 | 782 | case wxFileData::FileList_Type : |
23254b13 JS |
783 | case wxFileData::FileList_Time : break; |
784 | default : return; | |
785 | } | |
786 | ||
787 | if ((wxFileData::fileListFieldType)col == m_sort_field) | |
06cc1fb9 | 788 | m_sort_foward = !m_sort_foward; |
23254b13 JS |
789 | else |
790 | m_sort_field = (wxFileData::fileListFieldType)col; | |
791 | ||
06cc1fb9 | 792 | SortItems(m_sort_field, m_sort_foward); |
23254b13 JS |
793 | } |
794 | ||
795 | void wxFileCtrl::SortItems(wxFileData::fileListFieldType field, bool foward) | |
796 | { | |
797 | m_sort_field = field; | |
06cc1fb9 JS |
798 | m_sort_foward = foward; |
799 | long sort_dir = foward ? 1 : -1; | |
23254b13 JS |
800 | |
801 | switch (m_sort_field) | |
802 | { | |
803 | case wxFileData::FileList_Name : | |
804 | { | |
06cc1fb9 JS |
805 | wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataNameCompare, sort_dir); |
806 | break; | |
807 | } | |
808 | case wxFileData::FileList_Size : | |
809 | { | |
810 | wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataSizeCompare, sort_dir); | |
23254b13 JS |
811 | break; |
812 | } | |
813 | case wxFileData::FileList_Type : | |
814 | { | |
06cc1fb9 | 815 | wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataTypeCompare, sort_dir); |
23254b13 JS |
816 | break; |
817 | } | |
23254b13 JS |
818 | case wxFileData::FileList_Time : |
819 | { | |
06cc1fb9 | 820 | wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataTimeCompare, sort_dir); |
23254b13 JS |
821 | break; |
822 | } | |
823 | default : break; | |
824 | } | |
825 | } | |
826 | ||
7a82dabc VZ |
827 | wxFileCtrl::~wxFileCtrl() |
828 | { | |
118322a3 WS |
829 | // Normally the data are freed via an EVT_LIST_DELETE_ALL_ITEMS event and |
830 | // wxFileCtrl::OnListDeleteAllItems. But if the event is generated after | |
831 | // the destruction of the wxFileCtrl we need to free any data here: | |
832 | FreeAllItemsData(); | |
7a82dabc VZ |
833 | } |
834 | ||
8b17ba72 | 835 | //----------------------------------------------------------------------------- |
23254b13 | 836 | // wxGenericFileDialog |
8b17ba72 RR |
837 | //----------------------------------------------------------------------------- |
838 | ||
5e673a6a VS |
839 | #define ID_LIST_MODE (wxID_FILEDLGG ) |
840 | #define ID_REPORT_MODE (wxID_FILEDLGG + 1) | |
841 | #define ID_UP_DIR (wxID_FILEDLGG + 5) | |
842 | #define ID_PARENT_DIR (wxID_FILEDLGG + 6) | |
843 | #define ID_NEW_DIR (wxID_FILEDLGG + 7) | |
844 | #define ID_CHOICE (wxID_FILEDLGG + 8) | |
845 | #define ID_TEXT (wxID_FILEDLGG + 9) | |
846 | #define ID_LIST_CTRL (wxID_FILEDLGG + 10) | |
5e673a6a | 847 | #define ID_CHECK (wxID_FILEDLGG + 12) |
8b17ba72 | 848 | |
f74172ab | 849 | IMPLEMENT_DYNAMIC_CLASS(wxGenericFileDialog, wxFileDialogBase) |
23254b13 JS |
850 | |
851 | BEGIN_EVENT_TABLE(wxGenericFileDialog,wxDialog) | |
852 | EVT_BUTTON(ID_LIST_MODE, wxGenericFileDialog::OnList) | |
853 | EVT_BUTTON(ID_REPORT_MODE, wxGenericFileDialog::OnReport) | |
854 | EVT_BUTTON(ID_UP_DIR, wxGenericFileDialog::OnUp) | |
855 | EVT_BUTTON(ID_PARENT_DIR, wxGenericFileDialog::OnHome) | |
856 | EVT_BUTTON(ID_NEW_DIR, wxGenericFileDialog::OnNew) | |
857 | EVT_BUTTON(wxID_OK, wxGenericFileDialog::OnListOk) | |
858 | EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL, wxGenericFileDialog::OnSelected) | |
859 | EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL, wxGenericFileDialog::OnActivated) | |
860 | EVT_CHOICE(ID_CHOICE,wxGenericFileDialog::OnChoiceFilter) | |
861 | EVT_TEXT_ENTER(ID_TEXT,wxGenericFileDialog::OnTextEnter) | |
862 | EVT_TEXT(ID_TEXT,wxGenericFileDialog::OnTextChange) | |
863 | EVT_CHECKBOX(ID_CHECK,wxGenericFileDialog::OnCheck) | |
8b17ba72 RR |
864 | END_EVENT_TABLE() |
865 | ||
23254b13 | 866 | long wxGenericFileDialog::ms_lastViewStyle = wxLC_LIST; |
ca65c044 | 867 | bool wxGenericFileDialog::ms_lastShowHidden = false; |
655cf310 | 868 | |
fe6cf128 VZ |
869 | void wxGenericFileDialog::Init() |
870 | { | |
871 | m_bypassGenericImpl = false; | |
872 | ||
873 | m_choice = NULL; | |
874 | m_text = NULL; | |
875 | m_list = NULL; | |
876 | m_check = NULL; | |
877 | m_static = NULL; | |
878 | m_upDirButton = NULL; | |
879 | m_newDirButton = NULL; | |
880 | } | |
881 | ||
23254b13 | 882 | wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent, |
9cedab37 VZ |
883 | const wxString& message, |
884 | const wxString& defaultDir, | |
885 | const wxString& defaultFile, | |
886 | const wxString& wildCard, | |
fe6cf128 | 887 | long style, |
4e1901b7 | 888 | const wxPoint& pos, |
fe6cf128 | 889 | bool bypassGenericImpl ) : wxFileDialogBase() |
8b17ba72 | 890 | { |
fe6cf128 VZ |
891 | Init(); |
892 | Create( parent, message, defaultDir, defaultFile, wildCard, style, pos, bypassGenericImpl ); | |
4e1901b7 RR |
893 | } |
894 | ||
895 | bool wxGenericFileDialog::Create( wxWindow *parent, | |
abc2a4cc | 896 | const wxString& message, |
fe6cf128 | 897 | const wxString& defaultDir, |
abc2a4cc WS |
898 | const wxString& defaultFile, |
899 | const wxString& wildCard, | |
fe6cf128 VZ |
900 | long style, |
901 | const wxPoint& pos, | |
902 | bool bypassGenericImpl ) | |
4e1901b7 | 903 | { |
fe6cf128 VZ |
904 | m_bypassGenericImpl = bypassGenericImpl; |
905 | ||
7e4fb3b8 | 906 | if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFile, |
fe6cf128 VZ |
907 | wildCard, style, pos)) |
908 | { | |
909 | return false; | |
910 | } | |
911 | ||
912 | if (m_bypassGenericImpl) | |
913 | return true; | |
914 | ||
4e1901b7 | 915 | if (!wxDialog::Create( parent, wxID_ANY, message, pos, wxDefaultSize, |
fe6cf128 | 916 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )) |
4e1901b7 RR |
917 | { |
918 | return false; | |
919 | } | |
f74172ab | 920 | |
ca65c044 | 921 | if (wxConfig::Get(false)) |
eaf40b23 | 922 | { |
e7d9c398 | 923 | wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ViewStyle"), |
9cedab37 | 924 | &ms_lastViewStyle); |
e7d9c398 | 925 | wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ShowHidden"), |
9cedab37 | 926 | &ms_lastShowHidden); |
eaf40b23 VS |
927 | } |
928 | ||
9cedab37 VZ |
929 | if (m_dialogStyle == 0) |
930 | m_dialogStyle = wxOPEN; | |
7941ba11 | 931 | if ((m_dialogStyle & wxMULTIPLE ) && !(m_dialogStyle & wxOPEN)) |
9b00bb16 | 932 | m_dialogStyle |= wxOPEN; |
479cd5de | 933 | |
353f41cb | 934 | if ((m_dir.empty()) || (m_dir == wxT("."))) |
ac2def68 | 935 | { |
75ec8bd4 | 936 | m_dir = wxGetCwd(); |
ac2def68 | 937 | } |
7a82dabc | 938 | |
353f41cb | 939 | size_t len = m_dir.Len(); |
083f7497 | 940 | if ((len > 1) && (wxEndsWithPathSeparator(m_dir))) |
353f41cb RR |
941 | m_dir.Remove( len-1, 1 ); |
942 | ||
943 | m_path = m_dir; | |
75ec8bd4 | 944 | m_path += wxFILE_SEP_PATH; |
8b17ba72 | 945 | m_path += defaultFile; |
655cf310 | 946 | m_filterExtension = wxEmptyString; |
c8c0e54c | 947 | |
cae5359f | 948 | // layout |
4f5c180e | 949 | |
2b5f62a0 | 950 | bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); |
c8c0e54c | 951 | |
8b17ba72 | 952 | wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); |
c8c0e54c | 953 | |
8b17ba72 | 954 | wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL ); |
c8c0e54c | 955 | |
e6daf794 | 956 | wxBitmapButton *but; |
c8c0e54c | 957 | |
7a82dabc | 958 | but = new wxBitmapButton(this, ID_LIST_MODE, |
36668b35 | 959 | wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_BUTTON)); |
e6daf794 RR |
960 | #if wxUSE_TOOLTIPS |
961 | but->SetToolTip( _("View files as a list view") ); | |
962 | #endif | |
963 | buttonsizer->Add( but, 0, wxALL, 5 ); | |
c8c0e54c | 964 | |
60d2cc25 | 965 | but = new wxBitmapButton(this, ID_REPORT_MODE, |
36668b35 | 966 | wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_BUTTON)); |
e6daf794 RR |
967 | #if wxUSE_TOOLTIPS |
968 | but->SetToolTip( _("View files as a detailed view") ); | |
969 | #endif | |
970 | buttonsizer->Add( but, 0, wxALL, 5 ); | |
c8c0e54c | 971 | |
0b855868 | 972 | buttonsizer->Add( 30, 5, 1 ); |
e6daf794 | 973 | |
06cc1fb9 | 974 | m_upDirButton = new wxBitmapButton(this, ID_UP_DIR, |
36668b35 | 975 | wxArtProvider::GetBitmap(wxART_GO_DIR_UP, wxART_BUTTON)); |
e6daf794 | 976 | #if wxUSE_TOOLTIPS |
06cc1fb9 | 977 | m_upDirButton->SetToolTip( _("Go to parent directory") ); |
e6daf794 | 978 | #endif |
06cc1fb9 | 979 | buttonsizer->Add( m_upDirButton, 0, wxALL, 5 ); |
c8c0e54c | 980 | |
37fd1c97 | 981 | #ifndef __DOS__ // VS: Home directory is meaningless in MS-DOS... |
60d2cc25 | 982 | but = new wxBitmapButton(this, ID_PARENT_DIR, |
36668b35 | 983 | wxArtProvider::GetBitmap(wxART_GO_HOME, wxART_BUTTON)); |
e6daf794 RR |
984 | #if wxUSE_TOOLTIPS |
985 | but->SetToolTip( _("Go to home directory") ); | |
986 | #endif | |
987 | buttonsizer->Add( but, 0, wxALL, 5); | |
c8c0e54c | 988 | |
e6daf794 | 989 | buttonsizer->Add( 20, 20 ); |
75ec8bd4 | 990 | #endif //!__DOS__ |
c8c0e54c | 991 | |
06cc1fb9 | 992 | m_newDirButton = new wxBitmapButton(this, ID_NEW_DIR, |
36668b35 | 993 | wxArtProvider::GetBitmap(wxART_NEW_DIR, wxART_BUTTON)); |
e6daf794 | 994 | #if wxUSE_TOOLTIPS |
06cc1fb9 | 995 | m_newDirButton->SetToolTip( _("Create new directory") ); |
e6daf794 | 996 | #endif |
06cc1fb9 | 997 | buttonsizer->Add( m_newDirButton, 0, wxALL, 5 ); |
c8c0e54c | 998 | |
2b5f62a0 | 999 | if (is_pda) |
c15521c6 RR |
1000 | mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 0 ); |
1001 | else | |
1002 | mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 5 ); | |
c8c0e54c | 1003 | |
9c884972 | 1004 | wxBoxSizer *staticsizer = new wxBoxSizer( wxHORIZONTAL ); |
2b5f62a0 | 1005 | if (is_pda) |
ca65c044 WS |
1006 | staticsizer->Add( new wxStaticText( this, wxID_ANY, _("Current directory:") ), 0, wxRIGHT, 10 ); |
1007 | m_static = new wxStaticText( this, wxID_ANY, m_dir ); | |
9c884972 RR |
1008 | staticsizer->Add( m_static, 1 ); |
1009 | mainsizer->Add( staticsizer, 0, wxEXPAND | wxLEFT|wxRIGHT|wxBOTTOM, 10 ); | |
1010 | ||
cd6b752b | 1011 | long style2 = ms_lastViewStyle | wxSUNKEN_BORDER; |
9cedab37 | 1012 | if ( !(m_dialogStyle & wxMULTIPLE) ) |
cd6b752b | 1013 | style2 |= wxLC_SINGLE_SEL; |
9cedab37 | 1014 | |
23254b13 | 1015 | m_list = new wxFileCtrl( this, ID_LIST_CTRL, |
9548f380 | 1016 | wxEmptyString, ms_lastShowHidden, |
9cedab37 | 1017 | wxDefaultPosition, wxSize(540,200), |
cd6b752b | 1018 | style2); |
9cedab37 | 1019 | |
2b5f62a0 | 1020 | if (is_pda) |
c15521c6 | 1021 | { |
41fecb44 VS |
1022 | // PDAs have a different screen layout |
1023 | mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 5 ); | |
1024 | ||
41fecb44 VS |
1025 | wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL ); |
1026 | m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxPROCESS_ENTER ); | |
1027 | textsizer->Add( m_text, 1, wxCENTER | wxALL, 5 ); | |
1028 | mainsizer->Add( textsizer, 0, wxEXPAND ); | |
1029 | ||
ca06ee0d RR |
1030 | m_check = NULL; |
1031 | m_choice = new wxChoice( this, ID_CHOICE ); | |
1032 | textsizer->Add( m_choice, 1, wxCENTER|wxALL, 5 ); | |
41fecb44 VS |
1033 | |
1034 | buttonsizer = new wxBoxSizer( wxHORIZONTAL ); | |
5f7bcb48 VS |
1035 | buttonsizer->Add( new wxButton( this, wxID_OK ), 0, wxCENTER | wxALL, 5 ); |
1036 | buttonsizer->Add( new wxButton( this, wxID_CANCEL ), 0, wxCENTER | wxALL, 5 ); | |
41fecb44 | 1037 | mainsizer->Add( buttonsizer, 0, wxALIGN_RIGHT ); |
c15521c6 RR |
1038 | } |
1039 | else | |
1040 | { | |
41fecb44 VS |
1041 | mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 10 ); |
1042 | ||
1043 | wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL ); | |
1044 | m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxPROCESS_ENTER ); | |
1045 | textsizer->Add( m_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 ); | |
5f7bcb48 | 1046 | textsizer->Add( new wxButton( this, wxID_OK ), 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 ); |
41fecb44 VS |
1047 | mainsizer->Add( textsizer, 0, wxEXPAND ); |
1048 | ||
1049 | wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL ); | |
1050 | m_choice = new wxChoice( this, ID_CHOICE ); | |
1051 | choicesizer->Add( m_choice, 1, wxCENTER|wxALL, 10 ); | |
1052 | m_check = new wxCheckBox( this, ID_CHECK, _("Show hidden files") ); | |
9cedab37 | 1053 | m_check->SetValue( ms_lastShowHidden ); |
41fecb44 | 1054 | choicesizer->Add( m_check, 0, wxCENTER|wxALL, 10 ); |
5f7bcb48 | 1055 | choicesizer->Add( new wxButton( this, wxID_CANCEL ), 0, wxCENTER | wxALL, 10 ); |
41fecb44 | 1056 | mainsizer->Add( choicesizer, 0, wxEXPAND ); |
c15521c6 | 1057 | } |
24f932d2 | 1058 | |
b4cfe261 | 1059 | SetWildcard(wildCard); |
8b17ba72 | 1060 | |
ca65c044 | 1061 | SetAutoLayout( true ); |
8b17ba72 | 1062 | SetSizer( mainsizer ); |
c8c0e54c | 1063 | |
8b17ba72 RR |
1064 | mainsizer->Fit( this ); |
1065 | mainsizer->SetSizeHints( this ); | |
48fe8374 | 1066 | |
8b17ba72 | 1067 | Centre( wxBOTH ); |
ed58dbea | 1068 | |
9cedab37 | 1069 | m_text->SetFocus(); |
abc2a4cc | 1070 | |
4e1901b7 | 1071 | return true; |
8b17ba72 RR |
1072 | } |
1073 | ||
23254b13 | 1074 | wxGenericFileDialog::~wxGenericFileDialog() |
cae5359f | 1075 | { |
4e1901b7 | 1076 | if (!m_bypassGenericImpl) |
eaf40b23 | 1077 | { |
4e1901b7 RR |
1078 | if (wxConfig::Get(false)) |
1079 | { | |
1080 | wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ViewStyle"), | |
1081 | ms_lastViewStyle); | |
1082 | wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ShowHidden"), | |
1083 | ms_lastShowHidden); | |
1084 | } | |
c5ef41d3 | 1085 | |
4e1901b7 RR |
1086 | const int count = m_choice->GetCount(); |
1087 | for ( int i = 0; i < count; i++ ) | |
1088 | { | |
1089 | delete (wxString *)m_choice->GetClientData(i); | |
1090 | } | |
c5ef41d3 | 1091 | } |
cae5359f RR |
1092 | } |
1093 | ||
23254b13 | 1094 | int wxGenericFileDialog::ShowModal() |
9cedab37 VZ |
1095 | { |
1096 | m_list->GoToDir(m_dir); | |
06cc1fb9 | 1097 | UpdateControls(); |
2b5f62a0 | 1098 | m_text->SetValue(m_fileName); |
9cedab37 VZ |
1099 | |
1100 | return wxDialog::ShowModal(); | |
1101 | } | |
1102 | ||
16dce3b3 RR |
1103 | bool wxGenericFileDialog::Show( bool show ) |
1104 | { | |
1105 | if (show) | |
1106 | { | |
1107 | m_list->GoToDir(m_dir); | |
1108 | UpdateControls(); | |
1109 | m_text->SetValue(m_fileName); | |
1110 | } | |
1111 | ||
1112 | return wxDialog::Show( show ); | |
1113 | } | |
1114 | ||
23254b13 | 1115 | void wxGenericFileDialog::DoSetFilterIndex(int filterindex) |
2b5f62a0 VZ |
1116 | { |
1117 | wxString *str = (wxString*) m_choice->GetClientData( filterindex ); | |
1118 | m_list->SetWild( *str ); | |
1119 | m_filterIndex = filterindex; | |
1120 | if ( str->Left(2) == wxT("*.") ) | |
1121 | { | |
787d22ec JS |
1122 | m_filterExtension = str->Mid(1); |
1123 | if (m_filterExtension == _T(".*")) | |
2b5f62a0 VZ |
1124 | m_filterExtension.clear(); |
1125 | } | |
1126 | else | |
1127 | { | |
1128 | m_filterExtension.clear(); | |
1129 | } | |
1130 | } | |
1131 | ||
b4cfe261 VZ |
1132 | void wxGenericFileDialog::SetWildcard(const wxString& wildCard) |
1133 | { | |
1134 | wxFileDialogBase::SetWildcard(wildCard); | |
1135 | ||
1136 | wxArrayString wildDescriptions, wildFilters; | |
1137 | const size_t count = wxParseCommonDialogsFilter(m_wildCard, | |
1138 | wildDescriptions, | |
1139 | wildFilters); | |
1140 | wxCHECK_RET( count, wxT("wxFileDialog: bad wildcard string") ); | |
1141 | ||
7e4fb3b8 VZ |
1142 | const size_t countOld = m_choice->GetCount(); |
1143 | size_t n; | |
1144 | for ( n = 0; n < countOld; n++ ) | |
fe6cf128 VZ |
1145 | { |
1146 | delete (wxString *)m_choice->GetClientData(n); | |
1147 | } | |
7e4fb3b8 | 1148 | |
fe6cf128 | 1149 | for ( n = 0; n < count; n++ ) |
b4cfe261 VZ |
1150 | { |
1151 | m_choice->Append( wildDescriptions[n], new wxString( wildFilters[n] ) ); | |
1152 | } | |
1153 | ||
1154 | SetFilterIndex( 0 ); | |
1155 | } | |
1156 | ||
23254b13 | 1157 | void wxGenericFileDialog::SetFilterIndex( int filterindex ) |
04ea7f93 RR |
1158 | { |
1159 | m_choice->SetSelection( filterindex ); | |
2b5f62a0 VZ |
1160 | |
1161 | DoSetFilterIndex(filterindex); | |
04ea7f93 RR |
1162 | } |
1163 | ||
23254b13 | 1164 | void wxGenericFileDialog::OnChoiceFilter( wxCommandEvent &event ) |
cae5359f | 1165 | { |
2b5f62a0 | 1166 | DoSetFilterIndex((int)event.GetInt()); |
cae5359f RR |
1167 | } |
1168 | ||
23254b13 | 1169 | void wxGenericFileDialog::OnCheck( wxCommandEvent &event ) |
bf9e3e73 | 1170 | { |
9cedab37 | 1171 | m_list->ShowHidden( (ms_lastShowHidden = event.GetInt() != 0) ); |
bf9e3e73 RR |
1172 | } |
1173 | ||
23254b13 | 1174 | void wxGenericFileDialog::OnActivated( wxListEvent &event ) |
8b17ba72 | 1175 | { |
e1811a01 | 1176 | HandleAction( event.m_item.m_text ); |
8b17ba72 RR |
1177 | } |
1178 | ||
23254b13 | 1179 | void wxGenericFileDialog::OnTextEnter( wxCommandEvent &WXUNUSED(event) ) |
cae5359f RR |
1180 | { |
1181 | wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); | |
1182 | cevent.SetEventObject( this ); | |
1183 | GetEventHandler()->ProcessEvent( cevent ); | |
1184 | } | |
1185 | ||
ca65c044 | 1186 | static bool ignoreChanges = false; |
df413171 | 1187 | |
23254b13 | 1188 | void wxGenericFileDialog::OnTextChange( wxCommandEvent &WXUNUSED(event) ) |
df413171 JS |
1189 | { |
1190 | if (!ignoreChanges) | |
1191 | { | |
1192 | // Clear selections. Otherwise when the user types in a value they may | |
1193 | // not get the file whose name they typed. | |
1194 | if (m_list->GetSelectedItemCount() > 0) | |
1195 | { | |
7f04165e | 1196 | long item = m_list->GetNextItem(-1, wxLIST_NEXT_ALL, |
df413171 JS |
1197 | wxLIST_STATE_SELECTED); |
1198 | while ( item != -1 ) | |
7f04165e | 1199 | { |
df413171 JS |
1200 | m_list->SetItemState(item,0, wxLIST_STATE_SELECTED); |
1201 | item = m_list->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); | |
7f04165e | 1202 | } |
df413171 JS |
1203 | } |
1204 | } | |
1205 | } | |
1206 | ||
23254b13 | 1207 | void wxGenericFileDialog::OnSelected( wxListEvent &event ) |
8b17ba72 | 1208 | { |
e1811a01 | 1209 | wxString filename( event.m_item.m_text ); |
223d09f6 | 1210 | if (filename == wxT("..")) return; |
479cd5de | 1211 | |
06cc1fb9 | 1212 | wxString dir = m_list->GetDir(); |
5e673a6a VS |
1213 | if (!IsTopMostDir(dir)) |
1214 | dir += wxFILE_SEP_PATH; | |
e1811a01 | 1215 | dir += filename; |
da865fdd | 1216 | if (wxDirExists(dir)) return; |
479cd5de | 1217 | |
ca65c044 | 1218 | ignoreChanges = true; |
e1811a01 | 1219 | m_text->SetValue( filename ); |
ca65c044 | 1220 | ignoreChanges = false; |
8b17ba72 RR |
1221 | } |
1222 | ||
23254b13 | 1223 | void wxGenericFileDialog::HandleAction( const wxString &fn ) |
8b17ba72 | 1224 | { |
e1811a01 | 1225 | wxString filename( fn ); |
06cc1fb9 | 1226 | wxString dir = m_list->GetDir(); |
abc2a4cc | 1227 | if (filename.empty()) return; |
223d09f6 | 1228 | if (filename == wxT(".")) return; |
c8c0e54c | 1229 | |
b600ed13 VZ |
1230 | // "some/place/" means they want to chdir not try to load "place" |
1231 | bool want_dir = filename.Last() == wxFILE_SEP_PATH; | |
1232 | if (want_dir) | |
1233 | filename = filename.RemoveLast(); | |
1234 | ||
223d09f6 | 1235 | if (filename == wxT("..")) |
0b855868 RR |
1236 | { |
1237 | m_list->GoToParentDir(); | |
1238 | m_list->SetFocus(); | |
06cc1fb9 | 1239 | UpdateControls(); |
c8c0e54c | 1240 | return; |
0b855868 RR |
1241 | } |
1242 | ||
75ec8bd4 | 1243 | #ifdef __UNIX__ |
223d09f6 | 1244 | if (filename == wxT("~")) |
ed58dbea RR |
1245 | { |
1246 | m_list->GoToHomeDir(); | |
1247 | m_list->SetFocus(); | |
06cc1fb9 | 1248 | UpdateControls(); |
c8c0e54c | 1249 | return; |
ed58dbea | 1250 | } |
c8c0e54c | 1251 | |
b600ed13 | 1252 | if (filename.BeforeFirst(wxT('/')) == wxT("~")) |
ed58dbea | 1253 | { |
71f2fb52 | 1254 | filename = wxString(wxGetUserHome()) + filename.Remove(0, 1); |
ed58dbea | 1255 | } |
75ec8bd4 | 1256 | #endif // __UNIX__ |
ed58dbea | 1257 | |
854aa1e1 | 1258 | if (!(m_dialogStyle & wxSAVE)) |
cae5359f | 1259 | { |
854aa1e1 RR |
1260 | if ((filename.Find(wxT('*')) != wxNOT_FOUND) || |
1261 | (filename.Find(wxT('?')) != wxNOT_FOUND)) | |
c8c0e54c | 1262 | { |
854aa1e1 RR |
1263 | if (filename.Find(wxFILE_SEP_PATH) != wxNOT_FOUND) |
1264 | { | |
1265 | wxMessageBox(_("Illegal file specification."), _("Error"), wxOK | wxICON_ERROR ); | |
1266 | return; | |
1267 | } | |
1268 | m_list->SetWild( filename ); | |
c8c0e54c VZ |
1269 | return; |
1270 | } | |
cae5359f RR |
1271 | } |
1272 | ||
5e673a6a VS |
1273 | if (!IsTopMostDir(dir)) |
1274 | dir += wxFILE_SEP_PATH; | |
1275 | if (!wxIsAbsolutePath(filename)) | |
ed58dbea RR |
1276 | { |
1277 | dir += filename; | |
1278 | filename = dir; | |
1279 | } | |
c8c0e54c | 1280 | |
da865fdd | 1281 | if (wxDirExists(filename)) |
8b17ba72 RR |
1282 | { |
1283 | m_list->GoToDir( filename ); | |
06cc1fb9 | 1284 | UpdateControls(); |
c8c0e54c | 1285 | return; |
8b17ba72 | 1286 | } |
c8c0e54c | 1287 | |
b600ed13 VZ |
1288 | // they really wanted a dir, but it doesn't exist |
1289 | if (want_dir) | |
1290 | { | |
1291 | wxMessageBox(_("Directory doesn't exist."), _("Error"), | |
1292 | wxOK | wxICON_ERROR ); | |
1293 | return; | |
1294 | } | |
1295 | ||
2b5f62a0 VZ |
1296 | // append the default extension to the filename if it doesn't have any |
1297 | // | |
1298 | // VZ: the logic of testing for !wxFileExists() only for the open file | |
1299 | // dialog is not entirely clear to me, why don't we allow saving to a | |
1300 | // file without extension as well? | |
1301 | if ( !(m_dialogStyle & wxOPEN) || !wxFileExists(filename) ) | |
8b17ba72 | 1302 | { |
f74172ab | 1303 | filename = AppendExtension(filename, m_filterExtension); |
8b17ba72 | 1304 | } |
2b5f62a0 VZ |
1305 | |
1306 | // check that the file [doesn't] exist if necessary | |
1307 | if ( (m_dialogStyle & wxSAVE) && | |
1308 | (m_dialogStyle & wxOVERWRITE_PROMPT) && | |
1309 | wxFileExists( filename ) ) | |
8b17ba72 | 1310 | { |
2b5f62a0 | 1311 | wxString msg; |
88d6c988 | 1312 | msg.Printf( _("File '%s' already exists, do you really want to overwrite it?"), filename.c_str() ); |
655cf310 | 1313 | |
2b5f62a0 VZ |
1314 | if (wxMessageBox(msg, _("Confirm"), wxYES_NO) != wxYES) |
1315 | return; | |
1316 | } | |
1317 | else if ( (m_dialogStyle & wxOPEN) && | |
1318 | (m_dialogStyle & wxFILE_MUST_EXIST) && | |
1319 | !wxFileExists(filename) ) | |
1320 | { | |
1321 | wxMessageBox(_("Please choose an existing file."), _("Error"), | |
1322 | wxOK | wxICON_ERROR ); | |
8b17ba72 RR |
1323 | } |
1324 | ||
1325 | SetPath( filename ); | |
479cd5de | 1326 | |
3f6638b8 | 1327 | // change to the directory where the user went if asked |
fda09b3f | 1328 | if ( m_dialogStyle & wxCHANGE_DIR ) |
3f6638b8 VZ |
1329 | { |
1330 | wxString cwd; | |
1331 | wxSplitPath(filename, &cwd, NULL, NULL); | |
1332 | ||
0b98a252 | 1333 | if ( cwd != wxGetCwd() ) |
3f6638b8 VZ |
1334 | { |
1335 | wxSetWorkingDirectory(cwd); | |
1336 | } | |
1337 | } | |
1338 | ||
9b7e522a RR |
1339 | wxCommandEvent event; |
1340 | wxDialog::OnOK(event); | |
e1811a01 RR |
1341 | } |
1342 | ||
23254b13 | 1343 | void wxGenericFileDialog::OnListOk( wxCommandEvent &WXUNUSED(event) ) |
e1811a01 RR |
1344 | { |
1345 | HandleAction( m_text->GetValue() ); | |
8b17ba72 RR |
1346 | } |
1347 | ||
23254b13 | 1348 | void wxGenericFileDialog::OnList( wxCommandEvent &WXUNUSED(event) ) |
8b17ba72 RR |
1349 | { |
1350 | m_list->ChangeToListMode(); | |
9cedab37 | 1351 | ms_lastViewStyle = wxLC_LIST; |
0b855868 | 1352 | m_list->SetFocus(); |
8b17ba72 RR |
1353 | } |
1354 | ||
23254b13 | 1355 | void wxGenericFileDialog::OnReport( wxCommandEvent &WXUNUSED(event) ) |
8b17ba72 RR |
1356 | { |
1357 | m_list->ChangeToReportMode(); | |
9cedab37 | 1358 | ms_lastViewStyle = wxLC_REPORT; |
0b855868 | 1359 | m_list->SetFocus(); |
8b17ba72 RR |
1360 | } |
1361 | ||
23254b13 | 1362 | void wxGenericFileDialog::OnUp( wxCommandEvent &WXUNUSED(event) ) |
8b17ba72 RR |
1363 | { |
1364 | m_list->GoToParentDir(); | |
0b855868 | 1365 | m_list->SetFocus(); |
06cc1fb9 | 1366 | UpdateControls(); |
8b17ba72 RR |
1367 | } |
1368 | ||
23254b13 | 1369 | void wxGenericFileDialog::OnHome( wxCommandEvent &WXUNUSED(event) ) |
8b17ba72 RR |
1370 | { |
1371 | m_list->GoToHomeDir(); | |
0b855868 | 1372 | m_list->SetFocus(); |
06cc1fb9 | 1373 | UpdateControls(); |
0b855868 RR |
1374 | } |
1375 | ||
23254b13 | 1376 | void wxGenericFileDialog::OnNew( wxCommandEvent &WXUNUSED(event) ) |
0b855868 RR |
1377 | { |
1378 | m_list->MakeDir(); | |
8b17ba72 RR |
1379 | } |
1380 | ||
23254b13 | 1381 | void wxGenericFileDialog::SetPath( const wxString& path ) |
8b17ba72 RR |
1382 | { |
1383 | // not only set the full path but also update filename and dir | |
1384 | m_path = path; | |
9cedab37 | 1385 | if ( !path.empty() ) |
8b17ba72 RR |
1386 | { |
1387 | wxString ext; | |
1388 | wxSplitPath(path, &m_dir, &m_fileName, &ext); | |
9cedab37 | 1389 | if (!ext.empty()) |
c8c0e54c | 1390 | { |
223d09f6 | 1391 | m_fileName += wxT("."); |
8b17ba72 | 1392 | m_fileName += ext; |
c8c0e54c | 1393 | } |
8b17ba72 RR |
1394 | } |
1395 | } | |
c8c0e54c | 1396 | |
23254b13 | 1397 | void wxGenericFileDialog::GetPaths( wxArrayString& paths ) const |
7941ba11 RR |
1398 | { |
1399 | paths.Empty(); | |
28c9c76e RR |
1400 | if (m_list->GetSelectedItemCount() == 0) |
1401 | { | |
1402 | paths.Add( GetPath() ); | |
1403 | return; | |
1404 | } | |
479cd5de | 1405 | |
7941ba11 RR |
1406 | paths.Alloc( m_list->GetSelectedItemCount() ); |
1407 | ||
06cc1fb9 | 1408 | wxString dir = m_list->GetDir(); |
5e673a6a | 1409 | #ifdef __UNIX__ |
7a82dabc | 1410 | if (dir != wxT("/")) |
5e673a6a VS |
1411 | #endif |
1412 | dir += wxFILE_SEP_PATH; | |
7941ba11 RR |
1413 | |
1414 | wxListItem item; | |
1415 | item.m_mask = wxLIST_MASK_TEXT; | |
1416 | ||
1417 | item.m_itemId = m_list->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); | |
92da8bde | 1418 | while ( item.m_itemId != -1 ) |
68df5777 | 1419 | { |
7941ba11 RR |
1420 | m_list->GetItem( item ); |
1421 | paths.Add( dir + item.m_text ); | |
68df5777 | 1422 | item.m_itemId = m_list->GetNextItem( item.m_itemId, |
7941ba11 RR |
1423 | wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); |
1424 | } | |
1425 | } | |
1426 | ||
23254b13 | 1427 | void wxGenericFileDialog::GetFilenames(wxArrayString& files) const |
7941ba11 RR |
1428 | { |
1429 | files.Empty(); | |
28c9c76e RR |
1430 | if (m_list->GetSelectedItemCount() == 0) |
1431 | { | |
1432 | files.Add( GetFilename() ); | |
1433 | return; | |
1434 | } | |
7941ba11 RR |
1435 | files.Alloc( m_list->GetSelectedItemCount() ); |
1436 | ||
1437 | wxListItem item; | |
1438 | item.m_mask = wxLIST_MASK_TEXT; | |
1439 | ||
1440 | item.m_itemId = m_list->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); | |
92da8bde | 1441 | while ( item.m_itemId != -1 ) |
68df5777 | 1442 | { |
7941ba11 RR |
1443 | m_list->GetItem( item ); |
1444 | files.Add( item.m_text ); | |
68df5777 | 1445 | item.m_itemId = m_list->GetNextItem( item.m_itemId, |
7941ba11 RR |
1446 | wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); |
1447 | } | |
1448 | } | |
1449 | ||
06cc1fb9 JS |
1450 | void wxGenericFileDialog::UpdateControls() |
1451 | { | |
1452 | wxString dir = m_list->GetDir(); | |
1453 | m_static->SetLabel(dir); | |
1454 | ||
1455 | bool enable = !IsTopMostDir(dir); | |
1456 | m_upDirButton->Enable(enable); | |
1457 | ||
144cf6da | 1458 | #if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) |
06cc1fb9 | 1459 | m_newDirButton->Enable(enable); |
144cf6da | 1460 | #endif // defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) |
06cc1fb9 JS |
1461 | } |
1462 | ||
23254b13 | 1463 | #ifdef USE_GENERIC_FILEDIALOG |
655cf310 | 1464 | |
23254b13 | 1465 | IMPLEMENT_DYNAMIC_CLASS(wxFileDialog, wxGenericFileDialog); |
655cf310 | 1466 | |
23254b13 JS |
1467 | #endif // USE_GENERIC_FILEDIALOG |
1468 | ||
4e1901b7 | 1469 | #endif // wxUSE_FILEDLG |
9cedab37 | 1470 |