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