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 "dirctrlg.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"
41 #include "wx/settings.h"
44 #include "wx/statline.h"
47 #include "wx/generic/dirctrlg.h"
55 // If compiled under Windows, this macro can cause problems
60 #if !defined(__WXMSW__) || wxUSE_XPM_IN_MSW
62 static char * icon1_xpm
[] = {
63 /* width height ncolors chars_per_pixel */
91 static char * icon2_xpm
[] = {
92 /* width height ncolors chars_per_pixel */
120 static char * icon3_xpm
[] = {
121 /* width height ncolors chars_per_pixel */
146 static char * icon4_xpm
[] = {
173 static char * icon5_xpm
[] = {
200 static char *icon6_xpm
[] = {
230 static char * icon7_xpm
[] = {
257 static char * icon8_xpm
[] = {
284 static const int ID_DIRCTRL
= 1000;
285 static const int ID_TEXTCTRL
= 1001;
286 static const int ID_OK
= 1002;
287 static const int ID_CANCEL
= 1003;
288 static const int ID_NEW
= 1004;
289 //static const int ID_CHECK = 1005;
291 //-----------------------------------------------------------------------------
293 //-----------------------------------------------------------------------------
295 wxDirItemDataEx::wxDirItemDataEx(const wxString
& path
, const wxString
& name
,
300 /* Insert logic to detect hidden files here
301 * In UnixLand we just check whether the first char is a dot
302 * For FileNameFromPath read LastDirNameInThisPath ;-) */
303 // m_isHidden = (bool)(wxFileNameFromPath(*m_path)[0] == '.');
305 m_hasSubDirs
= HasSubDirs();
306 m_isExpanded
= FALSE
;
310 wxDirItemDataEx::~wxDirItemDataEx()
314 void wxDirItemDataEx::SetNewDirName( wxString path
)
317 m_name
= wxFileNameFromPath( path
);
320 bool wxDirItemDataEx::HasSubDirs()
322 wxString search
= m_path
+ wxT("/*");
324 wxString path
= wxFindFirstFile( search
, wxDIR
);
325 return (bool)(!path
.IsNull());
328 //-----------------------------------------------------------------------------
330 //-----------------------------------------------------------------------------
332 IMPLEMENT_DYNAMIC_CLASS(wxGenericDirCtrl
, wxControl
)
334 BEGIN_EVENT_TABLE(wxGenericDirCtrl
, wxControl
)
335 EVT_TREE_ITEM_EXPANDING (-1, wxGenericDirCtrl::OnExpandItem
)
336 EVT_TREE_ITEM_COLLAPSED (-1, wxGenericDirCtrl::OnCollapseItem
)
337 EVT_TREE_BEGIN_LABEL_EDIT (-1, wxGenericDirCtrl::OnBeginEditItem
)
338 EVT_TREE_END_LABEL_EDIT (-1, wxGenericDirCtrl::OnEndEditItem
)
339 EVT_SIZE (wxGenericDirCtrl::OnSize
)
342 wxGenericDirCtrl::wxGenericDirCtrl(void)
347 bool wxGenericDirCtrl::Create(wxWindow
*parent
,
353 const wxString
& filter
,
355 const wxString
& name
)
357 if (!wxControl::Create(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
360 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
364 long treeStyle
= wxTR_HAS_BUTTONS
;
365 if ((style
& wxDIRCTRL_3D_INTERNAL
) == 0)
366 treeStyle
|= wxNO_BORDER
;
368 long filterStyle
= 0;
369 if ((style
& wxDIRCTRL_3D_INTERNAL
) == 0)
370 filterStyle
|= wxNO_BORDER
;
372 m_treeCtrl
= new wxTreeCtrl(this, wxID_TREECTRL
, pos
, size
, treeStyle
);
374 if (!filter
.IsEmpty() && (style
& wxDIRCTRL_SHOW_FILTERS
))
375 m_filterListCtrl
= new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL
, wxDefaultPosition
, wxDefaultSize
, filterStyle
);
380 SetFilterIndex(defaultFilter
);
382 if (m_filterListCtrl
)
383 m_filterListCtrl
->FillFilterList(filter
, defaultFilter
);
385 m_imageList
= new wxImageList(16, 16, TRUE
);
386 #if !defined(__WXMSW__) || wxUSE_XPM_IN_MSW
387 m_imageList
->Add(wxIcon(icon1_xpm
));
388 m_imageList
->Add(wxIcon(icon2_xpm
));
389 m_imageList
->Add(wxIcon(icon3_xpm
));
390 m_imageList
->Add(wxIcon(icon4_xpm
));
391 m_imageList
->Add(wxIcon(icon5_xpm
));
392 m_imageList
->Add(wxIcon(icon6_xpm
));
393 m_imageList
->Add(wxIcon(icon7_xpm
));
394 m_imageList
->Add(wxIcon(icon8_xpm
));
395 #elif defined(__WXMSW__)
396 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CLOSED_FOLDER"), wxBITMAP_TYPE_RESOURCE
));
397 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_OPEN_FOLDER"), wxBITMAP_TYPE_RESOURCE
));
398 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FILE"), wxBITMAP_TYPE_RESOURCE
));
399 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_COMPUTER"), wxBITMAP_TYPE_RESOURCE
));
400 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_DRIVE"), wxBITMAP_TYPE_RESOURCE
));
401 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CDROM"), wxBITMAP_TYPE_RESOURCE
));
402 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FLOPPY"), wxBITMAP_TYPE_RESOURCE
));
403 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_REMOVEABLE"), wxBITMAP_TYPE_RESOURCE
));
405 #error "Sorry, we don't have icons available for this platforms."
407 m_treeCtrl
->SetImageList(m_imageList
);
409 m_showHidden
= FALSE
;
410 wxDirItemDataEx
* rootData
= new wxDirItemDataEx(wxT(""), wxT(""), TRUE
);
415 rootName
= _("Computer");
417 rootName
= _("Sections");
420 m_rootId
= m_treeCtrl
->AddRoot( rootName
, 3, -1, rootData
);
421 m_treeCtrl
->SetItemHasChildren(m_rootId
);
422 m_treeCtrl
->Expand(m_rootId
); // automatically expand first level
424 // Expand and select the default path
425 if (!m_defaultPath
.IsEmpty())
426 ExpandPath(m_defaultPath
);
433 wxGenericDirCtrl::~wxGenericDirCtrl()
435 m_treeCtrl
->SetImageList(NULL
);
439 void wxGenericDirCtrl::Init()
441 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 m_treeCtrl
->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
);
538 AddSection(wxT("/"), _("The Computer"), 0);
539 AddSection(wxGetHomeDir(), _("My Home"), 0 );
540 AddSection(wxT("/mnt"), _("Mounted Devices"), 0 );
541 AddSection(wxT("/usr/local"), _("User Local"), 0 );
542 AddSection(wxT("/usr"), _("User"), 0 );
543 AddSection(wxT("/var"), _("Variables"), 0 );
544 AddSection(wxT("/etc"), _("Etcetera"), 0 );
545 AddSection(wxT("/tmp"), _("Temporary"), 0 );
549 void wxGenericDirCtrl::OnBeginEditItem(wxTreeEvent
&event
)
551 // don't rename the main entry "Sections"
552 if (event
.GetItem() == m_rootId
)
558 // don't rename the individual sections
559 if (m_treeCtrl
->GetParent( event
.GetItem() ) == m_rootId
)
566 void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent
&event
)
568 if ((event
.GetLabel().IsEmpty()) ||
569 (event
.GetLabel() == _(".")) ||
570 (event
.GetLabel() == _("..")) ||
571 (event
.GetLabel().First( wxT("/") ) != wxNOT_FOUND
))
573 wxMessageDialog
dialog(this, _("Illegal directory name."), _("Error"), wxOK
| wxICON_ERROR
);
579 wxTreeItemId id
= event
.GetItem();
580 wxDirItemDataEx
*data
= (wxDirItemDataEx
*)m_treeCtrl
->GetItemData( id
);
583 wxString
new_name( wxPathOnly( data
->m_path
) );
584 new_name
+= wxT("/");
585 new_name
+= event
.GetLabel();
589 if (wxFileExists(new_name
))
591 wxMessageDialog
dialog(this, _("File name exists already."), _("Error"), wxOK
| wxICON_ERROR
);
596 if (wxRenameFile(data
->m_path
,new_name
))
598 data
->SetNewDirName( new_name
);
602 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
608 void wxGenericDirCtrl::OnExpandItem(wxTreeEvent
&event
)
610 wxTreeItemId parentId
= event
.GetItem();
615 void wxGenericDirCtrl::OnCollapseItem(wxTreeEvent
&event
)
617 wxTreeItemId child
, parent
= event
.GetItem();
619 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(event
.GetItem());
620 if (!data
->m_isExpanded
)
623 data
->m_isExpanded
= FALSE
;
625 /* Workaround because DeleteChildren has disapeared (why?) and
626 * CollapseAndReset doesn't work as advertised (deletes parent too) */
627 child
= m_treeCtrl
->GetFirstChild(parent
, cookie
);
630 m_treeCtrl
->Delete(child
);
631 /* Not GetNextChild below, because the cookie mechanism can't
632 * handle disappearing children! */
633 child
= m_treeCtrl
->GetFirstChild(parent
, cookie
);
637 void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId
)
639 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(parentId
);
641 if (data
->m_isExpanded
)
644 data
->m_isExpanded
= TRUE
;
646 if (parentId
== m_rootId
)
654 wxString search
,path
,filename
;
656 wxString
dirName(data
->m_path
);
659 // Check if this is a root directory and if so,
660 // whether the drive is avaiable.
661 if (dirName
.Len() == 3 && dirName
[1] == wxT(':'))
663 int currentDrive
= _getdrive();
664 int thisDrive
= (int) (dirName
[0] - 'a' + 1) ;
665 int err
= _chdrive( thisDrive
) ;
666 _chdrive( currentDrive
);
670 data
->m_isExpanded
= FALSE
;
671 wxMessageBox(wxT("Sorry, this drive is not available."));
677 // This may take a longish time. Go to busy cursor
681 if (dirName
.Last() == ':')
682 dirName
+= wxString(wxFILE_SEP_PATH
);
686 wxArrayString filenames
;
689 wxString eachFilename
;
695 if (d
.GetFirst(& eachFilename
, wxEmptyString
, wxDIR_DIRS
))
699 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
701 dirs
.Add(eachFilename
);
704 while (d
.GetNext(& eachFilename
)) ;
709 // Now do the filenames -- but only if we're allowed to
710 if ((GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) == 0)
716 if (d
.GetFirst(& eachFilename
, m_currentFilterStr
, wxDIR_FILES
))
720 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
722 filenames
.Add(eachFilename
);
725 while (d
.GetNext(& eachFilename
)) ;
731 // Add the sorted dirs
733 for (i
= 0; i
< dirs
.Count(); i
++)
735 wxString
eachFilename(dirs
[i
]);
737 if (path
.Last() != wxFILE_SEP_PATH
)
738 path
+= wxString(wxFILE_SEP_PATH
);
739 path
+= eachFilename
;
741 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,eachFilename
,TRUE
);
742 wxTreeItemId id
= m_treeCtrl
->AppendItem( parentId
, eachFilename
, 0, -1, dir_item
);
743 m_treeCtrl
->SetItemImage( id
, 1, wxTreeItemIcon_Expanded
);
745 // Has this got any children? If so, make it expandable.
746 int options
= wxDIR_DEFAULT
;
747 if (GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) // If only showing dirs, then we specify dirs only here
749 options
= wxDIR_DIRS
;
754 // Have to test for wxDIR_DIRS separately in case m_currentFilterStr is non-empty and
755 // and filters out any directories
756 if (dir2
.GetFirst(& str
, m_currentFilterStr
, options
) || dir2
.GetFirst(& str
, wxEmptyString
, wxDIR_DIRS
))
758 m_treeCtrl
->SetItemHasChildren(id
);
762 // Add the sorted filenames
763 if ((GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) == 0)
765 for (i
= 0; i
< filenames
.Count(); i
++)
767 wxString
eachFilename(filenames
[i
]);
769 if (path
.Last() != wxFILE_SEP_PATH
)
770 path
+= wxString(wxFILE_SEP_PATH
);
771 path
+= eachFilename
;
772 //path = dirName + wxString(wxT("/")) + eachFilename;
773 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,eachFilename
,FALSE
);
774 (void)m_treeCtrl
->AppendItem( parentId
, eachFilename
, 2, -1, dir_item
);
779 // Find the child that matches the first part of 'path'.
780 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
781 // then the child for /usr is returned.
782 wxTreeItemId
wxGenericDirCtrl::FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
)
784 wxString
path2(path
);
786 // Make sure all separators are as per the current platform
787 path2
.Replace(wxT("\\"), wxString(wxFILE_SEP_PATH
));
788 path2
.Replace(wxT("/"), wxString(wxFILE_SEP_PATH
));
790 // Append a separator to foil bogus substring matching
791 path2
+= wxString(wxFILE_SEP_PATH
);
793 // In MSW, case is not significant
799 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(parentId
, cookie
);
802 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(childId
);
804 if (data
&& data
->m_path
!= "")
806 wxString
childPath(data
->m_path
);
807 if (childPath
.Last() != wxFILE_SEP_PATH
)
808 childPath
+= wxString(wxFILE_SEP_PATH
);
810 // In MSW, case is not significant
812 childPath
.MakeLower();
815 if (childPath
.Len() <= path2
.Len())
817 wxString path3
= path2
.Mid(0, childPath
.Len());
818 if (childPath
== path3
)
820 if (path3
.Len() == path2
.Len())
829 childId
= m_treeCtrl
->GetNextChild(childId
, cookie
);
831 wxTreeItemId invalid
;
835 // Try to expand as much of the given path as possible,
836 // and select the given tree item.
837 bool wxGenericDirCtrl::ExpandPath(const wxString
& path
)
840 wxTreeItemId id
= FindChild(m_rootId
, path
, done
);
841 wxTreeItemId lastId
= id
; // The last non-zero id
842 while ((id
> 0) && !done
)
846 id
= FindChild(id
, path
, done
);
852 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(lastId
);
855 m_treeCtrl
->Expand(lastId
);
857 if ((GetWindowStyle() & wxDIRCTRL_SELECT_FIRST
) && data
->m_isDir
)
859 // Find the first file in this directory
861 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(lastId
, cookie
);
862 bool selectedChild
= FALSE
;
865 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(childId
);
867 if (data
&& data
->m_path
!= "" && !data
->m_isDir
)
869 m_treeCtrl
->SelectItem(childId
);
870 m_treeCtrl
->EnsureVisible(childId
);
871 selectedChild
= TRUE
;
874 childId
= m_treeCtrl
->GetNextChild(lastId
, cookie
);
878 m_treeCtrl
->SelectItem(lastId
);
879 m_treeCtrl
->EnsureVisible(lastId
);
884 m_treeCtrl
->SelectItem(lastId
);
885 m_treeCtrl
->EnsureVisible(lastId
);
894 wxString
wxGenericDirCtrl::GetPath() const
896 wxTreeItemId id
= m_treeCtrl
->GetSelection();
899 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
903 return wxEmptyString
;
906 wxString
wxGenericDirCtrl::GetFilePath() const
908 wxTreeItemId id
= m_treeCtrl
->GetSelection();
911 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
913 return wxEmptyString
;
918 return wxEmptyString
;
921 void wxGenericDirCtrl::SetPath(const wxString
& path
)
923 m_defaultPath
= path
;
930 void wxGenericDirCtrl::FindChildFiles(wxTreeItemId id
, int dirFlags
, wxArrayString
& filenames
)
932 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
934 // This may take a longish time. Go to busy cursor
939 wxString search
,path
,filename
;
941 wxString
dirName(data
->m_path
);
944 if (dirName
.Last() == ':')
945 dirName
+= wxString(wxFILE_SEP_PATH
);
949 wxString eachFilename
;
955 if (d
.GetFirst(& eachFilename
, m_currentFilterStr
, dirFlags
))
959 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
961 filenames
.Add(eachFilename
);
964 while (d
.GetNext(& eachFilename
)) ;
970 void wxGenericDirCtrl::SetFilterIndex(int n
)
975 if (ExtractWildcard(m_filter
, n
, f
, d
))
976 m_currentFilterStr
= f
;
978 m_currentFilterStr
= wxT("*.*");
981 void wxGenericDirCtrl::SetFilter(const wxString
& filter
)
986 if (ExtractWildcard(m_filter
, m_currentFilter
, f
, d
))
987 m_currentFilterStr
= f
;
989 m_currentFilterStr
= wxT("*.*");
992 // Extract description and actual filter from overall filter string
993 bool wxGenericDirCtrl::ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
)
995 wxArrayString filters
, descriptions
;
996 int count
= ParseFilter(filterStr
, filters
, descriptions
);
997 if (count
> 0 && n
< count
)
1000 description
= descriptions
[n
];
1007 // Parses the global filter, returning the number of filters.
1008 // Returns 0 if none or if there's a problem.
1009 // filterStr is in the form:
1011 // "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
1013 int wxGenericDirCtrl::ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
)
1015 wxString
str(filterStr
);
1017 wxString description
, filter
;
1019 bool finished
= FALSE
;
1022 pos
= str
.Find(wxT('|'));
1024 return 0; // Problem
1025 description
= str
.Left(pos
);
1026 str
= str
.Mid(pos
+1);
1027 pos
= str
.Find(wxT('|'));
1035 filter
= str
.Left(pos
);
1036 str
= str
.Mid(pos
+1);
1038 descriptions
.Add(description
);
1039 filters
.Add(filter
);
1043 return filters
.Count();
1046 void wxGenericDirCtrl::DoResize()
1048 wxSize sz
= GetClientSize();
1049 int verticalSpacing
= 3;
1053 if (m_filterListCtrl
)
1055 filterSz
= m_filterListCtrl
->GetSize();
1056 sz
.y
-= (filterSz
.y
+ verticalSpacing
);
1058 m_treeCtrl
->SetSize(0, 0, sz
.x
, sz
.y
);
1059 if (m_filterListCtrl
)
1061 m_filterListCtrl
->SetSize(0, sz
.y
+ verticalSpacing
, sz
.x
, filterSz
.y
);
1062 // Don't know why, but this needs refreshing after a resize (wxMSW)
1063 m_filterListCtrl
->Refresh();
1069 void wxGenericDirCtrl::OnSize(wxSizeEvent
&event
)
1074 //-----------------------------------------------------------------------------
1075 // wxDirFilterListCtrl
1076 //-----------------------------------------------------------------------------
1078 IMPLEMENT_CLASS(wxDirFilterListCtrl
, wxChoice
)
1080 BEGIN_EVENT_TABLE(wxDirFilterListCtrl
, wxChoice
)
1081 EVT_CHOICE(-1, wxDirFilterListCtrl::OnSelFilter
)
1084 bool wxDirFilterListCtrl::Create(wxGenericDirCtrl
* parent
, const wxWindowID id
,
1090 return wxChoice::Create(parent
, id
, pos
, size
, 0, NULL
, style
);
1093 void wxDirFilterListCtrl::Init()
1098 void wxDirFilterListCtrl::OnSelFilter(wxCommandEvent
& event
)
1100 int sel
= GetSelection();
1102 wxString currentPath
= m_dirCtrl
->GetPath();
1104 m_dirCtrl
->SetFilterIndex(sel
);
1106 // If the filter has changed, the view is out of date, so
1107 // collapse the tree.
1108 m_dirCtrl
->GetTreeCtrl()->Collapse(m_dirCtrl
->GetRootId());
1109 m_dirCtrl
->GetTreeCtrl()->Expand(m_dirCtrl
->GetRootId());
1111 // Try to restore the selection, or at least the directory
1112 m_dirCtrl
->ExpandPath(currentPath
);
1115 void wxDirFilterListCtrl::FillFilterList(const wxString
& filter
, int defaultFilter
)
1118 wxArrayString descriptions
, filters
;
1119 size_t n
= (size_t) m_dirCtrl
->ParseFilter(filter
, filters
, descriptions
);
1121 if (n
> 0 && defaultFilter
< (int) n
)
1124 for (i
= 0; i
< n
; i
++)
1125 Append(descriptions
[i
]);
1126 SetSelection(defaultFilter
);
1130 // wxGenericDirDialog implementation
1131 // This should be moved into dirdlgg.cpp eventually
1133 BEGIN_EVENT_TABLE(wxGenericDirDialog
, wxDialog
)
1134 EVT_BUTTON(wxID_OK
, wxGenericDirDialog::OnOK
)
1135 EVT_CLOSE(wxGenericDirDialog::OnCloseWindow
)
1138 wxGenericDirDialog::wxGenericDirDialog(wxWindow
* parent
, const wxString
& title
,
1139 const wxString
& defaultPath
, long style
, const wxPoint
& pos
, const wxSize
& sz
, const wxString
& name
):
1140 wxDialog(parent
, ID_DIRCTRL
, title
, pos
, sz
, style
, name
)
1142 wxBusyCursor cursor
;
1144 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
1147 m_dirCtrl
= new wxGenericDirCtrl(this, ID_DIRCTRL
,
1148 defaultPath
, wxPoint(5, 5),
1149 wxSize(300, 200), wxDIRCTRL_DIR_ONLY
);
1151 topsizer
->Add( m_dirCtrl
, 1, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
1153 // 2) TODO: text control for entering path?
1157 topsizer
->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
1161 wxSizer
* buttonsizer
= new wxBoxSizer( wxHORIZONTAL
);
1162 wxButton
* okButton
= new wxButton(this, wxID_OK
, _("OK"));
1163 buttonsizer
->Add( okButton
, 0, wxLEFT
|wxRIGHT
, 10 );
1164 wxButton
* cancelButton
= new wxButton(this, wxID_CANCEL
, _("Cancel"));
1165 buttonsizer
->Add( cancelButton
, 0, wxLEFT
|wxRIGHT
, 10 );
1167 /* TODO: new directory button
1168 wxButton* newButton = new wxButton( this, ID_NEW, _("New...") );
1169 buttonsizer->Add( newButton, 0, wxLEFT|wxRIGHT, 10 );
1171 topsizer
->Add( buttonsizer
, 0, wxALL
| wxCENTER
, 10 );
1173 okButton
->SetDefault();
1174 m_dirCtrl
->SetFocus();
1176 SetAutoLayout( TRUE
);
1177 SetSizer( topsizer
);
1179 topsizer
->SetSizeHints( this );
1180 topsizer
->Fit( this );
1185 void wxGenericDirDialog::OnCloseWindow(wxCloseEvent
& event
)
1187 EndModal(wxID_CANCEL
);
1190 void wxGenericDirDialog::OnOK(wxCommandEvent
& event
)
1195 void wxGenericDirDialog::SetPath(const wxString
& path
)
1197 m_dirCtrl
->SetPath(path
);
1200 wxString
wxGenericDirDialog::GetPath(void) const
1202 return m_dirCtrl
->GetPath();