-//static const int ID_CHECK = 1005;
-
-//-----------------------------------------------------------------------------
-// wxDirItemData
-//-----------------------------------------------------------------------------
-
-wxDirItemData::wxDirItemData(wxString& path, wxString& name)
-{
- m_path = path;
- m_name = name;
- /* Insert logic to detect hidden files here
- * In UnixLand we just check whether the first char is a dot
- * For FileNameFromPath read LastDirNameInThisPath ;-) */
- // m_isHidden = (bool)(wxFileNameFromPath(*m_path)[0] == '.');
- m_isHidden = FALSE;
- m_hasSubDirs = HasSubDirs();
-}
-
-wxDirItemData::~wxDirItemData()
-{
-}
-
-void wxDirItemData::SetNewDirName( wxString path )
-{
- m_path = path;
- m_name = wxFileNameFromPath( path );
-}
-
-bool wxDirItemData::HasSubDirs()
-{
- wxString search = m_path + "/*";
- wxLogNull log;
- wxString path = wxFindFirstFile( search, wxDIR );
- return (bool)(!path.IsNull());
-}
-
-//-----------------------------------------------------------------------------
-// wxDirCtrl
-//-----------------------------------------------------------------------------
-
-IMPLEMENT_DYNAMIC_CLASS(wxDirCtrl,wxTreeCtrl)
-
-BEGIN_EVENT_TABLE(wxDirCtrl,wxTreeCtrl)
- EVT_TREE_ITEM_EXPANDING (-1, wxDirCtrl::OnExpandItem)
- EVT_TREE_ITEM_COLLAPSED (-1, wxDirCtrl::OnCollapseItem)
- EVT_TREE_BEGIN_LABEL_EDIT (-1, wxDirCtrl::OnBeginEditItem)
- EVT_TREE_END_LABEL_EDIT (-1, wxDirCtrl::OnEndEditItem)
-END_EVENT_TABLE()
-
-wxDirCtrl::wxDirCtrl(void)
-{
- m_showHidden = FALSE;
-}
-
-wxDirCtrl::wxDirCtrl(wxWindow *parent, const wxWindowID id, const wxString &WXUNUSED(dir),
- const wxPoint& pos, const wxSize& size,
- const long style, const wxString& name )
- :
- wxTreeCtrl( parent, id, pos, size, style, wxDefaultValidator, name )
-{
- #ifndef __WXMSW__
- m_imageListNormal = new wxImageList(16, 16, TRUE);
- m_imageListNormal->Add(wxICON(icon1));
- m_imageListNormal->Add(wxICON(icon2));
- SetImageList(m_imageListNormal);
- #endif
-
- m_showHidden = FALSE;
- m_rootId = AddRoot( _("Sections") );
- SetItemHasChildren(m_rootId);
- Expand(m_rootId); // automatically expand first level
-}
-
-/* Quick macro. Don't worry, I'll #undef it later */
-#define ADD_SECTION(a,b) \
- if (wxPathExists((a))) { m_paths.Add( (a) ); m_names.Add( (b) ); };
-
-void wxDirCtrl::SetupSections()
-{
- wxString home;
-
- m_paths.Clear();
- m_names.Clear();
-#ifdef __WXMSW__
- // better than nothing
- ADD_SECTION(T("c:\\"), _("My Harddisk") )
-#else
- ADD_SECTION(T("/"), _("The Computer") )
- wxGetHomeDir(&home);
- ADD_SECTION(home, _("My Home") )
- ADD_SECTION(T("/mnt"), _("Mounted Devices") )
- ADD_SECTION(T("/usr"), _("User") )
- ADD_SECTION(T("/usr/local"), _("User Local") )
- ADD_SECTION(T("/var"), _("Variables") )
- ADD_SECTION(T("/etc"), _("Etcetera") )
- ADD_SECTION(T("/tmp"), _("Temporary") )
-#endif
-}
-#undef ADD_SECTION
-
-void wxDirCtrl::CreateItems(const wxTreeItemId &parent)
-{
- wxTreeItemId id;
- wxDirItemData *dir_item;
-
-// wxASSERT(m_paths.Count() == m_names.Count()); ?
-
- for (unsigned int i=0; i<m_paths.Count(); i++)
- {
- dir_item = new wxDirItemData(m_paths[i],m_names[i]);
-#ifdef __WXMSW__
- id = AppendItem( parent, m_names[i], -1, -1, dir_item);
-#else
- id = AppendItem( parent, m_names[i], 0, 1, dir_item);
-#endif
- if (dir_item->m_hasSubDirs) SetItemHasChildren(id);
- }
-}
-
-void wxDirCtrl::OnBeginEditItem(wxTreeEvent &event)
-{
- // don't rename the main entry "Sections"
- if (event.GetItem() == m_rootId)
- {
- event.Veto();
- return;
- }
-
- // don't rename the individual sections
- if (GetParent( event.GetItem() ) == m_rootId)
- {
- event.Veto();
- return;
- }
-}
-
-void wxDirCtrl::OnEndEditItem(wxTreeEvent &event)
-{
- if ((event.GetLabel().IsEmpty()) ||
- (event.GetLabel() == _(".")) ||
- (event.GetLabel() == _("..")) ||
- (event.GetLabel().First( T("/") ) != wxNOT_FOUND))
- {
- wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR );
- dialog.ShowModal();
- event.Veto();
- return;
- }
-
- wxTreeItemId id = event.GetItem();
- wxDirItemData *data = (wxDirItemData*)GetItemData( id );
- wxASSERT( data );
-
- wxString new_name( wxPathOnly( data->m_path ) );
- new_name += T("/");
- new_name += event.GetLabel();
-
- wxLogNull log;
-
- if (wxFileExists(new_name))
- {
- wxMessageDialog dialog(this, _("File name exists already."), _("Error"), wxOK | wxICON_ERROR );
- dialog.ShowModal();
- event.Veto();
- }
-
- if (wxRenameFile(data->m_path,new_name))
- {
- data->SetNewDirName( new_name );
- }
- else
- {
- wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
- dialog.ShowModal();
- event.Veto();
- }
-}
-
-void wxDirCtrl::OnExpandItem(wxTreeEvent &event)
-{
- if (event.GetItem() == m_rootId)
- {
- SetupSections();
- CreateItems(m_rootId);
- return;
- }
-
- // This may take a longish time. Go to busy cursor
- wxBeginBusyCursor();
-
- wxDirItemData *data = (wxDirItemData *)GetItemData(event.GetItem());
- wxASSERT(data);
-
- wxString search,path,filename;
-
- m_paths.Clear();
- m_names.Clear();
- search = data->m_path + "/*";
- for (path = wxFindFirstFile( search, wxDIR ); !path.IsNull();
- path=wxFindNextFile() )
- {
- filename = wxFileNameFromPath( path );
- /* Don't add "." and ".." to the tree. I think wxFindNextFile
- * also checks this, but I don't quite understand what happens
- * there. Also wxFindNextFile seems to swallow hidden dirs */
- if ((filename != ".") && (filename != ".."))
- {
- m_paths.Add(path);
- m_names.Add(filename);
- }
- }
-
- CreateItems( event.GetItem() );
- SortChildren( event.GetItem() );
-
- wxEndBusyCursor();
-}
-
-void wxDirCtrl::OnCollapseItem(wxTreeEvent &event )
-{
- wxTreeItemId child, parent = event.GetItem();
- long cookie;
- /* Workaround because DeleteChildren has disapeared (why?) and
- * CollapseAndReset doesn't work as advertised (deletes parent too) */
- child = GetFirstChild(parent, cookie);
- while (child.IsOk())
- {
- Delete(child);
- /* Not GetNextChild below, because the cookie mechanism can't
- * handle disappearing children! */
- child = GetFirstChild(parent, cookie);
- }
-}
-
-//-----------------------------------------------------------------------------
-// wxDirDialog
-//-----------------------------------------------------------------------------
-
-
-#if !USE_SHARED_LIBRARY
-IMPLEMENT_CLASS(wxDirDialog, wxDialog)
-#else
-IMPLEMENT_DYNAMIC_CLASS( wxDirDialog, wxDialog )
-#endif
-
-BEGIN_EVENT_TABLE( wxDirDialog, wxDialog )
- EVT_TREE_KEY_DOWN (ID_DIRCTRL, wxDirDialog::OnTreeKeyDown)
- EVT_TREE_SEL_CHANGED (ID_DIRCTRL, wxDirDialog::OnTreeSelected)
- EVT_SIZE ( wxDirDialog::OnSize)
- EVT_BUTTON (ID_OK, wxDirDialog::OnOK)
- EVT_BUTTON (ID_CANCEL, wxDirDialog::OnCancel)
- EVT_BUTTON (ID_NEW, wxDirDialog::OnNew)
- EVT_TEXT_ENTER (ID_TEXTCTRL, wxDirDialog::OnOK)
- // EVT_CHECKBOX (ID_CHECK, wxDirDialog::OnCheck)