From 99553e75b23814404c12c4d91fabfa3acfabe1b0 Mon Sep 17 00:00:00 2001 From: taynpg Date: Sat, 5 Apr 2025 21:58:23 +0800 Subject: [PATCH] pause --- gui/design/basepanel.cxx | 1 + gui/modeDirCtrl.cxx | 110 ++++++++++++++++++++++++++++++++++++--- gui/modeDirCtrl.h | 30 +++++++++-- 3 files changed, 130 insertions(+), 11 deletions(-) diff --git a/gui/design/basepanel.cxx b/gui/design/basepanel.cxx index 03403f9..a8e4729 100644 --- a/gui/design/basepanel.cxx +++ b/gui/design/basepanel.cxx @@ -14,6 +14,7 @@ void CBasePanel::Init() btnConnect_ = new wxButton(this, wxID_ANY, _("Connect")); btnDisconnect_ = new wxButton(this, wxID_ANY, _("DisConnect")); dirctrl_ = new CModeDirCtrl(this); + dirctrl_->SetRootPath("transm://op"); rbtLocal_ = new wxRadioButton(this, wxID_ANY, _("Local")); rbtRemote_ = new wxRadioButton(this, wxID_ANY, _("Remote")); lbState_ = new wxStaticText(this, wxID_ANY, _("State")); diff --git a/gui/modeDirCtrl.cxx b/gui/modeDirCtrl.cxx index 00b595f..2d5021d 100644 --- a/gui/modeDirCtrl.cxx +++ b/gui/modeDirCtrl.cxx @@ -1,16 +1,112 @@ #include "modeDirCtrl.h" +#include -CModeDirCtrl::CModeDirCtrl(wxWindow* parent, wxWindowID id) : wxGenericDirCtrl(parent, id) +wxString kTransmScheme1 = "transm:/"; +wxString kTransmScheme2 = "transm://"; + +CModeDirCtrl::CModeDirCtrl(wxWindow* parent, wxWindowID id) : wxTreeCtrl(parent, id), imageList_(new wxImageList(16, 16, true, 2)) { - wxFileSystem::AddHandler(new CTransmHandler()); - wxFileSystem::AddHandler(new wxLocalFSHandler()); - wxFileSystem fs; - wxFSFile* f = fs.OpenFile("transm://D:/test.txt"); - if (f == nullptr) { - wxLogError("Cannot open file"); + if (!wxFileSystem::HasHandlerForPath(kTransmScheme2)) { + wxFileSystem::AddHandler(new CTransmHandler()); } + if (!wxFileSystem::HasHandlerForPath("file://")) { + wxFileSystem::AddHandler(new wxLocalFSHandler()); + } + + 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); } CModeDirCtrl::~CModeDirCtrl() { } + +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) != "") { + 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(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(); +} diff --git a/gui/modeDirCtrl.h b/gui/modeDirCtrl.h index b617716..aa13f7d 100644 --- a/gui/modeDirCtrl.h +++ b/gui/modeDirCtrl.h @@ -2,17 +2,39 @@ #define MODEDIRCTRL_H #include "transmhandler.h" -#include +#include #include -class CModeDirCtrl : public wxGenericDirCtrl +class CModeDirCtrl : public wxTreeCtrl { public: CModeDirCtrl(wxWindow* parent, wxWindowID id = wxID_ANY); - ~CModeDirCtrl(); + ~CModeDirCtrl() override; + +public: + bool SetRootPath(const wxString& path); + void RefreshCurrent(); protected: - // void OnExpandItem(wxTreeEvent& event) override; + class TreeItemData : public wxTreeItemData + { + public: + explicit TreeItemData(const wxString& path) : path_(path) + { + } + wxString path_; + }; + + void BuildTree(); + void AddChildren(wxTreeItemId parent); + wxString GetFullPath(wxTreeItemId item) const; + + void OnItemActivated(wxTreeEvent& event); + void OnItemExpanding(wxTreeEvent& event); + +private: + wxString rootPath_{}; + wxImageList* imageList_{}; }; #endif // MODEDIRCTRL_H \ No newline at end of file