diff --git a/Information/InfoDirFile.hpp b/Information/InfoDirFile.hpp index 35471f3..ca2dd0c 100644 --- a/Information/InfoDirFile.hpp +++ b/Information/InfoDirFile.hpp @@ -31,7 +31,7 @@ struct DirFileInfo { } else if (size >= KB) { return wxString::Format("%.2f KB", static_cast(size) / KB); } else { - return wxString::Format("%llu B", size); + return wxT(""); } } diff --git a/UserInterface/RemoteControl.cxx b/UserInterface/RemoteControl.cxx index 4df05d4..cbed5c2 100644 --- a/UserInterface/RemoteControl.cxx +++ b/UserInterface/RemoteControl.cxx @@ -2,6 +2,27 @@ #include "LogControl.h" #include #include +#include + +class ButtonCellRenderer : public wxGridCellRenderer +{ +public: + void Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected) override + { + wxRendererNative::Get().DrawPushButton(&grid, dc, rect, wxCONTROL_PRESSED); + dc.DrawText(grid.GetCellValue(row, col), rect.x + 5, rect.y + (rect.height - dc.GetCharHeight()) / 2); + } + + wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col) override + { + return wxSize(80, 25); // 按钮默认大小 + } + + wxGridCellRenderer* Clone() const override + { + return new ButtonCellRenderer; + } +}; RemoteControl::RemoteControl(wxWindow* parent, std::shared_ptr& clientCore) : wxPanel(parent), clientCore_(clientCore) { @@ -17,6 +38,7 @@ RemoteControl::~RemoteControl() void RemoteControl::Init() { grid_ = new wxGrid(this, wxID_ANY); + grid_->EnableEditing(false); auto* topSizer = new wxBoxSizer(wxVERTICAL); auto* dirSizer = new wxBoxSizer(wxHORIZONTAL); @@ -47,6 +69,11 @@ void RemoteControl::Init() topSizer->Add(bottomSizer, 1, wxEXPAND | wxCENTER); SetSizer(topSizer); Layout(); + + idDown_ = wxNewId(); + + menuOperateFile_ = new wxMenu(); + menuOperateFile_->Append(idDown_, _("Download")); } void RemoteControl::BindEvent() @@ -62,15 +89,21 @@ void RemoteControl::BindEvent() grid_->DeleteRows(0, grid_->GetNumberRows()); } for (auto& dirInfo : dirInfoVec.vec) { - grid_->AppendRows(); + if (!grid_->AppendRows()) { + continue; + } + auto rowIndex = grid_->GetNumberRows() - 1; auto wxPath = wxString(dirInfo.fullPath.c_str()); - grid_->SetCellValue(grid_->GetNumberRows() - 1, 0, wxPath); - grid_->SetCellValue(grid_->GetNumberRows() - 1, 1, DirFileInfo::GetFileSize(dirInfo.size)); - grid_->SetCellValue(grid_->GetNumberRows() - 1, 2, DirFileInfo::GetFileTypeName(dirInfo.type)); - grid_->SetCellValue(grid_->GetNumberRows() - 1, 3, DirFileInfo::GetStrTime(dirInfo.lastModifyTime)); - grid_->SetCellValue(grid_->GetNumberRows() - 1, 4, wxString::Format("%o", dirInfo.permission)); + grid_->SetCellValue(rowIndex, 0, wxPath); + grid_->SetCellValue(rowIndex, 1, DirFileInfo::GetFileSize(dirInfo.size)); + grid_->SetCellValue(rowIndex, 2, DirFileInfo::GetFileTypeName(dirInfo.type)); + grid_->SetCellValue(rowIndex, 3, DirFileInfo::GetStrTime(dirInfo.lastModifyTime)); + grid_->SetCellValue(rowIndex, 4, wxString::Format("%o", dirInfo.permission)); + + grid_->DisableRowResize(rowIndex); } }); + grid_->Bind(wxEVT_GRID_LABEL_RIGHT_CLICK, &RemoteControl::OnRightClick, this); } void RemoteControl::AskHome(wxCommandEvent& event) @@ -109,9 +142,26 @@ void RemoteControl::GetDirContent(wxCommandEvent& event) } } +void RemoteControl::OnRightClick(wxGridEvent& event) +{ + if (event.GetRow() < 0 || event.GetCol() != -1) { + return; + } + wxArrayInt selectedRows = grid_->GetSelectedRows(); + if (selectedRows.GetCount() < 1) { + return; + } + grid_->PopupMenu(menuOperateFile_, event.GetPosition()); +} + void RemoteControl::SetGrid() { - grid_->CreateGrid(10, 5); + grid_->CreateGrid(10, 6); + + for (int i = 0; i < 10; ++i) { + grid_->DisableRowResize(i); + } + grid_->SetColLabelValue(0, _("FullPath")); grid_->SetColLabelValue(1, _("FileSize")); grid_->SetColLabelValue(2, _("FileType")); @@ -123,6 +173,9 @@ void RemoteControl::SetGrid() grid_->SetColSize(2, 100); grid_->SetColSize(3, 150); grid_->SetColSize(4, 100); + + grid_->SetCellRenderer(0, 5, new ButtonCellRenderer()); + grid_->SetCellValue(0, 5, _("Download")); } void RemoteControl::setRemoteID(const wxString& id) diff --git a/UserInterface/RemoteControl.h b/UserInterface/RemoteControl.h index 7441c6e..26d8a1c 100644 --- a/UserInterface/RemoteControl.h +++ b/UserInterface/RemoteControl.h @@ -27,6 +27,7 @@ private: private: void AskHome(wxCommandEvent& event); void GetDirContent(wxCommandEvent& event); + void OnRightClick(wxGridEvent& event); public: wxGrid* grid_; @@ -37,6 +38,11 @@ public: wxButton* btnUpLevel_; wxButton* btnRefresh_; + wxMenu* menuOperateFile_; + +private: + wxWindowID idDown_; + private: LogControl* logControl_; std::shared_ptr clientCore_; diff --git a/UserInterface/TaskControl.cxx b/UserInterface/TaskControl.cxx index e0d3381..22452f4 100644 --- a/UserInterface/TaskControl.cxx +++ b/UserInterface/TaskControl.cxx @@ -22,6 +22,11 @@ void TaskControl::Init() void TaskControl::SetGrid() { grid_->CreateGrid(10, 5); + + for (int i = 0; i < 10; ++i) { + grid_->DisableRowResize(i); + } + grid_->SetColLabelValue(0, _("id")); grid_->SetColLabelValue(1, _("LocalPurpose")); grid_->SetColLabelValue(2, _("LocalType"));