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->InitImageList();
|
|
|
|
this->SetImageList(this->img_list);
|
|
|
|
|
2015-10-22 11:06:34 -04:00
|
|
|
wxString defaultPath(".");
|
|
|
|
wxFileName fname(defaultPath);
|
|
|
|
fname.MakeAbsolute(defaultPath);
|
2015-07-14 10:40:53 -04:00
|
|
|
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-10-22 11:06:34 -04:00
|
|
|
{
|
|
|
|
delete this->img_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilePane::BindEvents()
|
|
|
|
{
|
|
|
|
this->Bind(wxEVT_TREELIST_ITEM_EXPANDING, &FilePane::OpenFolder, this, wxID_ANY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilePane::OpenFolder(wxTreeListEvent& event)
|
2015-06-05 16:50:52 -04:00
|
|
|
{
|
2015-07-07 10:01:17 -04:00
|
|
|
|
2015-10-22 11:06:34 -04:00
|
|
|
wxTreeListItem item = event.GetItem();
|
|
|
|
const wxString path = this->GetItemText(item, 0);
|
|
|
|
|
|
|
|
wxLogDebug(path);
|
2015-06-05 16:50:52 -04:00
|
|
|
}
|
|
|
|
|
2015-10-22 11:06:34 -04:00
|
|
|
/**
|
|
|
|
* Iterates through the specified folder and creates the tree view
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @param wxString &path
|
|
|
|
* @param wxTreeListItem &root
|
|
|
|
*/
|
2015-07-14 10:40:53 -04:00
|
|
|
void FilePane::CreateTree(const wxString &path, wxTreeListItem &root)
|
|
|
|
{
|
2015-10-22 11:06:34 -04:00
|
|
|
wxArrayString *files = new wxArrayString();
|
|
|
|
wxDir::GetAllFiles(path, files);
|
2015-07-14 10:40:53 -04:00
|
|
|
|
2015-10-22 11:06:34 -04:00
|
|
|
vector<wxString> examined;
|
|
|
|
vector<wxString>::iterator it;
|
2015-07-14 10:40:53 -04:00
|
|
|
|
2015-10-22 11:06:34 -04:00
|
|
|
for (wxString filename : *files)
|
2015-07-14 10:40:53 -04:00
|
|
|
{
|
2015-10-22 11:06:34 -04:00
|
|
|
wxFileName fname(filename);
|
|
|
|
|
|
|
|
// For loose files, just add directly to the tree
|
|
|
|
if (fname.GetDirCount() == 1)
|
|
|
|
{
|
|
|
|
this->AppendItem(root, fname.GetFullName(), Icon_File, Icon_File);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fname.RemoveDir(0);
|
|
|
|
wxArrayString folders = fname.GetDirs();
|
|
|
|
wxString curr_folder = folders[0];
|
|
|
|
|
|
|
|
it = find(examined.begin(), examined.end(), curr_folder);
|
|
|
|
|
|
|
|
// If the directory already exists, continue;
|
|
|
|
if (it != examined.end()) continue;
|
|
|
|
|
|
|
|
wxTreeListItem current = this->AppendItem(root, curr_folder, Icon_FolderClosed, Icon_FolderOpened);
|
|
|
|
examined.push_back(curr_folder);
|
|
|
|
|
|
|
|
// Recurse to create sub dirs
|
|
|
|
this->CreateTree(fname.GetPath(), current);
|
|
|
|
}
|
2015-07-14 10:40:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 11:06:34 -04:00
|
|
|
/*void FilePane::CreateFolderTree(StringVector dirList, wxTreeListItem &root)
|
|
|
|
{
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the image list object for the file pane widget
|
|
|
|
*/
|
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
|
|
|
}
|