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