diff --git a/UserInterface/CMakeLists.txt b/UserInterface/CMakeLists.txt index 3cf1be1..b2715e6 100644 --- a/UserInterface/CMakeLists.txt +++ b/UserInterface/CMakeLists.txt @@ -29,5 +29,5 @@ ControlManager.cxx ) add_executable(RelayFile ${MSOURCES}) -target_link_libraries(RelayFile PRIVATE wx::base wx::core wx::aui) +target_link_libraries(RelayFile PRIVATE wx::base wx::core wx::aui Util) set_target_properties(RelayFile PROPERTIES WIN32_EXECUTABLE TRUE) \ No newline at end of file diff --git a/UserInterface/ControlManager.cxx b/UserInterface/ControlManager.cxx index 98f64b9..875f2db 100644 --- a/UserInterface/ControlManager.cxx +++ b/UserInterface/ControlManager.cxx @@ -9,4 +9,6 @@ void ControlManager::Init() { header_ = new HeaderControl(parent_); local_ = new LocalControl(parent_); + remote_ = new RemoteControl(parent_); + task_ = new TaskControl(parent_); } \ No newline at end of file diff --git a/UserInterface/ControlManager.h b/UserInterface/ControlManager.h index ca76f12..ac2cdf3 100644 --- a/UserInterface/ControlManager.h +++ b/UserInterface/ControlManager.h @@ -3,6 +3,8 @@ #include "HeaderControl.h" #include "LocalControl.h" +#include "RemoteControl.h" +#include "TaskControl.h" #include class ControlManager @@ -20,6 +22,8 @@ private: public: HeaderControl* header_; LocalControl* local_; + RemoteControl* remote_; + TaskControl* task_; }; #endif // CONTROL_MANAGER_H \ No newline at end of file diff --git a/UserInterface/InterfaceDefine.hpp b/UserInterface/InterfaceDefine.hpp index a646ac8..d18ef67 100644 --- a/UserInterface/InterfaceDefine.hpp +++ b/UserInterface/InterfaceDefine.hpp @@ -1,6 +1,8 @@ #ifndef INTERFACEDEFINE_HPP #define INTERFACEDEFINE_HPP +#include + #define gBorder (5) #endif // INTERFACEDEFINE_HPP \ No newline at end of file diff --git a/UserInterface/LocalControl.cxx b/UserInterface/LocalControl.cxx index 715e494..39b9bde 100644 --- a/UserInterface/LocalControl.cxx +++ b/UserInterface/LocalControl.cxx @@ -2,8 +2,18 @@ LocalControl::LocalControl(wxWindow* parent) : wxPanel(parent) { + Init(); } LocalControl::~LocalControl() { } + +void LocalControl::Init() +{ + auto* topSizer = new wxBoxSizer(wxVERTICAL); + dirCtrl_ = new wxGenericDirCtrl(this, wxID_ANY); + topSizer->Add(dirCtrl_, 1, wxEXPAND); + SetSizer(topSizer); + Layout(); +} diff --git a/UserInterface/LocalControl.h b/UserInterface/LocalControl.h index 093adff..10eaaa1 100644 --- a/UserInterface/LocalControl.h +++ b/UserInterface/LocalControl.h @@ -1,13 +1,20 @@ #ifndef LOCALCONTROL_H #define LOCALCONTROL_H -#include +#include "InterfaceDefine.hpp" +#include class LocalControl : public wxPanel { public: LocalControl(wxWindow* parent); ~LocalControl() override; + +private: + void Init(); + +public: + wxGenericDirCtrl* dirCtrl_; }; #endif // LOCALCONTROL_H \ No newline at end of file diff --git a/UserInterface/RemoteControl.cxx b/UserInterface/RemoteControl.cxx index f9dc113..a3f8bc3 100644 --- a/UserInterface/RemoteControl.cxx +++ b/UserInterface/RemoteControl.cxx @@ -2,8 +2,35 @@ RemoteControl::RemoteControl(wxWindow* parent) : wxPanel(parent) { + Init(); + SetGrid(); } RemoteControl::~RemoteControl() { } + +void RemoteControl::Init() +{ + grid_ = new wxGrid(this, wxID_ANY); + auto* topSizer = new wxBoxSizer(wxVERTICAL); + topSizer->Add(grid_, 1, wxEXPAND); + SetSizer(topSizer); + Layout(); +} + +void RemoteControl::SetGrid() +{ + grid_->CreateGrid(10, 5); + grid_->SetColLabelValue(0, _("FullPath")); + grid_->SetColLabelValue(1, _("FileSize")); + grid_->SetColLabelValue(2, _("FileType")); + grid_->SetColLabelValue(3, _("LastModified")); + grid_->SetColLabelValue(4, _("Permissions")); + + grid_->SetColSize(0, 200); + grid_->SetColSize(1, 100); + grid_->SetColSize(2, 100); + grid_->SetColSize(3, 150); + grid_->SetColSize(4, 100); +} diff --git a/UserInterface/RemoteControl.h b/UserInterface/RemoteControl.h index 352a0a9..17542b1 100644 --- a/UserInterface/RemoteControl.h +++ b/UserInterface/RemoteControl.h @@ -1,13 +1,21 @@ #ifndef REMOTECONTROL_H #define REMOTECONTROL_H -#include +#include "InterfaceDefine.hpp" +#include class RemoteControl : public wxPanel { public: RemoteControl(wxWindow* parent); ~RemoteControl() override; + +private: + void Init(); + void SetGrid(); + +public: + wxGrid* grid_; }; #endif // REMOTECONTROL_H \ No newline at end of file diff --git a/UserInterface/TaskControl.cxx b/UserInterface/TaskControl.cxx index 5dd47bb..a515e4c 100644 --- a/UserInterface/TaskControl.cxx +++ b/UserInterface/TaskControl.cxx @@ -2,8 +2,29 @@ TaskControl::TaskControl(wxWindow* parent) : wxPanel(parent) { + Init(); + SetGrid(); } TaskControl::~TaskControl() { } + +void TaskControl::Init() +{ + grid_ = new wxGrid(this, wxID_ANY); + auto* topSizer = new wxBoxSizer(wxVERTICAL); + topSizer->Add(grid_, 1, wxEXPAND); + SetSizer(topSizer); + Layout(); +} + +void TaskControl::SetGrid() +{ + grid_->CreateGrid(10, 5); + grid_->SetColLabelValue(0, _("id")); + grid_->SetColLabelValue(1, _("LocalPurpose")); + grid_->SetColLabelValue(2, _("LocalType")); + grid_->SetColLabelValue(3, _("RemtoePurpose")); + grid_->SetColLabelValue(4, _("RemtoeType")); +} \ No newline at end of file diff --git a/UserInterface/TaskControl.h b/UserInterface/TaskControl.h index d10660b..78b2c1e 100644 --- a/UserInterface/TaskControl.h +++ b/UserInterface/TaskControl.h @@ -1,13 +1,21 @@ #ifndef TASKCONTROL_H #define TASKCONTROL_H -#include +#include "InterfaceDefine.hpp" +#include class TaskControl : public wxPanel { public: TaskControl(wxWindow* parent); ~TaskControl() override; + +private: + void Init(); + void SetGrid(); + +public: + wxGrid* grid_; }; #endif // TASKCONTROL_H \ No newline at end of file diff --git a/UserInterface/UserInterface.cxx b/UserInterface/UserInterface.cxx index d5261b4..15897ff 100644 --- a/UserInterface/UserInterface.cxx +++ b/UserInterface/UserInterface.cxx @@ -1,10 +1,17 @@ #include "UserInterface.h" +#include +#include +#include + +namespace fs = std::filesystem; UserInterface::UserInterface(const wxString& title) : wxFrame(nullptr, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600)) { mgr_.SetManagedWindow(this); + InitMenu(); InitUI(); InitData(); + TryRestoreLayout(); } UserInterface::~UserInterface() @@ -16,15 +23,58 @@ void UserInterface::InitUI() { // Add Panel controlMgr_ = std::make_shared(this); - mgr_.AddPane(controlMgr_->header_, wxAuiPaneInfo().Name("header").Caption(_("header")).CloseButton(false).Floatable(false).MinSize(-1, 40)); mgr_.AddPane(controlMgr_->local_, wxAuiPaneInfo().Name("local").Caption(_("local")).CloseButton(false).BestSize(300, 400)); + mgr_.AddPane(controlMgr_->remote_, wxAuiPaneInfo().Name("remote").Caption(_("remote")).CloseButton(false).BestSize(300, 400)); + mgr_.AddPane(controlMgr_->task_, + wxAuiPaneInfo().Name("task").Caption(_("task")).CloseButton(false).BestSize(300, 400).CenterPane()); // update mgr_.Update(); } +void UserInterface::InitMenu() +{ + menuBar_ = new wxMenuBar(); + wxMenu* auimenu = new wxMenu(); + auimenu->Append(ID_SaveLayout, "&SaveLayou\tCtrl-S", _("Save Layout")); + menuBar_->Append(auimenu, "&Aui"); + SetMenuBar(menuBar_); + + Bind(wxEVT_MENU, &UserInterface::OnSaveLayout, this, ID_SaveLayout); +} + void UserInterface::InitData() { + auto configDir = wxUtil::GetConfigDir(); + wxUtil::CreateConfigDir(configDir, wxT("RelayFile"), configDir_); + configPath_ = configDir + wxT("/RelayFile.ini"); +} + +void UserInterface::TryRestoreLayout() +{ + fs::path path(configPath_.ToStdString()); + if (!fs::exists(path)) { + return; + } + auto* config = new wxFileConfig(wxEmptyString, wxEmptyString, configPath_); + wxString perspective = config->Read("perspective"); + if (!perspective.IsEmpty()) { + mgr_.LoadPerspective(perspective); + } + delete config; +} + +void UserInterface::OnSaveLayout(wxCommandEvent& event) +{ + auto perspective = mgr_.SavePerspective(); + auto* config = new wxFileConfig(wxEmptyString, wxEmptyString, configPath_); + if (config->Write("perspective", perspective)) { + config->Flush(); + wxMessageBox(_("Save Layout Success"), _("Save Layout"), wxOK | wxICON_INFORMATION); + } else { + wxMessageBox(_("Save Layout Failed"), _("Save Layout"), wxOK | wxICON_ERROR); + } + delete config; } diff --git a/UserInterface/UserInterface.h b/UserInterface/UserInterface.h index 157d6e0..e9442f5 100644 --- a/UserInterface/UserInterface.h +++ b/UserInterface/UserInterface.h @@ -7,6 +7,10 @@ #include "ControlManager.h" +enum MenuID { + ID_SaveLayout = 1000, +}; + class UserInterface final : public wxFrame { public: @@ -15,10 +19,20 @@ public: private: void InitUI(); + void InitMenu(); void InitData(); +private: + void TryRestoreLayout(); + +private: + void OnSaveLayout(wxCommandEvent& event); + private: wxAuiManager mgr_; + wxMenuBar* menuBar_; + wxString configDir_; + wxString configPath_; std::shared_ptr controlMgr_; }; diff --git a/Util/Util.cxx b/Util/Util.cxx index ad48932..8c7ac3a 100644 --- a/Util/Util.cxx +++ b/Util/Util.cxx @@ -1,5 +1,9 @@ #include "Util.h" #include +#include +#include + +namespace fs = std::filesystem; TranUtil::TranUtil() { @@ -44,4 +48,23 @@ void MutBuffer::Clear() const char* MutBuffer::GetData() const { return buffer_.data(); -} \ No newline at end of file +} + +wxString wxUtil::GetConfigDir() +{ + auto userDir = wxGetUserHome(); + fs::path path(userDir.ToStdString()); + path.append(".config"); + return wxString::FromUTF8(path.string()); +} + +bool wxUtil::CreateConfigDir(const wxString& dir, const wxString& name, wxString& fullPath) +{ + fs::path path(dir.ToStdString()); + path.append(name.ToStdString()); + if (fs::exists(path)) { + return true; + } + fullPath = wxString::FromUTF8(path.string()); + return fs::create_directories(path); +} diff --git a/Util/Util.h b/Util/Util.h index 2e18c4c..4eb836c 100644 --- a/Util/Util.h +++ b/Util/Util.h @@ -3,6 +3,7 @@ #include #include +#include constexpr int MAX_BUFFER_SIZE = 1024 * 1024 * 10; @@ -29,4 +30,11 @@ private: std::vector buffer_; }; +class wxUtil +{ +public: + static wxString GetConfigDir(); + static bool CreateConfigDir(const wxString& dir, const wxString& name, wxString& fullPath); +}; + #endif // REMOTE_TRAN_UTIL \ No newline at end of file