2025-04-03 17:19:39 +08:00
|
|
|
#include "modeDirCtrl.h"
|
2025-04-05 21:58:23 +08:00
|
|
|
#include <wx/artprov.h>
|
2025-04-03 17:19:39 +08:00
|
|
|
|
2025-04-05 21:58:23 +08:00
|
|
|
wxString kTransmScheme1 = "transm:/";
|
|
|
|
wxString kTransmScheme2 = "transm://";
|
|
|
|
|
|
|
|
CModeDirCtrl::CModeDirCtrl(wxWindow* parent, wxWindowID id) : wxTreeCtrl(parent, id), imageList_(new wxImageList(16, 16, true, 2))
|
2025-04-03 17:19:39 +08:00
|
|
|
{
|
2025-04-05 21:58:23 +08:00
|
|
|
if (!wxFileSystem::HasHandlerForPath(kTransmScheme2)) {
|
|
|
|
wxFileSystem::AddHandler(new CTransmHandler());
|
|
|
|
}
|
|
|
|
if (!wxFileSystem::HasHandlerForPath("file://")) {
|
|
|
|
wxFileSystem::AddHandler(new wxLocalFSHandler());
|
2025-04-04 16:55:15 +08:00
|
|
|
}
|
2025-04-05 21:58:23 +08:00
|
|
|
|
|
|
|
imageList_->Add(wxArtProvider::GetBitmap(wxART_FOLDER, wxART_OTHER, wxSize(16, 16)));
|
|
|
|
imageList_->Add(wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16, 16)));
|
|
|
|
AssignImageList(imageList_);
|
|
|
|
|
|
|
|
Bind(wxEVT_TREE_ITEM_ACTIVATED, &CModeDirCtrl::OnItemActivated, this);
|
2025-04-03 17:19:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CModeDirCtrl::~CModeDirCtrl()
|
|
|
|
{
|
|
|
|
}
|
2025-04-05 21:58:23 +08:00
|
|
|
|
|
|
|
bool CModeDirCtrl::SetRootPath(const wxString& path)
|
|
|
|
{
|
|
|
|
rootPath_ = path;
|
|
|
|
DeleteAllItems();
|
|
|
|
|
|
|
|
wxTreeItemId root = AddRoot(path.AfterLast('/'), -1, -1, new TreeItemData(path));
|
|
|
|
|
|
|
|
SetItemImage(root, 0, wxTreeItemIcon_Normal);
|
|
|
|
|
|
|
|
AddChildren(root);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModeDirCtrl::RefreshCurrent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModeDirCtrl::BuildTree()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModeDirCtrl::AddChildren(wxTreeItemId parent)
|
|
|
|
{
|
|
|
|
if (!parent.IsOk()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString parentPath = GetFullPath(parent);
|
|
|
|
if (parentPath.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFileSystem fs;
|
|
|
|
fs.ChangePathTo(parentPath);
|
|
|
|
|
|
|
|
Freeze();
|
|
|
|
|
|
|
|
wxTreeItemIdValue cookie;
|
|
|
|
wxTreeItemId child = GetFirstChild(parent, cookie);
|
|
|
|
while (child.IsOk()) {
|
|
|
|
if (GetItemText(child) != "<dummy>") {
|
|
|
|
Delete(child);
|
|
|
|
}
|
|
|
|
child = GetNextChild(parent, cookie);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString filename = fs.FindFirst("*", wxDIR | wxFILE);
|
|
|
|
while (!filename.empty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString CModeDirCtrl::GetFullPath(wxTreeItemId item) const
|
|
|
|
{
|
|
|
|
if (!item.IsOk()) {
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
auto* data = static_cast<TreeItemData*>(GetItemData(item));
|
|
|
|
if (data) {
|
|
|
|
return data->path_;
|
|
|
|
}
|
|
|
|
wxString path;
|
|
|
|
wxTreeItemId parent = GetItemParent(item);
|
|
|
|
if (!parent.IsOk()) {
|
|
|
|
return rootPath_;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = GetFullPath(parent) + "/" + GetItemText(item);
|
|
|
|
path.Replace("//", "/");
|
|
|
|
if (path.StartsWith(kTransmScheme1) && !path.StartsWith(kTransmScheme2)) {
|
|
|
|
path.Replace(kTransmScheme1, kTransmScheme2);
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModeDirCtrl::OnItemActivated(wxTreeEvent& event)
|
|
|
|
{
|
|
|
|
auto path = GetFullPath(event.GetItem());
|
|
|
|
if (path.IsEmpty())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModeDirCtrl::OnItemExpanding(wxTreeEvent& event)
|
|
|
|
{
|
|
|
|
auto item = event.GetItem();
|
|
|
|
}
|