2015-07-07 10:01:17 -04:00
|
|
|
#include "src/widgets/FilePane.h"
|
2015-06-05 16:50:52 -04:00
|
|
|
|
2015-07-14 10:40:53 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
Icon_File,
|
|
|
|
Icon_FolderClosed,
|
|
|
|
Icon_FolderOpened
|
|
|
|
};
|
|
|
|
|
2015-06-05 16:50:52 -04:00
|
|
|
FilePane::FilePane(
|
|
|
|
wxWindow* parent,
|
2015-07-07 10:01:17 -04:00
|
|
|
wxWindowID id,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
long style,
|
|
|
|
const wxString &name
|
|
|
|
) : wxTreeListCtrl(parent, id, pos, size, style, name)
|
2015-06-05 16:50:52 -04:00
|
|
|
{
|
2015-07-07 10:01:17 -04:00
|
|
|
this->dir = new wxDir();
|
|
|
|
this->InitImageList();
|
|
|
|
this->SetImageList(this->img_list);
|
|
|
|
|
2015-07-14 10:40:53 -04:00
|
|
|
const wxString defaultPath = wxString(".");
|
|
|
|
wxTreeListItem root = this->GetRootItem();
|
|
|
|
this->CreateTree(defaultPath, root);
|
2015-06-05 16:50:52 -04:00
|
|
|
|
2015-07-07 10:01:17 -04:00
|
|
|
this->AppendColumn("",
|
|
|
|
wxCOL_WIDTH_AUTOSIZE,
|
|
|
|
wxALIGN_LEFT,
|
|
|
|
wxCOL_RESIZABLE | wxCOL_SORTABLE);
|
2015-06-18 13:34:54 -04:00
|
|
|
|
2015-07-14 10:40:53 -04:00
|
|
|
|
2015-06-05 16:50:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
FilePane::~FilePane()
|
|
|
|
{
|
2015-07-07 10:01:17 -04:00
|
|
|
|
2015-06-05 16:50:52 -04:00
|
|
|
}
|
|
|
|
|
2015-07-14 10:40:53 -04:00
|
|
|
void FilePane::CreateTree(const wxString &path, wxTreeListItem &root)
|
|
|
|
{
|
|
|
|
wxString *filename = new wxString("");
|
|
|
|
this->dir->Open(path);
|
|
|
|
|
|
|
|
this->dir->GetFirst(filename, wxEmptyString, wxDIR_DEFAULT | wxDIR_NO_FOLLOW);
|
|
|
|
|
|
|
|
this->AppendItem(root, *filename, Icon_FolderClosed, Icon_FolderOpened);
|
|
|
|
|
|
|
|
while (this->dir->GetNext(filename))
|
|
|
|
{
|
|
|
|
this->AppendItem(root, *filename, Icon_FolderClosed, Icon_FolderOpened);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 10:01:17 -04:00
|
|
|
void FilePane::InitImageList()
|
2015-06-05 16:50:52 -04:00
|
|
|
{
|
2015-07-07 10:01:17 -04:00
|
|
|
wxSize iconSize = wxArtProvider::GetSizeHint(wxART_LIST);
|
2015-06-05 16:50:52 -04:00
|
|
|
|
2015-07-07 10:01:17 -04:00
|
|
|
if (iconSize == wxDefaultSize)
|
|
|
|
{
|
|
|
|
iconSize = wxSize(16, 16);
|
|
|
|
}
|
2015-06-05 16:50:52 -04:00
|
|
|
|
2015-07-07 10:01:17 -04:00
|
|
|
this->img_list = new wxImageList(iconSize.x, iconSize.y);
|
|
|
|
|
|
|
|
static const char* icons[] =
|
|
|
|
{
|
|
|
|
wxART_NORMAL_FILE,
|
|
|
|
wxART_FOLDER,
|
|
|
|
wxART_FOLDER_OPEN
|
|
|
|
};
|
|
|
|
|
|
|
|
for (unsigned n = 0; n < WXSIZEOF(icons); n++)
|
|
|
|
{
|
|
|
|
this->img_list->Add(
|
|
|
|
wxArtProvider::GetIcon(icons[n], wxART_LIST, iconSize)
|
|
|
|
);
|
|
|
|
}
|
2015-06-05 16:50:52 -04:00
|
|
|
}
|