add:添加布局保存恢复。

This commit is contained in:
taynpg 2025-05-09 22:31:51 +08:00
parent 57f10b86af
commit c5fe1e349f
14 changed files with 190 additions and 6 deletions

View File

@ -29,5 +29,5 @@ ControlManager.cxx
) )
add_executable(RelayFile ${MSOURCES}) 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) set_target_properties(RelayFile PROPERTIES WIN32_EXECUTABLE TRUE)

View File

@ -9,4 +9,6 @@ void ControlManager::Init()
{ {
header_ = new HeaderControl(parent_); header_ = new HeaderControl(parent_);
local_ = new LocalControl(parent_); local_ = new LocalControl(parent_);
remote_ = new RemoteControl(parent_);
task_ = new TaskControl(parent_);
} }

View File

@ -3,6 +3,8 @@
#include "HeaderControl.h" #include "HeaderControl.h"
#include "LocalControl.h" #include "LocalControl.h"
#include "RemoteControl.h"
#include "TaskControl.h"
#include <memory> #include <memory>
class ControlManager class ControlManager
@ -20,6 +22,8 @@ private:
public: public:
HeaderControl* header_; HeaderControl* header_;
LocalControl* local_; LocalControl* local_;
RemoteControl* remote_;
TaskControl* task_;
}; };
#endif // CONTROL_MANAGER_H #endif // CONTROL_MANAGER_H

View File

@ -1,6 +1,8 @@
#ifndef INTERFACEDEFINE_HPP #ifndef INTERFACEDEFINE_HPP
#define INTERFACEDEFINE_HPP #define INTERFACEDEFINE_HPP
#include <wx/wx.h>
#define gBorder (5) #define gBorder (5)
#endif // INTERFACEDEFINE_HPP #endif // INTERFACEDEFINE_HPP

View File

@ -2,8 +2,18 @@
LocalControl::LocalControl(wxWindow* parent) : wxPanel(parent) LocalControl::LocalControl(wxWindow* parent) : wxPanel(parent)
{ {
Init();
} }
LocalControl::~LocalControl() LocalControl::~LocalControl()
{ {
} }
void LocalControl::Init()
{
auto* topSizer = new wxBoxSizer(wxVERTICAL);
dirCtrl_ = new wxGenericDirCtrl(this, wxID_ANY);
topSizer->Add(dirCtrl_, 1, wxEXPAND);
SetSizer(topSizer);
Layout();
}

View File

@ -1,13 +1,20 @@
#ifndef LOCALCONTROL_H #ifndef LOCALCONTROL_H
#define LOCALCONTROL_H #define LOCALCONTROL_H
#include <wx/wx.h> #include "InterfaceDefine.hpp"
#include <wx/dirctrl.h>
class LocalControl : public wxPanel class LocalControl : public wxPanel
{ {
public: public:
LocalControl(wxWindow* parent); LocalControl(wxWindow* parent);
~LocalControl() override; ~LocalControl() override;
private:
void Init();
public:
wxGenericDirCtrl* dirCtrl_;
}; };
#endif // LOCALCONTROL_H #endif // LOCALCONTROL_H

View File

@ -2,8 +2,35 @@
RemoteControl::RemoteControl(wxWindow* parent) : wxPanel(parent) RemoteControl::RemoteControl(wxWindow* parent) : wxPanel(parent)
{ {
Init();
SetGrid();
} }
RemoteControl::~RemoteControl() 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);
}

View File

@ -1,13 +1,21 @@
#ifndef REMOTECONTROL_H #ifndef REMOTECONTROL_H
#define REMOTECONTROL_H #define REMOTECONTROL_H
#include <wx/wx.h> #include "InterfaceDefine.hpp"
#include <wx/grid.h>
class RemoteControl : public wxPanel class RemoteControl : public wxPanel
{ {
public: public:
RemoteControl(wxWindow* parent); RemoteControl(wxWindow* parent);
~RemoteControl() override; ~RemoteControl() override;
private:
void Init();
void SetGrid();
public:
wxGrid* grid_;
}; };
#endif // REMOTECONTROL_H #endif // REMOTECONTROL_H

View File

@ -2,8 +2,29 @@
TaskControl::TaskControl(wxWindow* parent) : wxPanel(parent) TaskControl::TaskControl(wxWindow* parent) : wxPanel(parent)
{ {
Init();
SetGrid();
} }
TaskControl::~TaskControl() 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"));
}

View File

@ -1,13 +1,21 @@
#ifndef TASKCONTROL_H #ifndef TASKCONTROL_H
#define TASKCONTROL_H #define TASKCONTROL_H
#include <wx/wx.h> #include "InterfaceDefine.hpp"
#include <wx/grid.h>
class TaskControl : public wxPanel class TaskControl : public wxPanel
{ {
public: public:
TaskControl(wxWindow* parent); TaskControl(wxWindow* parent);
~TaskControl() override; ~TaskControl() override;
private:
void Init();
void SetGrid();
public:
wxGrid* grid_;
}; };
#endif // TASKCONTROL_H #endif // TASKCONTROL_H

View File

@ -1,10 +1,17 @@
#include "UserInterface.h" #include "UserInterface.h"
#include <Util.h>
#include <filesystem>
#include <wx/fileconf.h>
namespace fs = std::filesystem;
UserInterface::UserInterface(const wxString& title) : wxFrame(nullptr, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600)) UserInterface::UserInterface(const wxString& title) : wxFrame(nullptr, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600))
{ {
mgr_.SetManagedWindow(this); mgr_.SetManagedWindow(this);
InitMenu();
InitUI(); InitUI();
InitData(); InitData();
TryRestoreLayout();
} }
UserInterface::~UserInterface() UserInterface::~UserInterface()
@ -16,15 +23,58 @@ void UserInterface::InitUI()
{ {
// Add Panel // Add Panel
controlMgr_ = std::make_shared<ControlManager>(this); controlMgr_ = std::make_shared<ControlManager>(this);
mgr_.AddPane(controlMgr_->header_, mgr_.AddPane(controlMgr_->header_,
wxAuiPaneInfo().Name("header").Caption(_("header")).CloseButton(false).Floatable(false).MinSize(-1, 40)); 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_->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 // update
mgr_.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() 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;
} }

View File

@ -7,6 +7,10 @@
#include "ControlManager.h" #include "ControlManager.h"
enum MenuID {
ID_SaveLayout = 1000,
};
class UserInterface final : public wxFrame class UserInterface final : public wxFrame
{ {
public: public:
@ -15,10 +19,20 @@ public:
private: private:
void InitUI(); void InitUI();
void InitMenu();
void InitData(); void InitData();
private:
void TryRestoreLayout();
private:
void OnSaveLayout(wxCommandEvent& event);
private: private:
wxAuiManager mgr_; wxAuiManager mgr_;
wxMenuBar* menuBar_;
wxString configDir_;
wxString configPath_;
std::shared_ptr<ControlManager> controlMgr_; std::shared_ptr<ControlManager> controlMgr_;
}; };

View File

@ -1,5 +1,9 @@
#include "Util.h" #include "Util.h"
#include <algorithm> #include <algorithm>
#include <filesystem>
#include <wx/stdpaths.h>
namespace fs = std::filesystem;
TranUtil::TranUtil() TranUtil::TranUtil()
{ {
@ -44,4 +48,23 @@ void MutBuffer::Clear()
const char* MutBuffer::GetData() const const char* MutBuffer::GetData() const
{ {
return buffer_.data(); return buffer_.data();
} }
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);
}

View File

@ -3,6 +3,7 @@
#include <mutex> #include <mutex>
#include <vector> #include <vector>
#include <wx/wx.h>
constexpr int MAX_BUFFER_SIZE = 1024 * 1024 * 10; constexpr int MAX_BUFFER_SIZE = 1024 * 1024 * 10;
@ -29,4 +30,11 @@ private:
std::vector<char> buffer_; std::vector<char> buffer_;
}; };
class wxUtil
{
public:
static wxString GetConfigDir();
static bool CreateConfigDir(const wxString& dir, const wxString& name, wxString& fullPath);
};
#endif // REMOTE_TRAN_UTIL #endif // REMOTE_TRAN_UTIL