1998-05-20 10:01:55 -04:00
|
|
|
/*
|
|
|
|
* Author: Robert Roebling
|
|
|
|
*
|
|
|
|
* Copyright: (C) 1997,1998 Robert Roebling
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the wxWindows Licence, which
|
|
|
|
* you have received with this library (see Licence.htm).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "dirctrl.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "dirctrl.h"
|
|
|
|
#include "wx/gdicmn.h"
|
|
|
|
#include "wx/utils.h"
|
1998-07-27 16:50:48 -04:00
|
|
|
#include "wx/dnd.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxDirInfo
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(wxDirInfo,wxObject)
|
|
|
|
|
|
|
|
wxDirInfo::wxDirInfo( const wxString &path )
|
|
|
|
{
|
|
|
|
m_showHidden = FALSE;
|
|
|
|
m_path = path;
|
|
|
|
if (m_path == "/") m_name ="The Computer";
|
|
|
|
else
|
|
|
|
if (m_path == "/home")
|
|
|
|
{
|
|
|
|
m_name = "My Home";
|
1998-09-11 05:05:26 -04:00
|
|
|
m_path = "";
|
|
|
|
wxGetHomeDir( &m_path );
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (m_path == "/proc") m_name = "Info Filesystem";
|
|
|
|
else
|
|
|
|
if (m_path == "/mnt") m_name = "Mounted Devices";
|
|
|
|
else
|
|
|
|
if (m_path == "/usr/X11R6") m_name = "User X11";
|
|
|
|
else
|
|
|
|
if (m_path == "/usr") m_name = "User";
|
|
|
|
else
|
|
|
|
if (m_path == "/var") m_name = "Variables";
|
|
|
|
else
|
|
|
|
if (m_path == "/usr/local") m_name = "User local";
|
|
|
|
else
|
|
|
|
if (m_path == "/mnt") m_name = "Mounted Devices";
|
|
|
|
else
|
|
|
|
m_name = wxFileNameFromPath( m_path );
|
|
|
|
};
|
|
|
|
|
|
|
|
wxString wxDirInfo::GetName(void) const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
wxString wxDirInfo::GetPath(void) const
|
|
|
|
{
|
|
|
|
return m_path;
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxDirCtrl
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(wxDirCtrl,wxTreeCtrl)
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(wxDirCtrl,wxTreeCtrl)
|
|
|
|
EVT_TREE_ITEM_EXPANDED (-1, wxDirCtrl::OnExpandItem)
|
1998-07-10 19:08:39 -04:00
|
|
|
EVT_TREE_ITEM_COLLAPSED (-1, wxDirCtrl::OnCollapseItem)
|
1998-05-20 10:01:55 -04:00
|
|
|
EVT_TREE_DELETE_ITEM (-1, wxDirCtrl::OnDeleteItem)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
wxDirCtrl::wxDirCtrl(void)
|
|
|
|
{
|
|
|
|
m_showHidden = FALSE;
|
|
|
|
};
|
|
|
|
|
1998-07-10 19:08:39 -04:00
|
|
|
wxDirCtrl::wxDirCtrl(wxWindow *parent, const wxWindowID id, const wxString &WXUNUSED(dir),
|
1998-05-20 10:01:55 -04:00
|
|
|
const wxPoint& pos, const wxSize& size,
|
|
|
|
const long style, const wxString& name )
|
|
|
|
:
|
|
|
|
wxTreeCtrl( parent, id, pos, size, style, name )
|
|
|
|
{
|
|
|
|
m_showHidden = FALSE;
|
|
|
|
|
|
|
|
wxTreeItem item;
|
|
|
|
item.m_mask = wxTREE_MASK_TEXT | wxTREE_MASK_CHILDREN | wxTREE_MASK_DATA;
|
1998-07-10 19:08:39 -04:00
|
|
|
item.m_text = "Sections";
|
1998-05-20 10:01:55 -04:00
|
|
|
item.m_children = 1;
|
1998-07-10 19:08:39 -04:00
|
|
|
m_rootId = InsertItem( 0, item );
|
1998-07-27 16:50:48 -04:00
|
|
|
|
1998-09-11 05:05:26 -04:00
|
|
|
// SetDropTarget( new wxFileDropTarget() );
|
1998-07-10 19:08:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
void wxDirCtrl::OnExpandItem( const wxTreeEvent &event )
|
|
|
|
{
|
|
|
|
if (event.m_item.m_itemId == m_rootId)
|
|
|
|
{
|
|
|
|
|
|
|
|
wxTreeItem item;
|
|
|
|
item.m_mask = wxTREE_MASK_TEXT | wxTREE_MASK_CHILDREN | wxTREE_MASK_DATA;
|
|
|
|
item.m_children = 1;
|
|
|
|
|
|
|
|
wxDirInfo *info = new wxDirInfo( "/" );
|
|
|
|
item.m_text = info->GetName();
|
|
|
|
item.m_data = (long)info;
|
|
|
|
InsertItem( m_rootId, item );
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-07-10 19:08:39 -04:00
|
|
|
info = new wxDirInfo( "/home" );
|
|
|
|
item.m_text = info->GetName();
|
|
|
|
item.m_data = (long)info;
|
|
|
|
InsertItem( m_rootId, item );
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-07-10 19:08:39 -04:00
|
|
|
info = new wxDirInfo( "/mnt" );
|
|
|
|
item.m_text = info->GetName();
|
|
|
|
item.m_data = (long)info;
|
|
|
|
InsertItem( m_rootId, item );
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-07-10 19:08:39 -04:00
|
|
|
info = new wxDirInfo( "/usr" );
|
|
|
|
item.m_text = info->GetName();
|
|
|
|
item.m_data = (long)info;
|
|
|
|
InsertItem( m_rootId, item );
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-07-10 19:08:39 -04:00
|
|
|
info = new wxDirInfo( "/usr/X11R6" );
|
|
|
|
item.m_text = info->GetName();
|
|
|
|
item.m_data = (long)info;
|
|
|
|
InsertItem( m_rootId, item );
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-07-10 19:08:39 -04:00
|
|
|
info = new wxDirInfo( "/usr/local" );
|
|
|
|
item.m_text = info->GetName();
|
|
|
|
item.m_data = (long)info;
|
|
|
|
InsertItem( m_rootId, item );
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-07-10 19:08:39 -04:00
|
|
|
info = new wxDirInfo( "/var" );
|
|
|
|
item.m_text = info->GetName();
|
|
|
|
item.m_data = (long)info;
|
|
|
|
InsertItem( m_rootId, item );
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-07-10 19:08:39 -04:00
|
|
|
info = new wxDirInfo( "/proc" );
|
|
|
|
item.m_text = info->GetName();
|
|
|
|
item.m_data = (long)info;
|
|
|
|
InsertItem( m_rootId, item );
|
|
|
|
|
|
|
|
return;
|
|
|
|
};
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
wxDirInfo *info = (wxDirInfo *)event.m_item.m_data;
|
|
|
|
if (!info) return;
|
|
|
|
|
|
|
|
wxArrayString slist;
|
|
|
|
wxString search,path,filename;
|
|
|
|
|
|
|
|
search = info->GetPath();
|
|
|
|
search += "/*";
|
|
|
|
|
|
|
|
path = wxFindFirstFile( search, wxDIR );
|
|
|
|
while (!path.IsNull())
|
|
|
|
{
|
|
|
|
filename = wxFileNameFromPath( path );
|
|
|
|
if (m_showHidden || (filename[0] != '.'))
|
|
|
|
{
|
|
|
|
if ((filename != ".") &&
|
|
|
|
(filename != "..") &&
|
|
|
|
(path != "/home") &&
|
|
|
|
(path != "/usr/X11R6") &&
|
|
|
|
(path != "/usr/local") &&
|
|
|
|
(path != "/usr") &&
|
|
|
|
(path != "/var") &&
|
|
|
|
(path != "/home") &&
|
|
|
|
(path != "/proc") &&
|
|
|
|
(path != "/mnt")
|
|
|
|
)
|
1998-07-27 16:50:48 -04:00
|
|
|
|
|
|
|
slist.Add( path ); // ref counting in action !
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
path = wxFindNextFile();
|
|
|
|
};
|
|
|
|
|
1998-07-10 19:08:39 -04:00
|
|
|
for (uint i = 0; i < slist.Count(); i++)
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
|
|
|
search = slist[i];
|
|
|
|
search += "/*";
|
|
|
|
path = wxFindFirstFile( search, wxDIR );
|
|
|
|
|
|
|
|
wxDirInfo *child = new wxDirInfo( slist[i] );
|
|
|
|
wxTreeItem item;
|
|
|
|
item.m_mask = wxTREE_MASK_TEXT | wxTREE_MASK_CHILDREN | wxTREE_MASK_DATA;
|
|
|
|
item.m_text = child->GetName();
|
|
|
|
item.m_children = 0;
|
|
|
|
if (!path.IsNull()) item.m_children = 1;
|
|
|
|
item.m_data = (long)child;
|
|
|
|
InsertItem( event.m_item.m_itemId, item );
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
1998-07-10 19:08:39 -04:00
|
|
|
void wxDirCtrl::OnCollapseItem( const wxTreeEvent &event )
|
|
|
|
{
|
|
|
|
DeleteChildren( event.m_item.m_itemId );
|
|
|
|
};
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
void wxDirCtrl::OnDeleteItem( const wxTreeEvent &event )
|
|
|
|
{
|
|
|
|
wxDirInfo *info = (wxDirInfo *)event.m_item.m_data;
|
|
|
|
if (info) delete info;
|
|
|
|
};
|