-
-wxFileCtrl::wxFileCtrl()
-{
- m_dirName = wxT("/");
- m_showHidden = FALSE;
-}
-
-wxFileCtrl::wxFileCtrl( wxWindow *win, wxWindowID id,
- const wxString &dirName, const wxString &wild,
- const wxPoint &pos, const wxSize &size,
- long style, const wxValidator &validator, const wxString &name ) :
- wxListCtrl( win, id, pos, size, style, validator, name )
-{
- if (! g_IconsTable) g_IconsTable = new wxFileIconsTable;
- wxImageList *imageList = g_IconsTable -> GetImageList();
-
- SetImageList( imageList, wxIMAGE_LIST_SMALL );
-
- m_dirName = dirName;
- m_wild = wild;
- m_showHidden = FALSE;
- Update();
-}
-
-void wxFileCtrl::ChangeToListMode()
-{
- SetSingleStyle( wxLC_LIST );
- Update();
-}
-
-void wxFileCtrl::ChangeToReportMode()
-{
- SetSingleStyle( wxLC_REPORT );
- Update();
-}
-
-void wxFileCtrl::ChangeToIconMode()
-{
- SetSingleStyle( wxLC_ICON );
- Update();
-}
-
-void wxFileCtrl::ShowHidden( bool show )
-{
- m_showHidden = show;
- Update();
-}
-
-long wxFileCtrl::Add( wxFileData *fd, wxListItem &item )
-{
- long ret = -1;
- item.m_mask = wxLIST_MASK_TEXT + wxLIST_MASK_DATA + wxLIST_MASK_IMAGE;
- fd->MakeItem( item );
- long my_style = GetWindowStyleFlag();
- if (my_style & wxLC_REPORT)
- {
- ret = InsertItem( item );
- for (int i = 1; i < 5; i++) SetItem( item.m_itemId, i, fd->GetEntry( i) );
- }
- else if (my_style & wxLC_LIST)
- {
- ret = InsertItem( item );
- }
- return ret;
-}
-
-void wxFileCtrl::Update()
-{
- long my_style = GetWindowStyleFlag();
- int name_col_width = 0;
- if (my_style & wxLC_REPORT)
- {
- if (GetColumnCount() > 0)
- name_col_width = GetColumnWidth( 0 );
- }
-
- ClearAll();
- if (my_style & wxLC_REPORT)
- {
- if (name_col_width < 140) name_col_width = 140;
- InsertColumn( 0, _("Name"), wxLIST_FORMAT_LEFT, name_col_width );
- InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT, 60 );
- InsertColumn( 2, _("Date"), wxLIST_FORMAT_LEFT, 65 );
- InsertColumn( 3, _("Time"), wxLIST_FORMAT_LEFT, 50 );
- InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT, 120 );
- }
- wxFileData *fd = (wxFileData *) NULL;
- wxListItem item;
- item.m_itemId = 0;
- item.m_col = 0;
-
- if (m_dirName != wxT("/"))
- {
- wxString p( wxPathOnly(m_dirName) );
- if (p.IsEmpty()) p = wxT("/");
- fd = new wxFileData( wxT(".."), p );
- Add( fd, item );
- item.m_itemId++;
- }
-
- wxString res = m_dirName + wxT("/*");
- wxString f( wxFindFirstFile( res.GetData(), wxDIR ) );
- while (!f.IsEmpty())
- {
- res = wxFileNameFromPath( f );
- fd = new wxFileData( res, f );
- wxString s = fd->GetName();
- if (m_showHidden || (s[0] != wxT('.')))
- {
- Add( fd, item );
- item.m_itemId++;
- }
- f = wxFindNextFile();
- }
-
- res = m_dirName + wxT("/") + m_wild;
- f = wxFindFirstFile( res.GetData(), wxFILE );
- while (!f.IsEmpty())
- {
- res = wxFileNameFromPath( f );
- fd = new wxFileData( res, f );
- wxString s = fd->GetName();
- if (m_showHidden || (s[0] != wxT('.')))
- {
- Add( fd, item );
- item.m_itemId++;
- }
- f = wxFindNextFile();
- }
-
- SortItems( ListCompare, 0 );
-
- SetColumnWidth( 1, wxLIST_AUTOSIZE );
- SetColumnWidth( 2, wxLIST_AUTOSIZE );
- SetColumnWidth( 3, wxLIST_AUTOSIZE );
-}
-
-void wxFileCtrl::SetWild( const wxString &wild )
-{
- m_wild = wild;
- Update();
-}
-
-void wxFileCtrl::MakeDir()
-{
- wxString new_name( wxT("NewName") );
- wxString path( m_dirName );
- path += wxT("/");
- path += new_name;
- if (wxFileExists(path))
- {
- // try NewName0, NewName1 etc.
- int i = 0;
- do {
- new_name = _("NewName");
- wxString num;
- num.Printf( wxT("%d"), i );
- new_name += num;
-
- path = m_dirName;
- path += wxT("/");
- path += new_name;
- i++;
- } while (wxFileExists(path));
- }
-
- wxLogNull log;
- if (!wxMkdir(path))
- {
- wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
- dialog.ShowModal();
- return;
- }
-
- wxFileData *fd = new wxFileData( new_name, path );
- wxListItem item;
- item.m_itemId = 0;
- item.m_col = 0;
- long id = Add( fd, item );
-
- if (id != -1)
- {
- SortItems( ListCompare, 0 );
- id = FindItem( 0, (long)fd );
- EnsureVisible( id );
- EditLabel( id );
- }
-}
-
-void wxFileCtrl::GoToParentDir()
-{
- if (m_dirName != wxT("/"))
- {
- wxString fname( wxFileNameFromPath(m_dirName) );
- m_dirName = wxPathOnly( m_dirName );
- if (m_dirName.IsEmpty()) m_dirName = wxT("/");
- Update();
- long id = FindItem( 0, fname );
- if (id != -1)
- {
- SetItemState( id, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
- EnsureVisible( id );
- }
- }
-}
-
-void wxFileCtrl::GoToHomeDir()