1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGenericDirCtrl
4 // Author: Harm van der Heijden, Robert Roebling, Julian Smart
8 // Copyright: (c) Harm van der Heijden, Robert Roebling and Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dirctrl.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/dialog.h"
27 #include "wx/button.h"
28 #include "wx/layout.h"
29 #include "wx/msgdlg.h"
30 #include "wx/textdlg.h"
31 #include "wx/filefn.h"
32 #include "wx/cmndata.h"
33 #include "wx/gdicmn.h"
35 #include "wx/imaglist.h"
39 #include "wx/tokenzr.h"
43 #include "wx/statline.h"
46 #include "wx/generic/dirctrlg.h"
54 // If compiled under Windows, this macro can cause problems
59 #if !defined(__WXMSW__) || wxUSE_XPM_IN_MSW
61 static char * icon1_xpm
[] = {
62 /* width height ncolors chars_per_pixel */
90 static char * icon2_xpm
[] = {
91 /* width height ncolors chars_per_pixel */
119 static char * icon3_xpm
[] = {
120 /* width height ncolors chars_per_pixel */
145 static char * icon4_xpm
[] = {
172 static char * icon5_xpm
[] = {
199 static char *icon6_xpm
[] = {
229 static char * icon7_xpm
[] = {
256 static char * icon8_xpm
[] = {
283 static const int ID_DIRCTRL
= 1000;
284 static const int ID_TEXTCTRL
= 1001;
285 static const int ID_OK
= 1002;
286 static const int ID_CANCEL
= 1003;
287 static const int ID_NEW
= 1004;
288 //static const int ID_CHECK = 1005;
290 //-----------------------------------------------------------------------------
292 //-----------------------------------------------------------------------------
294 wxDirItemDataEx::wxDirItemDataEx(const wxString
& path
, const wxString
& name
,
299 /* Insert logic to detect hidden files here
300 * In UnixLand we just check whether the first char is a dot
301 * For FileNameFromPath read LastDirNameInThisPath ;-) */
302 // m_isHidden = (bool)(wxFileNameFromPath(*m_path)[0] == '.');
304 m_hasSubDirs
= HasSubDirs();
305 m_isExpanded
= FALSE
;
309 wxDirItemDataEx::~wxDirItemDataEx()
313 void wxDirItemDataEx::SetNewDirName( wxString path
)
316 m_name
= wxFileNameFromPath( path
);
319 bool wxDirItemDataEx::HasSubDirs()
321 wxString search
= m_path
+ wxT("/*");
323 wxString path
= wxFindFirstFile( search
, wxDIR
);
324 return (bool)(!path
.IsNull());
327 //-----------------------------------------------------------------------------
329 //-----------------------------------------------------------------------------
331 IMPLEMENT_DYNAMIC_CLASS(wxGenericDirCtrl
, wxControl
)
333 BEGIN_EVENT_TABLE(wxGenericDirCtrl
, wxControl
)
334 EVT_TREE_ITEM_EXPANDING (-1, wxGenericDirCtrl::OnExpandItem
)
335 EVT_TREE_ITEM_COLLAPSED (-1, wxGenericDirCtrl::OnCollapseItem
)
336 EVT_TREE_BEGIN_LABEL_EDIT (-1, wxGenericDirCtrl::OnBeginEditItem
)
337 EVT_TREE_END_LABEL_EDIT (-1, wxGenericDirCtrl::OnEndEditItem
)
338 EVT_SIZE (wxGenericDirCtrl::OnSize
)
341 wxGenericDirCtrl::wxGenericDirCtrl(void)
346 bool wxGenericDirCtrl::Create(wxWindow
*parent
,
352 const wxString
& filter
,
354 const wxString
& name
)
356 if (!wxControl::Create(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
359 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
363 long treeStyle
= wxTR_HAS_BUTTONS
;
364 if ((style
& wxDIRCTRL_3D_INTERNAL
) == 0)
365 treeStyle
|= wxNO_BORDER
;
367 long filterStyle
= 0;
368 if ((style
& wxDIRCTRL_3D_INTERNAL
) == 0)
369 filterStyle
|= wxNO_BORDER
;
371 m_treeCtrl
= new wxTreeCtrl(this, wxID_TREECTRL
, pos
, size
, treeStyle
);
373 if (!filter
.IsEmpty() && (style
& wxDIRCTRL_SHOW_FILTERS
))
374 m_filterListCtrl
= new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL
, wxDefaultPosition
, wxDefaultSize
, filterStyle
);
379 SetFilterIndex(defaultFilter
);
381 if (m_filterListCtrl
)
382 m_filterListCtrl
->FillFilterList(filter
, defaultFilter
);
384 m_imageList
= new wxImageList(16, 16, TRUE
);
385 #if !defined(__WXMSW__) || wxUSE_XPM_IN_MSW
386 m_imageList
->Add(wxIcon(icon1_xpm
));
387 m_imageList
->Add(wxIcon(icon2_xpm
));
388 m_imageList
->Add(wxIcon(icon3_xpm
));
389 m_imageList
->Add(wxIcon(icon4_xpm
));
390 m_imageList
->Add(wxIcon(icon5_xpm
));
391 m_imageList
->Add(wxIcon(icon6_xpm
));
392 m_imageList
->Add(wxIcon(icon7_xpm
));
393 m_imageList
->Add(wxIcon(icon8_xpm
));
394 #elif defined(__WXMSW__)
395 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CLOSED_FOLDER"), wxBITMAP_TYPE_RESOURCE
));
396 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_OPEN_FOLDER"), wxBITMAP_TYPE_RESOURCE
));
397 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FILE"), wxBITMAP_TYPE_RESOURCE
));
398 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_COMPUTER"), wxBITMAP_TYPE_RESOURCE
));
399 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_DRIVE"), wxBITMAP_TYPE_RESOURCE
));
400 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CDROM"), wxBITMAP_TYPE_RESOURCE
));
401 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FLOPPY"), wxBITMAP_TYPE_RESOURCE
));
402 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_REMOVEABLE"), wxBITMAP_TYPE_RESOURCE
));
404 #error "Sorry, we don't have icons available for this platforms."
406 m_treeCtrl
->SetImageList(m_imageList
);
408 m_showHidden
= FALSE
;
409 wxDirItemDataEx
* rootData
= new wxDirItemDataEx(wxT(""), wxT(""), TRUE
);
414 rootName
= _("Computer");
416 rootName
= _("Sections");
419 m_rootId
= m_treeCtrl
->AddRoot( rootName
, 3, -1, rootData
);
420 m_treeCtrl
->SetItemHasChildren(m_rootId
);
421 m_treeCtrl
->Expand(m_rootId
); // automatically expand first level
423 // Expand and select the default path
424 if (!m_defaultPath
.IsEmpty())
425 ExpandPath(m_defaultPath
);
432 wxGenericDirCtrl::~wxGenericDirCtrl()
434 m_treeCtrl
->SetImageList(NULL
);
438 void wxGenericDirCtrl::Init()
440 m_showHidden
= FALSE
;
444 m_currentFilterStr
= wxEmptyString
; // Default: any file
446 m_filterListCtrl
= NULL
;
449 void wxGenericDirCtrl::AddSection(const wxString
& path
, const wxString
& name
, int imageId
)
451 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,name
,TRUE
);
454 // Windows: sections are displayed as drives
455 wxTreeItemId id
= m_treeCtrl
->AppendItem( m_rootId
, name
, imageId
, -1, dir_item
);
457 // Unix: sections are displayed as folders
458 wxTreeItemId id
= m_treeCtrl
->AppendItem( m_rootId
, name
, 0, -1, dir_item
);
459 SetItemImage( id
, 1, wxTreeItemIcon_Expanded
);
461 // TODO: other operating systems.
463 m_treeCtrl
->SetItemHasChildren(id
);
466 void wxGenericDirCtrl::SetupSections()
471 wxChar driveBuffer
[256];
472 size_t n
= (size_t) GetLogicalDriveStrings(255, driveBuffer
);
477 path
.Printf(wxT("%c:\\"), driveBuffer
[i
]);
478 name
.Printf(wxT("(%c:)"), driveBuffer
[i
]);
481 int driveType
= ::GetDriveType(path
);
484 case DRIVE_REMOVABLE
:
485 if (path
== wxT("a:\\") || path
== wxT("b:\\"))
486 imageId
= 6; // Floppy
504 AddSection(path
, name
, imageId
);
506 while (driveBuffer
[i
] != wxT('\0'))
509 if (driveBuffer
[i
] == wxT('\0'))
516 /* Save current drive. */
517 currentDrive
= _getdrive();
519 /* If we can switch to the drive, it exists. */
520 for( drive
= 1; drive
<= 26; drive
++ )
523 path
.Printf(wxT("%c:\\"), (char) (drive
+ 'a' - 1));
524 name
.Printf(wxT("(%c:)"), (char) (drive
+ 'a' - 1));
526 if( !_chdrive( drive
) )
529 AddSection(path
, name
);
533 /* Restore original drive.*/
534 _chdrive( currentDrive
);
539 AddSection(wxT("/"), _("The Computer"), 0)
541 AddSection(home
, _("My Home"), 0 )
542 AddSection(wxT("/mnt"), _("Mounted Devices"), 0 )
543 AddSection(wxT("/usr/local"), _("User Local"), 0 )
544 AddSection(wxT("/usr"), _("User"), 0 )
545 AddSection(wxT("/var"), _("Variables"), 0 )
546 AddSection(wxT("/etc"), _("Etcetera"), 0 )
547 AddSection(wxT("/tmp"), _("Temporary"), 0 )
551 void wxGenericDirCtrl::OnBeginEditItem(wxTreeEvent
&event
)
553 // don't rename the main entry "Sections"
554 if (event
.GetItem() == m_rootId
)
560 // don't rename the individual sections
561 if (m_treeCtrl
->GetParent( event
.GetItem() ) == m_rootId
)
568 void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent
&event
)
570 if ((event
.GetLabel().IsEmpty()) ||
571 (event
.GetLabel() == _(".")) ||
572 (event
.GetLabel() == _("..")) ||
573 (event
.GetLabel().First( wxT("/") ) != wxNOT_FOUND
))
575 wxMessageDialog
dialog(this, _("Illegal directory name."), _("Error"), wxOK
| wxICON_ERROR
);
581 wxTreeItemId id
= event
.GetItem();
582 wxDirItemDataEx
*data
= (wxDirItemDataEx
*)m_treeCtrl
->GetItemData( id
);
585 wxString
new_name( wxPathOnly( data
->m_path
) );
586 new_name
+= wxT("/");
587 new_name
+= event
.GetLabel();
591 if (wxFileExists(new_name
))
593 wxMessageDialog
dialog(this, _("File name exists already."), _("Error"), wxOK
| wxICON_ERROR
);
598 if (wxRenameFile(data
->m_path
,new_name
))
600 data
->SetNewDirName( new_name
);
604 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
610 void wxGenericDirCtrl::OnExpandItem(wxTreeEvent
&event
)
612 wxTreeItemId parentId
= event
.GetItem();
617 void wxGenericDirCtrl::OnCollapseItem(wxTreeEvent
&event
)
619 wxTreeItemId child
, parent
= event
.GetItem();
621 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(event
.GetItem());
622 if (!data
->m_isExpanded
)
625 data
->m_isExpanded
= FALSE
;
627 /* Workaround because DeleteChildren has disapeared (why?) and
628 * CollapseAndReset doesn't work as advertised (deletes parent too) */
629 child
= m_treeCtrl
->GetFirstChild(parent
, cookie
);
632 m_treeCtrl
->Delete(child
);
633 /* Not GetNextChild below, because the cookie mechanism can't
634 * handle disappearing children! */
635 child
= m_treeCtrl
->GetFirstChild(parent
, cookie
);
639 void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId
)
641 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(parentId
);
643 if (data
->m_isExpanded
)
646 data
->m_isExpanded
= TRUE
;
648 if (parentId
== m_rootId
)
656 wxString search
,path
,filename
;
658 wxString
dirName(data
->m_path
);
661 // Check if this is a root directory and if so,
662 // whether the drive is avaiable.
663 if (dirName
.Len() == 3 && dirName
[1] == wxT(':'))
665 int currentDrive
= _getdrive();
666 int thisDrive
= (int) (dirName
[0] - 'a' + 1) ;
667 int err
= _chdrive( thisDrive
) ;
668 _chdrive( currentDrive
);
672 data
->m_isExpanded
= FALSE
;
673 wxMessageBox(wxT("Sorry, this drive is not available."));
679 // This may take a longish time. Go to busy cursor
683 if (dirName
.Last() == ':')
684 dirName
+= wxString(wxFILE_SEP_PATH
);
688 wxArrayString filenames
;
691 wxString eachFilename
;
697 if (d
.GetFirst(& eachFilename
, wxEmptyString
, wxDIR_DIRS
))
701 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
703 dirs
.Add(eachFilename
);
706 while (d
.GetNext(& eachFilename
)) ;
711 // Now do the filenames -- but only if we're allowed to
712 if ((GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) == 0)
718 if (d
.GetFirst(& eachFilename
, m_currentFilterStr
, wxDIR_FILES
))
722 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
724 filenames
.Add(eachFilename
);
727 while (d
.GetNext(& eachFilename
)) ;
733 // Add the sorted dirs
735 for (i
= 0; i
< dirs
.Count(); i
++)
737 wxString
eachFilename(dirs
[i
]);
739 if (path
.Last() != wxFILE_SEP_PATH
)
740 path
+= wxString(wxFILE_SEP_PATH
);
741 path
+= eachFilename
;
743 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,eachFilename
,TRUE
);
744 wxTreeItemId id
= m_treeCtrl
->AppendItem( parentId
, eachFilename
, 0, -1, dir_item
);
745 m_treeCtrl
->SetItemImage( id
, 1, wxTreeItemIcon_Expanded
);
747 // Has this got any children? If so, make it expandable.
748 int options
= wxDIR_DEFAULT
;
749 if (GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) // If only showing dirs, then we specify dirs only here
751 options
= wxDIR_DIRS
;
756 // Have to test for wxDIR_DIRS separately in case m_currentFilterStr is non-empty and
757 // and filters out any directories
758 if (dir2
.GetFirst(& str
, m_currentFilterStr
, options
) || dir2
.GetFirst(& str
, wxEmptyString
, wxDIR_DIRS
))
760 m_treeCtrl
->SetItemHasChildren(id
);
764 // Add the sorted filenames
765 if ((GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) == 0)
767 for (i
= 0; i
< filenames
.Count(); i
++)
769 wxString
eachFilename(filenames
[i
]);
771 if (path
.Last() != wxFILE_SEP_PATH
)
772 path
+= wxString(wxFILE_SEP_PATH
);
773 path
+= eachFilename
;
774 //path = dirName + wxString(wxT("/")) + eachFilename;
775 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,eachFilename
,FALSE
);
776 wxTreeItemId id
= m_treeCtrl
->AppendItem( parentId
, eachFilename
, 2, -1, dir_item
);
781 // Find the child that matches the first part of 'path'.
782 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
783 // then the child for /usr is returned.
784 wxTreeItemId
wxGenericDirCtrl::FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
)
786 wxString
path2(path
);
788 // Make sure all separators are as per the current platform
789 path2
.Replace(wxT("\\"), wxString(wxFILE_SEP_PATH
));
790 path2
.Replace(wxT("/"), wxString(wxFILE_SEP_PATH
));
792 // Append a separator to foil bogus substring matching
793 path2
+= wxString(wxFILE_SEP_PATH
);
795 // In MSW, case is not significant
801 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(parentId
, cookie
);
804 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(childId
);
806 if (data
&& data
->m_path
!= "")
808 wxString
childPath(data
->m_path
);
809 if (childPath
.Last() != wxFILE_SEP_PATH
)
810 childPath
+= wxString(wxFILE_SEP_PATH
);
812 // In MSW, case is not significant
814 childPath
.MakeLower();
817 if (childPath
.Len() <= path2
.Len())
819 wxString path3
= path2
.Mid(0, childPath
.Len());
820 if (childPath
== path3
)
822 if (path3
.Len() == path2
.Len())
831 childId
= m_treeCtrl
->GetNextChild(childId
, cookie
);
836 // Try to expand as much of the given path as possible,
837 // and select the given tree item.
838 bool wxGenericDirCtrl::ExpandPath(const wxString
& path
)
841 wxTreeItemId id
= FindChild(m_rootId
, path
, done
);
842 wxTreeItemId lastId
= id
; // The last non-zero id
843 while ((id
> 0) && !done
)
847 id
= FindChild(id
, path
, done
);
853 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(lastId
);
856 m_treeCtrl
->Expand(lastId
);
858 if ((GetWindowStyle() & wxDIRCTRL_SELECT_FIRST
) && data
->m_isDir
)
860 // Find the first file in this directory
862 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(lastId
, cookie
);
863 bool selectedChild
= FALSE
;
866 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(childId
);
868 if (data
&& data
->m_path
!= "" && !data
->m_isDir
)
870 m_treeCtrl
->SelectItem(childId
);
871 m_treeCtrl
->EnsureVisible(childId
);
872 selectedChild
= TRUE
;
875 childId
= m_treeCtrl
->GetNextChild(lastId
, cookie
);
879 m_treeCtrl
->SelectItem(lastId
);
880 m_treeCtrl
->EnsureVisible(lastId
);
885 m_treeCtrl
->SelectItem(lastId
);
886 m_treeCtrl
->EnsureVisible(lastId
);
895 wxString
wxGenericDirCtrl::GetPath() const
897 wxTreeItemId id
= m_treeCtrl
->GetSelection();
900 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
904 return wxEmptyString
;
907 wxString
wxGenericDirCtrl::GetFilePath() const
909 wxTreeItemId id
= m_treeCtrl
->GetSelection();
912 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
914 return wxEmptyString
;
919 return wxEmptyString
;
922 void wxGenericDirCtrl::SetPath(const wxString
& path
)
924 m_defaultPath
= path
;
931 void wxGenericDirCtrl::FindChildFiles(wxTreeItemId id
, int dirFlags
, wxArrayString
& filenames
)
933 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
935 // This may take a longish time. Go to busy cursor
940 wxString search
,path
,filename
;
942 wxString
dirName(data
->m_path
);
945 if (dirName
.Last() == ':')
946 dirName
+= wxString(wxFILE_SEP_PATH
);
950 wxString eachFilename
;
956 if (d
.GetFirst(& eachFilename
, m_currentFilterStr
, dirFlags
))
960 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
962 filenames
.Add(eachFilename
);
965 while (d
.GetNext(& eachFilename
)) ;
971 void wxGenericDirCtrl::SetFilterIndex(int n
)
976 if (ExtractWildcard(m_filter
, n
, f
, d
))
977 m_currentFilterStr
= f
;
979 m_currentFilterStr
= wxT("*.*");
982 void wxGenericDirCtrl::SetFilter(const wxString
& filter
)
987 if (ExtractWildcard(m_filter
, m_currentFilter
, f
, d
))
988 m_currentFilterStr
= f
;
990 m_currentFilterStr
= wxT("*.*");
993 // Extract description and actual filter from overall filter string
994 bool wxGenericDirCtrl::ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
)
996 wxArrayString filters
, descriptions
;
997 int count
= ParseFilter(filterStr
, filters
, descriptions
);
998 if (count
> 0 && n
< count
)
1000 filter
= filters
[n
];
1001 description
= descriptions
[n
];
1008 // Parses the global filter, returning the number of filters.
1009 // Returns 0 if none or if there's a problem.
1010 // filterStr is in the form:
1012 // "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
1014 int wxGenericDirCtrl::ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
)
1016 wxString
str(filterStr
);
1018 wxString description
, filter
;
1020 bool finished
= FALSE
;
1023 pos
= str
.Find(wxT('|'));
1025 return 0; // Problem
1026 description
= str
.Left(pos
);
1027 str
= str
.Mid(pos
+1);
1028 pos
= str
.Find(wxT('|'));
1036 filter
= str
.Left(pos
);
1037 str
= str
.Mid(pos
+1);
1039 descriptions
.Add(description
);
1040 filters
.Add(filter
);
1044 return filters
.Count();
1047 void wxGenericDirCtrl::DoResize()
1049 wxSize sz
= GetClientSize();
1050 int verticalSpacing
= 3;
1054 if (m_filterListCtrl
)
1056 filterSz
= m_filterListCtrl
->GetSize();
1057 sz
.y
-= (filterSz
.y
+ verticalSpacing
);
1059 m_treeCtrl
->SetSize(0, 0, sz
.x
, sz
.y
);
1060 if (m_filterListCtrl
)
1062 m_filterListCtrl
->SetSize(0, sz
.y
+ verticalSpacing
, sz
.x
, filterSz
.y
);
1063 // Don't know why, but this needs refreshing after a resize (wxMSW)
1064 m_filterListCtrl
->Refresh();
1070 void wxGenericDirCtrl::OnSize(wxSizeEvent
&event
)
1075 //-----------------------------------------------------------------------------
1076 // wxDirFilterListCtrl
1077 //-----------------------------------------------------------------------------
1079 IMPLEMENT_CLASS(wxDirFilterListCtrl
, wxChoice
)
1081 BEGIN_EVENT_TABLE(wxDirFilterListCtrl
, wxChoice
)
1082 EVT_CHOICE(-1, wxDirFilterListCtrl::OnSelFilter
)
1085 bool wxDirFilterListCtrl::Create(wxGenericDirCtrl
* parent
, const wxWindowID id
,
1091 return wxChoice::Create(parent
, id
, pos
, size
, 0, NULL
, style
);
1094 void wxDirFilterListCtrl::Init()
1099 void wxDirFilterListCtrl::OnSelFilter(wxCommandEvent
& event
)
1101 int sel
= GetSelection();
1103 wxString currentPath
= m_dirCtrl
->GetPath();
1105 m_dirCtrl
->SetFilterIndex(sel
);
1107 // If the filter has changed, the view is out of date, so
1108 // collapse the tree.
1109 m_dirCtrl
->GetTreeCtrl()->Collapse(m_dirCtrl
->GetRootId());
1110 m_dirCtrl
->GetTreeCtrl()->Expand(m_dirCtrl
->GetRootId());
1112 // Try to restore the selection, or at least the directory
1113 m_dirCtrl
->ExpandPath(currentPath
);
1116 void wxDirFilterListCtrl::FillFilterList(const wxString
& filter
, int defaultFilter
)
1119 wxArrayString descriptions
, filters
;
1120 size_t n
= (size_t) m_dirCtrl
->ParseFilter(filter
, filters
, descriptions
);
1122 if (n
> 0 && defaultFilter
< (int) n
)
1125 for (i
= 0; i
< n
; i
++)
1126 Append(descriptions
[i
]);
1127 SetSelection(defaultFilter
);
1131 // wxGenericDirDialog implementation
1132 // This should be moved into dirdlgg.cpp eventually
1134 BEGIN_EVENT_TABLE(wxGenericDirDialog
, wxDialog
)
1135 EVT_BUTTON(wxID_OK
, wxGenericDirDialog::OnOK
)
1136 EVT_CLOSE(wxGenericDirDialog::OnCloseWindow
)
1139 wxGenericDirDialog::wxGenericDirDialog(wxWindow
* parent
, const wxString
& title
,
1140 const wxString
& defaultPath
, long style
, const wxPoint
& pos
, const wxSize
& sz
, const wxString
& name
):
1141 wxDialog(parent
, ID_DIRCTRL
, title
, pos
, sz
, style
, name
)
1143 wxBusyCursor cursor
;
1145 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
1148 m_dirCtrl
= new wxGenericDirCtrl(this, ID_DIRCTRL
,
1149 defaultPath
, wxPoint(5, 5),
1150 wxSize(300, 200), wxDIRCTRL_DIR_ONLY
);
1152 topsizer
->Add( m_dirCtrl
, 1, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
1154 // 2) TODO: text control for entering path?
1158 topsizer
->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
1162 wxSizer
* buttonsizer
= new wxBoxSizer( wxHORIZONTAL
);
1163 wxButton
* okButton
= new wxButton(this, wxID_OK
, _("OK"));
1164 buttonsizer
->Add( okButton
, 0, wxLEFT
|wxRIGHT
, 10 );
1165 wxButton
* cancelButton
= new wxButton(this, wxID_CANCEL
, _("Cancel"));
1166 buttonsizer
->Add( cancelButton
, 0, wxLEFT
|wxRIGHT
, 10 );
1168 /* TODO: new directory button
1169 wxButton* newButton = new wxButton( this, ID_NEW, _("New...") );
1170 buttonsizer->Add( newButton, 0, wxLEFT|wxRIGHT, 10 );
1172 topsizer
->Add( buttonsizer
, 0, wxALL
| wxCENTER
, 10 );
1174 okButton
->SetDefault();
1175 m_dirCtrl
->SetFocus();
1177 SetAutoLayout( TRUE
);
1178 SetSizer( topsizer
);
1180 topsizer
->SetSizeHints( this );
1181 topsizer
->Fit( this );
1186 void wxGenericDirDialog::OnCloseWindow(wxCloseEvent
& event
)
1188 EndModal(wxID_CANCEL
);
1191 void wxGenericDirDialog::OnOK(wxCommandEvent
& event
)
1196 void wxGenericDirDialog::SetPath(const wxString
& path
)
1198 m_dirCtrl
->SetPath(path
);
1201 wxString
wxGenericDirDialog::GetPath(void) const
1203 return m_dirCtrl
->GetPath();